Advertisement
Guest User

Proto

a guest
Nov 24th, 2018
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.49 KB | None | 0 0
  1. Go to Authentication.Cs in Network=) AuthPackets
  2.  
  3. public void Deserialize(byte[] buffer)
  4.         {
  5.             if (buffer.Length == 312)
  6.             {
  7.                 ushort length = BitConverter.ToUInt16(buffer, 0);
  8.                 if (length == 312)
  9.                 {
  10.                     ushort type = BitConverter.ToUInt16(buffer, 2);
  11.                     byte[] temp = new byte[16];
  12.                     if (type == 1636)//1636
  13.                     {
  14.                         MemoryStream MS = new MemoryStream(buffer);
  15.                         BinaryReader BR = new BinaryReader(MS);
  16.                         BR.ReadUInt16();
  17.                         BR.ReadUInt16();
  18.                         Username = Encoding.Default.GetString(BR.ReadBytes(32));
  19.                         Username = Username.Replace("\0", "");
  20.                         BR.ReadBytes(36);
  21.                         Password = Encoding.Default.GetString(BR.ReadBytes(32));
  22.                         Password = Password.Replace("\0", "");
  23.                         BR.ReadBytes(32);
  24.                         Server = Encoding.Default.GetString(BR.ReadBytes(32));
  25.                         Server = Server.Replace("\0", "");
  26.                         BR.Close();
  27.                         MS.Close();
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.  
  33. In Same Folder
  34. Forward.cs
  35.  
  36. namespace Conquer_Online_Server.Network.AuthPackets
  37. {
  38.     using System;
  39.     using System.Text;
  40.  
  41.     public class Forward : Interfaces.IPacket
  42.     {
  43.         public enum ForwardType : byte
  44.         {
  45.             Ready = 2,
  46.             InvalidInfo = 1,
  47.             WrongAccount = 57,
  48.             ServersNotConfigured = 59,
  49.             InvalidAuthenticationProtocol = 73,
  50.             Banned = 25
  51.         }
  52.         byte[] Buffer;
  53.         public Forward()
  54.         {
  55.             Buffer = new byte[224 + 8];
  56.             Writer.WriteUInt16(224, 0, Buffer);
  57.             Writer.WriteUInt16(1637, 2, Buffer);
  58.         }
  59.         public uint Identifier
  60.         {
  61.             get
  62.             {
  63.                 return BitConverter.ToUInt32(Buffer, 4);
  64.             }
  65.             set
  66.             {
  67.                 Writer.WriteUInt32(value, 4, Buffer);
  68.             }
  69.         }
  70.         public ForwardType Type
  71.         {
  72.             get
  73.             {
  74.                 return (ForwardType)(byte)BitConverter.ToUInt32(Buffer, 8);
  75.             }
  76.             set
  77.             {
  78.                 Writer.WriteUInt32((byte)value, 8, Buffer);
  79.             }
  80.         }
  81.         public string IP
  82.         {
  83.             get
  84.             {
  85.                 return Encoding.Default.GetString(Buffer, 24, 16);
  86.             }
  87.             set
  88.             {
  89.                 Writer.WriteString(value, 24, Buffer);
  90.             }
  91.         }
  92.         public ushort Port
  93.         {
  94.             get
  95.             {
  96.                 return BitConverter.ToUInt16(Buffer, 16);
  97.             }
  98.             set
  99.             {
  100.                 Writer.WriteUInt16(value, 16, Buffer);
  101.             }
  102.         }
  103.         public void Deserialize(byte[] buffer)
  104.         {
  105.             //no implementation
  106.         }
  107.         public byte[] ToArray()
  108.         {
  109.             return Buffer;
  110.         }
  111.         public void Send(Client.GameState client)
  112.         {
  113.             client.Send(Buffer);
  114.         }
  115.     }
  116. }
  117.  
  118. Program.cs
  119. void GameServer_OnClientReceive
  120.  
  121. public static void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
  122.         {
  123.             if (obj.Connector == null)
  124.             {
  125.                 obj.Disconnect();
  126.                 return;
  127.             }
  128.             GameState Client = obj.Connector as GameState;
  129.             if (Client.Exchange)
  130.             {
  131.                 Client.Exchange = false;
  132.                 Client.Action = 1;
  133.                 var crypto = new GameCryptography(System.Text.Encoding.Default.GetBytes(Constants.GameCryptographyKey));
  134.                 byte[] otherData = new byte[length];
  135.                 Array.Copy(buffer, otherData, length);
  136.                 crypto.Decrypt(otherData, length);
  137.  
  138.                 bool extra = false;
  139.                 int pos = 0;
  140.                 if (BitConverter.ToInt32(otherData, length - 140) == 128)//no extra packet
  141.                 {
  142.                     pos = length - 140;
  143.                     Client.Cryptography.Decrypt(buffer, length);
  144.                 }
  145.                 else if (BitConverter.ToInt32(otherData, length - 180) == 128)//extra packet
  146.                 {
  147.                     pos = length - 180;
  148.                     extra = true;
  149.                     Client.Cryptography.Decrypt(buffer, length - 40);
  150.                 }
  151.                 int len = BitConverter.ToInt32(buffer, pos); pos += 4;
  152.                 if (len != 128)
  153.                 {
  154.                     Client.Disconnect();
  155.                     return;
  156.                 }
  157.                 byte[] pubKey = new byte[128];
  158.                 for (int x = 0; x < len; x++, pos++) pubKey[x] = buffer[pos];
  159.  
  160.                 string PubKey = System.Text.Encoding.Default.GetString(pubKey);
  161.                 Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography);
  162.  
  163.                 if (extra)
  164.                 {
  165.                     byte[] data = new byte[40];
  166.                     Buffer.BlockCopy(buffer, length - 40, data, 0, 40);
  167.                     processData(data, 40, Client);
  168.                 }
  169.             }
  170.             else
  171.             {
  172.                 processData(buffer, length, Client);
  173.             }
  174.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement