Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- case STATE_CRYPTED:
- int size = (Integer) session.getAttribute("size");
- int encryptSize = (Integer) session.getAttribute("encryptSize");
- if(in.remaining() >= size) {
- /*
- * We now read a short which is the client version and
- * check if it equals 317.
- */
- int version = in.getInt();
- if(version != Server.VERSION) {
- logger.info("Incorrect version : " + version);
- session.close(false);
- in.rewind();
- return false;
- }
- logger.info("version read");
- /*
- * The following byte indicates if we are using a low
- * memory version.
- */
- @SuppressWarnings("unused")
- boolean lowMemoryVersion = (in.get() & 0xFF) == 1;
- for(int i = 0; i < 24; i++) {
- in.get();
- }
- logger.info("low memory bytes read");
- /*
- * We know read the cache indices.
- */
- for(int i = 0; i < 16; i++) {
- in.getInt();
- }
- logger.info("cache indices read");
- /*
- * The encrypted size includes the size byte which we don't
- * need.
- */
- encryptSize--;
- /*
- * We check if there is a mismatch in the sizing.
- */
- int reportedSize = in.get() & 0xFF;
- //if(reportedSize != encryptSize) {
- // logger.info("Packet size mismatch (expected : " + encryptSize + ", reported : " + reportedSize + ")");
- // session.close(false);
- // in.rewind();
- // return false;
- //}
- if(reportedSize != 10) {
- //logger.info("Invalid login block opcode : " + blockOpcode);
- //session.close(false);
- //in.rewind();
- //return false;
- in.get();
- }
- logger.info("reportSize");
- /*
- * We read the client's session key.
- */
- long clientKey = in.getLong();
- /*
- * And verify it has the correct server session key.
- */
- long serverKey = (Long) session.getAttribute("serverKey");
- long reportedServerKey = in.getLong();
- logger.info("serverKey");
- if(reportedServerKey != serverKey) {
- //logger.info("Server key mismatch (expected : " + serverKey + ", reported : " + reportedServerKey + ")");
- //session.close(false);
- //in.rewind();
- //return false;
- }
- logger.info("serverKey Read");
- /*
- * The UID, found in random.dat in newer clients and
- * uid.dat in older clients is a way of identifying a
- * computer.
- *
- * However, some clients send a hardcoded or random UID,
- * making it useless in the private server scene.
- */
- //int uid = in.getInt();
- /*
- * We read and format the name and passwords.
- */
- String name = NameUtils.formatName(TextUtils.longToPlayerName(in.getLong()));
- String pass = IoBufferUtils.getRS2String(in);
- logger.info("Login request : username=" + name + " password=" + pass);
- /*
- * And setup the ISAAC cipher which is used to encrypt and
- * decrypt opcodes.
- *
- * However, without RSA, this is rendered useless anyway.
- */
- int[] sessionKey = new int[4];
- sessionKey[0] = (int) (clientKey >> 32);
- sessionKey[1] = (int) clientKey;
- sessionKey[2] = (int) (serverKey >> 32);
- sessionKey[3] = (int) serverKey;
- session.removeAttribute("state");
- session.removeAttribute("serverKey");
- session.removeAttribute("size");
- session.removeAttribute("encryptSize");
- ISAACCipher inCipher = null;// new ISAACCipher(sessionKey);
- for(int i = 0; i < 4; i++) {
- sessionKey[i] += 50;
- }
- ISAACCipher outCipher = null;// new ISAACCipher(sessionKey);
- /*
- * Now, the login has completed, and we do the appropriate
- * things to fire off the chain of events which will load
- * and check the saved games etc.
- */
- session.getFilterChain().remove("protocol");
- logger.info("Remove Protocol");
- session.getFilterChain().addFirst("protocol", new ProtocolCodecFilter(RS2CodecFactory.GAME));
- logger.info("Add Protocol");
- PlayerDetails pd = new PlayerDetails(session, name, pass, 0, inCipher, outCipher);
- logger.info("Loaded");
- World.getWorld().load(pd);
- logger.info("finished");
- }
- break;
- }
- in.rewind();
- return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement