Advertisement
Guest User

Untitled

a guest
May 1st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.69 KB | None | 0 0
  1. package src;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.DataInputStream;
  5. import java.io.File;
  6. import java.io.FileInputStream;
  7. import java.io.FileReader;
  8. import java.io.IOException;
  9. import java.net.URL;
  10. import java.net.URLConnection;
  11. import java.util.ArrayList;
  12. import java.util.Properties;
  13. import java.sql.*;
  14. import java.security.*;
  15. import java.io.IOException;
  16. import java.io.PrintStream;
  17. import java.util.zip.CRC32;
  18.  
  19. import login.*;
  20.  
  21.  
  22. public class server implements Runnable {
  23.  
  24.     public static int Uid, MIN;
  25.    
  26.     public static void timers() {
  27.         PlayerHandler.upTimeS++;
  28.         if (PlayerHandler.upTimeS == 60) {
  29.             PlayerHandler.upTimeM += 1;
  30.             PlayerHandler.upTimeS = 0;
  31.             if(MIN == 3)
  32.                 connections.clear();
  33.             MIN++;
  34.         }
  35.                    
  36.         if (PlayerHandler.upTimeM == 60) {
  37.             PlayerHandler.upTimeH += 1;
  38.             PlayerHandler.upTimeM = 0;
  39.         }
  40.     }
  41.    
  42.     public static String MySQLURL = "jdbc:mysql://localhost/new_forum";
  43.     public static String MySQLUser = "root";
  44.     public static String MySQLPassword = "not gunna happen, Ryan :P";
  45.     public static Connection conn;
  46.  
  47.     public static void createConnection() {
  48.         try {
  49.             Class.forName("com.mysql.jdbc.Driver").newInstance();
  50.             conn = DriverManager.getConnection(MySQLURL, MySQLUser,
  51.                     MySQLPassword);
  52.             misc.println("mysql connected");
  53.         } catch (Exception e) {
  54.             e.printStackTrace();
  55.         }
  56.     }
  57.    
  58.     public static connector connec = null;
  59.     public static boolean pickup = true;
  60.     public static boolean fightcaves = true;
  61.     public static ArrayList<String> banned = new ArrayList<String>();
  62.     public static ArrayList<Integer> bannedUid = new ArrayList<Integer>();
  63.     public static server clientHandler = null;
  64.     public static java.net.ServerSocket clientListener = null;
  65.     public static int MaxConnections = 100000;
  66.     public static int[] ConnectionCount = new int[MaxConnections];
  67.     public static ArrayList<String> connections = new ArrayList<String>();
  68.     public static MacroDetection macroDetection = new MacroDetection();
  69.     public static ClanChat clanChat = new ClanChat();
  70.     public static String[] Connections = new String[MaxConnections];
  71.     public static int delay = 50;
  72.     public static int NorthRock = 0;
  73.     public static int EastRock = 0;
  74.     public static int SouthRock = 0;
  75.     public static int WestRock = 0;
  76.     public static long delayUpdate = 0, lastRunite = 0;
  77.     public static DoorHandler doorHandler;
  78.     public static int EnergyRegian = 60;
  79.     public static boolean enforceClient = false;
  80.     public static GraphicsHandler GraphicsHandler = null;
  81.     public static ItemHandler itemHandler = null;
  82.     public static commandHandler commandHandler = null;
  83.     public static Wearing Wearing = null;
  84.     public static clickingSkills clickingSkills = null;
  85.     public static special special = null;
  86.     public static setConfig setConfig = null;
  87.     public static textHandler textHandler = null;
  88.     public static potions potions = null;
  89.     public static clickingMost clickingMost = null;
  90.     public static GetWepSound GetWepSound = null;
  91.     public static int[] ranks = new int[11];
  92.     public static String[] rankPpl = new String[11];
  93.     public static boolean loginServerConnected = true;
  94.     public static NPCHandler npcHandler = null;
  95.     public static ArrayList<Object> objects = new ArrayList<Object>();
  96.     public static PlayerHandler playerHandler = null;
  97.     public static ReportAbuse reportAbuse = null;  
  98.     public static int DuelPlace = 6402;
  99.     public static String[] DuelPlaces = new String[101];
  100.     public static int[] Dranks = new int[101];
  101.     public static String[] Drank = new String[101];
  102.     public static int[] Dranks2 = new int[101];
  103.     public static String[] Drank2 = new String[101];
  104.     public static int BattleNumber = 51;
  105.     public static WorldObject worldObject = new WorldObject();
  106.     public static int[][] runesRequired = new int[24][9];
  107.     public static int serverlistenerPort = 43594;
  108.     public static ShopHandler shopHandler = null;
  109.     public static boolean ShutDown = false;
  110.     public static boolean shutdownClientHandler;
  111.     public static int ShutDownCounter = 0;
  112.     public static boolean shutdownServer = false;
  113.     public static long startTime;
  114.     public static boolean trading = true, dueling = true, pking = true;
  115.     public static int updateSeconds = 1800;
  116.     public static boolean updateServer = false;
  117.     public static int world = 1;
  118.  
  119.     public static void calcTime() {
  120.         long curTime = System.currentTimeMillis();
  121.  
  122.         updateSeconds = 1800 - ((int) (curTime - startTime) / 1800);
  123.         // if (updateSeconds == 0)
  124.         // shutdownServer = true;
  125.     }
  126.  
  127.     public static void logError(String message) {
  128.         misc.println(message);
  129.     }
  130.  
  131.     public static void main(java.lang.String args[]) throws NullPointerException {
  132.         try {
  133.             connec = new connector();
  134.             connec.start();
  135.             connector.c = connec;
  136.             System.out.println("Login Server: Connected");
  137.             EventManager.initialise();
  138.             createConnection();
  139.             clanChat.refreshArrayList();
  140.             PlayerHandler.getID();
  141.             File f = new File("server.ini");
  142.  
  143.             if (!f.exists()) {
  144.                 misc.println("server.ini doesn't exist!");
  145.             }
  146.             Properties p = new Properties();
  147.  
  148.             p.load(new FileInputStream("./server.ini"));
  149.             int client = Integer.parseInt(p.getProperty("ClientRequired").trim());
  150.  
  151.             world = Integer.parseInt(p.getProperty("WorldId"));
  152.             serverlistenerPort = Integer.parseInt(
  153.                     p.getProperty("ServerPort").trim());
  154.             Uid = Integer.parseInt(p.getProperty("UID").trim());
  155.         } catch (Exception e) {
  156.             misc.println("Error loading settings");
  157.             e.printStackTrace();
  158.         }
  159.         clientHandler = new server();
  160.         Thread t = new Thread(clientHandler);
  161.  
  162.         t.start();
  163.         t.setPriority(2);
  164.        
  165.         playerHandler = new PlayerHandler();
  166.         npcHandler = new NPCHandler();
  167.         itemHandler = new ItemHandler();
  168.         commandHandler = new commandHandler();
  169.         doorHandler = new DoorHandler();
  170.         GraphicsHandler = new GraphicsHandler();
  171.  
  172.         Wearing = new Wearing();
  173.         special = new special();
  174.         clickingSkills = new clickingSkills();
  175.         reportAbuse = new ReportAbuse();
  176.         setConfig = new setConfig();
  177.         textHandler = new textHandler();
  178.         GetWepSound = new GetWepSound();
  179.         potions = new potions();
  180.         clickingMost = new clickingMost();
  181.         shopHandler = new ShopHandler();
  182.         GraphicsHandler = new GraphicsHandler();
  183.         process proc = new process();
  184.         Thread g = new Thread(proc);
  185.         g.setDaemon(true);
  186.         g.start();
  187.         g.setPriority(1);
  188.     }
  189.     public int[] ips = new int[1000];
  190.  
  191.     public long[] lastConnect = new long[1000];
  192.  
  193.     public server() {// the current way of controlling the server at runtime and a great
  194.         // debugging/testing tool
  195.         // jserv js = new jserv(this);
  196.         // js.start();
  197.     }
  198.  
  199.     public void banHost(String host, int num) {
  200.         if (false) {
  201.             banned.add(host);
  202.         } else {
  203.             try {
  204.                 misc.println("BANNING HOST " + host + " (flooding)");
  205.                 banned.add(host);
  206.                 delay = 2000;
  207.                 delayUpdate = System.currentTimeMillis() + 60000;
  208.             } catch (Exception e) {
  209.                 e.printStackTrace();
  210.             }
  211.         }
  212.  
  213.     }
  214.  
  215.     public boolean checkHost(String host) {
  216.         for (String h : banned) {
  217.             if (h.equals(host)) {
  218.                 return false;
  219.             }
  220.         }
  221.         int num = 0;
  222.  
  223.         for (String h : connections) {
  224.             if (host.equals(h)) {
  225.                 num++;
  226.             }
  227.         }
  228.         if (num > 5) {
  229.             banHost(host, num);
  230.             return false;
  231.         }
  232.         if (num >= 3) {
  233.             return false;
  234.         }
  235.  
  236.         if (checkLog("ipbans", host)) {
  237.             System.out.println("They are in ip ban list!");
  238.             return false; // ip ban added by bakatool
  239.         }
  240.         return true;
  241.     }
  242.  
  243.     public boolean checkLog(String file, String playerName) {
  244.         // check ipbans -bakatool
  245.         try {
  246.             BufferedReader in = new BufferedReader(
  247.                     new FileReader("config//" + file + ".txt"));
  248.             String data = null;
  249.  
  250.             while ((data = in.readLine()) != null) {
  251.                 if (playerName.equalsIgnoreCase(data)) {
  252.                     return true;
  253.                 }
  254.             }
  255.         } catch (IOException e) {
  256.             System.out.println("Critical error while checking for data!");
  257.             System.out.println(file + ":" + playerName);
  258.             e.printStackTrace();
  259.         }
  260.         return false;
  261.     }
  262.  
  263.     public int getConnections(String host) {
  264.         int count = 0;
  265.  
  266.         for (Player p : PlayerHandler.players) {
  267.             if ((p != null) && !p.disconnected
  268.                     && p.connectedFrom.equalsIgnoreCase(host)) {
  269.                 count++;
  270.             }
  271.         }
  272.         return count;
  273.     }
  274.  
  275.     public void killServer() {}
  276.  
  277.     public void run() {
  278.         // setup the listener
  279.         try {
  280.             shutdownClientHandler = false;
  281.             clientListener = new java.net.ServerSocket(serverlistenerPort, 1,
  282.                     null);
  283.             misc.println("SlashScape V2 - Online!");
  284.             while (true) {
  285.                 try {
  286.                     java.net.Socket s = clientListener.accept();
  287.  
  288.                     s.setTcpNoDelay(true);
  289.                     String connectingHost = s.getInetAddress().getHostName();
  290.                     //if (checkHost(connectingHost)) {
  291.                         playerHandler.newPlayerClient(s, connectingHost);
  292.                    // } else {
  293.                    //     s.close();
  294.                    // }
  295.                     if ((delayUpdate > 0)
  296.                             && (System.currentTimeMillis() > delayUpdate)) {
  297.                         delay = 50;
  298.                         delayUpdate = 0;
  299.                     }
  300.                     Thread.sleep(200);
  301.                 } catch (Exception e) {
  302.                     logError(e.getMessage());
  303.                 }
  304.             }
  305.         } catch (java.io.IOException ioe) {
  306.             if (!shutdownClientHandler) {
  307.                 misc.println("Server is already in use.");
  308.             } else {
  309.                 misc.println("ClientHandler was shut down.");
  310.             }
  311.         }
  312.     }
  313. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement