// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . // ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· // ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ // ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ // ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ // Magicbane Emulator Project © 2013 - 2022 // www.magicbane.com package engine.devcmd.cmds; import engine.devcmd.AbstractDevCmd; import engine.gameManager.GracefulShutdown; import engine.objects.AbstractGameObject; import engine.objects.PlayerCharacter; /** * Devcmd: graceful shutdown. * * Announces a countdown to every player, writes all online characters to the * database (skills/powers, stat modifiers, experience) and then stops the * login and world servers. Unlike './reboot' - which simply runs mbrestart.sh * and therefore kills the JVMs with SIGKILL - nothing still parked in a * deferred database job is lost. * * Usage: ./shutdown [seconds] (default 60, maximum 3600) */ public class ShutdownCmd extends AbstractDevCmd { private static final int DEFAULT_DELAY_SECONDS = 60; private static final int MAX_DELAY_SECONDS = 3600; public ShutdownCmd() { super("shutdown"); } @Override protected void _doCmd(PlayerCharacter pcSender, String[] args, AbstractGameObject target) { int delay = DEFAULT_DELAY_SECONDS; if (args.length > 0 && args[0].isEmpty() == false) { try { delay = Integer.parseInt(args[0].trim()); } catch (NumberFormatException e) { this.sendUsage(pcSender); return; } } if (delay < 0) delay = 0; if (delay > MAX_DELAY_SECONDS) delay = MAX_DELAY_SECONDS; throwbackInfo(pcSender, "Graceful shutdown started: player data will be saved in " + delay + " second(s)."); final int delaySeconds = delay; // The countdown sleeps, so run it off the message handling thread. Thread shutdownThread = new Thread(new Runnable() { @Override public void run() { GracefulShutdown.gracefulStop(delaySeconds); } }, "gracefulShutdown"); shutdownThread.setDaemon(false); shutdownThread.start(); } @Override protected String _getHelpString() { return "Gracefully shuts the server down: warns the players, saves every online character, then stops the servers"; } @Override protected String _getUsageString() { return "' /shutdown [seconds]'"; } }