feature/72-channelselection-and-character-creation #82

Merged
rainote merged 35 commits from feature/72-channelselection-and-character-creation into master 2023-11-14 19:47:01 +00:00
2 changed files with 28 additions and 10 deletions
Showing only changes of commit dc7daaef5c - Show all commits

View file

@ -28,6 +28,8 @@ insert_final_newline = true
indent_size = 4
dotnet_sort_system_directives_first = true
MA0004.report = DetectContext # (default) Try to detect the current context and report only if it considers ConfigureAwait is needed
MA0004.report = Always # Always report missing ConfigureAwait whatever the context
# Don't use this. qualifier
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion

View file

@ -44,16 +44,32 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
{
if (this._configuration.GetSection("Testing").GetValue<bool>("CreateAccountOnLogin"))
{
argon2Id.Salt = RandomNumberGenerator.GetBytes(16);
var finalAccount =
await this._wonderkingContext.Accounts.AddAsync(new Account(packet.Username, Array.Empty<byte>(), "",
0, argon2Id.Salt)).ConfigureAwait(true);
await this._wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
argon2Id.AssociatedData = finalAccount.Entity.Id.ToByteArray();
finalAccount.Entity.Password = await argon2Id.GetBytesAsync(16).ConfigureAwait(true);
this._wonderkingContext.Accounts.Update(finalAccount.Entity);
loginResponseReason = LoginResponseReason.Ok;
await this._wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
var transaction =
await _wonderkingContext.Database.BeginTransactionAsync().ConfigureAwait(true);
await using (transaction.ConfigureAwait(true))
{
try
{
argon2Id.Salt = RandomNumberGenerator.GetBytes(16);
var finalAccount =
await this._wonderkingContext.Accounts.AddAsync(new Account(packet.Username,
Array.Empty<byte>(), "",
0, argon2Id.Salt)).ConfigureAwait(true);
await this._wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
argon2Id.AssociatedData = finalAccount.Entity.Id.ToByteArray();
finalAccount.Entity.Password = await argon2Id.GetBytesAsync(16).ConfigureAwait(true);
this._wonderkingContext.Accounts.Update(finalAccount.Entity);
loginResponseReason = LoginResponseReason.Ok;
await this._wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
await transaction.CommitAsync().ConfigureAwait(true);
}
catch (Exception)
{
await transaction.RollbackAsync().ConfigureAwait(true); // Rollback the transaction on error
throw;
}
}
}
else
{