Server restart schedule by day.

This commit is contained in:
MobiusDevelopment
2020-01-15 10:01:39 +00:00
parent 411782efce
commit 6a1f4c21ac
51 changed files with 1037 additions and 68 deletions

View File

@ -762,6 +762,7 @@ public class Config
public static boolean SERVER_RESTART_SCHEDULE_MESSAGE;
public static int SERVER_RESTART_SCHEDULE_COUNTDOWN;
public static String[] SERVER_RESTART_SCHEDULE;
public static List<Integer> SERVER_RESTART_DAYS;
// --------------------------------------------------
// Vitality Settings
@ -1239,7 +1240,7 @@ public class Config
public static Map<Integer, Integer> L2TOP_REWARD = new HashMap<>();
public static int L2TOP_DUALBOXES_ALLOWED;
public static boolean ALLOW_L2TOP_GAME_SERVER_REPORT;
/**
* This class initializes all global variables for configuration.<br>
* If the key doesn't appear in properties file, a default value is set by this class. {@link #SERVER_CONFIG_FILE} (properties file) for configuring your server.
@ -1362,6 +1363,14 @@ public class Config
SERVER_RESTART_SCHEDULE_MESSAGE = serverSettings.getBoolean("ServerRestartScheduleMessage", false);
SERVER_RESTART_SCHEDULE_COUNTDOWN = serverSettings.getInt("ServerRestartScheduleCountdown", 600);
SERVER_RESTART_SCHEDULE = serverSettings.getString("ServerRestartSchedule", "08:00").split(",");
SERVER_RESTART_DAYS = new ArrayList<>();
for (String day : serverSettings.getString("ServerRestartDays", "").trim().split(","))
{
if (Util.isDigit(day))
{
SERVER_RESTART_DAYS.add(Integer.parseInt(day));
}
}
// Hosts and Subnets
final IPConfigData ipcd = new IPConfigData();

View File

@ -18,6 +18,7 @@ package org.l2jmobius.gameserver.instancemanager;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.logging.Logger;
import org.l2jmobius.Config;
@ -25,7 +26,7 @@ import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.gameserver.Shutdown;
/**
* @author Gigi
* @author Gigi, Mobius
*/
public class ServerRestartManager
{
@ -52,7 +53,15 @@ public class ServerRestartManager
if (restartTime.getTimeInMillis() < currentTime.getTimeInMillis())
{
restartTime.add(Calendar.DAY_OF_MONTH, 1);
restartTime.add(Calendar.DAY_OF_WEEK, 1);
}
if (!Config.SERVER_RESTART_DAYS.isEmpty())
{
while (!Config.SERVER_RESTART_DAYS.contains(restartTime.get(Calendar.DAY_OF_WEEK)))
{
restartTime.add(Calendar.DAY_OF_WEEK, 1);
}
}
delay = restartTime.getTimeInMillis() - currentTime.getTimeInMillis();
@ -70,7 +79,14 @@ public class ServerRestartManager
if (lastRestart != null)
{
nextRestartTime = new SimpleDateFormat("HH:mm").format(lastRestart.getTime());
if (Config.SERVER_RESTART_DAYS.isEmpty())
{
nextRestartTime = new SimpleDateFormat("HH:mm").format(lastRestart.getTime());
}
else
{
nextRestartTime = new SimpleDateFormat("MMMM d'" + getDayNumberSuffix(lastRestart.get(Calendar.DAY_OF_MONTH)) + "' HH:mm", Locale.UK).format(lastRestart.getTime());
}
ThreadPool.schedule(new ServerRestartTask(), lastDelay - (Config.SERVER_RESTART_SCHEDULE_COUNTDOWN * 1000));
LOGGER.info("Scheduled server restart at " + lastRestart.getTime() + ".");
}
@ -81,6 +97,33 @@ public class ServerRestartManager
}
}
private String getDayNumberSuffix(int day)
{
switch (day)
{
case 1:
case 21:
case 31:
{
return "st";
}
case 2:
case 22:
{
return "nd";
}
case 3:
case 23:
{
return "rd";
}
default:
{
return "th";
}
}
}
public String getNextRestartTime()
{
return nextRestartTime;