示例#1
0
 private static void GameShutdown()
 {
     try
     {
         PersistentOperations.Shutdown_Initiated = true;
         if (WebAPI.IsEnabled && WebAPI.IsRunning)
         {
             WebAPI.Unload();
         }
         Timers.CoreTimerStop();
         RegionReset.Exec();
         Phrases.Unload();
         CommandList.Unload();
         OutputLog.Shutdown();
     }
     catch (Exception e)
     {
         Log.Out(string.Format("[SERVERTOOLS] Error in API.GameShutdown: {0}", e.Message));
     }
 }
示例#2
0
        public override void Execute(List <string> _params, CommandSenderInfo _senderInfo)
        {
            try
            {
                if (!File.Exists(Phrases.FilePath))
                {
                    Phrases.ResetXml();
                    SingletonMonoBehaviour <SdtdConsole> .Instance.Output("[SERVERTOOLS] Phrase file has been reset to default");

                    return;
                }
                else
                {
                    SingletonMonoBehaviour <SdtdConsole> .Instance.Output("[SERVERTOOLS] Phrase file was not found. Unable to reset");

                    return;
                }
            }
            catch (Exception e)
            {
                Log.Out(string.Format("[SERVERTOOLS] Error in PhraseResetConsole.Execute: {0}", e.Message));
            }
        }
示例#3
0
        public static void Load()
        {
            try
            {
                Log.Out(string.Format("[SERVERTOOLS] Checking for save directory {0}", API.ConfigPath));
                if (!Directory.Exists(API.ConfigPath))
                {
                    Directory.CreateDirectory(API.ConfigPath);
                    Log.Out(string.Format("[SERVERTOOLS] Created directory {0}", API.ConfigPath));
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/ChatLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/DetectionLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/DetectionLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/BountyLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/BountyLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/AuctionLog"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/AuctionLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/BankLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/BankLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/DupeLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/DupeLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerReports"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerReports");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/PollLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/PollLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/ChatCommandLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatCommandLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/DamageLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/DamageLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/BlockLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/BlockLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/ConsoleCommandLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/ConsoleCommandLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/WebsiteLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/WebsiteLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/OutputLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/OutputLogs");
                }
            }
            catch (XmlException e)
            {
                Log.Out(string.Format("[SERVERTOOLS] Error in creation of directory {0}. Error = {1}", API.ConfigPath, e.Message));
            }

            try
            {
                StateManager.Awake();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the persistent database bin file. Restart the server and check for errors. Error = {0}", e.Message);
            }

            try
            {
                Config.Load();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the configuration file. Error = {0}", e.Message);
            }

            try
            {
                Mods.Load();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the tools. Restart the server and check for errors. Error = {0}", e.Message);
            }

            try
            {
                Triggers.LoadXml();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the EventTriggers.xml. Check for errors in the file. Error = {0}", e.Message);
            }

            try
            {
                Phrases.Load();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the Phrases.xml. Restart the server and check for errors. Error = {0}", e.Message);
            }

            try
            {
                HowToSetup.Load();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the HowToSetup.xml. Error = {0}", e.Message);
            }

            if (Fps.IsEnabled)
            {
                try
                {
                    Fps.SetTarget();
                }
                catch (XmlException e)
                {
                    Log.Out("[SERVERTOOLS] Failed to set the target fps. Error = {0}", e.Message);
                }
            }

            if (SleeperRespawn.IsEnabled)
            {
                try
                {
                    SdtdConsole.Instance.ExecuteSync(string.Format("sleeperreset"), null);
                }
                catch (XmlException e)
                {
                    Log.Out("[SERVERTOOLS] Failed to reset sleeper spawn points. Error = {0}", e.Message);
                }
            }

            try
            {
                Log.Out(string.Format("[SERVERTOOLS] Deleting old logs"));
                int      _daysBeforeDeleted = Days_Before_Log_Delete * -1;
                string[] files = Directory.GetFiles(API.ConfigPath + "/Logs/DetectionLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/BountyLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/AuctionLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/BankLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/DupeLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/PlayerLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/PlayerReports");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/PollLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/ChatLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/ChatCommandLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/DamageLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/BlockLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/ConsoleCommandLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/WebsiteLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                files = Directory.GetFiles(API.ConfigPath + "/Logs/OutputLogs");
                if (files != null && files.Length > 0)
                {
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                Log.Out(string.Format("[SERVERTOOLS] Log clean up completed"));
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to delete old logs. Error = {0}", e.Message);
            }

            PersistentOperations.EntityIdList();

            RestartVote.Cycle = true;

            Track.Cleanup();

            CountryBan.FileCheck();

            Timers.LogAlert();
            Timers.LoadAlert();
        }
 public static void Init()
 {
     Phrases.Init();
     LoadConfig();
     InitFileWatcher();
 }
示例#5
0
 public static void Load(int _state)
 {
     if (_state == 1)
     {
         try
         {
             Log.Out(string.Format("[SERVERTOOLS] Checking for save directory {0}", API.ConfigPath));
             if (!Directory.Exists(API.ConfigPath))
             {
                 Directory.CreateDirectory(API.ConfigPath);
                 Log.Out(string.Format("[SERVERTOOLS] Created directory {0}", API.ConfigPath));
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/ChatLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/DetectionLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/DetectionLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/BountyLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/BountyLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/AuctionLog"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/AuctionLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/BankLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/BankLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/DupeLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/DupeLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerReports"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerReports");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/PollLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/PollLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/ChatCommandLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatCommandLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/DamageLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/DamageLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/BlockLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/BlockLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/ConsoleCommandLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/ConsoleCommandLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/WebsiteLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/WebsiteLogs");
             }
             if (!Directory.Exists(API.ConfigPath + "/Logs/OutputLogs"))
             {
                 Directory.CreateDirectory(API.ConfigPath + "/Logs/OutputLogs");
             }
         }
         catch (XmlException e)
         {
             Log.Out(string.Format("[SERVERTOOLS] Error in creation of directory {0}. Error = {1}", API.ConfigPath, e.Message));
         }
         Load(2);
     }
     else if (_state == 2)
     {
         try
         {
             StateManager.Awake();
         }
         catch (XmlException e)
         {
             Log.Out("[SERVERTOOLS] Failed to load the persistent database bin file. Restart the server and check for errors. Error = {0}", e.Message);
         }
         Load(3);
     }
     else if (_state == 3)
     {
         try
         {
             LoadConfig.Load();
         }
         catch (XmlException e)
         {
             Log.Out("[SERVERTOOLS] Failed to load the configuration file. Error = {0}", e.Message);
         }
         Load(4);
     }
     else if (_state == 4)
     {
         try
         {
             Mods.Load();
         }
         catch (XmlException e)
         {
             Log.Out("[SERVERTOOLS] Failed to load the tools. Restart the server and check for errors. Error = {0}", e.Message);
         }
         Load(5);
     }
     else if (_state == 5)
     {
         try
         {
             LoadTriggers.LoadXml();
         }
         catch (XmlException e)
         {
             Log.Out("[SERVERTOOLS] Failed to load the EventTriggers.xml. Check for errors in the file. Error = {0}", e.Message);
         }
         Load(6);
     }
     else if (_state == 6)
     {
         try
         {
             Phrases.Load();
         }
         catch (XmlException e)
         {
             Log.Out("[SERVERTOOLS] Failed to load the Phrases.xml. Restart the server and check for errors. Error = {0}", e.Message);
         }
         try
         {
             HowToSetup.Load();
         }
         catch (XmlException e)
         {
             Log.Out("[SERVERTOOLS] Failed to load the HowToSetup.xml. Error = {0}", e.Message);
         }
         Load(7);
     }
     else if (_state == 7)
     {
         if (Fps.IsEnabled)
         {
             try
             {
                 Fps.SetTarget();
             }
             catch (XmlException e)
             {
                 Log.Out("[SERVERTOOLS] Failed to set the target fps. Error = {0}", e.Message);
             }
         }
         Load(8);
     }
     else if (_state == 8)
     {
         Log.Out(string.Format("[SERVERTOOLS] Deleting old logs"));
         int      _daysBeforeDeleted = Days_Before_Log_Delete * -1;
         string[] files = Directory.GetFiles(API.ConfigPath + "/Logs/DetectionLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/BountyLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/AuctionLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/BankLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/DupeLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/PlayerLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/PlayerReports");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/PollLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/ChatLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/ChatCommandLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/DamageLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/BlockLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/ConsoleCommandLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/WebsiteLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         files = Directory.GetFiles(API.ConfigPath + "/Logs/OutputLogs");
         if (files != null && files.Length > 0)
         {
             foreach (string file in files)
             {
                 FileInfo fi = new FileInfo(file);
                 if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                 {
                     fi.Delete();
                 }
             }
         }
         Log.Out(string.Format("[SERVERTOOLS] Log clean up completed"));
         Load(9);
     }
     else if (_state == 9)
     {
         RestartVote.Startup = true;
         Load(10);
     }
     else if (_state == 10)
     {
         Track.Cleanup();
         Load(11);
     }
     else if (_state == 11)
     {
         CountryBan.FileCheck();
         Load(12);
     }
     else if (_state == 12)
     {
         Timers.LogAlert();
         Timers.LoadAlert();
     }
 }
示例#6
0
        private static void LoadXml()
        {
            if (!Utils.FileExists(configFilePath))
            {
                UpdateXml();
                Phrases.Load();
                return;
            }
            XmlDocument xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.Load(configFilePath);
            }
            catch (XmlException e)
            {
                Log.Error(string.Format("[SERVERTOOLS] Failed loading {0}: {1}", configFilePath, e.Message));
                return;
            }
            XmlNode _XmlNode = xmlDoc.DocumentElement;

            foreach (XmlNode childNode in _XmlNode.ChildNodes)
            {
                if (childNode.Name == "Version")
                {
                    foreach (XmlNode subChild in childNode.ChildNodes)
                    {
                        if (subChild.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (subChild.NodeType != XmlNodeType.Element)
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Tools' section: {0}", subChild.OuterXml));
                            continue;
                        }
                        XmlElement _line = (XmlElement)subChild;
                        if (!_line.HasAttribute("Version"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring Version entry because of missing 'Version' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        double _oldversion;
                        if (!double.TryParse(_line.GetAttribute("Version"), out _oldversion))
                        {
                            Log.Out(string.Format("[SERVERTOOLS] Ignoring Version entry because of invalid (non-numeric) value for 'Version' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        if (_oldversion == version)
                        {
                            UpdateConfigs = false;
                        }
                    }
                }
                if (childNode.Name == "Tools")
                {
                    foreach (XmlNode subChild in childNode.ChildNodes)
                    {
                        if (subChild.NodeType == XmlNodeType.Comment)
                        {
                            continue;
                        }
                        if (subChild.NodeType != XmlNodeType.Element)
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Unexpected XML node found in 'Tools' section: {0}", subChild.OuterXml));
                            continue;
                        }
                        XmlElement _line = (XmlElement)subChild;
                        if (!_line.HasAttribute("Name"))
                        {
                            Log.Warning(string.Format("[SERVERTOOLS] Ignoring tool entry because of missing 'Name' attribute: {0}", subChild.OuterXml));
                            continue;
                        }
                        switch (_line.GetAttribute("Name"))
                        {
                        case "AdminChatCommands":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AdminChatCommands entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out AdminChat.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AdminChatCommands entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("PermissionLevelForMute"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AdminChatCommands entry because of missing 'PermissionLevelForMute' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!int.TryParse(_line.GetAttribute("PermissionLevelForMute"), out MutePlayer.PermLevelNeededforMute))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AdminChatCommands entry because of invalid (non-numeric) value for 'PermissionLevelForMute' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "AdminNameColoring":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AdminNameColoring entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out ChatHook.AdminNameColoring))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AdminNameColoring entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("Prefix"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AdminNameColoring entry because of missing 'Prefix' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            ChatHook.AdminPrefix = _line.GetAttribute("Prefix");
                            if (!_line.HasAttribute("Color"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AdminNameColoring entry because of missing 'Color' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            ChatHook.AdminColor = _line.GetAttribute("Color");
                            break;

                        case "AnnounceInvalidItemStack":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InvalidItemStack entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out InventoryCheck.AnounceInvalidStack))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InvalidItemStack entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "AutoSaveWorld":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AutoSaveWorld entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out AutoSaveWorld.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AutoSaveWorld entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("DelayBetweenWorldSaves"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AutoSaveWorld entry because of missing 'DelayBetweenWorldSaves' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!int.TryParse(_line.GetAttribute("DelayBetweenWorldSaves"), out AutoSaveWorld.DelayBetweenWorldSaves))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring AutoSaveWorld entry because of invalid (non-numeric) value for 'DelayBetweenWorldSaves' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "BadWordFilter":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring BadWordFilter entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out Badwords.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring BadWordFilter entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "ChatFloodProtection":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ChatFloodProtection entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out ChatHook.ChatFlood))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ChatFloodProtection entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "ChatLogger":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ChatLogger entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out ChatLog.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ChatLogger entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "ClanManager":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ClanManager entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out ClanManager.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ClanManager entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "CustomCommands":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring CustomCommands entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out CustomCommands.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring CustomCommands entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("ChatColor"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring CustomCommands entry because of missing 'ChatColor' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            CustomCommands.ChatColor = _line.GetAttribute("ChatColor");
                            break;

                        case "Day7":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Day7 entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out Day7.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Day7 entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "Gimme":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Gimme entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out Gimme.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Gimme entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("DelayBetweenGimmeUses"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring gimme entry because of missing 'DelayBetweenGimmeUses' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!int.TryParse(_line.GetAttribute("DelayBetweenGimmeUses"), out Gimme.DelayBetweenUses))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring gimme entry because of invalid (non-numeric) value for 'DelayBetweenGimmeUses' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("AlwaysShowResponse"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Gimme entry because of missing 'AlwaysShowResponse' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("AlwaysShowResponse"), out Gimme.AlwaysShowResponse))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Gimme entry because of invalid (true/false) value for 'AlwaysShowResponse' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "HighPingKicker":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring HighPingKicker entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out HighPingKicker.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring HighPingKicker entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("SamplesNeeded"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ping entry because of missing 'SamplesNeeded' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!int.TryParse(_line.GetAttribute("SamplesNeeded"), out HighPingKicker.SamplesNeeded))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ping entry because of invalid (non-numeric) value for 'SamplesNeeded' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("Maxping"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ping entry because of missing 'Maxping' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!int.TryParse(_line.GetAttribute("Maxping"), out HighPingKicker.MAXPING))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ping entry because of invalid (non-numeric) value for 'maxping' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "InfoTicker":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InfoTicker entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            bool _old = InfoTicker.IsEnabled;
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out InfoTicker.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InfoTicker entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("DelayBetweenMessages"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InfoTicker entry because of missing 'DelayBetweenMessages' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!int.TryParse(_line.GetAttribute("DelayBetweenMessages"), out InfoTicker.DelayBetweenMessages))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InfoTicker entry because of invalid (non-numeric) value for 'DelayBetweenMessages' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "InvalidItemKicker":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InvalidItemKicker entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out InventoryCheck.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InvalidItemKicker entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("Ban"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InvalidItemKicker entry because of missing 'Ban' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Ban"), out InventoryCheck.BanPlayer))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring InvalidItemKicker entry because of invalid (true/false) value for 'Ban' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "Killme":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring killme entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out KillMe.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring killme entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("DelayBetweenKillmeUses"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring killme entry because of missing 'DelayBetweenKillmeUses' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!int.TryParse(_line.GetAttribute("DelayBetweenKillmeUses"), out KillMe.DelayBetweenUses))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring killme entry because of invalid (non-numeric) value for 'DelayBetweenKillmeUses' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "Motd":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Motd entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out Motd.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Motd entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("Message"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Motd entry because of missing a Message attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (Motd.IsEnabled)
                            {
                                Motd.Message = _line.GetAttribute("Message");
                            }
                            break;

                        case "ReservedSlots":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ReservedSlots entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out ReservedSlots.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring ReservedSlots entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "SetHome":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring SetHome entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out TeleportHome.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring SetHome entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!_line.HasAttribute("DelayBetweenSetHomeUses"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring SetHome entry because of missing 'DelayBetweenSetHomeUses' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!int.TryParse(_line.GetAttribute("DelayBetweenSetHomeUses"), out TeleportHome.DelayBetweenUses))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring SetHome entry because of invalid (non-numeric) value for 'DelayBetweenSetHomeUses' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;

                        case "Watchlist":
                            if (!_line.HasAttribute("Enable"))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Watchlist entry because of missing 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            if (!bool.TryParse(_line.GetAttribute("Enable"), out Watchlist.IsEnabled))
                            {
                                Log.Warning(string.Format("[SERVERTOOLS] Ignoring Watchlist entry because of invalid (true/false) value for 'Enable' attribute: {0}", subChild.OuterXml));
                                continue;
                            }
                            break;
                        }
                    }
                }
            }
            if (UpdateConfigs)
            {
                UpdateXml();
            }
            Phrases.Load();
            Mods.Load();
            UpdateConfigs = true;
        }
示例#7
0
        public static void Load(int _state)
        {
            if (_state == 1)
            {
                try
                {
                    Log.Out(string.Format("[ServerTools] Checking for save directory {0}", API.ConfigPath));
                    if (!Directory.Exists(API.ConfigPath))
                    {
                        Directory.CreateDirectory(API.ConfigPath);
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/ChatLogs"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/ChatLogs"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatLogs");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/ChatLogs"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/DetectionLogs"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/DetectionLogs"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/DetectionLogs");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/DetectionLogs"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/BountyLogs"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/BountyLogs"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/BountyLogs");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/BountyLogs"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/AuctionLog"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/AuctionLog"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/AuctionLog");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/AuctionLog"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/BankLogs"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/BankLogs"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/BankLogs");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/BankLogs"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/DupeLogs"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/DupeLogs"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/DupeLogs");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/DupeLogs"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/PlayerLogs"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerLogs"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerLogs");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/PlayerLogs"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/PlayerReports"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerReports"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerReports");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/PlayerReports"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }
                    Log.Out(string.Format("[ServerTools] Checking for logs directory {0}", API.ConfigPath + "/Logs/PollLogs"));
                    if (!Directory.Exists(API.ConfigPath + "/Logs/PollLogs"))
                    {
                        Directory.CreateDirectory(API.ConfigPath + "/Logs/PollLogs");
                        Log.Out(string.Format("[ServerTools] Created directory {0}", API.ConfigPath + "/Logs/PollLogs"));
                    }
                    else
                    {
                        Log.Out("[ServerTools] Directory found");
                    }


                    string[] files = Directory.GetFiles(API.ConfigPath + "/Logs/DetectionLogs");
                    int      _daysBeforeDeleted = (Days_Before_Log_Delete * -1);
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                    files = Directory.GetFiles(API.ConfigPath + "/Logs/BountyLogs");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                    files = Directory.GetFiles(API.ConfigPath + "/Logs/AuctionLog");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                    files = Directory.GetFiles(API.ConfigPath + "/Logs/BankLogs");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                    files = Directory.GetFiles(API.ConfigPath + "/Logs/DupeLogs");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                    files = Directory.GetFiles(API.ConfigPath + "/Logs/PlayerLogs");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                    files = Directory.GetFiles(API.ConfigPath + "/Logs/PlayerReports");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                    files = Directory.GetFiles(API.ConfigPath + "/Logs/PollLogs");
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        if (fi.CreationTime < DateTime.Now.AddDays(_daysBeforeDeleted))
                        {
                            fi.Delete();
                        }
                    }
                }
                catch (XmlException e)
                {
                    Log.Out(string.Format("[ServerTools] Error in creation of directory {0}. Error = {1}", API.ConfigPath, e.Message));
                }
                Load(2);
            }
            if (_state == 2)
            {
                try
                {
                    LoadConfig.Load();
                }
                catch (XmlException e)
                {
                    Log.Out("[ServerTools] Failed to load the configuration file. Error = {0}", e.Message);
                }
                Load(3);
            }
            if (_state == 3)
            {
                try
                {
                    SQL.Connect();
                }
                catch (XmlException e)
                {
                    Log.Out("[ServerTools] Failed to connect to an sql database. ST requires this to operate. Error = {0}", e.Message);
                }
                Load(4);
            }
            if (_state == 4)
            {
                try
                {
                    Mods.Load();
                }
                catch (XmlException e)
                {
                    Log.Out("[ServerTools] Failed to load the tools. Restart the server and check for errors. Error = {0}", e.Message);
                }
                Load(5);
            }
            if (_state == 5)
            {
                try
                {
                    LoadTriggers.LoadXml();
                }
                catch (XmlException e)
                {
                    Log.Out("[ServerTools] Failed to load the EventTriggers.xml. Check for errors in the file. Error = {0}", e.Message);
                }
                Load(6);
            }
            if (_state == 6)
            {
                try
                {
                    Phrases.Load();
                }
                catch (XmlException e)
                {
                    Log.Out("[ServerTools] Failed to load the Phrases.xml. Restart the server and check for errors. Error = {0}", e.Message);
                }
                try
                {
                    HowToSetup.Load();
                }
                catch (XmlException e)
                {
                    Log.Out("[ServerTools] Failed to load the HowToSetup.xml. Error = {0}", e.Message);
                }
                Load(7);
            }
            if (_state == 7)
            {
                if (Fps.IsEnabled)
                {
                    try
                    {
                        Fps.SetTarget();
                    }
                    catch (XmlException e)
                    {
                        Log.Out("[ServerTools] Failed to set the target fps. Error = {0}", e.Message);
                    }
                }
                Load(8);
            }
            if (_state == 8)
            {
                Timers.LogAlert();
                Timers.LoadAlert();
                Load(9);
            }
            if (_state == 9)
            {
                RestartVote.Startup = true;
            }
        }
示例#8
0
        public static void Load()
        {
            if (!Directory.Exists(API.ConfigPath))
            {
                Directory.CreateDirectory(API.ConfigPath);
                Log.Out(string.Format("[SERVERTOOLS] Created new directory '{0}'", API.ConfigPath));
            }
            else
            {
                Log.Out(string.Format("[SERVERTOOLS] Located directory '{0}'", API.ConfigPath));
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/ChatLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/DetectionLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/DetectionLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/BountyLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/BountyLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/AuctionLog"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/AuctionLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/BankLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/BankLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/DupeLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/DupeLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerReports"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerReports");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/PollLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/PollLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/ChatCommandLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatCommandLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/DamageLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/DamageLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/BlockLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/BlockLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/ConsoleCommandLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/ConsoleCommandLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/WebPanelLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/WebPanelLogs");
            }
            if (!Directory.Exists(API.ConfigPath + "/Logs/OutputLogs"))
            {
                Directory.CreateDirectory(API.ConfigPath + "/Logs/OutputLogs");
            }
            if (!Directory.Exists(API.GamePath + "/Mods/ServerTools/Config"))
            {
                Directory.CreateDirectory(API.GamePath + "/Mods/ServerTools/Config");
            }
            if (!Directory.Exists(API.GamePath + "/Mods/ServerTools/Config/XUi"))
            {
                Directory.CreateDirectory(API.GamePath + "/Mods/ServerTools/Config/XUi");
            }

            StateManager.Awake();

            RunTimePatch.PatchAll();

            Config.Load();
            Log.Out("[SERVERTOOLS] Running ServerTools v.{0}", Config.Version);

            CommandList.BuildList();
            CommandList.Load();

            PersistentOperations.SetFolders();
            PersistentOperations.CreateCustomXUi();
            PersistentOperations.GetCurrencyName();
            PersistentOperations.EntityIdList();
            PersistentOperations.Player_Killing_Mode = GamePrefs.GetInt(EnumGamePrefs.PlayerKillingMode);

            Mods.Load();

            Phrases.Load();

            HowToSetup.Load();

            if (Fps.IsEnabled)
            {
                Fps.SetTarget();
            }

            if (SleeperRespawn.IsEnabled)
            {
                try
                {
                    SingletonMonoBehaviour <SdtdConsole> .Instance.ExecuteSync(string.Format("sleeperreset"), null);
                }
                catch (XmlException e)
                {
                    Log.Out("[SERVERTOOLS] Failed to reset sleeper spawn points. Error = {0}", e.Message);
                }
            }
            try
            {
                DeleteFiles("DetectionLogs");
                DeleteFiles("BountyLogs");
                DeleteFiles("AuctionLogs");
                DeleteFiles("BankLogs");
                DeleteFiles("DupeLogs");
                DeleteFiles("PlayerLogs");
                DeleteFiles("PlayerReports");
                DeleteFiles("PollLogs");
                DeleteFiles("ChatLogs");
                DeleteFiles("ChatCommandLogs");
                DeleteFiles("DamageLogs");
                DeleteFiles("BlockLogs");
                DeleteFiles("ConsoleCommandLogs");
                DeleteFiles("WebPanelLogs");
                DeleteFiles("OutputLogs");
                Log.Out(string.Format("[SERVERTOOLS] Xml log clean up complete"));
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to delete old logs. Error = {0}", e.Message);
            }

            if (PersistentContainer.Instance.WorldSeed == 0)
            {
                PersistentContainer.Instance.WorldSeed = GameManager.Instance.World.Seed;
                PersistentContainer.DataChange         = true;
            }
            else if (PersistentContainer.Instance.WorldSeed != GameManager.Instance.World.Seed)
            {
                PersistentContainer.Instance.WorldSeed = GameManager.Instance.World.Seed;
                PersistentContainer.DataChange         = true;
                if (!CleanBin.IsEnabled && PersistentContainer.Instance.Players.IDs.Count > 0)
                {
                    Log.Out("[SERVERTOOLS] Detected a new world. You have old ServerTools data saved from the last map. Run the Clean_Bin tool to remove the data of your choice");
                }
            }

            if (PersistentContainer.Instance.Connections == null)
            {
                Dictionary <string, byte[]> connections = new Dictionary <string, byte[]>();
                PersistentContainer.Instance.Connections = connections;
                Dictionary <string, DateTime> timeOuts = new Dictionary <string, DateTime>();
                PersistentContainer.Instance.ConnectionTimeOut = timeOuts;
                PersistentContainer.DataChange = true;
            }

            if (CleanBin.IsEnabled)
            {
                CleanBin.Exec();
                Log.Out("[SERVERTOOLS] ServerTools.bin has been cleaned. The tool will now disable automatically");
                CleanBin.IsEnabled = false;
                Config.WriteXml();
                Config.LoadXml();
            }

            Track.Cleanup();

            DroppedBagProtection.BuildList();
            BlackJack.BuildDeck();

            ActiveTools.Exec(true);

            Timers.Thirty_Second_Delay();
            Timers.PersistentDataSave();
        }
示例#9
0
        public static void Load()
        {
            try
            {
                Log.Out(string.Format("[SERVERTOOLS] Checking for save directory {0}", API.ConfigPath));
                if (!Directory.Exists(API.ConfigPath))
                {
                    Directory.CreateDirectory(API.ConfigPath);
                    Log.Out(string.Format("[SERVERTOOLS] Created directory {0}", API.ConfigPath));
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/ChatLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/DetectionLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/DetectionLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/BountyLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/BountyLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/AuctionLog"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/AuctionLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/BankLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/BankLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/DupeLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/DupeLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/PlayerReports"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/PlayerReports");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/PollLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/PollLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/ChatCommandLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/ChatCommandLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/DamageLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/DamageLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/BlockLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/BlockLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/ConsoleCommandLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/ConsoleCommandLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/WebPanelLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/WebPanelLogs");
                }
                if (!Directory.Exists(API.ConfigPath + "/Logs/OutputLogs"))
                {
                    Directory.CreateDirectory(API.ConfigPath + "/Logs/OutputLogs");
                }
            }
            catch (XmlException e)
            {
                Log.Out(string.Format("[SERVERTOOLS] Error in creation of directory @ {0}. Error = {1}", API.ConfigPath, e.Message));
            }

            try
            {
                StateManager.Awake();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the persistent database bin file. Restart the server and check for errors. Error = {0}", e.Message);
            }

            try
            {
                Config.Load();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the configuration file. Error = {0}", e.Message);
            }

            try
            {
                Mods.Load();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the tools. Restart the server and check for errors. Error = {0}", e.Message);
            }

            try
            {
                Triggers.LoadXml();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the EventTriggers.xml. Check for errors in the file. Error = {0}", e.Message);
            }

            try
            {
                Phrases.Load();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the Phrases.xml. Restart the server and check for errors. Error = {0}", e.Message);
            }

            try
            {
                HowToSetup.Load();
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to load the HowToSetup.xml. Error = {0}", e.Message);
            }

            if (Fps.IsEnabled)
            {
                try
                {
                    Fps.SetTarget();
                }
                catch (XmlException e)
                {
                    Log.Out("[SERVERTOOLS] Failed to set the target fps. Error = {0}", e.Message);
                }
            }

            if (SleeperRespawn.IsEnabled)
            {
                try
                {
                    SdtdConsole.Instance.ExecuteSync(string.Format("sleeperreset"), null);
                }
                catch (XmlException e)
                {
                    Log.Out("[SERVERTOOLS] Failed to reset sleeper spawn points. Error = {0}", e.Message);
                }
            }
            try
            {
                DeleteFiles("DetectionLogs");
                DeleteFiles("BountyLogs");
                DeleteFiles("AuctionLogs");
                DeleteFiles("BankLogs");
                DeleteFiles("DupeLogs");
                DeleteFiles("PlayerLogs");
                DeleteFiles("PlayerReports");
                DeleteFiles("PollLogs");
                DeleteFiles("ChatLogs");
                DeleteFiles("ChatCommandLogs");
                DeleteFiles("DamageLogs");
                DeleteFiles("BlockLogs");
                DeleteFiles("ConsoleCommandLogs");
                DeleteFiles("WebPanelLogs");
                DeleteFiles("OutputLogs");
                Log.Out(string.Format("[SERVERTOOLS] Log clean up completed"));
            }
            catch (XmlException e)
            {
                Log.Out("[SERVERTOOLS] Failed to delete old logs. Error = {0}", e.Message);
            }

            PersistentOperations.EntityIdList();
            CountryBan.BuildList();

            RestartVote.Cycle = true;

            Track.Cleanup();

            Timers.LogAlert();
            Timers.LoadAlert();
            Timers.PersistentDataSave();
        }