Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/config/CustomMods/SpecialMods.ini b/config/CustomMods/SpecialMods.ini
- index b2640c6..5464546 100644
- --- a/config/CustomMods/SpecialMods.ini
- +++ b/config/CustomMods/SpecialMods.ini
- @@ -4,3 +4,17 @@
- #Start with the super rod skill activated?
- GMStartupSuperHaste = True
- +#======================================================
- +# Auto Restart
- +#======================================================
- +# Enable / Disable Restart Auto
- +EnableRestartSystem = True
- +
- +# If EnableRestartSystem = True hours of the day
- +# Example: 22:00,23:00 (hh:mm,hh:mm...)
- +# NOTE: Separate ":" mm:hh and "," others restart time
- +RestartByTimeOfDay = 00:00
- +
- +# Seconds to restart the server ( 360 = 5 Minutos )
- +# default = 30, Max 360
- +RestartSeconds = 30
- \ No newline at end of file
- diff --git a/java/net/sf/l2j/Config.java b/java/net/sf/l2j/Config.java
- index a8aca42..61cacdf 100644
- --- a/java/net/sf/l2j/Config.java
- +++ b/java/net/sf/l2j/Config.java
- @@ -157,6 +157,9 @@
- public static String DISABLE_BOW_CLASSES_STRING;
- public static ArrayList<Integer> DISABLE_BOW_CLASSES = new ArrayList<>();
- public static boolean GM_SUPER_HASTE;
- + public static boolean RESTART_BY_TIME_OF_DAY;
- + public static int RESTART_SECONDS;
- + public static String[] RESTART_INTERVAL_BY_TIME_OF_DAY;
- // --------------------------------------------------
- // Events settings
- // --------------------------------------------------
- @@ -1217,6 +1220,9 @@
- private static final void loadSpecial()
- {
- final ExProperties Special = initProperties(SPECIAL_MODS);
- + RESTART_BY_TIME_OF_DAY = Boolean.parseBoolean(Special.getProperty("EnableRestartSystem", "false"));
- + RESTART_SECONDS = Integer.parseInt(Special.getProperty("RestartSeconds", "360"));
- + RESTART_INTERVAL_BY_TIME_OF_DAY = Special.getProperty("RestartByTimeOfDay", "20:00").split(",");
- GM_SUPER_HASTE = Boolean.parseBoolean(Special.getProperty("GMStartupSuperHaste", "true"));
- ANNOUNCE_PVP_KILL = Boolean.parseBoolean(Special.getProperty("AnnouncePvPKill", "false"));
- ANNOUNCE_PK_KILL = Boolean.parseBoolean(Special.getProperty("AnnouncePkKill", "false"));
- diff --git a/java/net/sf/l2j/gameserver/GameServer.java b/java/net/sf/l2j/gameserver/GameServer.java
- index a829cab..33aa989 100644
- --- a/java/net/sf/l2j/gameserver/GameServer.java
- +++ b/java/net/sf/l2j/gameserver/GameServer.java
- @@ -151,6 +151,12 @@
- HtmCache.getInstance();
- CrestCache.getInstance();
- + LOGGER.info("Restart Manager");
- + if(Config.RESTART_BY_TIME_OF_DAY)
- + Restart.getInstance().StartCalculationOfNextRestartTime();
- + else
- + LOGGER.info("# Auto Restart System is Disabled #");
- +
- StringUtil.printSection("World");
- World.getInstance();
- MapRegionData.getInstance();
- diff --git a/java/net/sf/l2j/gameserver/Restart.java b/java/net/sf/l2j/gameserver/Restart.java
- new file mode 100644
- index 0000000..8c1d2fc
- --- /dev/null
- +++ b/java/net/sf/l2j/gameserver/Restart.java
- @@ -0,0 +1,115 @@
- +/*
- + * This program 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.
- + *
- + * This program 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 net.sf.l2j.gameserver;
- +
- +import java.text.SimpleDateFormat;
- +import java.util.Calendar;
- +import java.util.logging.Logger;
- +
- +import net.sf.l2j.commons.pool.ThreadPool;
- +
- +import net.sf.l2j.Config;
- +
- +public class Restart
- +{
- + //Variaveis globais
- + private static Restart _instance = null;
- + protected static final Logger _log = Logger.getLogger(Restart.class.getName());
- + private Calendar NextRestart;
- + private SimpleDateFormat format = new SimpleDateFormat("HH:mm");
- +
- + //Singleton
- + public static Restart getInstance()
- + {
- + if(_instance == null)
- + _instance = new Restart();
- + return _instance;
- + }
- +
- + public String getRestartNextTime()
- + {
- + if(NextRestart.getTime() != null)
- + return format.format(NextRestart.getTime());
- + else
- + return "Erro";
- + }
- +
- + //Connstrutor
- + private Restart()
- + {
- + //:D
- + }
- +
- + public void StartCalculationOfNextRestartTime()
- + {
- + _log.info("#####################################");
- + _log.info("#[Restart System]: System actived...#");
- + _log.info("#####################################");
- + try
- + {
- + Calendar currentTime = Calendar.getInstance();
- + Calendar testStartTime = null;
- + long flush2 = 0,timeL = 0;
- + int count = 0;
- +
- + for (String timeOfDay : Config.RESTART_INTERVAL_BY_TIME_OF_DAY)
- + {
- + testStartTime = Calendar.getInstance();
- + testStartTime.setLenient(true);
- + String[] splitTimeOfDay = timeOfDay.split(":");
- + testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0]));
- + testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1]));
- + testStartTime.set(Calendar.SECOND, 00);
- + //Verifica a validade to tempo
- + if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis())
- + {
- + testStartTime.add(Calendar.DAY_OF_MONTH, 1);
- + }
- +
- + //TimeL Recebe o quanto falta de milisegundos para o restart
- + timeL = testStartTime.getTimeInMillis() - currentTime.getTimeInMillis();
- +
- + //Verifica qual horario sera o proximo restart
- + if(count == 0){
- + flush2 = timeL;
- + NextRestart = testStartTime;
- + }
- +
- + if(timeL < flush2){
- + flush2 = timeL;
- + NextRestart = testStartTime;
- + }
- +
- + count ++;
- + }
- + _log.info("[AutoRestart]: Next Restart Time: " + NextRestart.getTime().toString());
- + ThreadPool.schedule(new StartRestartTask(), flush2);
- + }
- + catch (Exception e)
- + {
- + System.out.println("[AutoRestart]: The restart automated server presented error in load restarts period config !");
- + }
- + }
- +
- + class StartRestartTask implements Runnable
- + {
- + @Override
- + public void run()
- + {
- + _log.info("Start automated restart GameServer.");
- + Shutdown.getInstance().autoRestart(Config.RESTART_SECONDS);
- + }
- + }
- +}
- \ No newline at end of file
- diff --git a/java/net/sf/l2j/gameserver/Shutdown.java b/java/net/sf/l2j/gameserver/Shutdown.java
- index 440d9aa..07d2932 100644
- --- a/java/net/sf/l2j/gameserver/Shutdown.java
- +++ b/java/net/sf/l2j/gameserver/Shutdown.java
- @@ -369,4 +369,16 @@
- {
- protected static final Shutdown INSTANCE = new Shutdown();
- }
- +
- + public void autoRestart(int time)
- + {
- + _secondsShut = time;
- +
- + countdown();
- +
- + _shutdownMode = GM_RESTART;
- +
- + SingletonHolder.INSTANCE.setMode(GM_RESTART);
- + System.exit(2);
- + }
- }
- \ No newline at end of file
- diff --git a/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java b/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
- index 717e11a..3e30838 100644
- --- a/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
- +++ b/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
- @@ -3,6 +3,7 @@
- import java.util.Map.Entry;
- import net.sf.l2j.Config;
- +import net.sf.l2j.gameserver.Restart;
- import net.sf.l2j.gameserver.communitybbs.manager.MailBBSManager;
- import net.sf.l2j.gameserver.data.SkillTable;
- import net.sf.l2j.gameserver.data.SkillTable.FrequentSkill;
- @@ -230,6 +231,10 @@
- {
- Olympiad.olympiadEnd(player);
- }
- + if(Config.RESTART_BY_TIME_OF_DAY)
- + {
- + ShowNextRestart(player);
- + }
- // Means that it's not ok multiBox situation, so logout
- if (!player.checkMultiBox())
- {
- @@ -305,7 +310,17 @@
- player.sendPacket(ActionFailed.STATIC_PACKET);
- }
- -
- + /**
- + * Envia mensagem para o player do proximo restart
- + * NOTE: RESTART_BY_TIME_OF_DAY = TRUE
- + *
- + * @param activeChar
- + */
- + private static void ShowNextRestart(Player activeChar)
- + {
- + activeChar.sendMessage("Next Restart: " + Restart.getInstance().getRestartNextTime());
- + }
- +
- @Override
- protected boolean triggersOnActionRequest()
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement