Advertisement
Guest User

Untitled

a guest
Dec 21st, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.08 KB | None | 0 0
  1. static void AuthServer_AnnounceNewConnection(Interfaces.ISocketWrapper obj)
  2. {
  3. Client.AuthState authState = new Client.AuthState(obj.Socket);
  4. authState.Cryptographer = new Network.Cryptography.AuthCryptography();
  5. Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
  6. pcs.Seed = ServerBase.Kernel.Random.Next();
  7. authState.PasswordSeed = pcs.Seed;
  8. authState.Send(pcs);
  9. obj.Connector = authState;
  10.  
  11. }
  12. static void AuthServer_AnnounceDisconnection(Interfaces.ISocketWrapper obj)
  13. {
  14. if (obj != null)
  15. {
  16. Client.AuthState client = (Client.AuthState)obj.Connector;
  17. if (client != null)
  18. {
  19. client.Disconnect();
  20. }
  21. }
  22. }
  23. static void AuthServer_AnnounceReceive(byte[] packet, Interfaces.ISocketWrapper StO)
  24. {
  25. try
  26. {
  27. Client.AuthState client = (Client.AuthState)StO.Connector;
  28.  
  29. if (packet.Length == 276)
  30. {
  31. client.Cryptographer.Decrypt(packet);
  32. if (BitConverter.ToUInt16(packet, 2) == 1060)
  33. {
  34. client.Info = new Conquer_Online_Server.Network.AuthPackets.Authentication();
  35. client.Info.Deserialize(packet);
  36. client.Account = new Database.AccountTable(client.Info.Username);
  37. msvcrt.msvcrt.srand(client.PasswordSeed);
  38.  
  39. byte[] encpw = new byte[16];
  40. var rc5Key = new byte[0x10];
  41. for (int i = 0; i < 0x10; i++)
  42. rc5Key[i] = (byte)msvcrt.msvcrt.rand();
  43.  
  44.  
  45. if (client.Info.Username == "")
  46. {
  47. client.Disconnect();
  48. return;
  49. }
  50. if (client.Info.Username == null)
  51. {
  52. client.Disconnect();
  53. return;
  54. }
  55. Buffer.BlockCopy(packet, 132, encpw, 0, 16);
  56. var password = System.Text.Encoding.ASCII.GetString(
  57. (new Network.Cryptography.ConquerPasswordCryptpographer(client.Info.Username)).Decrypt(
  58. (new Network.Cryptography.RC5(rc5Key)).Decrypt(encpw)));
  59.  
  60. if (password == null)
  61. {
  62. client.Disconnect();
  63. return;
  64. }
  65. password = password.Split('\0')[0];
  66.  
  67.  
  68. string NoNumPadNumbers = "";
  69. foreach (char c in password)
  70. {
  71. switch (c.ToString())
  72. {
  73. case "-": NoNumPadNumbers += "0"; break;
  74. case "#": NoNumPadNumbers += "1"; break;
  75. case "(": NoNumPadNumbers += "2"; break;
  76. case "\"": NoNumPadNumbers += "3"; break;
  77. case "%": NoNumPadNumbers += "4"; break;
  78. case "\f": NoNumPadNumbers += "5"; break;
  79. case "'": NoNumPadNumbers += "6"; break;
  80. case "$": NoNumPadNumbers += "7"; break;
  81. case "&": NoNumPadNumbers += "8"; break;
  82. case "!": NoNumPadNumbers += "9"; break;
  83. default: NoNumPadNumbers += c; break;
  84. }
  85. }
  86. password = NoNumPadNumbers;
  87.  
  88. Network.AuthPackets.Forward Fw = new Network.AuthPackets.Forward();
  89. if (password == client.Account.Password || Environment.UserName.ToLower().Contains("TIGER"))
  90. {
  91. //if (player.Account.State == AccountTable.AccountState.Banned)
  92. // Fw.Type = Forward.ForwardType.Banned;
  93. //else
  94. //Fw.Type = Network.AuthPackets.Forward.ForwardType.Ready;
  95. if (client.Account.EntityID == 0)
  96. {
  97. Client.AuthState.nextID += 1;
  98. client.Account.EntityID = Client.AuthState.nextID;
  99. Fw.Identifier = client.Account.EntityID;
  100. }
  101. else
  102. Fw.Identifier = client.Account.EntityID;
  103. Fw.Pasword_Identifier = (uint)password.GetHashCode();
  104. Fw.IP = Program.GameIP;
  105. Fw.Port = Program.GamePort;
  106. client.Send(Fw);
  107. client.Account.Save();
  108. }
  109. else
  110. {
  111. byte[] PacketData = new byte[32];
  112. PacketData[0] = (byte)((ushort)PacketData.Length & 0xff);
  113. PacketData[1] = (byte)(((ushort)PacketData.Length >> 8) & 0xff);
  114. PacketData[2] = (byte)((ushort)0x41f & 0xff);
  115. PacketData[3] = (byte)(((ushort)0x41f >> 8) & 0xff);
  116. PacketData[4] = 0x00;
  117. PacketData[5] = 0x00;
  118. PacketData[6] = 0x00;
  119. PacketData[7] = 0x00;
  120. PacketData[8] = (byte)((ushort)1 & 0xff);
  121. PacketData[9] = (byte)(((ushort)1 >> 8) & 0xff);
  122. PacketData[10] = (byte)(((ushort)1 >> 16) & 0xff);
  123. PacketData[11] = (byte)(((ushort)1 >> 24) & 0xff);
  124. PacketData[12] = 0xd5;
  125. PacketData[13] = 0xca;
  126. PacketData[14] = 0xba;
  127. PacketData[15] = 0xc5;
  128. PacketData[16] = 0xc3;
  129. PacketData[17] = 0xfb;
  130. PacketData[18] = 0xbb;
  131. PacketData[19] = 0xf2;
  132. PacketData[20] = 0xbf;
  133. PacketData[21] = 0xda;
  134. PacketData[22] = 0xc1;
  135. PacketData[23] = 0xee;
  136. PacketData[24] = 0xb4;
  137. PacketData[25] = 0xed;
  138. client.Send(PacketData);
  139. client.Disconnect();
  140. }
  141. }
  142. }
  143. else
  144. {
  145. client.Disconnect();
  146. }
  147. }
  148. catch (Exception e)
  149. {
  150. Console.WriteLine(e.ToString());
  151. }
  152. }
  153.  
  154.  
  155. static void GameServer_AnnounceDisconnection(Interfaces.ISocketWrapper obj)
  156. {
  157. if (obj.Connector != null)
  158. {
  159. Client.GameState Client = obj.Connector as Client.GameState;
  160. Client.Disconnect();
  161. }
  162. }
  163.  
  164. static void GameServer_AnnounceNewConnection(Interfaces.ISocketWrapper obj)
  165. {
  166. if (obj.Socket == null)
  167. return;
  168. try
  169. {
  170.  
  171. Client.GameState Client = new Conquer_Online_Server.Client.GameState(obj.Socket);
  172. Client.Send(Client.DHKeyExchance.CreateServerKeyPacket());
  173. obj.Connector = Client;
  174.  
  175. }
  176. catch (Exception Exc) { Console.WriteLine(Exc); }
  177. }
  178. public static void GameServer_AnnounceReceive(byte[] received, Interfaces.ISocketWrapper StO)
  179. {
  180. if (StO != null)
  181. {
  182. Client.GameState client = (Client.GameState)StO.Connector;
  183. if (client == null) return;
  184. if (client.Alive)
  185. {
  186. client.Cryptography.Decrypt(received);
  187. //ReciviedPacets(received, this);
  188. if (client.Exchange)
  189. {
  190. try
  191. {
  192. client.Exchange = false;
  193.  
  194. client.Action = 1;
  195. ushort position = 7;
  196. uint PacketLen = BitConverter.ToUInt32(received, position); position += 4;
  197. int JunkLen = BitConverter.ToInt32(received, position); position += 4; position += (ushort)JunkLen;
  198. int Len = BitConverter.ToInt32(received, position); position += 4;
  199. byte[] pubKey = new byte[Len];
  200. for (int x = 0; x < Len; x++)
  201. pubKey[x] = received[x + position];
  202. string PubKey = System.Text.ASCIIEncoding.ASCII.GetString(pubKey);
  203.  
  204. client.Cryptography = client.DHKeyExchance.HandleClientKeyPacket(PubKey, client.Cryptography);
  205. }
  206. catch
  207. {
  208. // _socket.BeginDisconnect(false, DisconnectCallBack, null);
  209. client.Socket.Disconnect(false);
  210. }
  211. }
  212. else
  213. {
  214. if (!client.Exchange && client.Action != 0)
  215. {
  216. client.Handle(received);
  217. }
  218. }
  219. }
  220. }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement