Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- s = new Server();
- s.playerHandler = new PlayerHandler();
- s.worldO = new WorldObjects();
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- s.myConnection = DriverManager.getConnection("jdbc:mysql://d-z317.com:3306/dontneedthis?useUnicode=true&characterEncoding=UTF-8", "dontneedthis", "dontneedthis");
- s.myStmt = s.myConnection.createStatement();
- } catch (Exception ex) { }
- s.obelisks = new Obelisks();
- s.npcHandler = new NPCHandler();
- s.itemHandler = new ItemHandler();
- s.pc = new PestControl();
- s.shopHandler = new ShopHandler();
- s.magicHandler = new MagicHandler();
- VirtualWorld.init();
- (new Thread(s)).start();
- int waitFails = 0;
- long lastTicks = System.currentTimeMillis();
- long timeSpent = 0;
- while (true) {
- try {
- Server.s.restartTime++;
- s.playerHandler.process();
- s.npcHandler.process();
- s.itemHandler.process();
- s.shopHandler.process();
- s.worldO.process();
- s.obelisks.process();
- s.garbageCollectDelay--;
- if (s.garbageCollectDelay == 0) {
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- s.myConnection = DriverManager.getConnection("jdbc:mysql://d-z317.com:3306/dontneedthis?useUnicode=true&characterEncoding=UTF-8", "dontneedthis", "dontneedthis");
- s.myStmt = s.myConnection.createStatement();
- } catch (Exception ex) { }
- s.garbageCollectDelay = 240;
- System.gc();
- }
- timeSpent = System.currentTimeMillis() - lastTicks;
- s.msLag = (int)(timeSpent);
- if (timeSpent >= s.CYCLE_TIME)
- timeSpent = 0;
- } catch (Exception _ex) {
- System.err.println("Server Exception");
- _ex.printStackTrace();
- }
- try {
- Thread.sleep(s.CYCLE_TIME-timeSpent);
- } catch (Exception _ex) {
- System.err.println("Thread Sleep Error");
- }
- lastTicks = System.currentTimeMillis();
- }
- }
- public void run() {
- try {
- newSocket = new ServerSocket(SERVER_PORT, 1, null);
- System.out.println("Starting Server On Port: " + SERVER_PORT);
- } catch (Exception e) {
- System.out.println("Error Starting Server On Port: "+SERVER_PORT);
- System.exit(0);
- }
- Socket s = null;
- String ConnectingIp = null;
- while (true) {
- try {
- s = newSocket.accept();
- s.setTcpNoDelay(true);
- ConnectingIp = s.getInetAddress().getHostAddress();
- if(connectionsFromIP(ConnectingIp) < 2) {
- System.out.println("Client connected from " + ConnectingIp);
- playerHandler.newPlayerClient(s, ConnectingIp);
- connections.add(ConnectingIp);
- } else {
- System.out.println("Client rejected from " + ConnectingIp);
- s.close();
- }
- } catch (Exception ea) {
- ea.printStackTrace();
- try {
- s.close();
- } catch (Exception e) {
- }
- }
- try {
- Thread.sleep(1);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement