Noticias:

Debes de estar registrado para poder ver el contenido indicado. Registrate o Conectate

Menú Principal

Auto restar Gameserver con properties

Iniciado por Swarlog, Ago 12, 2022, 02:12 AM

Tema anterior - Siguiente tema

Swarlog

[### Eclipse Workspace Patch 1.0
#P L2J_Server_BETA
Index: dist/game/config/L2JMods.properties
===================================================================
--- dist/game/config/L2JMods.properties (revisión: 6203)
+++ dist/game/config/L2JMods.properties (copia de trabajo)
@@ -481,4 +481,32 @@
 
 # Enables .changepassword voiced command which allows the players to change their account's password ingame.
 # Default: False
 AllowChangePassword = False

+# ---------------------------------------------------------------------------
+# Auto Restart System
+# ---------------------------------------------------------------------------
+# Enable auto restart system?
+EnableRestartSystem = True
+
+# Enable restart system first
+# Restart time countdown time (in seconds)
+# Default: 300 (5 minutes)
+RestartSeconds = 300
+
+# Restart hours interval
+# 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. Separate them by ","
+# Example: 12:00,00:00
+RestartInterval = 12:00,00:00
\ No newline at end of file
Index: java/com/l2jserver/gameserver/GameServer.java
===================================================================
--- java/com/l2jserver/gameserver/GameServer.java (revisión: 6203)
+++ java/com/l2jserver/gameserver/GameServer.java (copia de trabajo)
@@ -404,6 +409,15 @@
  _deadDetectThread = null;
  }
  System.gc();
+
+ if (Config.AUTO_RESTART_ENABLE)
+ {
+ GameServerRestart.getInstance().StartCalculationOfNextRestartTime();
+ }
+ else
+ {
+ _log.info("[Auto Restart]: System is disabled.");
+ }
  // maxMemory is the upper limit the jvm can use, totalMemory the size of
  // the current allocation pool, freeMemory the unused memory in the allocation pool
  long freeMem = ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory()) + Runtime.getRuntime().freeMemory()) / 1048576;
Index: java/com/l2jserver/Config.java
===================================================================
--- java/com/l2jserver/Config.java (revisión: 6203)
+++ java/com/l2jserver/Config.java (copia de trabajo)
@@ -783,7 +783,15 @@
  public static int L2JMOD_DUALBOX_CHECK_MAX_L2EVENT_PARTICIPANTS_PER_IP;
  public static Map<Integer, Integer> L2JMOD_DUALBOX_CHECK_WHITELIST;
  public static boolean L2JMOD_ALLOW_CHANGE_PASSWORD;

  // --------------------------------------------------
+ // AutoRestart Configs
+ // --------------------------------------------------
+ public static boolean AUTO_RESTART_ENABLE;
+ public static int AUTO_RESTART_TIME;
+ public static String[] AUTO_RESTART_INTERVAL;
+ // --------------------------------------------------
  // NPC Settings
  // --------------------------------------------------
  public static boolean ANNOUNCE_MAMMON_SPAWN;
@@ -2630,6 +2638,14 @@
  }
  L2JMOD_ALLOW_CHANGE_PASSWORD = L2JModSettings.getBoolean("AllowChangePassword", false);

+ // AutoRestart Configs
+ AUTO_RESTART_ENABLE = L2JModSettings.getBoolean("EnableRestartSystem", false);
+ AUTO_RESTART_TIME = L2JModSettings.getInt("RestartSeconds", 360);
+ AUTO_RESTART_INTERVAL = L2JModSettings.getString("RestartInterval", "00:00").split(",");
+
  // Load PvP L2Properties file (if exists)
  final PropertiesParser PVPSettings = new PropertiesParser(PVP_CONFIG_FILE);
 
Index: java/com/l2jserver/gameserver/Shutdown.java
===================================================================
--- java/com/l2jserver/gameserver/Shutdown.java (revisión: 6203)
+++ java/com/l2jserver/gameserver/Shutdown.java (copia de trabajo)
@@ -643,10 +643,19 @@
  }
  }
 
+ public void autoRestart(int time)
+ {
+ this._secondsShut = time;
+ countdown();
+ this._shutdownMode = 2;
+ System.exit(2);
+ }
+
  /**
  * Get the shutdown-hook instance the shutdown-hook instance is created by the first call of this function, but it has to be registered externally.<br>
  * @return instance of Shutdown, to be used as shutdown hook
  */
+
  public static Shutdown getInstance()
  {
  return SingletonHolder._instance;
Index: java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java
===================================================================
--- java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java (revisión: 6203)
+++ java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java (copia de trabajo)
@@ -20,6 +20,7 @@
 
 import com.l2jserver.Config;
 import com.l2jserver.gameserver.Announcements;
+import com.l2jserver.gameserver.GameServerRestart;
 import com.l2jserver.gameserver.LoginServerThread;
 import com.l2jserver.gameserver.SevenSigns;
 import com.l2jserver.gameserver.TaskPriority;
@@ -64,6 +65,7 @@
 import com.l2jserver.gameserver.network.SystemMessageId;
 import com.l2jserver.gameserver.network.communityserver.CommunityServerThread;
 import com.l2jserver.gameserver.network.communityserver.writepackets.WorldInfo;
+import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
 import com.l2jserver.gameserver.network.serverpackets.Die;
 import com.l2jserver.gameserver.network.serverpackets.EtcStatusUpdate;
 import com.l2jserver.gameserver.network.serverpackets.ExBasicActionList;
@@ -462,11 +464,18 @@
  activeChar.sendMessage(getText("TDJKIERhdGFQYWNrIFZlcnNpb246") + " " + Config.DATAPACK_VERSION);
  }
  }
+
  activeChar.sendMessage(getText("Q29weXJpZ2h0IDIwMDQtMjAxMg==" + Config.EOL));
 
  SevenSigns.getInstance().sendCurrentPeriodMsg(activeChar);
  Announcements.getInstance().showAnnouncements(activeChar);
 
+ if (Config.AUTO_RESTART_ENABLE)
+ {
+ CreatureSay msg3 = new CreatureSay(2, 20, "[SERVER]", "Next Restart at " + GameServerRestart.getInstance().getRestartNextTime() + " hs.");
+ activeChar.sendPacket(msg3);
+ }
+
  if (showClanNotice)
  {
  final NpcHtmlMessage notice = new NpcHtmlMessage();
Index: java/com/l2jserver/gameserver/GameServerRestart.java
===================================================================
--- java/com/l2jserver/gameserver/GameServerRestart.java (revisión: 0)
+++ java/com/l2jserver/gameserver/GameServerRestart.java (revisión: 0)
@@ -0,0 +1,98 @@
+package com.l2jserver.gameserver;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.logging.Logger;
+
+import com.l2jserver.Config;
+
+public class GameServerRestart
+{
+ private static GameServerRestart _instance = null;
+ protected static final Logger _log = Logger.getLogger(GameServerRestart.class.getName());
+ private Calendar NextRestart;
+ private final SimpleDateFormat format = new SimpleDateFormat("HH:mm");
+
+ public static GameServerRestart getInstance()
+ {
+ if (_instance == null)
+ {
+ _instance = new GameServerRestart();
+ }
+ return _instance;
+ }
+
+ public String getRestartNextTime()
+ {
+ if (this.NextRestart.getTime() != null)
+ {
+ return this.format.format(this.NextRestart.getTime());
+ }
+ return "[Auto Restart]: Error on getRestartNextTime.";
+ }
+
+ public void StartCalculationOfNextRestartTime()
+ {
+ _log.info("[Auto Restart]: System activated.");
+ try
+ {
+ Calendar currentTime = Calendar.getInstance();
+ Calendar testStartTime = null;
+ long flush2 = 0L;
+ long timeL = 0L;
+ int count = 0;
+
+ for (String timeOfDay : Config.AUTO_RESTART_INTERVAL)
+ {
+ testStartTime = Calendar.getInstance();
+ testStartTime.setLenient(true);
+ String[] splitTimeOfDay = timeOfDay.split(":");
+ testStartTime.set(11, Integer.parseInt(splitTimeOfDay[0]));
+ testStartTime.set(12, Integer.parseInt(splitTimeOfDay[1]));
+ testStartTime.set(13, 0);
+
+ if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis())
+ {
+ testStartTime.add(5, 1);
+ }
+
+ timeL = testStartTime.getTimeInMillis() - currentTime.getTimeInMillis();
+
+ if (count == 0)
+ {
+ flush2 = timeL;
+ this.NextRestart = testStartTime;
+ }
+
+ if (timeL < flush2)
+ {
+ flush2 = timeL;
+ this.NextRestart = testStartTime;
+ }
+
+ count++;
+ }
+
+ _log.info("[Auto Restart]: Next restart time: " + this.NextRestart.getTime().toString());
+ ThreadPoolManager.getInstance().scheduleGeneral(new StartRestartTask(), flush2);
+ }
+ catch (Exception e)
+ {
+ System.out.println("[Auto Restart]: The auto restart has problem with the config file, please, check and correct it.!");
+ }
+ }
+
+ class StartRestartTask implements Runnable
+ {
+ StartRestartTask()
+ {
+ }
+
+ @Override
+ public void run()
+ {
+ GameServerRestart._log.info("[Auto Restart]: Auto restart started.");
+ Shutdown.getInstance().autoRestart(Config.AUTO_RESTART_TIME);
+ }
+ }
+}
\ No newline at end of file
/code]