Added shutdown command, added character limit

This commit is contained in:
Light2
2013-12-15 02:15:08 +01:00
parent 1f4458997b
commit 60373502e1
7 changed files with 67 additions and 11 deletions
+37
View File
@@ -35,6 +35,8 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.mina.core.service.IoHandler;
import protocol.swg.ChatSystemMessage;
import net.engio.mbassy.bus.config.BusConfiguration;
import resources.common.RadialOptions;
import resources.common.ThreadMonitor;
@@ -108,6 +110,7 @@ public class NGECore {
private Config config = null;
private volatile boolean isShuttingDown = false;
private ConcurrentHashMap<Integer, Client> clients = new ConcurrentHashMap<Integer, Client>();
@@ -503,5 +506,39 @@ public class NGECore {
return eventBusConfig;
}
public void initiateShutdown() {
if(isShuttingDown)
return;
try {
for(int minutes = 15; minutes > 1; minutes--) {
simulationService.notifyAllClients(new ChatSystemMessage("The server will be shutting down soon. Please find a safe place to logout. (" + minutes + " minutes left)", (byte) 0 ).serialize());
Thread.sleep(60000);
}
setGalaxyStatus(3);
simulationService.notifyAllClients(new ChatSystemMessage("The server will be shutting down soon. Please find a safe place to logout. (" + 1 + " minutes left)", (byte) 0 ).serialize());
Thread.sleep(30000);
simulationService.notifyAllClients(new ChatSystemMessage("You will be disconnected in 30 seconds so the server can perform a final save before shutting down. Please find a safe place to logout now.", (byte) 0 ).serialize());
Thread.sleep(20000);
simulationService.notifyAllClients(new ChatSystemMessage("You will be disconnected in 10 seconds so the server can perform a final save before shutting down. Please find a safe place to logout now.", (byte) 0 ).serialize());
Thread.sleep(10000);
simulationService.notifyAllClients(new ChatSystemMessage("You will now be disconnected so the server can perform a final save before shutting down.", (byte) 0 ).serialize());
synchronized(getActiveConnectionsMap()) {
for(Client client : getActiveConnectionsMap().values()) {
client.getSession().close(true);
}
}
System.exit(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}