Scheduled server restart improvements.

This commit is contained in:
MobiusDev
2016-04-30 08:37:44 +00:00
parent e43016c459
commit e229e4240b
5 changed files with 27 additions and 29 deletions

View File

@@ -139,21 +139,19 @@ CharMaxNumber = 7
# Scheduled Server Restart # Scheduled Server Restart
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Enable disable scheduled server restart. # Enable scheduled server restart.
# Default: False # Default: False
ServerRestartSchedule = False ServerRestartScheduleEnabled = False
# Send a message when player enters the game. # Send a message when player enters the game.
# Default: False # Default: False
ServerRestartScheduleMessage = False ServerRestartScheduleMessage = False
# Restart time countdown (in seconds). # Restart time countdown (in seconds).
# Default: 300 (5 minutes) # Default: 600 (10 minutes)
ServerRestartScheduleCountdown = 300 ServerRestartScheduleCountdown = 600
# Scheduled restart hours. # Scheduled restart schedule.
# If you put 12:00 the server countdown for the restart will start at that time.
# After 5 minutes (300 seconds) the server will be restarted.
# You can put more than one value separated by commas (,). # You can put more than one value separated by commas (,).
# Example: 12:00,00:00 # Example: 12:00, 00:00
ServerRestartScheduleHours = 07:00 ServerRestartSchedule = 08:00

View File

@@ -989,10 +989,10 @@ public final class Config
public static boolean SERVER_LIST_BRACKET; public static boolean SERVER_LIST_BRACKET;
public static boolean LOGIN_SERVER_SCHEDULE_RESTART; public static boolean LOGIN_SERVER_SCHEDULE_RESTART;
public static long LOGIN_SERVER_SCHEDULE_RESTART_TIME; public static long LOGIN_SERVER_SCHEDULE_RESTART_TIME;
public static boolean SERVER_RESTART_SCHEDULE; public static boolean SERVER_RESTART_SCHEDULE_ENABLED;
public static boolean SERVER_RESTART_SCHEDULE_MESSAGE; public static boolean SERVER_RESTART_SCHEDULE_MESSAGE;
public static int SERVER_RESTART_SCHEDULE_COUNTDOWN; public static int SERVER_RESTART_SCHEDULE_COUNTDOWN;
public static String[] SERVER_RESTART_SCHEDULE_HOURS; public static String[] SERVER_RESTART_SCHEDULE;
// -------------------------------------------------- // --------------------------------------------------
// MMO Settings // MMO Settings
@@ -1228,10 +1228,10 @@ public final class Config
SERVER_LIST_AGE = serverSettings.getInt("ServerListAge", 0); SERVER_LIST_AGE = serverSettings.getInt("ServerListAge", 0);
SERVER_LIST_BRACKET = serverSettings.getBoolean("ServerListBrackets", false); SERVER_LIST_BRACKET = serverSettings.getBoolean("ServerListBrackets", false);
SERVER_RESTART_SCHEDULE = serverSettings.getBoolean("ServerRestartSchedule", false); SERVER_RESTART_SCHEDULE_ENABLED = serverSettings.getBoolean("ServerRestartScheduleEnabled", false);
SERVER_RESTART_SCHEDULE_MESSAGE = serverSettings.getBoolean("ServerRestartScheduleMessage", false); SERVER_RESTART_SCHEDULE_MESSAGE = serverSettings.getBoolean("ServerRestartScheduleMessage", false);
SERVER_RESTART_SCHEDULE_COUNTDOWN = serverSettings.getInt("ServerRestartScheduleCountdown", 300); SERVER_RESTART_SCHEDULE_COUNTDOWN = serverSettings.getInt("ServerRestartScheduleCountdown", 600);
SERVER_RESTART_SCHEDULE_HOURS = serverSettings.getString("ServerRestartScheduleHours", "00:00").split(","); SERVER_RESTART_SCHEDULE = serverSettings.getString("ServerRestartSchedule", "08:00").split(",");
try try
{ {

View File

@@ -459,7 +459,7 @@ public final class GameServer
System.exit(1); System.exit(1);
} }
if (Config.SERVER_RESTART_SCHEDULE) if (Config.SERVER_RESTART_SCHEDULE_ENABLED)
{ {
ServerRestartManager.getInstance(); ServerRestartManager.getInstance();
} }

View File

@@ -38,18 +38,16 @@ public class ServerRestartManager
try try
{ {
final Calendar currentTime = Calendar.getInstance(); final Calendar currentTime = Calendar.getInstance();
final Calendar restartTime = currentTime; final Calendar restartTime = Calendar.getInstance();
Calendar lastRestart = currentTime; Calendar lastRestart = null;
restartTime.setLenient(true);
long delay = 0; long delay = 0;
long lastDelay = 0; long lastDelay = 0;
int count = 0;
for (String timeOfDay : Config.SERVER_RESTART_SCHEDULE_HOURS) for (String scheduledTime : Config.SERVER_RESTART_SCHEDULE)
{ {
final String[] splitTimeOfDay = timeOfDay.split(":"); final String[] splitTime = scheduledTime.trim().split(":");
restartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0])); restartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTime[0]));
restartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1])); restartTime.set(Calendar.MINUTE, Integer.parseInt(splitTime[1]));
restartTime.set(Calendar.SECOND, 00); restartTime.set(Calendar.SECOND, 00);
if (restartTime.getTimeInMillis() < currentTime.getTimeInMillis()) if (restartTime.getTimeInMillis() < currentTime.getTimeInMillis())
@@ -58,7 +56,7 @@ public class ServerRestartManager
} }
delay = restartTime.getTimeInMillis() - currentTime.getTimeInMillis(); delay = restartTime.getTimeInMillis() - currentTime.getTimeInMillis();
if (count == 0) if (lastDelay == 0)
{ {
lastDelay = delay; lastDelay = delay;
lastRestart = restartTime; lastRestart = restartTime;
@@ -68,12 +66,14 @@ public class ServerRestartManager
lastDelay = delay; lastDelay = delay;
lastRestart = restartTime; lastRestart = restartTime;
} }
count++;
} }
nextRestartTime = new SimpleDateFormat("HH:mm").format(lastRestart.getTime()); if (lastRestart != null)
ThreadPoolManager.getInstance().scheduleGeneral(new ServerRestartTask(), lastDelay); {
_log.info("Scheduled server restart at " + lastRestart.getTime().toString() + "."); nextRestartTime = new SimpleDateFormat("HH:mm").format(lastRestart.getTime());
ThreadPoolManager.getInstance().scheduleGeneral(new ServerRestartTask(), lastDelay - (Config.SERVER_RESTART_SCHEDULE_COUNTDOWN * 1000));
_log.info("Scheduled server restart at " + lastRestart.getTime().toString() + ".");
}
} }
catch (Exception e) catch (Exception e)
{ {

View File

@@ -505,7 +505,7 @@ public class EnterWorld extends L2GameClientPacket
AnnouncementsTable.getInstance().showAnnouncements(activeChar); AnnouncementsTable.getInstance().showAnnouncements(activeChar);
if ((Config.SERVER_RESTART_SCHEDULE) && (Config.SERVER_RESTART_SCHEDULE_MESSAGE)) if ((Config.SERVER_RESTART_SCHEDULE_ENABLED) && (Config.SERVER_RESTART_SCHEDULE_MESSAGE))
{ {
activeChar.sendPacket(new CreatureSay(2, ChatType.BATTLEFIELD, "[SERVER]", "Next restart is scheduled at " + ServerRestartManager.getInstance().getNextRestartTime() + ".")); activeChar.sendPacket(new CreatureSay(2, ChatType.BATTLEFIELD, "[SERVER]", "Next restart is scheduled at " + ServerRestartManager.getInstance().getNextRestartTime() + "."));
} }