From a61863d6ad632ace64f2ae25a2ba4457cfcbbfe2 Mon Sep 17 00:00:00 2001 From: nexus4880 <38168516+nexus4880@users.noreply.github.com> Date: Sat, 7 Sep 2024 09:42:33 -0700 Subject: [PATCH 1/4] Fix generating new profile every time account starts game --- Fuyu.Backend.Core/Services/AccountService.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Fuyu.Backend.Core/Services/AccountService.cs b/Fuyu.Backend.Core/Services/AccountService.cs index b22efd7..a8e3d30 100644 --- a/Fuyu.Backend.Core/Services/AccountService.cs +++ b/Fuyu.Backend.Core/Services/AccountService.cs @@ -138,6 +138,12 @@ public static ERegisterStatus RegisterGame(string sessionId, string game, string { var account = CoreOrm.GetAccount(sessionId); + // TODO: refactor the account to only have one aid per game + if (account.Games.TryGetValue(game, out var aids) && aids.Count > 0) + { + return ERegisterStatus.AlreadyExists; + } + string address; switch (game) From 6b4dcf191ebb5d64c31daa89608535511fb40d58 Mon Sep 17 00:00:00 2001 From: nexus4880 <38168516+nexus4880@users.noreply.github.com> Date: Sat, 7 Sep 2024 10:01:20 -0700 Subject: [PATCH 2/4] Changed Fuyu account to only support 1 aid per game --- Fuyu.Backend.Core/DTO/Accounts/Account.cs | 6 ++-- Fuyu.Backend.Core/Services/AccountService.cs | 37 +++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Fuyu.Backend.Core/DTO/Accounts/Account.cs b/Fuyu.Backend.Core/DTO/Accounts/Account.cs index eb7624c..a05796f 100644 --- a/Fuyu.Backend.Core/DTO/Accounts/Account.cs +++ b/Fuyu.Backend.Core/DTO/Accounts/Account.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Runtime.Serialization; namespace Fuyu.Backend.Core.DTO.Accounts @@ -16,6 +15,9 @@ public class Account public string Password; [DataMember] - public Dictionary> Games; + public int? EftAid; + + [DataMember] + public int? ArenaAid; } } \ No newline at end of file diff --git a/Fuyu.Backend.Core/Services/AccountService.cs b/Fuyu.Backend.Core/Services/AccountService.cs index a8e3d30..775fd48 100644 --- a/Fuyu.Backend.Core/Services/AccountService.cs +++ b/Fuyu.Backend.Core/Services/AccountService.cs @@ -121,11 +121,8 @@ public static ERegisterStatus RegisterAccount(string username, string password) Id = GetNewAccountId(), Username = username.ToLowerInvariant(), Password = password, - Games = new Dictionary>() - { - { "eft", new List() }, - { "arena", new List() }, - } + EftAid = null, + ArenaAid = null }; CoreOrm.SetOrAddAccount(account); @@ -138,21 +135,25 @@ public static ERegisterStatus RegisterGame(string sessionId, string game, string { var account = CoreOrm.GetAccount(sessionId); - // TODO: refactor the account to only have one aid per game - if (account.Games.TryGetValue(game, out var aids) && aids.Count > 0) - { - return ERegisterStatus.AlreadyExists; - } - string address; switch (game) { case "eft": + if (account.EftAid.HasValue) + { + return ERegisterStatus.AlreadyExists; + } + address = "http://localhost:8010"; break; case "arena": + if (account.ArenaAid.HasValue) + { + return ERegisterStatus.AlreadyExists; + } + address = "http://localhost:8020"; break; @@ -176,7 +177,19 @@ public static ERegisterStatus RegisterGame(string sessionId, string game, string var response = Json.Parse(responseJson); // set game account id - account.Games[game].Add(response.AccountId); + switch (game) + { + case "eft": + { + account.EftAid = response.AccountId; + break; + } + case "arena": + { + account.ArenaAid = response.AccountId; + break; + } + } } CoreOrm.SetOrAddAccount(account); From 1ecaa7b33ec1893f914a0ea4bcda9c38081bd93b Mon Sep 17 00:00:00 2001 From: nexus4880 <38168516+nexus4880@users.noreply.github.com> Date: Sat, 7 Sep 2024 10:06:55 -0700 Subject: [PATCH 3/4] Changed Account back to Dictionary in order to leave room for expansion, but keeping the List removed so as to only have 1 account id per game for now --- Fuyu.Backend.Core/DTO/Accounts/Account.cs | 6 ++-- Fuyu.Backend.Core/Services/AccountService.cs | 35 ++++++-------------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/Fuyu.Backend.Core/DTO/Accounts/Account.cs b/Fuyu.Backend.Core/DTO/Accounts/Account.cs index a05796f..519ccc7 100644 --- a/Fuyu.Backend.Core/DTO/Accounts/Account.cs +++ b/Fuyu.Backend.Core/DTO/Accounts/Account.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Runtime.Serialization; namespace Fuyu.Backend.Core.DTO.Accounts @@ -15,9 +16,6 @@ public class Account public string Password; [DataMember] - public int? EftAid; - - [DataMember] - public int? ArenaAid; + public Dictionary Games; } } \ No newline at end of file diff --git a/Fuyu.Backend.Core/Services/AccountService.cs b/Fuyu.Backend.Core/Services/AccountService.cs index 775fd48..88e6665 100644 --- a/Fuyu.Backend.Core/Services/AccountService.cs +++ b/Fuyu.Backend.Core/Services/AccountService.cs @@ -121,8 +121,11 @@ public static ERegisterStatus RegisterAccount(string username, string password) Id = GetNewAccountId(), Username = username.ToLowerInvariant(), Password = password, - EftAid = null, - ArenaAid = null + Games = new Dictionary + { + { "eft", null }, + { "arena", null } + } }; CoreOrm.SetOrAddAccount(account); @@ -134,26 +137,20 @@ public static ERegisterStatus RegisterAccount(string username, string password) public static ERegisterStatus RegisterGame(string sessionId, string game, string edition) { var account = CoreOrm.GetAccount(sessionId); + if (account.Games.TryGetValue(game, out var aid) && aid.HasValue) + { + return ERegisterStatus.AlreadyExists; + } string address; switch (game) { case "eft": - if (account.EftAid.HasValue) - { - return ERegisterStatus.AlreadyExists; - } - address = "http://localhost:8010"; break; case "arena": - if (account.ArenaAid.HasValue) - { - return ERegisterStatus.AlreadyExists; - } - address = "http://localhost:8020"; break; @@ -177,19 +174,7 @@ public static ERegisterStatus RegisterGame(string sessionId, string game, string var response = Json.Parse(responseJson); // set game account id - switch (game) - { - case "eft": - { - account.EftAid = response.AccountId; - break; - } - case "arena": - { - account.ArenaAid = response.AccountId; - break; - } - } + account.Games[game] = response.AccountId; } CoreOrm.SetOrAddAccount(account); From e2493b52c528b0d0ee41ac6248ae65b334770b0a Mon Sep 17 00:00:00 2001 From: nexus4880 <38168516+nexus4880@users.noreply.github.com> Date: Sat, 7 Sep 2024 10:10:19 -0700 Subject: [PATCH 4/4] Updated Fuyu.Tests.Backend.EFT.BackendTest to reflect these changes --- Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs b/Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs index c423011..efbe359 100644 --- a/Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs +++ b/Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs @@ -39,7 +39,7 @@ public static void AssemblyInitialize(TestContext testContext) Fuyu.Backend.Core.Services.AccountService.RegisterAccount("test-username", "test-password"); var coreSessionId = Fuyu.Backend.Core.Services.AccountService.LoginAccount("test-username", "test-password"); Fuyu.Backend.Core.Services.AccountService.RegisterGame(coreSessionId, "eft", "unheard"); - var eftAccountId = CoreOrm.GetAccount(coreSessionId).Games["eft"][0]; + var eftAccountId = CoreOrm.GetAccount(coreSessionId).Games["eft"].Value; var eftSessionId = Fuyu.Backend.EFT.Services.AccountService.LoginAccount(eftAccountId); // create request clients