Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 5.72 KB | None | 0 0
  1. package dragonkk.rs2rsps.net.codec;
  2.  
  3. import java.io.File;
  4. import java.util.GregorianCalendar;
  5.  
  6. import Codeusa.wtfBase.io.InStream;
  7. import Codeusa.wtfBase.io.OutStream;
  8. import Codeusa.wtfBase.model.World;
  9. import Codeusa.wtfBase.model.player.Player;
  10. import Codeusa.wtfBase.util.Constants;
  11. import Codeusa.wtfBase.util.Misc;
  12. import Codeusa.wtfBase.util.Serializer;
  13.  
  14.  
  15. public class LoginDecoder {
  16.  
  17.     private static File AccountFile(String name) {
  18.         return new File("./data/savedgames/" + name + ".ser");
  19.     }
  20.  
  21.     private static File WorldAccountFile(String name) {
  22.         return new File("./data/savedWorldGames/" + name + ".ser");
  23.     }
  24.  
  25.     public static void decode(ConnectionHandler p, InStream in) {
  26.         if (p.getConnectionStage() == Constants.LOGIN_START) {
  27.             OutStream outstream = new OutStream();
  28.             outstream.writeByte(0);
  29.             outstream.writeLong(p.getSessionKey());
  30.             p.write(outstream);
  31.             p.setConnectionStage(Constants.LOGIN_CYPTION);
  32.         } else if (p.getConnectionStage() == Constants.LOGIN_CYPTION) {
  33.             if (3 > in.remaining()) {
  34.                 return;
  35.             }
  36.             int loginType = in.readUnsignedByte(); //world 16 normal, 18 reconnect
  37.             if (loginType != 16 && loginType != 18) {
  38.                 p.setConnectionStage(Constants.DISCONNECT);
  39.                 return;
  40.             }
  41.             int loginPacketSize = in.readUnsignedShort();
  42.             if (loginPacketSize > in.remaining()) {
  43.                 return;
  44.             }
  45.             int clientVersion = in.readInt();
  46.             if (clientVersion != Constants.REVISION) {
  47.                 p.setConnectionStage(Constants.DISCONNECT);
  48.                 return;
  49.             }
  50.             int unknown0 = in.readUnsignedByte();
  51.             int displayMode = in.readUnsignedByte();
  52.             p.setDisplayMode(displayMode);
  53.             int screenSizeX = in.readUnsignedShort();
  54.             int screenSizeY = in.readUnsignedShort();
  55.             int unknown3 = in.readUnsignedByte();
  56.             InStream inStream1 = new InStream(24); //new dunno
  57.             inStream1.addBytes(in.buffer(), in.offset(), 24);
  58.             in.skip(24);
  59.             String settings = in.readRS2String();
  60.             int unknown4 = in.readInt();
  61.             int size = in.readUnsignedByte();
  62.             InStream inStream2 = new InStream(size); //options etc
  63.             inStream2.addBytes(in.buffer(), in.offset(), size);
  64.             in.skip(size);
  65.             InStream inStream3 = new InStream(14); //new dunno
  66.             inStream1.addBytes(in.buffer(), in.offset(), 14);
  67.             in.skip(14);
  68.             in.readShort(); //new dunno
  69.             in.readLong(); //new dunno
  70.             int[] idxSizes = new int[33];
  71.             for(int index = 0; index < idxSizes.length; index++)
  72.                 idxSizes[index] = in.readInt();
  73.             in.skip(6);
  74.             if(in.readUnsignedByte() != 10) {
  75.                 p.setConnectionStage(Constants.DISCONNECT);
  76.                 return;
  77.             }
  78.             int sessionKey[] = new int[4];
  79.             for (int i = 0; i < 4; i++)
  80.                 sessionKey[i] = in.readInt();
  81.             long l = in.readLong();
  82.             int hash = (int) (31 & l >> 16);
  83.             if (hash != p.getNameHash()) {
  84.                 p.setConnectionStage(Constants.DISCONNECT);
  85.                 return;
  86.             }
  87.             String Username = Misc.formatPlayerNameForProtocol(Misc.longToString(l));
  88.             String Password = in.readRS2String();
  89.             //ISAAC, not using
  90.             for (int i = 0; i < 4; i++) sessionKey[i] += 50;
  91.  
  92.             byte OpCode = 0;
  93.             File account = AccountFile(Username);
  94.             Player player = null;
  95.             if (account == null || Username == null || Password == null) {
  96.                 OpCode = Constants.INVALID_PASSWORD;
  97.             } else if (World.isOnList(Username)) {
  98.                 OpCode = Constants.ALREADY_ONLINE;
  99.             } else if (!account.exists()) {
  100.                 player = new Player(Username, Password, new GregorianCalendar(), new GregorianCalendar(), (short) 1, "", (byte) 1);
  101.                 OpCode = 2;
  102.             } else {
  103.                 player = Serializer.LoadAccount(account);
  104.                 if (!Password.equals(player.getPassword())) {
  105.                     OpCode = Constants.INVALID_PASSWORD;
  106.                 } else if (player.isBanned()) {
  107.                     OpCode = Constants.BANNED;
  108.                 } else {
  109.                     OpCode = 2;
  110.                 }
  111.             }
  112.             long waitTime = 0;
  113.             if(OpCode == 2) {
  114.                 String ip = "" + p.getChannel().getLocalAddress();
  115.                 ip = ip.replaceAll("/", "");
  116.                 ip = ip.replaceAll(" ", "");
  117.                 ip = ip.substring(0, ip.indexOf(":"));
  118.                 int ipInt = Misc.IPAddressToNumber(ip);
  119.                 if(World.getIps().containsKey(ipInt)) {
  120.                     waitTime = (System.currentTimeMillis() - World.getIps().get(ipInt))/1000;
  121.                     if(waitTime <= 42) {
  122.                         //OpCode = 21;
  123.                     }
  124.                 }
  125.             }
  126.             OutStream outstream = new OutStream();
  127.             outstream.writeByte(OpCode);
  128.             if(OpCode == 21)
  129.                 outstream.writeByte((int) (42-waitTime));
  130.             //login timer opcode 21 byte time
  131.             p.write(outstream);
  132.  
  133.             if (OpCode != 2) {
  134.                 p.setConnectionStage(Constants.DISCONNECT);
  135.                 return;
  136.             }
  137.             p.setConnectionStage(Constants.REMOVE_ID);
  138.             p.setPlayer(player);
  139.             World.registerConnection(p);
  140.         } else {
  141.             p.setConnectionStage(Constants.DISCONNECT);
  142.         }
  143.     }
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement