Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. private void dataArrival(IAsyncResult iAr)
  2. {
  3. if (Session == null || !Session.isValid) // Safety above all
  4. {
  5. return;
  6. }
  7.  
  8. try
  9. {
  10. int bytesReceived = Socket.EndReceive(iAr);
  11. receivedBytesCounter += bytesReceived;
  12.  
  13. string Data = System.Text.Encoding.Default.GetString(dataBuffer, 0, bytesReceived);
  14.  
  15. if (Data.Length <= 0)
  16. {
  17. return;
  18. }
  19.  
  20. Logging.Log("Session " + Session.ID + "<< " + Data, Logging.logType.debugEvent);
  21.  
  22. if (encryptionClient != null)
  23. {
  24. Data = encryptionClient.Decipher(Data);
  25. }
  26.  
  27. if (Data == "<policy-file-request/>" + Convert.ToChar(0))
  28. {
  29. Logging.Log("Session " + Session.ID + " requested the policy file.");
  30. Logging.Log("Sending XML cross domain policy file to session " + Session.ID + ".");
  31.  
  32. sendMessage(xmlPolicy.getPolicy());
  33.  
  34. Engine.Sessions.destroySession(Session.ID);
  35.  
  36. /*string Key = Engine.Security.Ciphering.generateKey();
  37.  
  38. serverMessage Message = new serverMessage(1); // "@A"
  39. Message.Append(Key);
  40. sendMessage(Message);
  41.  
  42. Session.gameConnection.initializeEncryption(Key);
  43.  
  44. Logging.Log("Initialized RC4 instance for session " + Session.ID + ", public key: " + Key);*/
  45. }
  46. else
  47. {
  48. while (Data.Length > 0)
  49. {
  50. int v = base64Encoding.Decode(Data.Substring(1, 2)); // Decode length of this message
  51. Request = new clientMessage(Data.Substring(3, v)); // Get message content and create clientMessage object
  52.  
  53. //Logging.Log("Session " + Session.ID + "<< " + Request.ID + " : " + Request.encodedID + " " + Request.Content, Logging.logType.clientMessageEvent);
  54.  
  55. processMessage();
  56. Data = Data.Substring(v + 3);
  57. }
  58. }
  59.  
  60. if (Session != null && Session.isValid) // Session is still allowed to process messages
  61. {
  62. Socket.BeginReceive(dataBuffer, 0, dataBuffer.Length, SocketFlags.None, dataArrival, null);
  63. }
  64. }
  65.  
  66. catch (ObjectDisposedException) { }
  67. catch (SocketException ex)
  68. {
  69. if (Session != null)
  70. {
  71. Logging.Log("USER D/C: " + ex.Message);
  72. Engine.Sessions.destroySession(Session.ID);
  73. }
  74. return;
  75. }
  76. catch (ArgumentOutOfRangeException ex) // Wrong structured packet
  77. {
  78. if (Session != null)
  79. {
  80. Logging.Log("USER D/C: " + ex.Message);
  81. Engine.Sessions.destroySession(Session.ID); // Something is wrong with client, weird data?
  82. }
  83. return;
  84. }
  85. catch (Exception ex)
  86. {
  87. Logging.Log("Unhandled exception occurred in dataArrival method of session, stack trace: \r\n" + ex.StackTrace, Logging.logType.commonError);
  88. }
  89. }
  90.  
  91. private void processMessage()
  92. {
  93. if (Request.Content.Contains("\x01"))
  94. {
  95. Session.isValid = false;
  96. Engine.Sessions.destroySession(Session.ID);
  97. Engine.Net.Game.blackListIpAddress(ipAddress);
  98. Logging.Log("Session " + Session.ID + " (ip: " + ipAddress + ") sent message with char1 (message breaker), hax! IP address blacklisted.");
  99. return;
  100. }
  101.  
  102. try
  103. {
  104. messageHandler.handleRequest(Request);
  105. }
  106. catch (Exception e)
  107. {
  108. Logging.Log("Unhandled error occurred in processMessage(). Error: " + e.Message);
  109.  
  110. // Transmit client error report
  111. Response.Initialize(299); // "Dk"
  112. Response.appendWired(1337); // Server ID
  113. Response.appendWired(Request.ID); // Last message ID
  114. Response.appendClosedValue(DateTime.Now.ToString());
  115. sendResponse();
  116. return;
  117. }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement