diff --git a/trunk/dist/game/config/Server.ini b/trunk/dist/game/config/Server.ini index a2059efd9d..6ee07cf372 100644 --- a/trunk/dist/game/config/Server.ini +++ b/trunk/dist/game/config/Server.ini @@ -139,21 +139,19 @@ CharMaxNumber = 7 # Scheduled Server Restart # --------------------------------------------------------------------------- -# Enable disable scheduled server restart. +# Enable scheduled server restart. # Default: False -ServerRestartSchedule = False +ServerRestartScheduleEnabled = False # Send a message when player enters the game. # Default: False ServerRestartScheduleMessage = False # Restart time countdown (in seconds). -# Default: 300 (5 minutes) -ServerRestartScheduleCountdown = 300 +# Default: 600 (10 minutes) +ServerRestartScheduleCountdown = 600 -# Scheduled restart hours. -# 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. +# Scheduled restart schedule. # You can put more than one value separated by commas (,). -# Example: 12:00,00:00 -ServerRestartScheduleHours = 07:00 +# Example: 12:00, 00:00 +ServerRestartSchedule = 08:00 diff --git a/trunk/java/com/l2jmobius/Config.java b/trunk/java/com/l2jmobius/Config.java index 744a9c2d36..efc810b8e1 100644 --- a/trunk/java/com/l2jmobius/Config.java +++ b/trunk/java/com/l2jmobius/Config.java @@ -989,10 +989,10 @@ public final class Config public static boolean SERVER_LIST_BRACKET; public static boolean LOGIN_SERVER_SCHEDULE_RESTART; 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 int SERVER_RESTART_SCHEDULE_COUNTDOWN; - public static String[] SERVER_RESTART_SCHEDULE_HOURS; + public static String[] SERVER_RESTART_SCHEDULE; // -------------------------------------------------- // MMO Settings @@ -1228,10 +1228,10 @@ public final class Config SERVER_LIST_AGE = serverSettings.getInt("ServerListAge", 0); 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_COUNTDOWN = serverSettings.getInt("ServerRestartScheduleCountdown", 300); - SERVER_RESTART_SCHEDULE_HOURS = serverSettings.getString("ServerRestartScheduleHours", "00:00").split(","); + SERVER_RESTART_SCHEDULE_COUNTDOWN = serverSettings.getInt("ServerRestartScheduleCountdown", 600); + SERVER_RESTART_SCHEDULE = serverSettings.getString("ServerRestartSchedule", "08:00").split(","); try { diff --git a/trunk/java/com/l2jmobius/gameserver/GameServer.java b/trunk/java/com/l2jmobius/gameserver/GameServer.java index 857bd637ef..5877c0b5dc 100644 --- a/trunk/java/com/l2jmobius/gameserver/GameServer.java +++ b/trunk/java/com/l2jmobius/gameserver/GameServer.java @@ -459,7 +459,7 @@ public final class GameServer System.exit(1); } - if (Config.SERVER_RESTART_SCHEDULE) + if (Config.SERVER_RESTART_SCHEDULE_ENABLED) { ServerRestartManager.getInstance(); } diff --git a/trunk/java/com/l2jmobius/gameserver/instancemanager/ServerRestartManager.java b/trunk/java/com/l2jmobius/gameserver/instancemanager/ServerRestartManager.java index bfc7d7ef2a..25414ee46f 100644 --- a/trunk/java/com/l2jmobius/gameserver/instancemanager/ServerRestartManager.java +++ b/trunk/java/com/l2jmobius/gameserver/instancemanager/ServerRestartManager.java @@ -38,18 +38,16 @@ public class ServerRestartManager try { final Calendar currentTime = Calendar.getInstance(); - final Calendar restartTime = currentTime; - Calendar lastRestart = currentTime; - restartTime.setLenient(true); + final Calendar restartTime = Calendar.getInstance(); + Calendar lastRestart = null; long delay = 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(":"); - restartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0])); - restartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1])); + final String[] splitTime = scheduledTime.trim().split(":"); + restartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTime[0])); + restartTime.set(Calendar.MINUTE, Integer.parseInt(splitTime[1])); restartTime.set(Calendar.SECOND, 00); if (restartTime.getTimeInMillis() < currentTime.getTimeInMillis()) @@ -58,7 +56,7 @@ public class ServerRestartManager } delay = restartTime.getTimeInMillis() - currentTime.getTimeInMillis(); - if (count == 0) + if (lastDelay == 0) { lastDelay = delay; lastRestart = restartTime; @@ -68,12 +66,14 @@ public class ServerRestartManager lastDelay = delay; lastRestart = restartTime; } - count++; } - nextRestartTime = new SimpleDateFormat("HH:mm").format(lastRestart.getTime()); - ThreadPoolManager.getInstance().scheduleGeneral(new ServerRestartTask(), lastDelay); - _log.info("Scheduled server restart at " + lastRestart.getTime().toString() + "."); + if (lastRestart != null) + { + 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) { diff --git a/trunk/java/com/l2jmobius/gameserver/network/clientpackets/EnterWorld.java b/trunk/java/com/l2jmobius/gameserver/network/clientpackets/EnterWorld.java index 88ef633831..fb65de9bb3 100644 --- a/trunk/java/com/l2jmobius/gameserver/network/clientpackets/EnterWorld.java +++ b/trunk/java/com/l2jmobius/gameserver/network/clientpackets/EnterWorld.java @@ -505,7 +505,7 @@ public class EnterWorld extends L2GameClientPacket 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() + ".")); }