Sarada-L2

Auto Restart para l2jban acis

Feb 3rd, 2021 (edited)
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.34 KB | None | 0 0
  1. Index: package net.sf.l2j.gameserver.Restart.java
  2. +/*
  3. + * This program is free software: you can redistribute it and/or modify it under
  4. + * the terms of the GNU General Public License as published by the Free Software
  5. + * Foundation, either version 3 of the License, or (at your option) any later
  6. + * version.
  7. + *
  8. + * This program is distributed in the hope that it will be useful, but WITHOUT
  9. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  11. + * details.
  12. + *
  13. + * You should have received a copy of the GNU General Public License along with
  14. + * this program. If not, see <http://www.gnu.org/licenses/>.
  15. + */
  16. +package net.sf.l2j.gameserver;
  17. +
  18. +import java.text.SimpleDateFormat;
  19. +import java.util.Calendar;
  20. +import java.util.logging.Logger;
  21. +
  22. +import net.sf.l2j.Config;
  23. +
  24. +public class Restart
  25. +{
  26. + //Variaveis globais
  27. + private static Restart _instance = null;
  28. + protected static final Logger _log = Logger.getLogger(Restart.class.getName());
  29. + private Calendar NextRestart;
  30. + private SimpleDateFormat format = new SimpleDateFormat("HH:mm");
  31. +
  32. + //Singleton
  33. + public static Restart getInstance()
  34. + {
  35. + if(_instance == null)
  36. + _instance = new Restart();
  37. + return _instance;
  38. + }
  39. +
  40. + public String getRestartNextTime()
  41. + {
  42. + if(NextRestart.getTime() != null)
  43. + return format.format(NextRestart.getTime());
  44. + else
  45. + return "Erro";
  46. + }
  47. +
  48. + //Connstrutor
  49. + private Restart()
  50. + {
  51. + //:D
  52. + }
  53. +
  54. + public void StartCalculationOfNextRestartTime()
  55. + {
  56. + _log.info("#####################################");
  57. + _log.info("#[Restart System]: System actived...#");
  58. + _log.info("#####################################");
  59. + try
  60. + {
  61. + Calendar currentTime = Calendar.getInstance();
  62. + Calendar testStartTime = null;
  63. + long flush2 = 0,timeL = 0;
  64. + int count = 0;
  65. +
  66. + for (String timeOfDay : Config.RESTART_INTERVAL_BY_TIME_OF_DAY)
  67. + {
  68. + testStartTime = Calendar.getInstance();
  69. + testStartTime.setLenient(true);
  70. + String[] splitTimeOfDay = timeOfDay.split(":");
  71. + testStartTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(splitTimeOfDay[0]));
  72. + testStartTime.set(Calendar.MINUTE, Integer.parseInt(splitTimeOfDay[1]));
  73. + testStartTime.set(Calendar.SECOND, 00);
  74. + //Verifica a validade to tempo
  75. + if (testStartTime.getTimeInMillis() < currentTime.getTimeInMillis())
  76. + {
  77. + testStartTime.add(Calendar.DAY_OF_MONTH, 1);
  78. + }
  79. +
  80. + //TimeL Recebe o quanto falta de milisegundos para o restart
  81. + timeL = testStartTime.getTimeInMillis() - currentTime.getTimeInMillis();
  82. +
  83. + //Verifica qual horario sera o proximo restart
  84. + if(count == 0){
  85. + flush2 = timeL;
  86. + NextRestart = testStartTime;
  87. + }
  88. +
  89. + if(timeL < flush2){
  90. + flush2 = timeL;
  91. + NextRestart = testStartTime;
  92. + }
  93. +
  94. + count ++;
  95. + }
  96. + _log.info("[AutoRestart]: Next Restart Time: " + NextRestart.getTime().toString());
  97. + ThreadPool.schedule(new StartRestartTask(), flush2);
  98. + }
  99. + catch (Exception e)
  100. + {
  101. + System.out.println("[AutoRestart]: The restart automated server presented error in load restarts period config !");
  102. + }
  103. + }
  104. +
  105. + class StartRestartTask implements Runnable
  106. + {
  107. + @Override
  108. + public void run()
  109. + {
  110. + _log.info("Start automated restart GameServer.");
  111. + Shutdown.getInstance().autoRestart(Config.RESTART_SECONDS);
  112. + }
  113. + }
  114. +}
  115.  
  116. Index: package net/sf/l2j/gameserver/Shutdown.java
  117.  
  118. private static class SingletonHolder
  119. {
  120. protected static final Shutdown _instance = new Shutdown();
  121. }
  122.  
  123. + public void autoRestart(int time)
  124. + {
  125. + _secondsShut = time;
  126. +
  127. + countdown();
  128. +
  129. + _shutdownMode = GM_RESTART;
  130. +
  131. + SingletonHolder._instance.setMode(GM_RESTART);
  132. + System.exit(2);
  133. + }
  134.  
  135.  
  136. Index: package net/sf/l2j/gameserver/GameServer.java
  137.  
  138.  
  139. Util.printSection("World Bosses");
  140. GrandBossManager.getInstance();
  141.  
  142. +if(Config.RESTART_BY_TIME_OF_DAY)
  143. +Restart.getInstance().StartCalculationOfNextRestartTime();
  144. +else
  145. +_log.info("# Auto Restart System is Disabled #");
  146.  
  147.  
  148. Index: package net/sf/l2j/Config.java
  149.  
  150. public static int MONSTER_LOCS_COUNT;
  151. public static int[][] MONSTER_LOCS;
  152. + public static boolean RESTART_BY_TIME_OF_DAY;
  153. + public static int RESTART_SECONDS;
  154. + public static String[] RESTART_INTERVAL_BY_TIME_OF_DAY;
  155.  
  156.  
  157. ALT_GIVE_PVP_IN_ARENA = L2JDev.getProperty("AltGivePvpInArena", false);
  158. SHOW_HP_PVP = L2JDev.getProperty("ShowHpPvP", false);
  159. + RESTART_BY_TIME_OF_DAY = Boolean.parseBoolean(L2JDev.getProperty("EnableRestartSystem", "false"));
  160. + RESTART_SECONDS = Integer.parseInt(L2JDev.getProperty("RestartSeconds", "360"));
  161. + RESTART_INTERVAL_BY_TIME_OF_DAY = L2JDev.getProperty("RestartByTimeOfDay", "20:00").split(",");
  162.  
  163.  
  164. Index: package net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  165.  
  166. import net.sf.l2j.gameserver.GameTimeController;
  167. +import net.sf.l2j.gameserver.Restart;
  168.  
  169.  
  170. SevenSigns.getInstance().sendCurrentPeriodMsg(activeChar);
  171. AnnouncementTable.getInstance().showAnnouncements(activeChar, false);
  172. + if(Config.RESTART_BY_TIME_OF_DAY)
  173. + {
  174. + ShowNextRestart(activeChar);
  175. + }
  176.  
  177.  
  178.  
  179.  
  180.  
  181. + private static void ShowNextRestart(Player activeChar)
  182. + {
  183. + activeChar.sendMessage("Next Restart: " + Restart.getInstance().getRestartNextTime());
  184. + }
  185. private void onEnterPin(Player activeChar)
  186. {
  187. String last = "";
  188. String curr = "";
  189. try
  190. {
  191. last = LastIP(activeChar);
  192.  
  193.  
  194.  
  195. Index: pasta datapack sua revisão caminho -> gameserver\config\L2JDev.properties
  196.  
  197. #=============================================================
  198. # Healer Party Restrictions
  199. #=============================================================
  200.  
  201. # Max Bishop, Cardinal, Elder, etc per PARTY
  202. MaxHealerOnParty = 2
  203. # Max Dominator per PARTY
  204. MaxCombatHealerOnParty = 3
  205.  
  206. +#======================================================
  207. +# Auto Restart
  208. +#======================================================
  209. +# Enable / Disable Restart Auto
  210. +EnableRestartSystem = True
  211. +
  212. +# If EnableRestartSystem = True hours of the day
  213. +# Example: 22:00,23:00 (hh:mm,hh:mm...)
  214. +# NOTE: Separate ":" mm:hh and "," others restart time
  215. +RestartByTimeOfDay = 00:00
  216. +
  217. +# Seconds to restart the server ( 360 = 5 Minutos )
  218. +# default = 30, Max 360
  219. +RestartSeconds = 30
Add Comment
Please, Sign In to add comment