Noticias:

No tienes permiso para ver los enlaces. Para poder verlos Registrate o Conectate.

Menú Principal

Auto Restart Game Server + properties

Iniciado por Swarlog, Jul 25, 2025, 11:25 PM

Tema anterior - Siguiente tema

Swarlog

Index: dist/game/config/Server.properties
===================================================================
--- dist/game/config/Server.properties	(revision 10299)
+++ dist/game/config/Server.properties	(working copy)
@@ -117,4 +117,28 @@
 
 # Maximum number of characters per account.
 # Default: 7 (client limit)
-CharMaxNumber = 7
\ No newline at end of file
+CharMaxNumber = 7
+
+
+# ---------------------------------------------------------------------------
+# Auto Restart Game Server
+# ---------------------------------------------------------------------------
+
+# Enable auto restart game server.
+# Default: False
+GameServerAutoRestart = False
+
+# Enable auto message info to enter player.
+# Default: False
+GameServerShowMessageInfo = False
+
+# Restart time countdown time (in seconds).
+# Default: 300 (5 minutes)
+GameServerAutoRestartCountdown = 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
+GameServerAutoRestartInterval = 12:00,00:00
Index: java/com/l2jserver/Config.java
===================================================================
--- java/com/l2jserver/Config.java	(revision 10299)
+++ java/com/l2jserver/Config.java	(working copy)
@@ -934,6 +934,10 @@
 	public static int REQUEST_ID;
 	public static boolean RESERVE_HOST_ON_LOGIN = false;
 	public static List<Integer> PROTOCOL_LIST;
+	public static boolean GAME_SERVER_AUTO_RESTART;
+	public static boolean GAME_SERVER_SHOW_MESSAGE_INFO;
+	public static int GAME_SERVER_AUTO_RESTART_COUNTDOWN;
+	public static String[] GAME_SERVER_AUTO_RESTART_INTERVAL;
 	public static boolean LOGIN_SERVER_SCHEDULE_RESTART;
 	public static long LOGIN_SERVER_SCHEDULE_RESTART_TIME;
 	
@@ -1165,6 +1169,11 @@
 			MAX_CHARACTERS_NUMBER_PER_ACCOUNT = serverSettings.getInt("CharMaxNumber", 7);
 			MAXIMUM_ONLINE_USERS = serverSettings.getInt("MaximumOnlineUsers", 100);
 			
+			GAME_SERVER_AUTO_RESTART = serverSettings.getBoolean("GameServerAutoRestart", false);
+			GAME_SERVER_SHOW_MESSAGE_INFO = serverSettings.getBoolean("GameServerShowMessageInfo", false);
+			GAME_SERVER_AUTO_RESTART_COUNTDOWN = serverSettings.getInt("GameServerAutoRestartCountdown", 300);
+			GAME_SERVER_AUTO_RESTART_INTERVAL = serverSettings.getString("GameServerAutoRestartInterval", "00:00").split(",");
+			
 			String[] protocols = serverSettings.getString("AllowedProtocolRevisions", "267;268;271;273").split(";");
 			PROTOCOL_LIST = new ArrayList<>(protocols.length);
 			for (String protocol : protocols)
Index: java/com/l2jserver/gameserver/GameServer.java
===================================================================
--- java/com/l2jserver/gameserver/GameServer.java	(revision 10299)
+++ java/com/l2jserver/gameserver/GameServer.java	(working copy)
@@ -387,6 +387,11 @@
 			OfflineTradersTable.getInstance().restoreOfflineTraders();
 		}
 		
+		if (Config.GAME_SERVER_AUTO_RESTART)
+		{
+			GameServerRestart.getInstance().StartCalculationOfNextRestartTime();
+		}
+		
 		if (Config.DEADLOCK_DETECTOR)
 		{
 			_deadDetectThread = new DeadLockDetector();
Index: java/com/l2jserver/gameserver/GameServerRestart.java
===================================================================
--- java/com/l2jserver/gameserver/GameServerRestart.java	(revision 0)
+++ java/com/l2jserver/gameserver/GameServerRestart.java	(working copy)
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2004-2015 L2J Server
+ * 
+ * This file is part of L2J Server.
+ * 
+ * L2J Server is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * L2J Server is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+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.GAME_SERVER_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.GAME_SERVER_AUTO_RESTART_COUNTDOWN);
+		}
+	}
+}
Index: java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java
===================================================================
--- java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java	(revision 10299)
+++ java/com/l2jserver/gameserver/network/clientpackets/EnterWorld.java	(working copy)
@@ -21,6 +21,7 @@
 import java.util.Base64;
 
 import com.l2jserver.Config;
+import com.l2jserver.gameserver.GameServerRestart;
 import com.l2jserver.gameserver.LoginServerThread;
 import com.l2jserver.gameserver.SevenSigns;
 import com.l2jserver.gameserver.cache.HtmCache;
@@ -61,6 +62,7 @@
 import com.l2jserver.gameserver.model.skills.CommonSkill;
 import com.l2jserver.gameserver.model.zone.ZoneId;
 import com.l2jserver.gameserver.network.SystemMessageId;
+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;
@@ -439,6 +441,16 @@
 		SevenSigns.getInstance().sendCurrentPeriodMsg(activeChar);
 		AnnouncementsTable.getInstance().showAnnouncements(activeChar);
 		
+		if (Config.GAME_SERVER_AUTO_RESTART)
+		{
+			if (Config.GAME_SERVER_SHOW_MESSAGE_INFO)
+			{
+				// activeChar.sendMessage("[INFO SERVER]", "Next Restart at " + GameServerRestart.getInstance().getRestartNextTime() + " hs.");
+				CreatureSay msg3 = new CreatureSay(2, 20, "[INFO SERVER]", "Next Restart at " + GameServerRestart.getInstance().getRestartNextTime() + " hs.");
+				activeChar.sendPacket(msg3);
+			}
+		}
+		
 		if (showClanNotice)
 		{
 			final NpcHtmlMessage notice = new NpcHtmlMessage();
Index: java/com/l2jserver/gameserver/Shutdown.java
===================================================================
--- java/com/l2jserver/gameserver/Shutdown.java	(revision 10299)
+++ java/com/l2jserver/gameserver/Shutdown.java	(working copy)
@@ -636,6 +636,14 @@
 		}
 	}
 	
+	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