public CMKey(Octet data) { _packetLength = data.UnMarshalByte(); _keyLength = data.UnMarshalByte(); _key = data.UnMarshalBytes(_keyLength); _unknown = data.UnMarshalByte(); }
private byte[] _hash; // Hashed password public Login(Octet data) { _packetLength = data.UnMarshalByte(); _usernameLength = data.UnMarshalByte(); _username = Encoding.ASCII.GetString(data.UnMarshalBytes(_usernameLength)); _hashLength = data.UnMarshalByte(); _hash = data.UnMarshalBytes(_hashLength); }
public RoleList(Octet data) { _packetLength = data.UnMarshalByte(); _userId = data.UnMarshalInt32(); _unknown1 = data.UnMarshalInt32(); _unknown2 = data.UnMarshalInt32(); }
private void ClearPacketHandler(byte[] recvbuf, int buflen) { if (buflen == 0) { Console.WriteLine("Client sent empty packet. Disconnecting..."); IsConnected = false; return; } byte[] arrData = new byte[buflen]; Array.Copy(recvbuf, arrData, buflen); Octet data = new Octet(arrData); byte packetid = data.UnMarshalByte(); switch (packetid) { case (byte)LinkServerPacket.LoginRequest: Login loginPacket = new Login(data); _username = loginPacket.Username; _passwordHash = loginPacket.Hash; Console.WriteLine("User {0} is trying to login", _username); string passHash = BitConverter.ToString(_passwordHash).Replace("-", string.Empty); string dbHashString = _database.GetUserPasswd(_username, passHash); if (dbHashString.Equals(passHash)) { SMKey smkeyPacket = new SMKey(); SendReply(smkeyPacket.GetBytes()); _smKey = smkeyPacket.GetSMKey(); HMACMD5 hmacmd5 = new HMACMD5(Encoding.ASCII.GetBytes(_username)); byte[] array = new byte[_passwordHash.Length + _smKey.Length]; _passwordHash.CopyTo(array, 0); _smKey.CopyTo(array, _passwordHash.Length); byte[] RC4_C2SKEY = hmacmd5.ComputeHash(array); C2S_Crypto = new RC4(RC4_C2SKEY); _isEncrypted = true; } else { ErrorInfo errorPacket = new ErrorInfo(2); SendReply(errorPacket.GetBytes()); Console.WriteLine("Login error!"); } break; default: IsConnected = false; Console.WriteLine("Unknown packet. Disconnecting..."); Console.WriteLine(BitConverter.ToString(recvbuf, 0, buflen)); break; } }
private void EncryptedPacketHandler(byte[] recvbuf, int buflen) { if (buflen == 0) { Console.WriteLine("Client sent empty packet. Disconnecting..."); IsConnected = false; return; } byte[] arrData = new byte[buflen]; Array.Copy(recvbuf, arrData, buflen); C2S_Crypto.decrypt(arrData); Octet data = new Octet(arrData); byte packetid = data.UnMarshalByte(); switch (packetid) { case (byte)LinkServerPacket.KeyExchange: CMKey smkeyPacket = new CMKey(data); _cmKey = smkeyPacket.GetCMKey(); HMACMD5 hmacmd5 = new HMACMD5(Encoding.ASCII.GetBytes(_username)); byte[] array = new byte[_passwordHash.Length + _cmKey.Length]; _passwordHash.CopyTo(array, 0); _cmKey.CopyTo(array, _passwordHash.Length); byte[] RC4_S2CKEY = hmacmd5.ComputeHash(array); S2C_Crypto = new RC4(RC4_S2CKEY); _isCompressed = true; _userId = _database.GetIdByUsername(_username); OnlineAnnounce announcePacket = new OnlineAnnounce(_userId); SendReply(announcePacket.GetBytes()); break; case (byte)LinkServerPacket.RoleList: RoleList roleListPacket = new RoleList(data); Console.WriteLine("TODO: Get Roles by ID"); LastLoginInfo loginInfo = new LastLoginInfo(_userId); SendReply(loginInfo.GetBytes()); //Console.WriteLine("TODO: Iterate over roles and send them"); //// Finally... //RoleListRe finalRole = new RoleListRe(-1, _userId); //SendReply(finalRole.GetBytes()); break; default: IsConnected = false; Console.WriteLine("Unknown packet. Disconnecting..."); Console.WriteLine(BitConverter.ToString(arrData, 0, arrData.Length)); break; } }