Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case 0: //first login packets
- if(2 <= in.remaining()) {
- int protocolId = in.get() & 0xff;
- int nameHash = in.get() & 0xff;
- if(protocolId == 15) {
- session.setAttribute("LOGIN_STAGE", -1);
- } else {
- long serverSessionKey = ((long) (java.lang.Math.random() * 99999999D) << 32) + (long) (java.lang.Math.random() * 99999999D);
- StaticPacketBuilder s1Response = new StaticPacketBuilder();
- s1Response.setBare(true).addByte((byte) 0).addLong(serverSessionKey);
- session.setAttribute("SERVER_SESSION_KEY", serverSessionKey);
- session.write(s1Response.toPacket());
- session.setAttribute("LOGIN_STAGE", 1);
- session.setAttribute("NAME_HASH", nameHash);
- //Logger.log("protocolId="+protocolId+"; namePart="+namePart);
- }
- return true;
- } else {
- in.rewind();
- return false;
- }
- case 1: //here's where we get the username and password
- @SuppressWarnings("unused")
- int loginType = -1, loginPacketSize = -1;
- if(3 <= in.remaining()) {
- loginType = in.get() & 0xff; //should be 16 or 18
- loginPacketSize = in.getUnsignedShort();
- //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);
- @SuppressWarnings("unused")
- int loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2); // can't be negative
- int clientVersion = p.readInt();
- if(clientVersion != 508) {
- Logger.getInstance().error("Invalid ver : " + clientVersion);
- session.close();
- return true;
- }
- @SuppressWarnings("unused")
- int lowMemoryVersion = p.readByte() & 0xff; // is this still low mem ver?
- p.readInt();
- for(int n=0; n<24; n++) {
- int cacheIDX = p.readByte(); //i don't care personally
- if(cacheIDX == 0) {
- // possibly a bot
- session.close();
- return true;
- }
- }
- p.readRS2String(); // settings string?
- for(int n=0; n<29; n++) {
- int junk = p.readInt();
- if(junk == 0 && n != 0) {
- // possibly a bot
- session.close();
- return true;
- }
- }
- int tmpEncryptPacketSize = p.readByte() & 0xff; //hopefully same as (--loginEncryptPacketSize)
- boolean hd = true;
- if(tmpEncryptPacketSize != 10) {
- @SuppressWarnings("unused")
- int encryptPacketId = p.readByte() & 0xff; //hopefully 10
- hd = false;
- }
- long clientSessionKey = p.readLong();
- long serverSessionKey = p.readLong();
- //int uid = p.readInt(); //unique identifier for this session i think ?
- long l = p.readLong();
- int hash = (int) (31 & l >> 16);
- if(hash != (Integer) session.getAttribute("NAME_HASH")) {
- // invalid name hash (possibly a bot attacking)
- session.close();
- return true;
- }
- String user = Misc.longToPlayerName(l), //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;
- // set in ISAAC
- for(int i = 0; i < 4; i++) sessionKey[i] += 50;
- // set out ISAAC
- session.removeAttribute("LOGIN_STAGE");
- session.removeAttribute("NAME_HASH");
- /**
- * Here's where we add the user to the login queue, and if the login is
- * accepted, we change their session filter to a standard RS2ProtocolCodec.
- */
- logger.debug("Login request: [username="+user+",password="+pass+"].");
- PlayerDetails d = new PlayerDetails(user, pass, session, hd);
- workerThread.loadPlayer(d);
- session.setIdleTime(IdleStatus.BOTH_IDLE, Constants.SESSION_IDLE_TIME);
- session.getFilterChain().remove("protocolFilter");
- session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new CodecFactory()));
- return true;
- } else {
- in.rewind();
- return false;
- }
- }
- } catch(Exception e) {
- //logger.stackTrace(e);
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement