Advertisement
Guest User

Untitled

a guest
May 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.29 KB | None | 0 0
  1.             case 0: //first login packets
  2.                 if(2 <= in.remaining()) {
  3.                     int protocolId = in.get() & 0xff;
  4.                     int nameHash = in.get() & 0xff;
  5.                     if(protocolId == 15) {
  6.                         session.setAttribute("LOGIN_STAGE", -1);
  7.                     } else {
  8.                         long serverSessionKey = ((long) (java.lang.Math.random() * 99999999D) << 32) + (long) (java.lang.Math.random() * 99999999D);
  9.                         StaticPacketBuilder s1Response = new StaticPacketBuilder();
  10.                         s1Response.setBare(true).addByte((byte) 0).addLong(serverSessionKey);
  11.                         session.setAttribute("SERVER_SESSION_KEY", serverSessionKey);
  12.                         session.write(s1Response.toPacket());
  13.                         session.setAttribute("LOGIN_STAGE", 1);
  14.                         session.setAttribute("NAME_HASH", nameHash);
  15.                         //Logger.log("protocolId="+protocolId+"; namePart="+namePart);
  16.                     }
  17.                     return true;
  18.                 } else {
  19.                     in.rewind();
  20.                     return false;
  21.                 }
  22.             case 1: //here's where we get the username and password
  23.                 @SuppressWarnings("unused")
  24.                 int loginType = -1, loginPacketSize = -1;
  25.                 if(3 <= in.remaining()) {
  26.                     loginType = in.get() & 0xff; //should be 16 or 18
  27.                     loginPacketSize = in.getUnsignedShort();
  28.                     //Logger.log("loginType="+loginType);
  29.                 } else {
  30.                     in.rewind();
  31.                     return false;
  32.                 }
  33.                 if(loginPacketSize <= in.remaining()) {
  34.                     byte[] payload = new byte[loginPacketSize];
  35.                     in.get(payload);
  36.                     Packet p = new Packet(session, -1, payload);
  37.                     @SuppressWarnings("unused")
  38.                     int loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2); // can't be negative
  39.                     int clientVersion = p.readInt();
  40.                     if(clientVersion != 508) {
  41.                         Logger.getInstance().error("Invalid ver : " + clientVersion);
  42.                         session.close();
  43.                         return true;
  44.                     }
  45.                     @SuppressWarnings("unused")
  46.                     int lowMemoryVersion = p.readByte() & 0xff; // is this still low mem ver?
  47.                     p.readInt();
  48.                     for(int n=0; n<24; n++) {
  49.                         int cacheIDX = p.readByte(); //i don't care personally
  50.                         if(cacheIDX == 0) {
  51.                             // possibly a bot
  52.                             session.close();
  53.                             return true;
  54.                         }
  55.                     }
  56.                     p.readRS2String(); // settings string?
  57.                     for(int n=0; n<29; n++) {
  58.                         int junk = p.readInt();
  59.                         if(junk == 0 && n != 0) {
  60.                             // possibly a bot
  61.                             session.close();
  62.                             return true;
  63.                         }
  64.                     }
  65.                     int tmpEncryptPacketSize = p.readByte() & 0xff; //hopefully same as (--loginEncryptPacketSize)
  66.                     boolean hd = true;
  67.                     if(tmpEncryptPacketSize != 10) {
  68.                         @SuppressWarnings("unused")
  69.                         int encryptPacketId = p.readByte() & 0xff; //hopefully 10
  70.                         hd = false;
  71.                     }
  72.                     long clientSessionKey = p.readLong();
  73.                     long serverSessionKey = p.readLong();
  74.                     //int uid = p.readInt(); //unique identifier for this session i think ?
  75.                     long l = p.readLong();
  76.                     int hash = (int) (31 & l >> 16);
  77.                     if(hash != (Integer) session.getAttribute("NAME_HASH")) {
  78.                         // invalid name hash (possibly a bot attacking)
  79.                         session.close();
  80.                         return true;
  81.                     }
  82.                     String  user = Misc.longToPlayerName(l), //given username
  83.                             pass = p.readRS2String(); //given password
  84.                    
  85.                     int sessionKey[] = new int[4];
  86.                     sessionKey[0] = (int)(clientSessionKey >> 32);
  87.                     sessionKey[1] = (int)clientSessionKey;
  88.                     sessionKey[2] = (int)(serverSessionKey >> 32);
  89.                     sessionKey[3] = (int)serverSessionKey;
  90.                    
  91.                     // set in ISAAC
  92.                     for(int i = 0; i < 4; i++) sessionKey[i] += 50;
  93.                     // set out ISAAC
  94.                    
  95.                     session.removeAttribute("LOGIN_STAGE");
  96.                     session.removeAttribute("NAME_HASH");
  97.                    
  98.                     /**
  99.                      * Here's where we add the user to the login queue, and if the login is
  100.                      * accepted, we change their session filter to a standard RS2ProtocolCodec.
  101.                      */
  102.                     logger.debug("Login request: [username="+user+",password="+pass+"].");
  103.                    
  104.                     PlayerDetails d = new PlayerDetails(user, pass, session, hd);
  105.                     workerThread.loadPlayer(d);
  106.                    
  107.                     session.setIdleTime(IdleStatus.BOTH_IDLE, Constants.SESSION_IDLE_TIME);
  108.                    
  109.                     session.getFilterChain().remove("protocolFilter");
  110.                     session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new CodecFactory()));
  111.                    
  112.                     return true;
  113.                 } else {
  114.                     in.rewind();
  115.                     return false;
  116.                 }
  117.             }
  118.         } catch(Exception e) {
  119.             //logger.stackTrace(e);
  120.         }
  121.         return false;
  122.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement