diff --git a/game-example/carpanet/CarpaNetHandler.cs b/game-example/carpanet/CarpaNetHandler.cs index 432f61e..b4ed56f 100644 --- a/game-example/carpanet/CarpaNetHandler.cs +++ b/game-example/carpanet/CarpaNetHandler.cs @@ -28,9 +28,13 @@ public partial class CarpaNetHandler : TsunagiteHandler, IOAuthSessionStore { cfg = new() { ClientId = "https://tsunagite.dev/native-client-metadata.json", RedirectUri = $"http://127.0.0.1:2797/", - Scope = "atproto include:dev.tsunagite.permissions%23hosted?aud=api.tsunagite.dev", - SessionStore = this + Scope = "atproto include:dev.tsunagite.permissions%23hosted?aud=api.tsunagite.dev repo:dev.tsunagite.score?action=create repo:dev.tsunagite.profile?action=create repo:dev.tsunagite.profile?action=update", + SessionStore = this, + JsonOptions = new() { + + } }; + cfg.JsonOptions.TypeInfoResolverChain.Add(SourceGenerationContext.Default); } public override void _Ready() { @@ -38,16 +42,19 @@ public partial class CarpaNetHandler : TsunagiteHandler, IOAuthSessionStore { public override async Task Authorize(string handle) { if (!LoadId() || handle != handleInfo.Handle) { + GD.Print("Resolving handle"); handleInfo = await Handles.Resolve(handle); SaveId(); } using OAuthSession sess = new(cfg); - string authUrl = await sess.AuthorizeAsync(handle); - CallbackServer.Authorize(authUrl); - - string callbackUrl = (await ToSignal(CallbackServer, CallbackServer.SignalName.CallbackRecieved))[0].AsString(); - GD.Print("Callback URL: " + callbackUrl); try { + GD.Print("Authorizing async"); + string authUrl = await sess.AuthorizeAsync(handle); + CallbackServer.Authorize(authUrl); + GD.Print("Awaiting callback"); + string callbackUrl = (await ToSignal(CallbackServer, CallbackServer.SignalName.CallbackRecieved))[0].AsString(); + GD.Print("Callback URL: " + callbackUrl); + client = await sess.CallbackAsync(callbackUrl); EmitSignal(TsunagiteHandler.SignalName.AuthComplete, client.IsAuthenticated); } catch (Exception e) { @@ -188,4 +195,4 @@ public partial class CarpaNetHandler : TsunagiteHandler, IOAuthSessionStore { async Task IOAuthSessionStore.DeleteAsync(string sub, CancellationToken cancellationToken = default) { DirAccess.RemoveAbsolute(SessionPath); } -} \ No newline at end of file +} diff --git a/game-example/carpanet/RecordCreation.cs b/game-example/carpanet/RecordCreation.cs index 98452f5..e9ab2c6 100644 --- a/game-example/carpanet/RecordCreation.cs +++ b/game-example/carpanet/RecordCreation.cs @@ -1,12 +1,11 @@ using System.Text.Json.Nodes; using System.Text.Json.Serialization; -[JsonSerializable(typeof(RecordCreation))] public class RecordCreation { - [JsonPropertyName("repo")] - public string Repo {get; set;} - [JsonPropertyName("collection")] - public string Collection {get; set;} - [JsonPropertyName("record")] - public JsonObject Record {get; set;} -} \ No newline at end of file + [JsonPropertyName("repo")] + public string Repo {get; set;} + [JsonPropertyName("collection")] + public string Collection {get; set;} + [JsonPropertyName("record")] + public JsonObject Record {get; set;} +} diff --git a/game-example/carpanet/RecordCreationResponse.cs b/game-example/carpanet/RecordCreationResponse.cs index c800f46..8fe23e3 100644 --- a/game-example/carpanet/RecordCreationResponse.cs +++ b/game-example/carpanet/RecordCreationResponse.cs @@ -1,9 +1,8 @@ using System.Text.Json.Serialization; -[JsonSerializable(typeof(RecordCreationResponse))] public class RecordCreationResponse { - [JsonPropertyName("uri")] - public string Uri {get; set;} - [JsonPropertyName("cid")] - public string Cid {get; set;} -} \ No newline at end of file + [JsonPropertyName("uri")] + public string Uri {get; set;} + [JsonPropertyName("cid")] + public string Cid {get; set;} +} diff --git a/game-example/carpanet/SourceGenerationContext.cs b/game-example/carpanet/SourceGenerationContext.cs new file mode 100644 index 0000000..cdbb2d2 --- /dev/null +++ b/game-example/carpanet/SourceGenerationContext.cs @@ -0,0 +1,6 @@ +using System.Text.Json.Serialization; + +[JsonSourceGenerationOptions(WriteIndented = true)] +[JsonSerializable(typeof(RecordCreationResponse))] +[JsonSerializable(typeof(RecordCreation))] +internal partial class SourceGenerationContext : JsonSerializerContext {} \ No newline at end of file diff --git a/game-example/carpanet/SourceGenerationContext.cs.uid b/game-example/carpanet/SourceGenerationContext.cs.uid new file mode 100644 index 0000000..08586be --- /dev/null +++ b/game-example/carpanet/SourceGenerationContext.cs.uid @@ -0,0 +1 @@ +uid://w8h8wg7cbpok diff --git a/game-example/hosted/HostedLeaderboardView.cs b/game-example/hosted/HostedLeaderboardView.cs index bc591d3..9ee03f1 100644 --- a/game-example/hosted/HostedLeaderboardView.cs +++ b/game-example/hosted/HostedLeaderboardView.cs @@ -27,14 +27,14 @@ public partial class HostedLeaderboardView : VBoxContainer { JsonElement scores = doc.RootElement.GetProperty("scores"); List scoreDisplays = []; foreach (JsonElement elem in scores.EnumerateArray()) { - JsonElement profile = elem.GetProperty("profile"); + bool hasProfile = elem.TryGetProperty("profile", out JsonElement profile); JsonElement score = elem.GetProperty("score"); ScoreDisplay disp = SCORE_DISPLAY.Instantiate() as ScoreDisplay; JsonElement comps = score.GetProperty("scoreComponents"); disp.Accuracy = float.Parse(comps.GetProperty("accuracy").GetProperty("value").GetString()); disp.Points = comps.GetProperty("points").GetProperty("value").GetInt32(); disp.Lamp = Enum.Parse(comps.GetProperty("lamp").GetProperty("value").GetString()); - disp.Player = profile.GetProperty("displayName").GetString(); + disp.Player = hasProfile? profile.GetProperty("displayName").GetString() : elem.GetProperty("handle").GetString(); scoreDisplays.Add(disp); } GetNode