public static void HandleLoginRequest(PacketStream P, ref LoginClient Client) { Logger.LogInfo("Received LoginRequest!\r\n"); byte PacketLength = (byte)P.ReadByte(); byte AccountStrLength = (byte)P.ReadByte(); byte[] AccountNameBuf = new byte[AccountStrLength]; P.Read(AccountNameBuf, 0, AccountStrLength); string AccountName = Encoding.ASCII.GetString(AccountNameBuf); Logger.LogInfo("Accountname: " + AccountName + "\r\n"); byte HashLength = (byte)P.ReadByte(); byte[] HashBuf = new byte[HashLength]; P.Read(HashBuf, 0, HashLength); Client.Hash = HashBuf; byte KeyLength = (byte)P.ReadByte(); Client.EncKey = new byte[KeyLength]; P.Read(Client.EncKey, 0, KeyLength); byte Version1 = (byte)P.ReadByte(); byte Version2 = (byte)P.ReadByte(); byte Version3 = (byte)P.ReadByte(); byte Version4 = (byte)P.ReadByte(); Logger.LogInfo("Done reading LoginRequest, checking account...\r\n"); //Database.CheckAccount(AccountName, Client, HashBuf); if (Account.DoesAccountExist(AccountName) && Account.IsCorrectPassword(AccountName, HashBuf)) { //0x01 = InitLoginNotify PacketStream OutPacket = new PacketStream(0x01, 2); OutPacket.WriteByte(0x01); OutPacket.WriteByte(0x01); Client.Username = AccountName; //This is neccessary to encrypt packets. Client.Password = Account.GetPassword(AccountName); Client.Send(OutPacket.ToArray()); Logger.LogInfo("Sent InitLoginNotify!\r\n"); } else { PacketStream OutPacket = new PacketStream(0x02, 2); P.WriteByte(0x02); P.WriteByte(0x01); Client.Send(P.ToArray()); Logger.LogInfo("Bad accountname - sent SLoginFailResponse!\r\n"); Client.Disconnect(); } }
/** * Actual packet handlers */ public static void HandleLoginRequest(ref LoginClient Client, PacketStream P) { Logger.LogInfo("Received LoginRequest!\r\n"); ushort PacketLength = (ushort)P.ReadUShort(); byte AccountStrLength = (byte)P.ReadByte(); byte[] AccountNameBuf = new byte[AccountStrLength]; P.Read(AccountNameBuf, 0, AccountStrLength); string AccountName = Encoding.ASCII.GetString(AccountNameBuf); Logger.LogInfo("Accountname: " + AccountName + "\r\n"); byte HashLength = (byte)P.ReadByte(); byte[] HashBuf = new byte[HashLength]; P.Read(HashBuf, 0, HashLength); Client.Hash = HashBuf; byte KeyLength = (byte)P.ReadByte(); Client.EncKey = new byte[KeyLength]; P.Read(Client.EncKey, 0, KeyLength); byte Version1 = (byte)P.ReadByte(); byte Version2 = (byte)P.ReadByte(); byte Version3 = (byte)P.ReadByte(); byte Version4 = (byte)P.ReadByte(); Logger.LogInfo("Done reading LoginRequest, checking account...\r\n"); using (var db = DataAccess.Get()) { var account = db.Accounts.GetByUsername(AccountName); if (account == null) { PacketStream OutPacket = new PacketStream(0x02, 2); OutPacket.WriteHeader(); OutPacket.WriteByte(0x01); Client.Send(OutPacket); Logger.LogInfo("Bad accountname - sent SLoginFailResponse!\r\n"); Client.Disconnect(); return; } if (account.IsCorrectPassword(AccountName, HashBuf)) { //0x01 = InitLoginNotify PacketStream OutPacket = new PacketStream(0x01, 1); OutPacket.WriteHeader(); Client.Username = AccountName; //This is neccessary to encrypt packets. //TODO: Put something else here //Client.Password = Account.GetPassword(AccountName); Client.Send(OutPacket.ToArray()); Logger.LogInfo("Sent InitLoginNotify!\r\n"); } } }