Guest User

Untitled

a guest
Apr 10th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. final Player player = RSChannelHandler.get(channel);
  2. if(player != null) {
  3. switch(loginState) {
  4. case OPCODE:
  5. if(buffer.readableBytes() >= 2) {
  6. final int opcode = buffer.readByte() & 0xFF;
  7. if(opcode != 14) {
  8. player.disconnect();
  9. throw new IllegalStateException("Invalid request '" + opcode + "', 14 was expected.");
  10. }
  11.  
  12. @SuppressWarnings("unused")
  13. final int hash = buffer.readByte() & 0xFF;
  14. player.write(new MessageBuilder().put(INITIAL_RESPONSE).putByte(0).putLong(random.nextLong()));
  15.  
  16. checkpoint(LoginState.DETAILS);
  17. }
  18. break;
  19. case DETAILS:
  20. final int opcode = buffer.readByte();
  21. if (opcode != 16 && opcode != 18) {
  22. player.disconnect();
  23. throw new IllegalStateException("Invalid logintype '" + opcode + "', 16 or 18 was expected.");
  24. }
  25.  
  26. final int loginPacketSize = buffer.readByte();
  27. final int loginEncryptPacketSize = loginPacketSize - 41;
  28. if (loginEncryptPacketSize <= 0) {
  29. player.disconnect();
  30. throw new IllegalStateException("Invalid RSA packet size '" + loginEncryptPacketSize + "'");
  31. }
  32.  
  33. final int magicId = buffer.readByte() & 0xFF;
  34. if (magicId != 255) {
  35. player.disconnect();
  36. throw new IllegalStateException("Invalid magic id '" + magicId + "', 255 was expected.");
  37. }
  38.  
  39. final int versionId = buffer.readShort();
  40. if(versionId != 317) {
  41. player.disconnect();
  42. throw new IllegalStateException("Invalid client version '" + versionId + "', 289 was expected.");
  43. }
  44.  
  45. @SuppressWarnings("unused")
  46. final int lowMemoryVersion = buffer.readByte();
  47. for (int i = 0; i < 9; i++) {
  48. Integer.toHexString(buffer.readInt());
  49. }
  50.  
  51. final int length = buffer.readByte() & 0xFF;
  52. if(length < loginEncryptPacketSize) {
  53. player.disconnect();
  54. throw new IllegalStateException("Invalid login encrypted '" + length + "', " + loginEncryptPacketSize + " was expected.");
  55. }
  56.  
  57. int tmp = buffer.readByte();
  58. if (tmp != 10) {
  59. player.disconnect();
  60. throw new IllegalStateException("Invalid login opcode '" + tmp + "', 10 was expected.");
  61. }
  62.  
  63. final long clientSessionKey = buffer.readLong();
  64. final long serverSessionKey = buffer.readLong();
  65.  
  66. @SuppressWarnings("unused")
  67. final int uid = buffer.readInt();
  68.  
  69. final String username = ChannelBufferUtils.readRS2String(buffer);
  70. final String password = ChannelBufferUtils.readRS2String(buffer);
  71.  
  72. if(username == null || username.length() == 0) {
  73. player.debug("Invalid username, dropping connection.");
  74. player.disconnect();
  75. throw new IllegalStateException("Invalid username '" + username + "'.");
  76. }
  77.  
  78. player.setUsername(username);
  79. player.setPassword(password);
  80.  
  81. final int sessionKey[] = new int[4];
  82. sessionKey[0] = (int) (clientSessionKey >> 32);
  83. sessionKey[1] = (int) clientSessionKey;
  84. sessionKey[2] = (int) (serverSessionKey >> 32);
  85. sessionKey[3] = (int) serverSessionKey;
Add Comment
Please, Sign In to add comment