Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package src;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileReader;
- import java.io.IOException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.ArrayList;
- import java.util.Properties;
- import java.sql.*;
- import java.security.*;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.util.zip.CRC32;
- import login.*;
- public class server implements Runnable {
- public static int Uid;
- public static void timers() {
- PlayerHandler.upTimeS++;
- if (PlayerHandler.upTimeS == 60) {
- PlayerHandler.upTimeM += 1;
- PlayerHandler.upTimeS = 0;
- }
- if (PlayerHandler.upTimeM == 60) {
- PlayerHandler.upTimeH += 1;
- PlayerHandler.upTimeM = 0;
- }
- }
- public static String MySQLURL = "jdbc:mysql://localhost/new_forum";
- public static String MySQLUser = "root";
- public static String MySQLPassword = "not gunna happen, Ryan :P";
- public static Connection conn;
- public static void createConnection() {
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- conn = DriverManager.getConnection(MySQLURL, MySQLUser,
- MySQLPassword);
- misc.println("mysql connected");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static connector connec = null;
- public static boolean pickup = true;
- public static boolean fightcaves = true;
- public static ArrayList<String> banned = new ArrayList<String>();
- public static ArrayList<Integer> bannedUid = new ArrayList<Integer>();
- public static server clientHandler = null;
- public static java.net.ServerSocket clientListener = null;
- public static int MaxConnections = 100000;
- public static int[] ConnectionCount = new int[MaxConnections];
- public static ArrayList<String> connections = new ArrayList<String>();
- public static MacroDetection macroDetection = new MacroDetection();
- public static ClanChat clanChat = new ClanChat();
- public static String[] Connections = new String[MaxConnections];
- public static int delay = 50;
- public static int NorthRock = 0;
- public static int EastRock = 0;
- public static int SouthRock = 0;
- public static int WestRock = 0;
- public static long delayUpdate = 0, lastRunite = 0;
- public static DoorHandler doorHandler;
- public static int EnergyRegian = 60;
- public static boolean enforceClient = false;
- public static GraphicsHandler GraphicsHandler = null;
- public static ItemHandler itemHandler = null;
- public static commandHandler commandHandler = null;
- public static Wearing Wearing = null;
- public static clickingSkills clickingSkills = null;
- public static special special = null;
- public static setConfig setConfig = null;
- public static textHandler textHandler = null;
- public static potions potions = null;
- public static clickingMost clickingMost = null;
- public static GetWepSound GetWepSound = null;
- public static int[] ranks = new int[11];
- public static String[] rankPpl = new String[11];
- public static boolean loginServerConnected = true;
- public static NPCHandler npcHandler = null;
- public static ArrayList<Object> objects = new ArrayList<Object>();
- public static PlayerHandler playerHandler = null;
- public static ReportAbuse reportAbuse = null;
- public static int DuelPlace = 6402;
- public static String[] DuelPlaces = new String[101];
- public static int[] Dranks = new int[101];
- public static String[] Drank = new String[101];
- public static int[] Dranks2 = new int[101];
- public static String[] Drank2 = new String[101];
- public static int BattleNumber = 51;
- public static WorldObject worldObject = new WorldObject();
- public static int[][] runesRequired = new int[24][9];
- public static int serverlistenerPort = 43594;
- public static ShopHandler shopHandler = null;
- public static boolean ShutDown = false;
- public static boolean shutdownClientHandler;
- public static int ShutDownCounter = 0;
- public static boolean shutdownServer = false;
- public static long startTime;
- public static boolean trading = true, dueling = true, pking = true;
- public static int updateSeconds = 1800;
- public static boolean updateServer = false;
- public static int world = 1;
- public static void calcTime() {
- long curTime = System.currentTimeMillis();
- updateSeconds = 1800 - ((int) (curTime - startTime) / 1800);
- // if (updateSeconds == 0)
- // shutdownServer = true;
- }
- public static void logError(String message) {
- misc.println(message);
- }
- public static void main(java.lang.String args[]) throws NullPointerException {
- try {
- connec = new connector();
- connec.start();
- connector.c = connec;
- System.out.println("Login Server: Connected");
- EventManager.initialise();
- createConnection();
- clanChat.refreshArrayList();
- PlayerHandler.getID();
- File f = new File("server.ini");
- if (!f.exists()) {
- misc.println("server.ini doesn't exist!");
- }
- Properties p = new Properties();
- p.load(new FileInputStream("./server.ini"));
- int client = Integer.parseInt(p.getProperty("ClientRequired").trim());
- world = Integer.parseInt(p.getProperty("WorldId"));
- serverlistenerPort = Integer.parseInt(
- p.getProperty("ServerPort").trim());
- Uid = Integer.parseInt(p.getProperty("UID").trim());
- } catch (Exception e) {
- misc.println("Error loading settings");
- e.printStackTrace();
- }
- clientHandler = new server();
- Thread t = new Thread(clientHandler);
- t.start();
- t.setPriority(2);
- playerHandler = new PlayerHandler();
- npcHandler = new NPCHandler();
- itemHandler = new ItemHandler();
- commandHandler = new commandHandler();
- doorHandler = new DoorHandler();
- GraphicsHandler = new GraphicsHandler();
- Wearing = new Wearing();
- special = new special();
- clickingSkills = new clickingSkills();
- reportAbuse = new ReportAbuse();
- setConfig = new setConfig();
- textHandler = new textHandler();
- GetWepSound = new GetWepSound();
- potions = new potions();
- clickingMost = new clickingMost();
- shopHandler = new ShopHandler();
- GraphicsHandler = new GraphicsHandler();
- process proc = new process();
- Thread g = new Thread(proc);
- g.setDaemon(true);
- g.start();
- g.setPriority(1);
- }
- public int[] ips = new int[1000];
- public long[] lastConnect = new long[1000];
- public server() {// the current way of controlling the server at runtime and a great
- // debugging/testing tool
- // jserv js = new jserv(this);
- // js.start();
- }
- public void banHost(String host, int num) {
- if (false) {
- banned.add(host);
- } else {
- try {
- misc.println("BANNING HOST " + host + " (flooding)");
- banned.add(host);
- delay = 2000;
- delayUpdate = System.currentTimeMillis() + 60000;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public boolean checkHost(String host) {
- for (String h : banned) {
- if (h.equals(host)) {
- return false;
- }
- }
- int num = 0;
- for (String h : connections) {
- if (host.equals(h)) {
- num++;
- }
- }
- if (num > 5) {
- banHost(host, num);
- return false;
- }
- if (num >= 3) {
- return false;
- }
- if (checkLog("ipbans", host)) {
- System.out.println("They are in ip ban list!");
- return false; // ip ban added by bakatool
- }
- return true;
- }
- public boolean checkLog(String file, String playerName) {
- // check ipbans -bakatool
- try {
- BufferedReader in = new BufferedReader(
- new FileReader("config//" + file + ".txt"));
- String data = null;
- while ((data = in.readLine()) != null) {
- if (playerName.equalsIgnoreCase(data)) {
- return true;
- }
- }
- } catch (IOException e) {
- System.out.println("Critical error while checking for data!");
- System.out.println(file + ":" + playerName);
- e.printStackTrace();
- }
- return false;
- }
- public int getConnections(String host) {
- int count = 0;
- for (Player p : PlayerHandler.players) {
- if ((p != null) && !p.disconnected
- && p.connectedFrom.equalsIgnoreCase(host)) {
- count++;
- }
- }
- return count;
- }
- public void killServer() {}
- public void run() {
- // setup the listener
- try {
- shutdownClientHandler = false;
- clientListener = new java.net.ServerSocket(serverlistenerPort, 1,
- null);
- misc.println("SlashScape V2 - Online!");
- while (true) {
- try {
- java.net.Socket s = clientListener.accept();
- s.setTcpNoDelay(true);
- String connectingHost = s.getInetAddress().getHostName();
- if (true) {
- if (connectingHost.contains(
- "74-129-182-147.dhcp.insightbb.com")) {
- s.close();
- } else {
- connections.add(connectingHost);
- if (checkHost(connectingHost)) {
- playerHandler.newPlayerClient(s, connectingHost);
- } else {
- s.close();
- }
- }
- } else {
- s.close();
- }
- if ((delayUpdate > 0)
- && (System.currentTimeMillis() > delayUpdate)) {
- delay = 50;
- delayUpdate = 0;
- }
- Thread.sleep(50);
- } catch (Exception e) {
- logError(e.getMessage());
- }
- }
- } catch (java.io.IOException ioe) {
- if (!shutdownClientHandler) {
- misc.println("Server is already in use.");
- } else {
- misc.println("ClientHandler was shut down.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement