Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. static void GameServer_AnnounceNewConnection(Interfaces.ISocketWrapper obj)
  2. {
  3. obj.Connector = new Client.GameState(obj.Socket);
  4. Client.GameState Client = obj.Connector as Client.GameState;
  5. Client.Send(Client.DHKeyExchance.CreateServerKeyPacket());
  6. }
  7.  
  8. static void GameServer_AnnounceReceive(byte[] arg1, Interfaces.ISocketWrapper arg2)
  9. {
  10. Client.GameState Client = arg2.Connector as Client.GameState;
  11. // bool bf = false;
  12. try
  13. {
  14.  
  15.  
  16. Client.Cryptography.Decrypt(arg1);
  17.  
  18. }
  19. catch { }
  20. if (Client != null)
  21. {
  22. if (Client.Exchange)
  23. {
  24. try
  25. {
  26. Client.Exchange = false;
  27.  
  28. Client.Action = 1;
  29. //string PubKey = "";
  30. //BinaryReader reader = new BinaryReader(new MemoryStream(arg1));
  31. //reader.ReadBytes(11);
  32. //int offset = reader.ReadInt32() + 4 + 11;
  33. //if (offset < arg1.Length)
  34. //{
  35. // reader.ReadBytes(offset);
  36. // int nSize = reader.ReadInt32();
  37. // if (nSize > 0)
  38. // {
  39. // PubKey = Encoding.UTF7.GetString(reader.ReadBytes(nSize));
  40. // }
  41. //}
  42. //Console.WriteLine(PubKey);
  43. //Client.Cryptography = Client.DHKeyExchance.HandleClientKeyPacket(PubKey, Client.Cryptography);
  44.  
  45. ushort position = 7;
  46.  
  47. uint PacketLen = BitConverter.ToUInt32(arg1, position); position += 4;
  48. int JunkLen = BitConverter.ToInt32(arg1, position); position += 4; position += (ushort)JunkLen;
  49. int Len = BitConverter.ToInt32(arg1, position); position += 4;
  50.  
  51. byte[] pubKey = new byte[Len];
  52. for (int x = 0; x < Len; x++)
  53. pubKey[x] = arg1[x + position];
  54. string PubKey = System.Text.UTF7Encoding.UTF7.GetString(pubKey);
  55.  
  56.  
  57.  
  58. Client.Cryptography = Client.DHKeyExchance.HandleClientKeyPacket(PubKey, Client.Cryptography);
  59. //Client.cc = Client.DHKeyExchance.HandleClientKeyPacket2(PubKey, Client.cc);
  60.  
  61.  
  62.  
  63.  
  64. }
  65. catch
  66. {
  67. Client.Socket.Disconnect(false);
  68. }
  69. }
  70. else
  71. {
  72. if (!Client.Exchange && Client.Action != 0)
  73. Network.PacketHandler.HandleBuffer(arg1, Client);
  74.  
  75. // Client.Action = 1;
  76.  
  77. }
  78.  
  79.  
  80. //finally
  81. //{
  82.  
  83. }
  84.  
  85. }
  86.  
  87. static void GameServer_AnnounceDisconnection(Interfaces.ISocketWrapper obj)
  88. {
  89. if (obj.Connector != null)
  90. {
  91. Client.GameState Client = obj.Connector as Client.GameState;
  92. Client.Disconnect();
  93. }
  94. }
  95.  
  96. static void AuthServer_AnnounceNewConnection(Interfaces.ISocketWrapper obj)
  97. {
  98. Client.AuthState authState = new Client.AuthState(obj.Socket);
  99. authState.Cryptographer = new Network.Cryptography.AuthCryptography();
  100. Network.AuthPackets.PasswordCryptographySeed pcs = new PasswordCryptographySeed();
  101. pcs.Seed = ServerBase.Kernel.Random.Next();
  102. authState.PasswordSeed = pcs.Seed;
  103. authState.Send(pcs);
  104. obj.Connector = authState;
  105. }
  106.  
  107. static void AuthServer_OnClientSend(byte[] arg1, Interfaces.ISocketWrapper arg2)
  108. {
  109. Client.AuthState authState = new Client.AuthState(arg2.Socket);
  110. authState.Cryptographer = new Network.Cryptography.AuthCryptography();
  111. Network.GamePackets.PasswordP1 pas = new PasswordP1();
  112. pas.Unknow1 = 32;
  113. pas.Name = authState.Account.Username;
  114. //authState.Send(pas);
  115. arg2.Connector = authState;
  116. }
  117.  
  118. static void AuthServer_AnnounceReceive(byte[] arg1, Interfaces.ISocketWrapper arg2)
  119. {
  120. if (arg1.Length == 240 || arg1.Length == 276)
  121. {
  122. Client.AuthState player = arg2.Connector as Client.AuthState;
  123. player.Cryptographer.Decrypt(arg1);
  124. byte[] usernamearray = new byte[16];
  125. Buffer.BlockCopy(arg1, 8, usernamearray, 0, 16);
  126. string username = Encoding.Default.GetString(usernamearray).Replace("\0", "");
  127. usernames = username;
  128. player.Account = new AccountTable(usernames);
  129. byte[] passwordarray = new byte[16];
  130. Buffer.BlockCopy(arg1, 72, passwordarray, 0, 16);
  131. string password = Encoding.Default.GetString(passwordarray).Replace("\0", "");
  132. string NoNumPadNumbers = "";
  133. foreach (char c in password)
  134. {
  135. switch (c.ToString())
  136. {
  137. case "-": NoNumPadNumbers += "0"; break;
  138. case "#": NoNumPadNumbers += "1"; break;
  139. case "(": NoNumPadNumbers += "2"; break;
  140. case "\"": NoNumPadNumbers += "3"; break;
  141. case "%": NoNumPadNumbers += "4"; break;
  142. case "\f": NoNumPadNumbers += "5"; break;
  143. case "'": NoNumPadNumbers += "6"; break;
  144. case "$": NoNumPadNumbers += "7"; break;
  145. case "&": NoNumPadNumbers += "8"; break;
  146. case "!": NoNumPadNumbers += "9"; break;
  147. default: NoNumPadNumbers += c; break;
  148. }
  149. }
  150. password = NoNumPadNumbers;
  151. Forward Fw = new Forward();
  152. if (password == player.Account.Password)
  153. {
  154. Fw.Type = Forward.ForwardType.Ready;
  155. }
  156. else
  157. {
  158. Fw.Type = Forward.ForwardType.InvalidInfo;
  159. }
  160. if (Fw.Type != Network.AuthPackets.Forward.ForwardType.InvalidInfo)
  161. {
  162. Fw.Identifier = Network.AuthPackets.Forward.Incrementer.Next;
  163. ServerBase.Kernel.AwaitingPool.Add(Fw.Identifier, player.Account);
  164. }
  165. Fw.IP = GameIP;
  166. Fw.Port = GamePort;
  167. player.Send(Fw);
  168. }
  169. else
  170. {
  171. arg2.Socket.Disconnect(false);
  172. }
  173. }
  174.  
  175. static void AuthServer_AnnounceDisconnection(Interfaces.ISocketWrapper obj)
  176. {
  177.  
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement