SHARE
TWEET

Untitled

a guest Jun 15th, 2017 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package rsca.gs.phandler;
  2.  
  3. import java.net.InetSocketAddress;
  4.  
  5. import org.apache.mina.common.IoSession;
  6.  
  7. import rsca.config.Config;
  8. import rsca.gs.Instance;
  9. import rsca.gs.builders.RSCPacketBuilder;
  10. import rsca.gs.connection.Packet;
  11. import rsca.gs.model.Player;
  12. import rsca.gs.model.World;
  13. import rsca.gs.phandler.PacketHandler;
  14. import rsca.gs.util.Logger;
  15. import rsca.gs.util.RSA;
  16.  
  17. public class PlayerLogin implements PacketHandler {
  18.  
  19.     /**
  20.      * World instance
  21.      */
  22.     public static final World world = Instance.getWorld();
  23.  
  24.     public void handlePacket(Packet p1, IoSession session) throws Exception {
  25.        
  26.         Player player = (Player) session.getAttachment();
  27.         final String ip = ((InetSocketAddress) session.getRemoteAddress()).getAddress().toString().replaceAll("/", "");
  28.        
  29.         byte loginCode;
  30.         try {
  31.            
  32.             byte[] data = RSA.decrypt(p1.getData());
  33.             Packet p = new Packet(session, data);
  34.            
  35.             boolean reconnecting = (p.readByte() == 1);
  36.  
  37.             int clientVersion = p.readInt();
  38.            
  39.            
  40.             if(Config.SERVER_VERSION != clientVersion) {
  41.                 Logger.println("ip: " + ip + " | clientversion: " + clientVersion + " : " + Config.SERVER_VERSION);
  42.             }
  43.            
  44.             int[] sessionKeys = new int[4];
  45.             for (int key = 0; key < sessionKeys.length; key++) {
  46.                 sessionKeys[key] = p.readInt();
  47.             }
  48.             String username = "";
  49.             String password = "";
  50.            
  51.             username = p.readString(20).trim();
  52.             password = p.readString(20).trim();
  53.            
  54.             if (world.countPlayers() >= Config.MAX_PLAYERS) {
  55.                 loginCode = 10;
  56.             }
  57.             else if (clientVersion < Config.SERVER_VERSION) {
  58.                 loginCode = 4;
  59.             }
  60.             else if (!player.setSessionKeys(sessionKeys)) {
  61.                 loginCode = 5;
  62.             }
  63.             else {
  64.                 player.load(username, password, 0, reconnecting);
  65.                 if (clientVersion < 39) {
  66.                     player.clientWarn(true);
  67.                 }
  68.                 return;
  69.             }
  70.         } catch (Exception e) {
  71.             System.err.println("Login exception with: " + ip);
  72.             e.printStackTrace();
  73.             loginCode = 4;
  74.         }
  75.        
  76.         RSCPacketBuilder pb = new RSCPacketBuilder();
  77.         pb.setBare(true);
  78.         pb.addByte((byte) loginCode);
  79.         session.write(pb.toPacket());
  80.         player.destroy(true);
  81.     }
  82. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top