SHOW:
|
|
- or go back to the newest paste.
| 1 | diff --git a/config/CustomMods/SpecialMods.ini b/config/CustomMods/SpecialMods.ini | |
| 2 | index b2640c6..5464546 100644 | |
| 3 | --- a/config/CustomMods/SpecialMods.ini | |
| 4 | +++ b/config/CustomMods/SpecialMods.ini | |
| 5 | @@ -4,3 +4,17 @@ | |
| 6 | #Start with the super rod skill activated? | |
| 7 | GMStartupSuperHaste = True | |
| 8 | ||
| 9 | +#====================================================== | |
| 10 | +# Auto Restart | |
| 11 | +#====================================================== | |
| 12 | +# Enable / Disable Restart Auto | |
| 13 | +EnableRestartSystem = True | |
| 14 | + | |
| 15 | +# If EnableRestartSystem = True hours of the day | |
| 16 | +# Example: 22:00,23:00 (hh:mm,hh:mm...) | |
| 17 | +# NOTE: Separate ":" mm:hh and "," others restart time | |
| 18 | +RestartByTimeOfDay = 00:00 | |
| 19 | + | |
| 20 | +# Seconds to restart the server ( 360 = 5 Minutos ) | |
| 21 | +# default = 30, Max 360 | |
| 22 | +RestartSeconds = 30 | |
| 23 | \ No newline at end of file | |
| 24 | diff --git a/java/net/sf/l2j/Config.java b/java/net/sf/l2j/Config.java | |
| 25 | index a8aca42..61cacdf 100644 | |
| 26 | --- a/java/net/sf/l2j/Config.java | |
| 27 | +++ b/java/net/sf/l2j/Config.java | |
| 28 | @@ -157,6 +157,9 @@ | |
| 29 | public static String DISABLE_BOW_CLASSES_STRING; | |
| 30 | public static ArrayList<Integer> DISABLE_BOW_CLASSES = new ArrayList<>(); | |
| 31 | public static boolean GM_SUPER_HASTE; | |
| 32 | + public static boolean RESTART_BY_TIME_OF_DAY; | |
| 33 | + public static int RESTART_SECONDS; | |
| 34 | + public static String[] RESTART_INTERVAL_BY_TIME_OF_DAY; | |
| 35 | // -------------------------------------------------- | |
| 36 | // Events settings | |
| 37 | // -------------------------------------------------- | |
| 38 | @@ -1217,6 +1220,9 @@ | |
| 39 | private static final void loadSpecial() | |
| 40 | {
| |
| 41 | final ExProperties Special = initProperties(SPECIAL_MODS); | |
| 42 | + RESTART_BY_TIME_OF_DAY = Boolean.parseBoolean(Special.getProperty("EnableRestartSystem", "false"));
| |
| 43 | + RESTART_SECONDS = Integer.parseInt(Special.getProperty("RestartSeconds", "360"));
| |
| 44 | + RESTART_INTERVAL_BY_TIME_OF_DAY = Special.getProperty("RestartByTimeOfDay", "20:00").split(",");
| |
| 45 | GM_SUPER_HASTE = Boolean.parseBoolean(Special.getProperty("GMStartupSuperHaste", "true"));
| |
| 46 | ANNOUNCE_PVP_KILL = Boolean.parseBoolean(Special.getProperty("AnnouncePvPKill", "false"));
| |
| 47 | ANNOUNCE_PK_KILL = Boolean.parseBoolean(Special.getProperty("AnnouncePkKill", "false"));
| |
| 48 | diff --git a/java/net/sf/l2j/gameserver/GameServer.java b/java/net/sf/l2j/gameserver/GameServer.java | |
| 49 | index a829cab..33aa989 100644 | |
| 50 | --- a/java/net/sf/l2j/gameserver/GameServer.java | |
| 51 | +++ b/java/net/sf/l2j/gameserver/GameServer.java | |
| 52 | @@ -151,6 +151,12 @@ | |
| 53 | HtmCache.getInstance(); | |
| 54 | CrestCache.getInstance(); | |
| 55 | ||
| 56 | + LOGGER.info("Restart Manager");
| |
| 57 | + if(Config.RESTART_BY_TIME_OF_DAY) | |
| 58 | + Restart.getInstance().StartCalculationOfNextRestartTime(); | |
| 59 | + else | |
| 60 | + LOGGER.info("# Auto Restart System is Disabled #");
| |
| 61 | + | |
| 62 | StringUtil.printSection("World");
| |
| 63 | World.getInstance(); | |
| 64 | MapRegionData.getInstance(); | |
| 65 | diff --git a/java/net/sf/l2j/gameserver/Restart.java b/java/net/sf/l2j/gameserver/Restart.java | |
| 66 | new file mode 100644 | |
| 67 | index 0000000..8c1d2fc | |
| 68 | --- /dev/null | |
| 69 | +++ b/java/net/sf/l2j/gameserver/Restart.java | |
| 70 | @@ -0,0 +1,115 @@ | |
| 71 | - | +/* |
| 71 | + | /* |
| 72 | - | + * This program is free software: you can redistribute it and/or modify it under |
| 72 | + | * This program is free software: you can redistribute it and/or modify it under |
| 73 | - | + * the terms of the GNU General Public License as published by the Free Software |
| 73 | + | * the terms of the GNU General Public License as published by the Free Software |
| 74 | - | + * Foundation, either version 3 of the License, or (at your option) any later |
| 74 | + | * Foundation, either version 3 of the License, or (at your option) any later |
| 75 | - | + * version. |
| 75 | + | * version. |
| 76 | - | + * |
| 76 | + | * |
| 77 | - | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 77 | + | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 78 | - | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 78 | + | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 79 | - | + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 79 | + | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 80 | - | + * details. |
| 80 | + | * details. |
| 81 | - | + * |
| 81 | + | * |
| 82 | - | + * You should have received a copy of the GNU General Public License along with |
| 82 | + | * You should have received a copy of the GNU General Public License along with |
| 83 | - | + * this program. If not, see <http://www.gnu.org/licenses/>. |
| 83 | + | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 84 | - | + */ |
| 84 | + | */ |
| 85 | - | +package net.sf.l2j.gameserver; |
| 85 | + | package net.sf.l2j.gameserver; |
| 86 | ||
| 87 | - | +import java.text.SimpleDateFormat; |
| 87 | + | import java.text.SimpleDateFormat; |
| 88 | - | +import java.util.Calendar; |
| 88 | + | import java.util.Calendar; |
| 89 | - | +import java.util.logging.Logger; |
| 89 | + | import java.util.logging.Logger; |
| 90 | ||
| 91 | - | +import net.sf.l2j.commons.pool.ThreadPool; |
| 91 | + | import net.sf.l2j.commons.pool.ThreadPool; |
| 92 | ||
| 93 | - | +import net.sf.l2j.Config; |
| 93 | + | import net.sf.l2j.Config; |
| 94 | ||
| 95 | - | +public class Restart |
| 95 | + | public class Restart |
| 96 | - | +{
|
| 96 | + | {
|
| 97 | - | + //Variaveis globais |
| 97 | + | //Variaveis globais |
| 98 | - | + private static Restart _instance = null; |
| 98 | + | private static Restart _instance = null; |
| 99 | - | + protected static final Logger _log = Logger.getLogger(Restart.class.getName()); |
| 99 | + | protected static final Logger _log = Logger.getLogger(Restart.class.getName()); |
| 100 | - | + private Calendar NextRestart; |
| 100 | + | private Calendar NextRestart; |
| 101 | - | + private SimpleDateFormat format = new SimpleDateFormat("HH:mm");
|
| 101 | + | private SimpleDateFormat format = new SimpleDateFormat("HH:mm");
|
| 102 | - | + |
| 102 | + | |
| 103 | - | + //Singleton |
| 103 | + | //Singleton |
| 104 | - | + public static Restart getInstance() |
| 104 | + | public static Restart getInstance() |
| 105 | {
| |
| 106 | - | + if(_instance == null) |
| 106 | + | if(_instance == null) |
| 107 | - | + _instance = new Restart(); |
| 107 | + | _instance = new Restart(); |
| 108 | - | + return _instance; |
| 108 | + | return _instance; |
| 109 | } | |
| 110 | - | + |
| 110 | + | |
| 111 | - | + public String getRestartNextTime() |
| 111 | + | public String getRestartNextTime() |
| 112 | {
| |
| 113 | - | + if(NextRestart.getTime() != null) |
| 113 | + | if(NextRestart.getTime() != null) |
| 114 | - | + return format.format(NextRestart.getTime()); |
| 114 | + | return format.format(NextRestart.getTime()); |
| 115 | else | |
| 116 | - | + return "Erro"; |
| 116 | + | return "Erro"; |
| 117 | } | |
| 118 | - | + |
| 118 | + | |
| 119 | - | + //Connstrutor |
| 119 | + | //Connstrutor |
| 120 | - | + private Restart() |
| 120 | + | private Restart() |
| 121 | {
| |
| 122 | - | + //:D |
| 122 | + | //:D |
| 123 | } | |
| 124 | - | + |
| 124 | + | |
| 125 | - | + public void StartCalculationOfNextRestartTime() |
| 125 | + | public void StartCalculationOfNextRestartTime() |
| 126 | {
| |
| 127 | - | + _log.info("#####################################");
|
| 127 | + | _log.info("#####################################");
|
| 128 | - | + _log.info("#[Restart System]: System actived...#");
|
| 128 | + | _log.info("#[Restart System]: System actived...#");
|
| 129 | - | + _log.info("#####################################");
|
| 129 | + | _log.info("#####################################");
|
| 130 | - | + try |
| 130 | + | try |
| 131 | - | + {
|
| 131 | + | {
|
| 132 | - | + Calendar currentTime = Calendar.getInstance(); |
| 132 | + | Calendar currentTime = Calendar.getInstance(); |
| 133 | - | + Calendar testStartTime = null; |
| 133 | + | Calendar testStartTime = null; |
| 134 | - | + long flush2 = 0,timeL = 0; |
| 134 | + | long flush2 = 0,timeL = 0; |
| 135 | - | + int count = 0; |
| 135 | + | int count = 0; |
| 136 | - | + |
| 136 | + | |
| 137 | - | + for (String timeOfDay : Config.RESTART_INTERVAL_BY_TIME_OF_DAY) |
| 137 | + | for (String timeOfDay : Config.RESTART_INTERVAL_BY_TIME_OF_DAY) |
| 138 | - | + {
|
| 138 | + | {
|
| 139 | - | + testStartTime = Calendar.getInstance(); |
| 139 | + | testStartTime = Calendar.getInstance(); |
| 140 | - | + testStartTime.setLenient(true); |
| 140 | + | testStartTime.setLenient(true); |
| 141 | - | + String[] splitTimeOfDay = timeOfDay.split(":");
|
| 141 | + | String[] splitTimeOfDay = timeOfDay.split(":");
|
| 142 | - | + testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0])); |
| 142 | + | testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0])); |
| 143 | - | + testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1])); |
| 143 | + | testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1])); |
| 144 | - | + testStartTime.set(Calendar.SECOND, 00); |
| 144 | + | testStartTime.set(Calendar.SECOND, 00); |
| 145 | - | + //Verifica a validade to tempo |
| 145 | + | //Verifica a validade to tempo |
| 146 | - | + if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis()) |
| 146 | + | if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis()) |
| 147 | - | + {
|
| 147 | + | {
|
| 148 | - | + testStartTime.add(Calendar.DAY_OF_MONTH, 1); |
| 148 | + | testStartTime.add(Calendar.DAY_OF_MONTH, 1); |
| 149 | - | + } |
| 149 | + | } |
| 150 | - | + |
| 150 | + | |
| 151 | - | + //TimeL Recebe o quanto falta de milisegundos para o restart |
| 151 | + | //TimeL Recebe o quanto falta de milisegundos para o restart |
| 152 | - | + timeL = testStartTime.getTimeInMillis() - currentTime.getTimeInMillis(); |
| 152 | + | timeL = testStartTime.getTimeInMillis() - currentTime.getTimeInMillis(); |
| 153 | - | + |
| 153 | + | |
| 154 | - | + //Verifica qual horario sera o proximo restart |
| 154 | + | //Verifica qual horario sera o proximo restart |
| 155 | - | + if(count == 0){
|
| 155 | + | if(count == 0){
|
| 156 | - | + flush2 = timeL; |
| 156 | + | flush2 = timeL; |
| 157 | - | + NextRestart = testStartTime; |
| 157 | + | NextRestart = testStartTime; |
| 158 | - | + } |
| 158 | + | } |
| 159 | - | + |
| 159 | + | |
| 160 | - | + if(timeL < flush2){
|
| 160 | + | if(timeL < flush2){
|
| 161 | - | + flush2 = timeL; |
| 161 | + | flush2 = timeL; |
| 162 | - | + NextRestart = testStartTime; |
| 162 | + | NextRestart = testStartTime; |
| 163 | - | + } |
| 163 | + | } |
| 164 | - | + |
| 164 | + | |
| 165 | - | + count ++; |
| 165 | + | count ++; |
| 166 | - | + } |
| 166 | + | } |
| 167 | - | + _log.info("[AutoRestart]: Next Restart Time: " + NextRestart.getTime().toString());
|
| 167 | + | _log.info("[AutoRestart]: Next Restart Time: " + NextRestart.getTime().toString());
|
| 168 | - | + ThreadPool.schedule(new StartRestartTask(), flush2); |
| 168 | + | ThreadPool.schedule(new StartRestartTask(), flush2); |
| 169 | - | + } |
| 169 | + | } |
| 170 | - | + catch (Exception e) |
| 170 | + | catch (Exception e) |
| 171 | - | + {
|
| 171 | + | {
|
| 172 | - | + System.out.println("[AutoRestart]: The restart automated server presented error in load restarts period config !");
|
| 172 | + | System.out.println("[AutoRestart]: The restart automated server presented error in load restarts period config !");
|
| 173 | - | + } |
| 173 | + | } |
| 174 | } | |
| 175 | - | + |
| 175 | + | |
| 176 | - | + class StartRestartTask implements Runnable |
| 176 | + | class StartRestartTask implements Runnable |
| 177 | {
| |
| 178 | - | + @Override |
| 178 | + | @Override |
| 179 | - | + public void run() |
| 179 | + | public void run() |
| 180 | - | + {
|
| 180 | + | {
|
| 181 | - | + _log.info("Start automated restart GameServer.");
|
| 181 | + | _log.info("Start automated restart GameServer.");
|
| 182 | - | + Shutdown.getInstance().autoRestart(Config.RESTART_SECONDS); |
| 182 | + | Shutdown.getInstance().autoRestart(Config.RESTART_SECONDS); |
| 183 | - | + } |
| 183 | + | } |
| 184 | } | |
| 185 | - | +} |
| 185 | + | } |
| 186 | \ No newline at end of file | |
| 187 | diff --git a/java/net/sf/l2j/gameserver/Shutdown.java b/java/net/sf/l2j/gameserver/Shutdown.java | |
| 188 | index 440d9aa..07d2932 100644 | |
| 189 | --- a/java/net/sf/l2j/gameserver/Shutdown.java | |
| 190 | +++ b/java/net/sf/l2j/gameserver/Shutdown.java | |
| 191 | @@ -369,4 +369,16 @@ | |
| 192 | {
| |
| 193 | protected static final Shutdown INSTANCE = new Shutdown(); | |
| 194 | } | |
| 195 | + | |
| 196 | + public void autoRestart(int time) | |
| 197 | + {
| |
| 198 | + _secondsShut = time; | |
| 199 | + | |
| 200 | + countdown(); | |
| 201 | + | |
| 202 | + _shutdownMode = GM_RESTART; | |
| 203 | + | |
| 204 | + SingletonHolder.INSTANCE.setMode(GM_RESTART); | |
| 205 | + System.exit(2); | |
| 206 | + } | |
| 207 | } | |
| 208 | \ No newline at end of file | |
| 209 | diff --git a/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java b/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java | |
| 210 | index 717e11a..3e30838 100644 | |
| 211 | --- a/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java | |
| 212 | +++ b/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java | |
| 213 | @@ -3,6 +3,7 @@ | |
| 214 | import java.util.Map.Entry; | |
| 215 | ||
| 216 | import net.sf.l2j.Config; | |
| 217 | +import net.sf.l2j.gameserver.Restart; | |
| 218 | import net.sf.l2j.gameserver.communitybbs.manager.MailBBSManager; | |
| 219 | import net.sf.l2j.gameserver.data.SkillTable; | |
| 220 | import net.sf.l2j.gameserver.data.SkillTable.FrequentSkill; | |
| 221 | @@ -230,6 +231,10 @@ | |
| 222 | {
| |
| 223 | Olympiad.olympiadEnd(player); | |
| 224 | } | |
| 225 | + if(Config.RESTART_BY_TIME_OF_DAY) | |
| 226 | + {
| |
| 227 | + ShowNextRestart(player); | |
| 228 | + } | |
| 229 | // Means that it's not ok multiBox situation, so logout | |
| 230 | if (!player.checkMultiBox()) | |
| 231 | {
| |
| 232 | @@ -305,7 +310,17 @@ | |
| 233 | ||
| 234 | player.sendPacket(ActionFailed.STATIC_PACKET); | |
| 235 | } | |
| 236 | - | |
| 237 | + /** | |
| 238 | + * Envia mensagem para o player do proximo restart | |
| 239 | + * NOTE: RESTART_BY_TIME_OF_DAY = TRUE | |
| 240 | + * | |
| 241 | + * @param activeChar | |
| 242 | + */ | |
| 243 | + private static void ShowNextRestart(Player activeChar) | |
| 244 | + {
| |
| 245 | + activeChar.sendMessage("Next Restart: " + Restart.getInstance().getRestartNextTime());
| |
| 246 | + } | |
| 247 | + | |
| 248 | @Override | |
| 249 | protected boolean triggersOnActionRequest() | |
| 250 | {
| |
| 251 |