void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj) { if (obj.Connector == null) { obj.Disconnect(); return; } Client.GameClient Client = obj.Connector as Client.GameClient; if (Client.Exchange) { Client.Exchange = false; Client.Action = 1; var crypto = new Cryptography.GameCryptography(System.Text.Encoding.Default.GetBytes(Constants.GameCryptographyKey)); byte[] otherData = new byte[length]; Array.Copy(buffer, otherData, length); crypto.Decrypt(otherData, length); bool extra = false; int pos = 0; if (BitConverter.ToInt32(otherData, length - 140) == 128)//no extra packet { pos = length - 140; Client.Cryptography.Decrypt(buffer, length); } else if (BitConverter.ToInt32(otherData, length - 176) == 128)//extra packet { pos = length - 176; extra = true; Client.Cryptography.Decrypt(buffer, length - 36); } int len = BitConverter.ToInt32(buffer, pos); pos += 4; if (len != 128) { Client.Disconnect(); return; } byte[] pubKey = new byte[128]; for (int x = 0; x < len; x++, pos++) { pubKey[x] = buffer[pos]; } string PubKey = System.Text.Encoding.Default.GetString(pubKey); Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography); if (extra) { byte[] data = new byte[36]; Buffer.BlockCopy(buffer, length - 36, data, 0, 36); processData(data, 36, Client); } } else { processData(buffer, length, Client); } }
void GameServer_OnClientDisconnect(ClientWrapper obj) { if (obj.Connector != null) { (obj.Connector as Client.GameClient).Disconnect(); } else { obj.Disconnect(); } }