Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix generating new profile every time account starts game #30

Merged
merged 4 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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