chore: remove ConfigureAwait
This commit is contained in:
parent
f09ab06066
commit
bccbaa87d9
6 changed files with 35 additions and 38 deletions
|
@ -1,4 +1,4 @@
|
||||||
// // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
// // Copyright (c) 2023 Timothy Schenk.Subject to the GNU AGPL Version 3 License.
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NetCoreServer;
|
using NetCoreServer;
|
||||||
|
@ -26,7 +26,7 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
||||||
var guildNameResponsePacket = new CharacterSelectionSetGuildNamePacket { GuildNames = Array.Empty<string>() };
|
var guildNameResponsePacket = new CharacterSelectionSetGuildNamePacket { GuildNames = Array.Empty<string>() };
|
||||||
|
|
||||||
var account = await _wonderkingContext.Accounts
|
var account = await _wonderkingContext.Accounts
|
||||||
.FirstOrDefaultAsync(a => a.Id == authSession.AccountId).ConfigureAwait(true);
|
.FirstOrDefaultAsync(a => a.Id == authSession.AccountId);
|
||||||
if (account != null && account.Characters.Count > 0)
|
if (account != null && account.Characters.Count > 0)
|
||||||
{
|
{
|
||||||
responsePacket = new ChannelSelectionResponsePacket
|
responsePacket = new ChannelSelectionResponsePacket
|
||||||
|
@ -55,13 +55,13 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
||||||
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
||||||
.Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).AsEnumerable())
|
.Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).AsEnumerable())
|
||||||
})
|
})
|
||||||
.ToArrayAsync().ConfigureAwait(true)
|
.ToArrayAsync()
|
||||||
};
|
};
|
||||||
|
|
||||||
guildNameResponsePacket.GuildNames = await _wonderkingContext.Characters
|
guildNameResponsePacket.GuildNames = await _wonderkingContext.Characters
|
||||||
.Where(c => c.Account.Id == authSession.AccountId)
|
.Where(c => c.Account.Id == authSession.AccountId)
|
||||||
.Where(c => c.Guild != null)
|
.Where(c => c.Guild != null)
|
||||||
.Select(character => character.Guild.Name).ToArrayAsync().ConfigureAwait(true);
|
.Select(character => character.Guild.Name).ToArrayAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -74,11 +74,11 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await authSession.SendAsync(responsePacket).ConfigureAwait(false);
|
await authSession.SendAsync(responsePacket);
|
||||||
if (guildNameResponsePacket.GuildNames.Length > 0 &&
|
if (guildNameResponsePacket.GuildNames.Length > 0 &&
|
||||||
guildNameResponsePacket.GuildNames.Select(n => n != string.Empty).Any())
|
guildNameResponsePacket.GuildNames.Select(n => n != string.Empty).Any())
|
||||||
{
|
{
|
||||||
await authSession.SendAsync(guildNameResponsePacket).ConfigureAwait(false);
|
await authSession.SendAsync(guildNameResponsePacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
// // Copyright (c) 2023 Timothy Schenk.Subject to the GNU AGPL Version 3 License.
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NetCoreServer;
|
using NetCoreServer;
|
||||||
|
@ -43,7 +43,7 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
||||||
|
|
||||||
var toBeAddedCharacter = CreateDefaultCharacter(packet, account, items, firstJobConfig);
|
var toBeAddedCharacter = CreateDefaultCharacter(packet, account, items, firstJobConfig);
|
||||||
account?.Characters.Add(toBeAddedCharacter);
|
account?.Characters.Add(toBeAddedCharacter);
|
||||||
await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
|
await _wonderkingContext.SaveChangesAsync();
|
||||||
|
|
||||||
var character = await _wonderkingContext.Characters.AsNoTrackingWithIdentityResolution().AsSplitQuery()
|
var character = await _wonderkingContext.Characters.AsNoTrackingWithIdentityResolution().AsSplitQuery()
|
||||||
.Where(c => c.Account.Id == authSession.AccountId && c.Name == packet.Name)
|
.Where(c => c.Account.Id == authSession.AccountId && c.Name == packet.Name)
|
||||||
|
@ -65,13 +65,13 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
|
||||||
EquippedCashItems = GetItemIDsByInventoryTab(c.InventoryItems
|
EquippedCashItems = GetItemIDsByInventoryTab(c.InventoryItems
|
||||||
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
.Where(item => item.InventoryTab == InventoryTab.WornCashEquipment)
|
||||||
.Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).AsEnumerable())
|
.Select(item => new Tuple<ushort, byte>(item.ItemId, item.Slot)).AsEnumerable())
|
||||||
}).FirstAsync().ConfigureAwait(true);
|
}).FirstAsync();
|
||||||
await authSession.SendAsync(new CharacterCreationResponsePacket
|
await authSession.SendAsync(new CharacterCreationResponsePacket
|
||||||
{
|
{
|
||||||
Character = character,
|
Character = character,
|
||||||
Slot = packet.Slot,
|
Slot = packet.Slot,
|
||||||
isDuplicate = false
|
isDuplicate = false
|
||||||
}).ConfigureAwait(false);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private InventoryItem[] CreateDefaultItems(CharacterCreationPacket packet, JobSpecificMapping firstJobConfig)
|
private InventoryItem[] CreateDefaultItems(CharacterCreationPacket packet, JobSpecificMapping firstJobConfig)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
// // Copyright (c) 2023 Timothy Schenk.Subject to the GNU AGPL Version 3 License.
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NetCoreServer;
|
using NetCoreServer;
|
||||||
|
@ -27,17 +27,17 @@ public class CharacterDeletionHandler : IPacketHandler<CharacterDeletePacket>
|
||||||
|
|
||||||
var character = await _wonderkingContext.Characters.FirstOrDefaultAsync(x => x.Name == packet.Name &&
|
var character = await _wonderkingContext.Characters.FirstOrDefaultAsync(x => x.Name == packet.Name &&
|
||||||
x.Account.Id == authSession.AccountId)
|
x.Account.Id == authSession.AccountId)
|
||||||
.ConfigureAwait(true);
|
;
|
||||||
var response = new CharacterDeleteResponsePacket { IsDeleted = 0 };
|
var response = new CharacterDeleteResponsePacket { IsDeleted = 0 };
|
||||||
if (character == null)
|
if (character == null)
|
||||||
{
|
{
|
||||||
await authSession.SendAsync(response).ConfigureAwait(false);
|
await authSession.SendAsync(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_wonderkingContext.Characters.Remove(character);
|
_wonderkingContext.Characters.Remove(character);
|
||||||
await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false);
|
await _wonderkingContext.SaveChangesAsync();
|
||||||
|
|
||||||
await authSession.SendAsync(response).ConfigureAwait(false);
|
await authSession.SendAsync(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
// // Copyright (c) 2023 Timothy Schenk.Subject to the GNU AGPL Version 3 License.
|
||||||
|
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using NetCoreServer;
|
using NetCoreServer;
|
||||||
using Server.DB;
|
using Server.DB;
|
||||||
using Wonderking.Packets.Incoming;
|
using Wonderking.Packets.Incoming;
|
||||||
|
@ -16,15 +17,13 @@ public class CharacterNameCheckHandler : IPacketHandler<CharacterNameCheckPacket
|
||||||
_wonderkingContext = wonderkingContext;
|
_wonderkingContext = wonderkingContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task HandleAsync(CharacterNameCheckPacket packet, TcpSession session)
|
public async Task HandleAsync(CharacterNameCheckPacket packet, TcpSession session)
|
||||||
{
|
{
|
||||||
var isTaken = _wonderkingContext.Characters.Any(c => c.Name == packet.Name);
|
var isTaken = await _wonderkingContext.Characters.AnyAsync(c => c.Name == packet.Name);
|
||||||
var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken };
|
var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken };
|
||||||
if (session is AuthSession authSession)
|
if (session is AuthSession authSession)
|
||||||
{
|
{
|
||||||
return authSession.SendAsync(responsePacket);
|
await authSession.SendAsync(responsePacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
// // Copyright (c) 2023 Timothy Schenk.Subject to the GNU AGPL Version 3 License.
|
||||||
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -34,14 +34,14 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
||||||
LoginResponseReason loginResponseReason;
|
LoginResponseReason loginResponseReason;
|
||||||
_logger.LoginData(packet.Username, packet.Password);
|
_logger.LoginData(packet.Username, packet.Password);
|
||||||
var account = await _wonderkingContext.Accounts.FirstOrDefaultAsync(a => a.Username == packet.Username)
|
var account = await _wonderkingContext.Accounts.FirstOrDefaultAsync(a => a.Username == packet.Username)
|
||||||
.ConfigureAwait(false);
|
;
|
||||||
|
|
||||||
if (account == null)
|
if (account == null)
|
||||||
{
|
{
|
||||||
if (_configuration.GetSection("Testing").GetValue<bool>("CreateAccountOnLogin"))
|
if (_configuration.GetSection("Testing").GetValue<bool>("CreateAccountOnLogin"))
|
||||||
{
|
{
|
||||||
loginResponseReason = await CreateAccountOnLoginAsync(packet.Username, packet.Password)
|
loginResponseReason = await CreateAccountOnLoginAsync(packet.Username, packet.Password)
|
||||||
.ConfigureAwait(true);
|
;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -52,8 +52,7 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var salt = account.Salt;
|
var salt = account.Salt;
|
||||||
var tempPasswordBytes = await GetPasswordHashAsync(packet.Password, salt, account.Id)
|
var tempPasswordBytes = await GetPasswordHashAsync(packet.Password, salt, account.Id);
|
||||||
.ConfigureAwait(false);
|
|
||||||
loginResponseReason = tempPasswordBytes.SequenceEqual(account.Password)
|
loginResponseReason = tempPasswordBytes.SequenceEqual(account.Password)
|
||||||
? LoginResponseReason.Ok
|
? LoginResponseReason.Ok
|
||||||
: LoginResponseReason.WrongPassword;
|
: LoginResponseReason.WrongPassword;
|
||||||
|
@ -95,8 +94,8 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
||||||
{
|
{
|
||||||
LoginResponseReason loginResponseReason;
|
LoginResponseReason loginResponseReason;
|
||||||
var transaction =
|
var transaction =
|
||||||
await _wonderkingContext.Database.BeginTransactionAsync().ConfigureAwait(true);
|
await _wonderkingContext.Database.BeginTransactionAsync();
|
||||||
await using (transaction.ConfigureAwait(false))
|
await using (transaction)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -104,20 +103,19 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
|
||||||
var finalAccount =
|
var finalAccount =
|
||||||
await _wonderkingContext.Accounts.AddAsync(new Account(username,
|
await _wonderkingContext.Accounts.AddAsync(new Account(username,
|
||||||
Array.Empty<byte>(), "",
|
Array.Empty<byte>(), "",
|
||||||
0, salt)).ConfigureAwait(true);
|
0, salt));
|
||||||
await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
|
await _wonderkingContext.SaveChangesAsync();
|
||||||
finalAccount.Entity.Password =
|
finalAccount.Entity.Password =
|
||||||
await GetPasswordHashAsync(password, salt, finalAccount.Entity.Id)
|
await GetPasswordHashAsync(password, salt, finalAccount.Entity.Id);
|
||||||
.ConfigureAwait(true);
|
|
||||||
_wonderkingContext.Accounts.Update(finalAccount.Entity);
|
_wonderkingContext.Accounts.Update(finalAccount.Entity);
|
||||||
loginResponseReason = LoginResponseReason.Ok;
|
loginResponseReason = LoginResponseReason.Ok;
|
||||||
await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true);
|
await _wonderkingContext.SaveChangesAsync();
|
||||||
|
|
||||||
await transaction.CommitAsync().ConfigureAwait(true);
|
await transaction.CommitAsync();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
await transaction.RollbackAsync().ConfigureAwait(true); // Rollback the transaction on error
|
await transaction.RollbackAsync(); // Rollback the transaction on error
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
// // Copyright (c) 2023 Timothy Schenk.Subject to the GNU AGPL Version 3 License.
|
||||||
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
@ -121,7 +121,7 @@ using var host = builder.Build();
|
||||||
using (var scope = host.Services.CreateScope())
|
using (var scope = host.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var db = scope.ServiceProvider.GetRequiredService<WonderkingContext>();
|
var db = scope.ServiceProvider.GetRequiredService<WonderkingContext>();
|
||||||
await db.Database.MigrateAsync().ConfigureAwait(true);
|
await db.Database.MigrateAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
await host.RunAsync().ConfigureAwait(true);
|
await host.RunAsync();
|
||||||
|
|
Loading…
Reference in a new issue