Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected boolean doDecode(IoSession session, IoBuffer buffer, ProtocolDecoderOutput out) throws Exception {
- LoginStage stage = (LoginStage) session.getAttribute("loginStage", LoginStage.REQUEST);
- switch (stage) {
- case REQUEST:
- if (buffer.remaining() < 2) {
- buffer.rewind();
- return false;
- }
- int loginOpcode = buffer.get() & 0xff;
- if (loginOpcode != 14) {
- session.close(false);
- return false;
- }
- buffer.position(buffer.position() + 1);
- int responseCode = 0x0;
- long key = random.nextLong();
- session.setAttribute("serverKey", key);
- session.write(new Streams().put(INITIAL_RESPONSE).put((byte) responseCode).putLong(key).toPacket());
- session.setAttribute("loginStage", LoginStage.INFO_BLOCK);
- return true;
- case INFO_BLOCK:
- if (buffer.remaining() < 7) {
- buffer.rewind();
- return false;
- }
- int sessionStatus = buffer.get() & 0xff;
- if (sessionStatus != 16 && sessionStatus != 18) {
- session.close(false);
- return false;
- }
- int encryptedBlockSize = (buffer.get() & 0xff) - 40;
- int magicId = buffer.get() & 0xff;
- if (magicId != 255) {
- session.close(false);
- return false;
- }
- int clientRevision = buffer.getShort() & 0xffff;
- if (clientRevision != 317) {
- session.close(false);
- return false;
- }
- buffer.position(buffer.position() + 37);
- encryptedBlockSize--;
- int reportedSize = buffer.get() & 0xff;
- if (reportedSize != encryptedBlockSize) {
- buffer.rewind();
- return false;
- }
- int rsaOpcode = buffer.get();
- if (rsaOpcode != 10) {
- session.close(false);
- return false;
- }
- long clientKey = buffer.getLong();
- long serverKey = (Long) session.getAttribute("serverKey");
- if (serverKey != buffer.getLong()) {
- System.out.println("" + serverKey + " -- ");
- session.close(false);
- return false;
- }
- buffer.position(buffer.position() + 4);
- String username = ProtocolUtils.getRs2String(buffer);
- String password = ProtocolUtils.getRs2String(buffer);
- Player player = new Player(3200, 3200, 0, username, password);
- session.setAttribute("player", player);
- World.getInstance().register(player);
- int[] isaacSeed = new int[] {
- (int) (clientKey >> 0x20), (int) clientKey, (int) (serverKey >> 0x20), (int) serverKey
- };
- session.setAttribute("decrypter", new ISAACCipher(isaacSeed));
- for (int i = 0; i < isaacSeed.length; i++)
- isaacSeed[i] += 0x32;
- session.setAttribute("encrypter", new ISAACCipher(isaacSeed));
- session.removeAttribute("loginStage");
- session.removeAttribute("serverKey");
- session.write(new Streams().put((byte) 2).put((Byte) player.getAttribute("staffStatus")).put((byte) 0).toPacket());
- session.getFilterChain().remove("protocol");
- session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(Rs2CodecFactory.GAME));
- player.setSession(session, true);
- player.getSender().sendLogin();
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement