Advertisement
Guest User

Untitled

a guest
May 3rd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.70 KB | None | 0 0
  1. Object loginStageObj = session.getAttribute("LOGIN_STAGE");
  2.             int loginStage = 0;
  3.             if(loginStageObj != null) {
  4.                 loginStage = (Integer)loginStageObj;
  5.             }
  6.             //Logger.log("recv login packet, stage: "+loginStage);
  7.             switch(loginStage) {
  8.             case 0: //first login packets
  9.                 if(2 <= in.remaining()) {
  10.                     int protocolId = in.get() & 0xff;
  11.                     int namePart = in.get() & 0xff;
  12.                     long serverSessionKey = ((long) (java.lang.Math.random() * 99999999D) << 32) + (long) (java.lang.Math.random() * 99999999D);
  13.                     StaticPacketBuilder s1Response = new StaticPacketBuilder();
  14.                     s1Response.setBare(true).addBytes(STAGE1RESPONSE).addLong(serverSessionKey);
  15.                     session.setAttribute("SERVER_SESSION_KEY", serverSessionKey);
  16.                     session.write(s1Response.toPacket());
  17.                     session.setAttribute("LOGIN_STAGE", 1);
  18.                     //Logger.log("protocolId="+protocolId+"; namePart="+namePart);
  19.                     return true;
  20.                 } else {
  21.                     in.rewind();
  22.                     return false;
  23.                 }
  24.             case 1: //here's where we get the username and password
  25.                 int loginType = -1, loginPacketSize = -1;
  26.                 if(2 <= in.remaining()) {
  27.                     loginType = in.get() & 0xff; //should be 16 or 18
  28.                     loginPacketSize = in.get() & 0xff;
  29.                     //Logger.log("loginType="+loginType);
  30.                 } else {
  31.                     in.rewind();
  32.                     return false;
  33.                 }
  34.                 if(loginPacketSize <= in.remaining()) {
  35.                     byte[] payload = new byte[loginPacketSize];
  36.                     in.get(payload);
  37.                     Packet p = new Packet(session, -1, payload);
  38.                     int loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2); // can't be negative
  39.                     if((p.readByte() & 0xff) != 255 || p.readShort() != 317) {
  40.                         // this is bad apparently
  41.                     }
  42.                     int lowMemoryVersion = p.readByte() & 0xff;
  43.                     for(int n=0; n<9; n++) {
  44.                         int dataFileSum = p.readInt(); //i don't care personally
  45.                     }
  46.                     int tmpEncryptPacketSize = p.readByte() & 0xff; //hopefully same as (--loginEncryptPacketSize)
  47.                     int encryptPacketId = p.readByte() & 0xff; //hopefully 10
  48.                     long clientSessionKey = p.readLong();
  49.                     long serverSessionKey = p.readLong();
  50.                     int uid = p.readInt(); //unique identifier for this session i think ?
  51.                     String  user = p.readRS2String(), //given username
  52.                             pass = p.readRS2String(); //given password
  53.                     int sessionKey[] = new int[4];
  54.                     sessionKey[0] = (int)(clientSessionKey >> 32);
  55.                     sessionKey[1] = (int)clientSessionKey;
  56.                     sessionKey[2] = (int)(serverSessionKey >> 32);
  57.                     sessionKey[3] = (int)serverSessionKey;
  58.                    
  59.                     session.setAttribute("CRYPTION_IN", new ISAACCipher(sessionKey));
  60.                     for(int i = 0; i < 4; i++)
  61. sessionKey[i] += 50;
  62.                     session.setAttribute("CRYPTION_OUT", new ISAACCipher(sessionKey));
  63.                    
  64.                     session.removeAttribute("LOGIN_STAGE");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement