Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. static void GameServer_OnClientReceive(byte[] buffer, int length, Wrapper obj)
  2. {
  3. if (obj.Connector == null)
  4. {
  5. obj.Disconnect();
  6. return;
  7. }
  8. Client.GameState Client = obj.Connector as Client.GameState;
  9. if (Client.Exchange)
  10. {
  11. Client.Exchange = false;
  12. Client.Action = 1;
  13. var crypto = new GameCryptography(Program.Encoding.GetBytes(ServerBase.Constants.GameCryptographyKey));
  14. byte[] otherData = new byte[length];
  15. Array.Copy(buffer, otherData, length);
  16. crypto.Decrypt(otherData, length);
  17.  
  18. bool extra = false;
  19. int pos = 0;
  20. if (BitConverter.ToInt32(otherData, length - 140) == 128)//no extra packet
  21. {
  22. pos = length - 140;
  23. Client.Cryptography.Decrypt(buffer, length);
  24. }
  25. else if (BitConverter.ToInt32(otherData, length - 180) == 128)//extra packet + 4 3d
  26. {
  27. pos = length - 180;
  28. extra = true;
  29. Client.Cryptography.Decrypt(buffer, length - 40);
  30. }
  31. int len = BitConverter.ToInt32(buffer, pos); pos += 4;
  32. if (len != 128)
  33. {
  34. Client.Disconnect();
  35. return;
  36. }
  37. byte[] pubKey = new byte[128];
  38. for (int x = 0; x < len; x++, pos++) pubKey[x] = buffer[pos];
  39.  
  40. string PubKey = Program.Encoding.GetString(pubKey);
  41. Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography);
  42.  
  43. if (extra)
  44. {
  45. byte[] data = new byte[40];
  46. Buffer.BlockCopy(buffer, length - 40, data, 0, 40);
  47. processData(data, 40, Client);
  48. }
  49. }
  50. else
  51. {
  52. processData(buffer, length, Client);
  53. }
  54. }
  55.  
  56. public class Forward : Interfaces.IPacket
  57. {
  58. public static ServerBase.Counter Incrementer;
  59. public enum ForwardType : byte { Ready = 2, InvalidInfo = 1, Banned = 12 }
  60. byte[] Buffer;
  61. public Forward()
  62. {
  63. Buffer = new byte[224 + 8];//224
  64. Network.Writer.WriteUInt16(224, 0, Buffer);
  65. Network.Writer.WriteUInt16(1637, 2, Buffer);//1637
  66. }
  67. public uint Identifier
  68. {
  69. get
  70. {
  71. return BitConverter.ToUInt32(Buffer, 4);
  72. }
  73. set
  74. {
  75. Network.Writer.WriteUInt32(value, 4, Buffer);
  76. }
  77. }
  78. public ForwardType Type
  79. {
  80. get
  81. {
  82. return (ForwardType)(uint)BitConverter.ToUInt32(Buffer, 8);
  83. }
  84. set
  85. {
  86. Network.Writer.WriteUInt32((uint)value, 8, Buffer);
  87. }
  88. }
  89. public string IP
  90. {
  91. get
  92. {
  93. return Program.Encoding.GetString(Buffer, 24, 16);//24
  94. }
  95. set
  96. {
  97. Network.Writer.WriteString(value, 24, Buffer);//24
  98. }
  99. }
  100. public ushort Port
  101. {
  102. get
  103. {
  104. return BitConverter.ToUInt16(Buffer, 16);//16
  105. }
  106. set
  107. {
  108. Network.Writer.WriteUInt16(value, 16, Buffer);//16
  109. }
  110. }
  111. public void Deserialize(byte[] buffer) { }
  112. public byte[] ToArray()
  113. {
  114. return Buffer;
  115. }
  116. public void Send(Client.GameState client)
  117. {
  118. client.Send(Buffer);
  119. }
  120. }
  121.  
  122. public class Authentication : Interfaces.IPacket
  123. {
  124. public string Username;
  125. public string Password;
  126. public string Server;
  127. public Authentication() { }
  128. public void Deserialize(byte[] buffer)
  129. {
  130.  
  131. Username = Program.Encoding.GetString(buffer, 8, 32);
  132. Username = Username.Replace("\0", "");
  133.  
  134. Password = Program.Encoding.GetString(buffer, 72, 32);
  135. Password = Password.Replace("\0", "");
  136.  
  137. Server = Program.Encoding.GetString(buffer, 136, 16);
  138. Server = Server.Replace("\0", "");
  139.  
  140. string Mac = Program.Encoding.GetString(buffer, 152, 16);
  141. Mac = Mac.Replace("\0", "");
  142.  
  143. string res = Program.Encoding.GetString(buffer, 193, 16);
  144. res = res.Replace("\0", "");
  145. }
  146. public byte[] ToArray() { throw new NotImplementedException(); }
  147. public void Send(Client.GameState client) { }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement