public ServerConfig(List<ChatCommand> commands)
        {
            ChatCommands = commands;

            if (MyAPIGateway.Utilities.IsDedicated)
                ServerIsClient = false;

            Config = new ServerConfigurationStruct();

            //cfg
            ConfigFileName = string.Format(ConfigFileNameFormat, Path.GetFileNameWithoutExtension(MyAPIGateway.Session.CurrentPath));
            LoadOrCreateConfig();

            if (Config.EnableLog)
            {
                ChatCommandLogic.Instance.Debug = true;
                Logger.Init();
                Logger.Debug("Log Enabled.");
            }

            //motd
            MotdFileName = string.Format(MotdFileNameFormat, Config.MotdFileSuffix);
            LoadOrCreateMotdFile();
            //chat log
            GcLogFileName = string.Format(GcLogFileNameFormat, Path.GetFileNameWithoutExtension(MyAPIGateway.Session.CurrentPath));
            LoadOrCreateChatLog();
            //permissions
            PermissionFileName = string.Format(PermissionFileNameFormat, Path.GetFileNameWithoutExtension(MyAPIGateway.Session.CurrentPath));
            LoadOrCreatePermissionFile();
            //pm log
            if (Config.LogPrivateMessages)
            {
                PmLogFileName = string.Format(PmLogFileNameFormat, Path.GetFileNameWithoutExtension(MyAPIGateway.Session.CurrentPath));
                LoadOrCreatePmLog();
            }

            if (Config.NoGrindIndestructible)
            {
                MyAPIGateway.Session.DamageSystem.RegisterBeforeDamageHandler(0, IndestructibleDamageHandler);
                RegisteredIndestructibleDamageHandler = true;
                Logger.Debug("Registered indestructible damage handler.");
            }
            
            Logger.Debug("Config loaded.");
        }
        private void LoadConfig()
        {
            TextReader reader = MyAPIGateway.Utilities.ReadFileInLocalStorage(ConfigFileName, typeof(ServerConfig));

            var xmlText = reader.ReadToEnd();
            reader.Close();

            if (string.IsNullOrWhiteSpace(xmlText))
                return;

            try
            {
                Config = MyAPIGateway.Utilities.SerializeFromXML<ServerConfigurationStruct>(xmlText);
            }
            catch (Exception ex)
            {
                AdminNotification notification = new AdminNotification()
                {
                    Date = DateTime.Now,
                    Content = string.Format(@"There is an error in the config file. It couldn't be read. The server was started with default settings.

            Message:
            {0}

            If you can't find the error, simply delete the file. The server will create a new one with default settings on restart.", ex.Message)
                };

                AdminNotificator.StoreAndNotify(notification);
            }

            var sendLogPms = Config.LogPrivateMessages != CommandPrivateMessage.LogPrivateMessages;
            CommandPrivateMessage.LogPrivateMessages = Config.LogPrivateMessages;
            if (sendLogPms)
                ConnectionHelper.SendMessageToAllPlayers(new MessageConfig()
                {
                    Config = new ServerConfigurationStruct()
                    {
                        LogPrivateMessages = CommandPrivateMessage.LogPrivateMessages
                    },
                    Action = ConfigAction.LogPrivateMessages
                });
        }
        public ServerConfig(List<ChatCommand> commands)
        {
            ChatCommands = commands;

            if (MyAPIGateway.Utilities.IsDedicated)
                ServerIsClient = false;

            Config = new ServerConfigurationStruct();

            //cfg
            ConfigFileName = string.Format(ConfigFileNameFormat, Path.GetFileNameWithoutExtension(MyAPIGateway.Session.CurrentPath));
            LoadOrCreateConfig();
            //motd
            MotdFileName = string.Format(MotdFileNameFormat, Config.MotdFileSuffix);
            LoadOrCreateMotdFile();
            //chat log
            GcLogFileName = string.Format(GcLogFileNameFormat, Path.GetFileNameWithoutExtension(MyAPIGateway.Session.CurrentPath));
            LoadOrCreateChatLog();
            //permissions
            PermissionFileName = string.Format(PermissionFileNameFormat, Path.GetFileNameWithoutExtension(MyAPIGateway.Session.CurrentPath));
            LoadOrCreatePermissionFile();
            //pm log
            if (Config.LogPrivateMessages)
            {
                PmLogFileName = string.Format(PmLogFileNameFormat, Path.GetFileNameWithoutExtension(MyAPIGateway.Session.CurrentPath));
                LoadOrCreatePmLog();
            }
            Logger.Debug("Config loaded.");
        }
        private void LoadConfig()
        {
            TextReader reader = MyAPIGateway.Utilities.ReadFileInLocalStorage(ConfigFileName, typeof(ServerConfig));

            var xmlText = reader.ReadToEnd();
            reader.Close();

            if (string.IsNullOrWhiteSpace(xmlText))
                return;

            try
            {
                Config = MyAPIGateway.Utilities.SerializeFromXML<ServerConfigurationStruct>(xmlText);
            }
            catch (Exception ex)
            {
                ChatCommandLogic.Instance.AdminNotification = string.Format(@"There is an error in the config file. It couldn't be read. The server was started with default settings.

            Message:
            {0}

            If you can't find the error, simply delete the file. The server will create a new one with default settings on restart.", ex.Message);
            }

            var sendMotdHl = !Config.MotdHeadLine.Equals(CommandMessageOfTheDay.HeadLine);
            CommandMessageOfTheDay.HeadLine = Config.MotdHeadLine;
            if (sendMotdHl)
                ConnectionHelper.SendMessageToAllPlayers(ConnectionHelper.ConnectionKeys.MotdHeadLine, CommandMessageOfTheDay.HeadLine);

            var sendMotdSic = Config.MotdShowInChat != CommandMessageOfTheDay.ShowInChat;
            CommandMessageOfTheDay.ShowInChat = Config.MotdShowInChat;
            if (sendMotdSic)
                ConnectionHelper.SendMessageToAllPlayers(ConnectionHelper.ConnectionKeys.MotdShowInChat, CommandMessageOfTheDay.ShowInChat.ToString());

            var sendLogPms = Config.LogPrivateMessages != CommandPrivateMessage.LogPrivateMessages;
            CommandPrivateMessage.LogPrivateMessages = Config.LogPrivateMessages;
            if (sendLogPms)
                ConnectionHelper.SendMessageToAllPlayers(ConnectionHelper.ConnectionKeys.LogPrivateMessages, CommandPrivateMessage.LogPrivateMessages.ToString());
        }