Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void handleLogin() throws Exception {
- switch (getStage()) {
- case CONNECTED:
- if (inData.remaining() < 2) {
- inData.compact();
- return;
- }
- // Validate the request.
- int request = inData.get() & 0xff;
- inData.get(); // Name hash.
- if (request != 14) {
- System.err.println("Invalid login request: " + request);
- disconnect();
- return;
- }
- // Write the response.
- StreamBuffer.OutBuffer out = StreamBuffer.newOutBuffer(17);
- out.writeLong(0); // First 8 bytes are ignored by the client.
- out.writeByte(0); // The response opcode, 0 for logging in.
- out.writeLong(new SecureRandom().nextLong()); // SSK.
- send(out.getBuffer());
- setStage(Stage.LOGGING_IN);
- break;
- case LOGGING_IN:
- if (inData.remaining() < 2) {
- inData.compact();
- return;
- }
- // Validate the login type.
- int loginType = inData.get();
- if (loginType != 16 && loginType != 18) {
- System.err.println("Invalid login type: " + loginType);
- player.disconnect();
- return;
- }
- // Ensure that we can read all of the login block.
- int blockLength = inData.get() & 0xff;
- int loginEncryptSize = blockLength - (36 + 1 + 1 + 2);
- if (inData.remaining() < blockLength) {
- inData.compact();
- return;
- }
- // Read the login block.
- StreamBuffer.InBuffer in = StreamBuffer.newInBuffer(inData);
- // Set the magic id
- in.readByte();
- // Set the client version.
- in.readShort();
- in.readByte(); // Skip the high/low memory version.
- // Skip the CRC keys.
- for (int i = 0; i < 9; i++) {
- in.readInt();
- }
- in.readByte(); // Skip RSA block length.
- // Validate that the RSA block was decoded properly.
- int rsaOpcode = in.readByte();
- System.out.println(rsaOpcode);
- if (rsaOpcode != 10) {
- System.err.println("Unable to decode RSA block properly!");
- player.disconnect();
- return;
- }
- // Set up the ISAAC ciphers.
- long clientHalf = in.readLong();
- long serverHalf = in.readLong();
- int[] isaacSeed = { (int) (clientHalf >> 32), (int) clientHalf, (int) (serverHalf >> 32), (int) serverHalf };
- player.setDecryptor(new ISAACCipher(isaacSeed));
- for (int i = 0; i < isaacSeed.length; i++) {
- isaacSeed[i] += 50;
- }
- player.setEncryptor(new ISAACCipher(isaacSeed));
- // Read the user authentication.
- in.readInt(); // Skip the user ID.
- String username = in.readString().trim();
- String password = in.readString().toLowerCase().trim();
- player.setPassword(password);
- player.setUsername(username);
- break;
- }
- }
Add Comment
Please, Sign In to add comment