Guest User

Untitled

a guest
Oct 15th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. private void handleLogin() throws Exception {
  2. switch (getStage()) {
  3. case CONNECTED:
  4. if (inData.remaining() < 2) {
  5. inData.compact();
  6. return;
  7. }
  8.  
  9. // Validate the request.
  10. int request = inData.get() & 0xff;
  11. inData.get(); // Name hash.
  12. if (request != 14) {
  13. System.err.println("Invalid login request: " + request);
  14. disconnect();
  15. return;
  16. }
  17.  
  18. // Write the response.
  19. StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(17);
  20. out.writeLong(0); // First 8 bytes are ignored by the client.
  21. out.writeByte(0); // The response opcode, 0 for logging in.
  22. out.writeLong(new SecureRandom().nextLong()); // SSK.
  23. send(out.getBuffer());
  24.  
  25. setStage(Stage.LOGGING_IN);
  26. break;
  27. case LOGGING_IN:
  28. if (inData.remaining() < 2) {
  29. inData.compact();
  30. return;
  31. }
  32.  
  33. // Validate the login type.
  34. int loginType = inData.get();
  35. if (loginType != 16 && loginType != 18) {
  36. System.err.println("Invalid login type: " + loginType);
  37. player.disconnect();
  38. return;
  39. }
  40.  
  41. // Ensure that we can read all of the login block.
  42. int blockLength = inData.get() & 0xff;
  43. int loginEncryptSize = blockLength - (36 + 1 + 1 + 2);
  44. if (inData.remaining() < blockLength) {
  45. inData.compact();
  46. return;
  47. }
  48.  
  49. // Read the login block.
  50. StreamBuffer.InBuffer in = StreamBuffer.newInBuffer(inData);
  51.  
  52. // Set the magic id
  53. in.readByte();
  54.  
  55. // Set the client version.
  56. in.readShort();
  57.  
  58. in.readByte(); // Skip the high/low memory version.
  59.  
  60. // Skip the CRC keys.
  61. for (int i = 0; i < 9; i++) {
  62. in.readInt();
  63. }
  64. in.readByte(); // Skip RSA block length.
  65. // Validate that the RSA block was decoded properly.
  66. int rsaOpcode = in.readByte();
  67. System.out.println(rsaOpcode);
  68. if (rsaOpcode != 10) {
  69. System.err.println("Unable to decode RSA block properly!");
  70. player.disconnect();
  71. return;
  72. }
  73. // Set up the ISAAC ciphers.
  74. long clientHalf = in.readLong();
  75. long serverHalf = in.readLong();
  76. int[] isaacSeed = { (int) (clientHalf >> 32), (int) clientHalf, (int) (serverHalf >> 32), (int) serverHalf };
  77. player.setDecryptor(new ISAACCipher(isaacSeed));
  78. for (int i = 0; i < isaacSeed.length; i++) {
  79. isaacSeed[i] += 50;
  80. }
  81. player.setEncryptor(new ISAACCipher(isaacSeed));
  82.  
  83. // Read the user authentication.
  84. in.readInt(); // Skip the user ID.
  85. String username = in.readString().trim();
  86. String password = in.readString().toLowerCase().trim();
  87. player.setPassword(password);
  88. player.setUsername(username);
  89. break;
  90. }
  91. }
Add Comment
Please, Sign In to add comment