diff --git a/Server/PacketHandlers/ChannelSelectionHandler.cs b/Server/PacketHandlers/ChannelSelectionHandler.cs index 2ed2982..3f5ea6d 100644 --- a/Server/PacketHandlers/ChannelSelectionHandler.cs +++ b/Server/PacketHandlers/ChannelSelectionHandler.cs @@ -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 NetCoreServer; @@ -26,7 +26,7 @@ public class ChannelSelectionHandler : IPacketHandler var guildNameResponsePacket = new CharacterSelectionSetGuildNamePacket { GuildNames = Array.Empty() }; 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) { responsePacket = new ChannelSelectionResponsePacket @@ -55,13 +55,13 @@ public class ChannelSelectionHandler : IPacketHandler .Where(item => item.InventoryTab == InventoryTab.WornCashEquipment) .Select(item => new Tuple(item.ItemId, item.Slot)).AsEnumerable()) }) - .ToArrayAsync().ConfigureAwait(true) + .ToArrayAsync() }; guildNameResponsePacket.GuildNames = await _wonderkingContext.Characters .Where(c => c.Account.Id == authSession.AccountId) .Where(c => c.Guild != null) - .Select(character => character.Guild.Name).ToArrayAsync().ConfigureAwait(true); + .Select(character => character.Guild.Name).ToArrayAsync(); } else { @@ -74,11 +74,11 @@ public class ChannelSelectionHandler : IPacketHandler }; } - await authSession.SendAsync(responsePacket).ConfigureAwait(false); + await authSession.SendAsync(responsePacket); if (guildNameResponsePacket.GuildNames.Length > 0 && guildNameResponsePacket.GuildNames.Select(n => n != string.Empty).Any()) { - await authSession.SendAsync(guildNameResponsePacket).ConfigureAwait(false); + await authSession.SendAsync(guildNameResponsePacket); } } diff --git a/Server/PacketHandlers/CharacterCreationHandler.cs b/Server/PacketHandlers/CharacterCreationHandler.cs index a384213..c8fe322 100644 --- a/Server/PacketHandlers/CharacterCreationHandler.cs +++ b/Server/PacketHandlers/CharacterCreationHandler.cs @@ -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 NetCoreServer; @@ -43,7 +43,7 @@ public class CharacterCreationHandler : IPacketHandler var toBeAddedCharacter = CreateDefaultCharacter(packet, account, items, firstJobConfig); account?.Characters.Add(toBeAddedCharacter); - await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true); + await _wonderkingContext.SaveChangesAsync(); var character = await _wonderkingContext.Characters.AsNoTrackingWithIdentityResolution().AsSplitQuery() .Where(c => c.Account.Id == authSession.AccountId && c.Name == packet.Name) @@ -65,13 +65,13 @@ public class CharacterCreationHandler : IPacketHandler EquippedCashItems = GetItemIDsByInventoryTab(c.InventoryItems .Where(item => item.InventoryTab == InventoryTab.WornCashEquipment) .Select(item => new Tuple(item.ItemId, item.Slot)).AsEnumerable()) - }).FirstAsync().ConfigureAwait(true); + }).FirstAsync(); await authSession.SendAsync(new CharacterCreationResponsePacket { Character = character, Slot = packet.Slot, isDuplicate = false - }).ConfigureAwait(false); + }); } private InventoryItem[] CreateDefaultItems(CharacterCreationPacket packet, JobSpecificMapping firstJobConfig) diff --git a/Server/PacketHandlers/CharacterDeletionHandler.cs b/Server/PacketHandlers/CharacterDeletionHandler.cs index a54dc3a..fc5ef48 100644 --- a/Server/PacketHandlers/CharacterDeletionHandler.cs +++ b/Server/PacketHandlers/CharacterDeletionHandler.cs @@ -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 NetCoreServer; @@ -27,17 +27,17 @@ public class CharacterDeletionHandler : IPacketHandler var character = await _wonderkingContext.Characters.FirstOrDefaultAsync(x => x.Name == packet.Name && x.Account.Id == authSession.AccountId) - .ConfigureAwait(true); + ; var response = new CharacterDeleteResponsePacket { IsDeleted = 0 }; if (character == null) { - await authSession.SendAsync(response).ConfigureAwait(false); + await authSession.SendAsync(response); return; } _wonderkingContext.Characters.Remove(character); - await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false); + await _wonderkingContext.SaveChangesAsync(); - await authSession.SendAsync(response).ConfigureAwait(false); + await authSession.SendAsync(response); } } diff --git a/Server/PacketHandlers/CharacterNameCheckHandler.cs b/Server/PacketHandlers/CharacterNameCheckHandler.cs index 4dc27f8..4c99202 100644 --- a/Server/PacketHandlers/CharacterNameCheckHandler.cs +++ b/Server/PacketHandlers/CharacterNameCheckHandler.cs @@ -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 Server.DB; using Wonderking.Packets.Incoming; @@ -16,15 +17,13 @@ public class CharacterNameCheckHandler : IPacketHandler c.Name == packet.Name); + var isTaken = await _wonderkingContext.Characters.AnyAsync(c => c.Name == packet.Name); var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken }; if (session is AuthSession authSession) { - return authSession.SendAsync(responsePacket); + await authSession.SendAsync(responsePacket); } - - return Task.CompletedTask; } } diff --git a/Server/PacketHandlers/LoginHandler.cs b/Server/PacketHandlers/LoginHandler.cs index 4408386..a8fd13d 100644 --- a/Server/PacketHandlers/LoginHandler.cs +++ b/Server/PacketHandlers/LoginHandler.cs @@ -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.Text; @@ -34,14 +34,14 @@ public class LoginHandler : IPacketHandler LoginResponseReason loginResponseReason; _logger.LoginData(packet.Username, packet.Password); var account = await _wonderkingContext.Accounts.FirstOrDefaultAsync(a => a.Username == packet.Username) - .ConfigureAwait(false); + ; if (account == null) { if (_configuration.GetSection("Testing").GetValue("CreateAccountOnLogin")) { loginResponseReason = await CreateAccountOnLoginAsync(packet.Username, packet.Password) - .ConfigureAwait(true); + ; } else { @@ -52,8 +52,7 @@ public class LoginHandler : IPacketHandler else { var salt = account.Salt; - var tempPasswordBytes = await GetPasswordHashAsync(packet.Password, salt, account.Id) - .ConfigureAwait(false); + var tempPasswordBytes = await GetPasswordHashAsync(packet.Password, salt, account.Id); loginResponseReason = tempPasswordBytes.SequenceEqual(account.Password) ? LoginResponseReason.Ok : LoginResponseReason.WrongPassword; @@ -95,8 +94,8 @@ public class LoginHandler : IPacketHandler { LoginResponseReason loginResponseReason; var transaction = - await _wonderkingContext.Database.BeginTransactionAsync().ConfigureAwait(true); - await using (transaction.ConfigureAwait(false)) + await _wonderkingContext.Database.BeginTransactionAsync(); + await using (transaction) { try { @@ -104,20 +103,19 @@ public class LoginHandler : IPacketHandler var finalAccount = await _wonderkingContext.Accounts.AddAsync(new Account(username, Array.Empty(), "", - 0, salt)).ConfigureAwait(true); - await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true); + 0, salt)); + await _wonderkingContext.SaveChangesAsync(); finalAccount.Entity.Password = - await GetPasswordHashAsync(password, salt, finalAccount.Entity.Id) - .ConfigureAwait(true); + await GetPasswordHashAsync(password, salt, finalAccount.Entity.Id); _wonderkingContext.Accounts.Update(finalAccount.Entity); loginResponseReason = LoginResponseReason.Ok; - await _wonderkingContext.SaveChangesAsync().ConfigureAwait(true); + await _wonderkingContext.SaveChangesAsync(); - await transaction.CommitAsync().ConfigureAwait(true); + await transaction.CommitAsync(); } catch (Exception) { - await transaction.RollbackAsync().ConfigureAwait(true); // Rollback the transaction on error + await transaction.RollbackAsync(); // Rollback the transaction on error throw; } } diff --git a/Server/Program.cs b/Server/Program.cs index 523634a..ed2cdb4 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -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.Reflection; @@ -121,7 +121,7 @@ using var host = builder.Build(); using (var scope = host.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService(); - await db.Database.MigrateAsync().ConfigureAwait(true); + await db.Database.MigrateAsync(); } -await host.RunAsync().ConfigureAwait(true); +await host.RunAsync();