Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.openproto.net;
- import java.nio.ByteBuffer;
- import java.nio.channels.SocketChannel;
- import java.security.SecureRandom;
- import net.burtleburtle.bob.rand.IsaacRandom;
- /**
- * This class is used for logging the player into the server. It is basically a
- * utility class for doing so. This currently only supports the 317 revision.
- * @author Andrew
- */
- public class LoginHandler {
- /**
- * This will attempt to log a player into the server. If the buffer does not
- * contain 17 bytes (the amount of bytes needed), this method will return.
- * @param session The DeadSession attempting the log into the server.
- * @param buf The buffer containing the login block (must be size of 17).
- * @throws Exception If there is a problem sending the response.
- */
- public static void handle(DeadSession session, SocketChannel channel, ByteBuffer buf) throws Exception {
- if (buf.position() < 17 || session == null) return;
- long ignoredBytes = buf.getLong(); // first 8 bytes ignored
- int responseCode = buf.get(); // response code = 0 for logging in
- long ssk = buf.getLong(); // the server session key
- ByteBuffer out = ByteBuffer.allocate(512); // output buffer
- out.put((byte) 16).put((byte) (85)); // block size TODO: TUNE SIZE
- out.put((byte) (255)).putShort((short) 317); // magic id and revision
- out.put((byte) 0); // memory version. generally ignored
- for (int i = 0; i < 9; i++) out.putInt(0); // crc keys
- out.put((byte) 0); // RSA block length. TODO: FIX - APOLLO READS THIS LMAO
- out.put((byte) 10); // RSA key value (confirming RSA works). should be 10 when unencrypted.
- SecureRandom random = new SecureRandom(); // secure random
- long clientHalf = random.nextLong(); // client half
- out.putLong(clientHalf).putLong(ssk); // for ISAAC
- int[] isaacSeed = {(int) (clientHalf >> 32), (int) clientHalf, (int) (ssk >> 32), (int) ssk};
- IsaacRandom encryptor = new IsaacRandom(isaacSeed);
- session.setEncryptor(encryptor); // set the encryptor
- for (int i = 0; i < isaacSeed.length; i++) isaacSeed[i] += 50;
- IsaacRandom decryptor = new IsaacRandom(isaacSeed);
- out.putInt(32); // the users identification number
- out.put(("usernamelol" + session.id).getBytes()).put((byte) 10); //username
- out.put("passwords".getBytes()).put((byte) 10); //password
- out.flip(); // flip the buffer to prepair for writing
- session.loggedIn = true;
- session.queue(out); // queue the data for writing
- }
- }
Add Comment
Please, Sign In to add comment