public void HandleLoginPacket(Client client, Packet packet) { C2SLoginPacket loginPacket = new C2SLoginPacket(packet); Account account = client.DatabaseContext.Account .Include(a => a.Characters)? .First(a => a.Login == loginPacket.Username && a.Password == loginPacket.Password); if (account == null || account.AccountId <= 0) { S2CLoginAnswerPacket loginAnswerPacket = new S2CLoginAnswerPacket(LoginResult.AccountInvalid); client.PacketStream.Write(loginAnswerPacket); } else { S2CLoginAnswerPacket loginAnswerPacket = new S2CLoginAnswerPacket(LoginResult.Success); client.PacketStream.Write(loginAnswerPacket); S2CCharacterListPacket characterListPacket = new S2CCharacterListPacket(account.AccountId, account.Characters); client.PacketStream.Write(characterListPacket); List <GameServer> gameServerList = client.DatabaseContext.GameServer.ToList(); S2CGameServerListPacket gameServerListPacket = new S2CGameServerListPacket(gameServerList); client.PacketStream.Write(gameServerListPacket); client.Account = account; } }
public void HandleCharacterDeletePacket(Client client, Packet packet) { C2SCharacterDeletePacket characterDeletePacket = new C2SCharacterDeletePacket(packet); if (client.Account.Characters.Exists(c => c.CharacterId == characterDeletePacket.CharacterId)) { client.DatabaseContext.Character.Remove( client.Account.Characters.Find(c => c.CharacterId == characterDeletePacket.CharacterId)); client.DatabaseContext.SaveChanges(); S2CCharacterDeleteAnswerPacket characterDeleteAnswerPacket = new S2CCharacterDeleteAnswerPacket(0); client.PacketStream.Write(characterDeleteAnswerPacket); client.Account = client.DatabaseContext.Account.Include(a => a.Characters) .First(a => a.AccountId == client.Account.AccountId); S2CCharacterListPacket characterListPacket = new S2CCharacterListPacket(client.Account.AccountId, client.Account.Characters); client.PacketStream.Write(characterListPacket); } }