Skip to content

Commit

Permalink
Merge pull request #30 from nexus4880/main
Browse files Browse the repository at this point in the history
Fix generating new profile every time account starts game
  • Loading branch information
seionmoya authored Sep 7, 2024
2 parents a471b57 + e2493b5 commit cebb378
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Fuyu.Backend.Core/DTO/Accounts/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public class Account
public string Password;

[DataMember]
public Dictionary<string, List<int>> Games;
public Dictionary<string, int?> Games;
}
}
12 changes: 8 additions & 4 deletions Fuyu.Backend.Core/Services/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ public static ERegisterStatus RegisterAccount(string username, string password)
Id = GetNewAccountId(),
Username = username.ToLowerInvariant(),
Password = password,
Games = new Dictionary<string, List<int>>()
Games = new Dictionary<string, int?>
{
{ "eft", new List<int>() },
{ "arena", new List<int>() },
{ "eft", null },
{ "arena", null }
}
};

Expand All @@ -137,6 +137,10 @@ 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;

Expand Down Expand Up @@ -170,7 +174,7 @@ public static ERegisterStatus RegisterGame(string sessionId, string game, string
var response = Json.Parse<FuyuGameRegisterResponse>(responseJson);

// set game account id
account.Games[game].Add(response.AccountId);
account.Games[game] = response.AccountId;
}

CoreOrm.SetOrAddAccount(account);
Expand Down
2 changes: 1 addition & 1 deletion Fuyu.Tests.Backend.EFT/EndToEnd/BackendTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cebb378

Please sign in to comment.