Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Go to Authentication.Cs in Network=) AuthPackets
- public void Deserialize(byte[] buffer)
- {
- if (buffer.Length == 312)
- {
- ushort length = BitConverter.ToUInt16(buffer, 0);
- if (length == 312)
- {
- ushort type = BitConverter.ToUInt16(buffer, 2);
- byte[] temp = new byte[16];
- if (type == 1636)//1636
- {
- MemoryStream MS = new MemoryStream(buffer);
- BinaryReader BR = new BinaryReader(MS);
- BR.ReadUInt16();
- BR.ReadUInt16();
- Username = Encoding.Default.GetString(BR.ReadBytes(32));
- Username = Username.Replace("\0", "");
- BR.ReadBytes(36);
- Password = Encoding.Default.GetString(BR.ReadBytes(32));
- Password = Password.Replace("\0", "");
- BR.ReadBytes(32);
- Server = Encoding.Default.GetString(BR.ReadBytes(32));
- Server = Server.Replace("\0", "");
- BR.Close();
- MS.Close();
- }
- }
- }
- }
- In Same Folder
- Forward.cs
- namespace Conquer_Online_Server.Network.AuthPackets
- {
- using System;
- using System.Text;
- public class Forward : Interfaces.IPacket
- {
- public enum ForwardType : byte
- {
- Ready = 2,
- InvalidInfo = 1,
- WrongAccount = 57,
- ServersNotConfigured = 59,
- InvalidAuthenticationProtocol = 73,
- Banned = 25
- }
- byte[] Buffer;
- public Forward()
- {
- Buffer = new byte[224 + 8];
- Writer.WriteUInt16(224, 0, Buffer);
- Writer.WriteUInt16(1637, 2, Buffer);
- }
- public uint Identifier
- {
- get
- {
- return BitConverter.ToUInt32(Buffer, 4);
- }
- set
- {
- Writer.WriteUInt32(value, 4, Buffer);
- }
- }
- public ForwardType Type
- {
- get
- {
- return (ForwardType)(byte)BitConverter.ToUInt32(Buffer, 8);
- }
- set
- {
- Writer.WriteUInt32((byte)value, 8, Buffer);
- }
- }
- public string IP
- {
- get
- {
- return Encoding.Default.GetString(Buffer, 24, 16);
- }
- set
- {
- Writer.WriteString(value, 24, Buffer);
- }
- }
- public ushort Port
- {
- get
- {
- return BitConverter.ToUInt16(Buffer, 16);
- }
- set
- {
- Writer.WriteUInt16(value, 16, Buffer);
- }
- }
- public void Deserialize(byte[] buffer)
- {
- //no implementation
- }
- public byte[] ToArray()
- {
- return Buffer;
- }
- public void Send(Client.GameState client)
- {
- client.Send(Buffer);
- }
- }
- }
- Program.cs
- void GameServer_OnClientReceive
- public static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
- {
- if (obj.Connector == null)
- {
- obj.Disconnect();
- return;
- }
- GameState Client = obj.Connector as GameState;
- if (Client.Exchange)
- {
- Client.Exchange = false;
- Client.Action = 1;
- var crypto = new 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 - 180) == 128)//extra packet
- {
- 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 = System.Text.Encoding.Default.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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement