This will restart your server is you have 0 players online.
It is cached at start up and it is static, so it has a low priority towards lagg etc. It will monitor the server every 5 minutes to check the users online, if theres 0 users, it'll suspect that the server is crashed. And will restart
When it restarts, aslong as your server machine is fast, it'll restart almost instantly after it's monitoration
new class ( ../net/> Monitor.java )
PHP Code:
package palidino76.rs2.net;
import palidino76.rs2.Engine;
public class Monitor implements Runnable {
/* Varibles */
public static final boolean restart = true;
public static final int timer = 120;
public Restarter() {
if(Engine.getPlayerCount() == 0) {
(new Thread(this)).start();
}
}
public void run() {
try {
Thread.sleep(timer * 300000);
} catch (Exception e) {}
System.out.println("[SERVER] 0 Users online. The server has suspected a server Crash.");
System.out.println("[SERVER] Server restarted.");
try {
Thread.sleep(2000);
} catch (Exception e) {}
try {
Thread.sleep(2000);
} catch (Exception e) {}
try {
Thread.sleep(2000);
} catch (Exception e) {}
System.exit(0);
}
}
Change imports though
In your Server.java 'main' method
PHP Code:
if (Minitor.restart) {
new Restarter();
}
Add to run.bat under @echo off
and under the userver thing (palidino/server 43597)
Add imports and done