Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean doDecode(IoSession session, ByteBuffer in,
- ProtocolDecoderOutput out) {
- //synchronized (session) {
- 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:
- if (2 <= in.remaining()) {
- int protocol = in.get() & 0xff;
- @SuppressWarnings("unused")
- int nameHash = in.get() & 0xff;
- if (protocol == 14) {
- long serverSessionKey = ((long) (java.lang.Math
- .random() * 99999999D) << 32)
- + (long) (java.lang.Math.random() * 99999999D);
- StaticPacketBuilder s1Response = new StaticPacketBuilder();
- s1Response
- .setBare(true)
- .addBytes(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 })
- .addByte((byte) 0).addLong(serverSessionKey);
- session.setAttribute("SERVER_SESSION_KEY",
- serverSessionKey);
- session.write(s1Response.toPacket());
- session.setAttribute("LOGIN_STAGE", 1);
- }
- return true;
- } else {
- in.rewind();
- return false;
- }
- case 1:
- @SuppressWarnings("unused")
- int loginType = -1,
- loginPacketSize = -1,
- loginEncryptPacketSize = -1;
- if (2 <= in.remaining()) {
- loginType = in.get() & 0xff; // should be 16 or 18
- System.out.println("loginType: "+loginType);
- /*loginPacketSize = in.get() & 0xff;
- loginEncryptPacketSize = loginPacketSize - (36 + 1 + 1 + 2);
- if (loginPacketSize <= 0 || loginEncryptPacketSize <= 0) {
- System.out.println("Zero or negative login size.");
- session.close();
- return false;
- }*/
- } else {
- in.rewind();
- return false;
- }
- if (loginPacketSize <= in.remaining()) {
- int magic = in.getUnsignedShort();
- int version = in.get();
- if (magic != 16) {
- System.out.println("Wrong magic id.");
- session.close();
- return false;
- }
- int uid = in.getInt();
- String name = readRS2String(in);
- String pass = readRS2String(in);
- int cacheLen = in.get();
- System.out.println(cacheLen+":"+name+":"+pass);
- for (int i = 0; i < 17; i++)
- in.getInt();
- //System.out.println(name+":"+pass);
- load(session, uid, name, pass, version);
- // WorkerThread.load(session, name, pass, inC, outC);
- session.getFilterChain().remove("protocolFilter");
- session.getFilterChain().addLast("protocolFilter",
- new ProtocolCodecFilter(new GameCodecFactory()));
- return true;
- } else {
- in.rewind();
- return false;
- }
- }
- //}
- return false;
- }
Add Comment
Please, Sign In to add comment