Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void GameServer_OnClientReceive(byte[] buffer, int length, Wrapper obj)
- {
- if (obj.Connector == null)
- {
- obj.Disconnect();
- return;
- }
- Client.GameState Client = obj.Connector as Client.GameState;
- if (Client.Exchange)
- {
- Client.Exchange = false;
- Client.Action = 1;
- var crypto = new GameCryptography(Program.Encoding.GetBytes(ServerBase.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 - 180) == 128)//extra packet + 4 3d
- {
- pos = length - 180;
- extra = true;
- Client.Cryptography.Decrypt(buffer, length - 40);
- }
- 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 = Program.Encoding.GetString(pubKey);
- Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography);
- if (extra)
- {
- byte[] data = new byte[40];
- Buffer.BlockCopy(buffer, length - 40, data, 0, 40);
- processData(data, 40, Client);
- }
- }
- else
- {
- processData(buffer, length, Client);
- }
- }
- public class Forward : Interfaces.IPacket
- {
- public static ServerBase.Counter Incrementer;
- public enum ForwardType : byte { Ready = 2, InvalidInfo = 1, Banned = 12 }
- byte[] Buffer;
- public Forward()
- {
- Buffer = new byte[224 + 8];//224
- Network.Writer.WriteUInt16(224, 0, Buffer);
- Network.Writer.WriteUInt16(1637, 2, Buffer);//1637
- }
- public uint Identifier
- {
- get
- {
- return BitConverter.ToUInt32(Buffer, 4);
- }
- set
- {
- Network.Writer.WriteUInt32(value, 4, Buffer);
- }
- }
- public ForwardType Type
- {
- get
- {
- return (ForwardType)(uint)BitConverter.ToUInt32(Buffer, 8);
- }
- set
- {
- Network.Writer.WriteUInt32((uint)value, 8, Buffer);
- }
- }
- public string IP
- {
- get
- {
- return Program.Encoding.GetString(Buffer, 24, 16);//24
- }
- set
- {
- Network.Writer.WriteString(value, 24, Buffer);//24
- }
- }
- public ushort Port
- {
- get
- {
- return BitConverter.ToUInt16(Buffer, 16);//16
- }
- set
- {
- Network.Writer.WriteUInt16(value, 16, Buffer);//16
- }
- }
- public void Deserialize(byte[] buffer) { }
- public byte[] ToArray()
- {
- return Buffer;
- }
- public void Send(Client.GameState client)
- {
- client.Send(Buffer);
- }
- }
- public class Authentication : Interfaces.IPacket
- {
- public string Username;
- public string Password;
- public string Server;
- public Authentication() { }
- public void Deserialize(byte[] buffer)
- {
- Username = Program.Encoding.GetString(buffer, 8, 32);
- Username = Username.Replace("\0", "");
- Password = Program.Encoding.GetString(buffer, 72, 32);
- Password = Password.Replace("\0", "");
- Server = Program.Encoding.GetString(buffer, 136, 16);
- Server = Server.Replace("\0", "");
- string Mac = Program.Encoding.GetString(buffer, 152, 16);
- Mac = Mac.Replace("\0", "");
- string res = Program.Encoding.GetString(buffer, 193, 16);
- res = res.Replace("\0", "");
- }
- public byte[] ToArray() { throw new NotImplementedException(); }
- public void Send(Client.GameState client) { }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement