A rhythm game net ranking service built on ATproto.

it wad ipv6, clean up all the debugging code

LemmaEOF 98e0695e d0cc1cf8

+3 -27
+3 -27
game-example/microcosm/MicrocosmLeaderboardView.cs
··· 18 18 19 19 private int processedScores = 0; 20 20 private int scoresToProcess = 0; 21 - private Dictionary<string, JsonElement> scores = new(); 22 - 23 - private HttpRequest testingRequest = null; 24 - private float connectingTime = 0; 21 + private readonly Dictionary<string, JsonElement> scores = []; 25 22 26 23 // Called when the node enters the scene tree for the first time. 27 24 public override void _Ready() { ··· 31 28 // Called every frame. 'delta' is the elapsed time since the previous frame. 32 29 public override void _Process(double delta) { 33 30 if (scoresToProcess > 0 && processedScores >= scoresToProcess) { 34 - GD.Print("Building displays!"); 35 31 BuildDisplays(); 36 32 scoresToProcess = 0; 37 - } 38 - if (testingRequest != null) { 39 - HttpClient.Status status = testingRequest.GetHttpClientStatus(); 40 - if (status == HttpClient.Status.Requesting) { 41 - GD.Print($"Changed to requesting at {DateTime.Now.ToUniversalTime()} after {connectingTime} seconds connecting"); 42 - testingRequest = null; 43 - } else if (status == HttpClient.Status.Connecting) { 44 - connectingTime += (float) delta; 45 - } 46 33 } 47 34 } 48 35 ··· 55 42 HttpResult res = new(await ToSignal(ConstellationRequest, HttpRequest.SignalName.RequestCompleted)); 56 43 JsonDocument doc = JsonDocument.Parse(res.Body); 57 44 scoresToProcess = doc.RootElement.GetProperty("total").GetInt32(); 58 - GD.Print($"Scores to process: {scoresToProcess}"); 45 + GetNode<Label>("Status").Text = "Loading score data..."; 59 46 foreach (JsonElement e in doc.RootElement.GetProperty("records").EnumerateArray()) { 60 47 HttpRequest slingshotRequest = new(); 61 48 slingshotRequest.RequestCompleted += _OnScoreReceived; 62 49 AddChild(slingshotRequest); 63 - if (testingRequest == null) { 64 - testingRequest = slingshotRequest; 65 - } 66 50 //TODO: Tsunagite user profile 67 51 string did = e.GetProperty("did").GetString(); 68 52 string uri = $"at://{did}/dev.tsunagite.score/{e.GetProperty("rkey").GetString().URIEncode()}"; 69 - GetNode<Label>("Status").Text = $"Getting score {e.GetProperty("rkey")}"; 70 - GD.Print($"Before query: {DateTime.Now.ToUniversalTime()}"); 71 53 err = slingshotRequest.Request($"https://slingshot.microcosm.blue/xrpc/com.bad-example.repo.getUriRecord?at_uri={uri}", ["User-Agent: Tsunagite-Client"]); 72 54 if (err != Error.Ok) { 73 55 GD.PrintErr($"Error making Slingshot query: {err}"); ··· 77 59 78 60 private async void BuildDisplays() { 79 61 List<ScoreDisplay> scoreDisplays = []; 62 + GetNode<Label>("Status").Text = "Resolving user data..."; 80 63 foreach (KeyValuePair<string, JsonElement> score in scores) { 81 64 ScoreDisplay disp = SCORE_DISPLAY.Instantiate() as ScoreDisplay; 82 65 JsonElement comps = score.Value.GetProperty("scoreComponents"); ··· 84 67 disp.Points = comps.GetProperty("points").GetProperty("value").GetInt32(); 85 68 disp.Lamp = Enum.Parse<Lamp>(comps.GetProperty("lamp").GetProperty("value").GetString()); 86 69 87 - GetNode<Label>("Status").Text = $"Resolving handle for {score.Key}"; 88 - GD.Print($"Before query: {DateTime.Now.ToUniversalTime()}"); 89 70 HttpRequest slingshotRequest = new(); 90 71 AddChild(slingshotRequest); 91 72 Error err = slingshotRequest.Request($"https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc?identifier={score.Key.URIEncode()}", ["User-Agent: Tsunagite-Client"]); ··· 93 74 GD.PrintErr($"Error while resolving DID doc: {err}"); 94 75 } 95 76 HttpResult didDoc = new(await ToSignal(slingshotRequest, HttpRequest.SignalName.RequestCompleted)); 96 - GD.Print($"After query: {DateTime.Now.ToUniversalTime()}"); 97 - GD.Print($"{didDoc.Status}, {didDoc.Result}, {didDoc.Body}"); 98 77 disp.Player = JsonDocument.Parse(didDoc.Body).RootElement.GetProperty("handle").GetString(); 99 78 scoreDisplays.Add(disp); 100 79 } ··· 108 87 109 88 private void _OnScoreReceived(long result, long responseCode, string[] headers, byte[] body) { 110 89 HttpResult score = new(result, responseCode, headers, body); 111 - GD.Print($"After query: {DateTime.Now.ToUniversalTime()}"); 112 90 if (score.Status == 200) { 113 91 JsonElement response = JsonDocument.Parse(score.Body).RootElement; 114 92 JsonElement scoreElem = response.GetProperty("value"); 115 93 string noUri = response.GetProperty("uri").GetString()["at://".Length..]; 116 94 string did = noUri[0..noUri.IndexOf('/')]; 117 - GD.Print($"{did}"); 118 95 if (scores.TryGetValue(did, out JsonElement value)) { 119 96 float thisPercent = float.Parse(scoreElem.GetProperty("scoreComponents").GetProperty("accuracy").GetProperty("value").GetString()); 120 97 float otherPercent = float.Parse(value.GetProperty("scoreComponents").GetProperty("accuracy").GetProperty("value").GetString()); ··· 125 102 } else { 126 103 GD.PrintErr($"Error {score.Status} while trying to fetch score : {score.Result}"); 127 104 } 128 - GD.Print("Score processed!"); 129 105 processedScores++; 130 106 } 131 107 }