Advertisement
Guest User

Untitled

a guest
Jul 4th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Threading;
  3.  
  4. namespace ServerTools
  5. {
  6.     public class ShutDownWorld
  7.     {
  8.         public static bool IsEnabled = false;
  9.         public static bool IsRunning = false;
  10.         public static int DelayBetweenShutDown = 120;
  11.         private static Thread th;
  12.  
  13.         public static void Start()
  14.         {
  15.             th = new Thread(new ThreadStart(Shutdown));
  16.             th.IsBackground = true;
  17.             th.Start();
  18.             IsRunning = true;
  19.             Log.Out("[SERVERTOOLS] AutoShutDown has started.");
  20.         }
  21.  
  22.         public static void Stop()
  23.         {
  24.             if (!IsEnabled)
  25.             {
  26.                 th.Abort();
  27.                 IsRunning = false;
  28.                 Log.Out("[SERVERTOOLS] AutoShutDown has stopped.");
  29.             }
  30.         }
  31.  
  32.         private static void Shutdown()
  33.         {
  34.             while (IsEnabled)
  35.             {
  36.                 Thread.Sleep(60000 * (DelayBetweenShutDown-30))
  37.                 NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 30 minutes"), "Server", false, "", false));
  38.                 Thread.Sleep(60000 * 5);
  39.                 NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 25 minutes"), "Server", false, "", false));
  40.                 Thread.Sleep(60000 * 5);
  41.                 NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 20 minutes"), "Server", false, "", false));
  42.                 Thread.Sleep(60000 * 5);
  43.                 NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 15 minutes"), "Server", false, "", false));
  44.                 Thread.Sleep(60000 * 5);
  45.                 NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 10 minutes"), "Server", false, "", false));
  46.                 Thread.Sleep(60000 * 5);
  47.                 NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 5 minutes"), "Server", false, "", false));
  48.                 Thread.Sleep(60000 * 4);
  49.                 NetPackageGameMessage(EnumGameMessages.Chat, string.Format("{0}{1}[-]", CustomCommands.ChatColor, "Server is restarting in 1 minute"), "Server", false, "", false));
  50.                 Thread.Sleep(60000 * 1);
  51.                 List<ClientInfo> _cInfoList = ConnectionManager.Instance.GetClients();
  52.                 ClientInfo _cInfo = _cInfoList.RandomObject();
  53.                 SdtdConsole.Instance.ExecuteSync("shutdown", _cInfo);
  54.                 Log.Out("[SERVERTOOLS] World ShutDown.");
  55.                 Thread.Sleep(60000 * DelayBetweenShutDown);
  56.             }
  57.             Stop();
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement