Advertisement
Guest User

Untitled

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