Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Threading;
- namespace ServerTools
- {
- public class ShutDownWorld
- {
- public static bool IsEnabled = false;
- public static bool IsRunning = false;
- public static int DelayBetweenShutDown = 120;
- private static Thread th;
- public static void Start()
- {
- th = new Thread(new ThreadStart(Save));
- th.IsBackground = true;
- th.Start();
- IsRunning = true;
- Log.Out("[SERVERTOOLS] AutoShutDown has started.");
- }
- public static void Stop()
- {
- if (!IsEnabled)
- {
- th.Abort();
- IsRunning = false;
- Log.Out("[SERVERTOOLS] AutoShutDown has stopped.");
- }
- }
- private static void Save()
- {
- while (IsEnabled)
- {
- Thread.Sleep(60000 * (DelayBetweenShutDown-30))
- NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 30 minutes"), "Server", false, "", false));
- Thread.Sleep(60000 * 5);
- NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 25 minutes"), "Server", false, "", false));
- Thread.Sleep(60000 * 5);
- NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 20 minutes"), "Server", false, "", false));
- Thread.Sleep(60000 * 5);
- NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 15 minutes"), "Server", false, "", false));
- Thread.Sleep(60000 * 5);
- NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 10 minutes"), "Server", false, "", false));
- Thread.Sleep(60000 * 5);
- NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 5 minutes"), "Server", false, "", false));
- Thread.Sleep(60000 * 4);
- NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 1 minute"), "Server", false, "", false));
- Thread.Sleep(60000 * 1);
- List<ClientInfo> _cInfoList = ConnectionManager.Instance.GetClients();
- ClientInfo _cInfo = _cInfoList.RandomObject();
- SdtdConsole.Instance.ExecuteSync("shutdown", _cInfo);
- Log.Out("[SERVERTOOLS] World ShutDown.");
- Thread.Sleep(60000 * DelayBetweenShutDown);
- }
- Stop();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement