Advertisement
Guest User

Untitled

a guest
Jun 4th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. case STATE_CRYPTED:
  2. int size = (Integer) session.getAttribute("size");
  3. int encryptSize = (Integer) session.getAttribute("encryptSize");
  4. if(in.remaining() >= size) {
  5.  
  6. /*
  7. * We now read a short which is the client version and
  8. * check if it equals 317.
  9. */
  10. int version = in.getInt();
  11. if(version != Server.VERSION) {
  12. logger.info("Incorrect version : " + version);
  13. session.close(false);
  14. in.rewind();
  15. return false;
  16. }
  17. logger.info("version read");
  18.  
  19. /*
  20. * The following byte indicates if we are using a low
  21. * memory version.
  22. */
  23. @SuppressWarnings("unused")
  24. boolean lowMemoryVersion = (in.get() & 0xFF) == 1;
  25.  
  26. for(int i = 0; i < 24; i++) {
  27. in.get();
  28. }
  29. logger.info("low memory bytes read");
  30.  
  31. /*
  32. * We know read the cache indices.
  33. */
  34. for(int i = 0; i < 16; i++) {
  35. in.getInt();
  36. }
  37. logger.info("cache indices read");
  38.  
  39. /*
  40. * The encrypted size includes the size byte which we don't
  41. * need.
  42. */
  43. encryptSize--;
  44.  
  45. /*
  46. * We check if there is a mismatch in the sizing.
  47. */
  48. int reportedSize = in.get() & 0xFF;
  49. //if(reportedSize != encryptSize) {
  50. // logger.info("Packet size mismatch (expected : " + encryptSize + ", reported : " + reportedSize + ")");
  51. // session.close(false);
  52. // in.rewind();
  53. // return false;
  54. //}
  55.  
  56.  
  57. if(reportedSize != 10) {
  58. //logger.info("Invalid login block opcode : " + blockOpcode);
  59. //session.close(false);
  60. //in.rewind();
  61. //return false;
  62. in.get();
  63. }
  64. logger.info("reportSize");
  65.  
  66. /*
  67. * We read the client's session key.
  68. */
  69. long clientKey = in.getLong();
  70.  
  71. /*
  72. * And verify it has the correct server session key.
  73. */
  74. long serverKey = (Long) session.getAttribute("serverKey");
  75. long reportedServerKey = in.getLong();
  76. logger.info("serverKey");
  77. if(reportedServerKey != serverKey) {
  78. //logger.info("Server key mismatch (expected : " + serverKey + ", reported : " + reportedServerKey + ")");
  79. //session.close(false);
  80. //in.rewind();
  81. //return false;
  82. }
  83. logger.info("serverKey Read");
  84.  
  85. /*
  86. * The UID, found in random.dat in newer clients and
  87. * uid.dat in older clients is a way of identifying a
  88. * computer.
  89. *
  90. * However, some clients send a hardcoded or random UID,
  91. * making it useless in the private server scene.
  92. */
  93. //int uid = in.getInt();
  94.  
  95. /*
  96. * We read and format the name and passwords.
  97. */
  98. String name = NameUtils.formatName(TextUtils.longToPlayerName(in.getLong()));
  99. String pass = IoBufferUtils.getRS2String(in);
  100. logger.info("Login request : username=" + name + " password=" + pass);
  101.  
  102. /*
  103. * And setup the ISAAC cipher which is used to encrypt and
  104. * decrypt opcodes.
  105. *
  106. * However, without RSA, this is rendered useless anyway.
  107. */
  108. int[] sessionKey = new int[4];
  109. sessionKey[0] = (int) (clientKey >> 32);
  110. sessionKey[1] = (int) clientKey;
  111. sessionKey[2] = (int) (serverKey >> 32);
  112. sessionKey[3] = (int) serverKey;
  113.  
  114. session.removeAttribute("state");
  115. session.removeAttribute("serverKey");
  116. session.removeAttribute("size");
  117. session.removeAttribute("encryptSize");
  118.  
  119. ISAACCipher inCipher = null;// new ISAACCipher(sessionKey);
  120. for(int i = 0; i < 4; i++) {
  121. sessionKey[i] += 50;
  122. }
  123. ISAACCipher outCipher = null;// new ISAACCipher(sessionKey);
  124.  
  125. /*
  126. * Now, the login has completed, and we do the appropriate
  127. * things to fire off the chain of events which will load
  128. * and check the saved games etc.
  129. */
  130. session.getFilterChain().remove("protocol");
  131. logger.info("Remove Protocol");
  132. session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(RS2CodecFactory.GAME));
  133.  
  134. logger.info("Add Protocol");
  135. PlayerDetails pd = new PlayerDetails(session, name, pass, 0, inCipher, outCipher);
  136. logger.info("Loaded");
  137. World.getWorld().load(pd);
  138. logger.info("finished");
  139. }
  140. break;
  141. }
  142. in.rewind();
  143. return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement