Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object loginStageObj = session.getAttribute("LOGIN_STAGE");
- int loginStage = 0;
- if(loginStageObj != null) {
- loginStage = (Integer)loginStageObj;
- }
- //Logger.log("recv login packet, stage: "+loginStage);
- switch(loginStage) {
- case 0: //first login packets
- if(2 <= in.remaining()) {
- int protocolId = in.get() & 0xff;
- int namePart = in.get() & 0xff;
- long serverSessionKey = ((long) (java.lang.Math.random() * 99999999D) << 32) + (long) (java.lang.Math.random() * 99999999D);
- StaticPacketBuilder s1Response = new StaticPacketBuilder();
- s1Response.setBare(true).addBytes(STAGE1RESPONSE).addLong(serverSessionKey);
- session.setAttribute("SERVER_SESSION_KEY", serverSessionKey);
- session.write(s1Response.toPacket());
- session.setAttribute("LOGIN_STAGE", 1);
- //Logger.log("protocolId="+protocolId+"; namePart="+namePart);
- return true;
- } else {
- in.rewind();
- return false;
- }
- case 1: //here's where we get the username and password
- int loginType = -1, loginPacketSize = -1;
- if(2 <= in.remaining()) {
- loginType = in.get() & 0xff; //should be 16 or 18
- loginPacketSize = in.get() & 0xff;
- //Logger.log("loginType="+loginType);
- } else {
- in.rewind();
- return false;
- }
- if(loginPacketSize <= in.remaining()) {
- byte[] payload = new byte[loginPacketSize];
- in.get(payload);
- Packet p = new Packet(session, -1, payload);
- int loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2); // can't be negative
- if((p.readByte() & 0xff) != 255 || p.readShort() != 317) {
- // this is bad apparently
- }
- int lowMemoryVersion = p.readByte() & 0xff;
- for(int n=0; n<9; n++) {
- int dataFileSum = p.readInt(); //i don't care personally
- }
- int tmpEncryptPacketSize = p.readByte() & 0xff; //hopefully same as (--loginEncryptPacketSize)
- int encryptPacketId = p.readByte() & 0xff; //hopefully 10
- long clientSessionKey = p.readLong();
- long serverSessionKey = p.readLong();
- int uid = p.readInt(); //unique identifier for this session i think ?
- String user = p.readRS2String(), //given username
- pass = p.readRS2String(); //given password
- int sessionKey[] = new int[4];
- sessionKey[0] = (int)(clientSessionKey >> 32);
- sessionKey[1] = (int)clientSessionKey;
- sessionKey[2] = (int)(serverSessionKey >> 32);
- sessionKey[3] = (int)serverSessionKey;
- session.setAttribute("CRYPTION_IN", new ISAACCipher(sessionKey));
- for(int i = 0; i < 4; i++)
- sessionKey[i] += 50;
- session.setAttribute("CRYPTION_OUT", new ISAACCipher(sessionKey));
- session.removeAttribute("LOGIN_STAGE");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement