public static NetworkMessage Build(BigEndianReader stream) { ushort header = stream.ReadUShort(); uint id = (uint) header >> 2; int lenght = GetMessageLenght(stream, header); if (id > int.MinValue) { byte[] buffer = (lenght > 0) ? stream.ReadBytes(lenght) : new byte[] {}; return Build(id, new BigEndianReader(buffer)); } throw new Exception("Invalid packet id : " + id); }
public void CheckAccount() { if (message == null) { Logger.Error("Trying to check an account without identification message."); client.Stop(); return; } if (message.Version.ToString() != CURRENT_VERSION) { client.Send( new IdentificationFailedForBadVersionMessage((sbyte) IdentificationFailureReasonEnum.BAD_VERSION, new Common.Protocol.Net.Types.Version.Version(2,11,2,72101,1,0))); client.Stop(); return; } byte[] credentials = RSA.Decrypt(message.Credentials); BigEndianReader reader = new BigEndianReader(credentials); reader.Seek(Encoding.UTF8.GetByteCount(salt)); int lenght = reader.ReadByte(); string username = Encoding.UTF8.GetString(reader.ReadBytes(lenght)); string password = Encoding.UTF8.GetString(reader.ReadBytes(reader.Available)); AccountModel account = AccountsTable.Load(username); if (account == null || account.Password != password) { client.Send(new IdentificationFailedMessage((sbyte)IdentificationFailureReasonEnum.WRONG_CREDENTIALS)); client.Stop(); } else if (account.Banned) { client.Send(new IdentificationFailedBannedMessage((sbyte)IdentificationFailureReasonEnum.BANNED, 0)); client.Stop(); } else { ValidAccount(account, message.Autoconnect); } }