public override void ProcessServer()
 {
     switch (Action)
     {
         case ConfigAction.Save:
             ChatCommandLogic.Instance.ServerCfg.Save();
             ConnectionHelper.SendChatMessage(SenderSteamId, "Config saved.");
             break;
         case ConfigAction.Reload:
             ChatCommandLogic.Instance.ServerCfg.ReloadConfig();
             ConnectionHelper.SendChatMessage(SenderSteamId, "Config reloaded.");
             break;
         case ConfigAction.AdminLevel:
             ChatCommandLogic.Instance.ServerCfg.UpdateAdminLevel(Config.AdminLevel);
             ConnectionHelper.SendChatMessage(SenderSteamId, string.Format("Updated default admin level to {0}. Please note that you have to use '/cfg save' to save it permanently.", Config.AdminLevel));
             break;
         case ConfigAction.NoGrindIndestructible:
             ChatCommandLogic.Instance.ServerCfg.SetNoGrindIndestructible(Config.NoGrindIndestructible);
             ConnectionHelper.SendChatMessage(SenderSteamId, string.Format("Set NoGrindIndestructible to {0}. ", Config.NoGrindIndestructible));
             break;
         case ConfigAction.Show:
             Config = ChatCommandLogic.Instance.ServerCfg.Config;
             ConnectionHelper.SendMessageToPlayer(SenderSteamId, this);
             break;
     }
 }
Ejemplo n.º 2
0
        public override void ProcessServer()
        {
            switch (Action)
            {
            case ConfigAction.Save:
                ChatCommandLogic.Instance.ServerCfg.Save();
                MessageClientTextMessage.SendMessage(SenderSteamId, "Server", "Config saved.");
                break;

            case ConfigAction.Reload:
                ChatCommandLogic.Instance.ServerCfg.ReloadConfig();
                MessageClientTextMessage.SendMessage(SenderSteamId, "Server", "Config reloaded.");
                break;

            case ConfigAction.AdminLevel:
                ChatCommandLogic.Instance.ServerCfg.UpdateAdminLevel(Config.AdminLevel);
                MessageClientTextMessage.SendMessage(SenderSteamId, "Server", string.Format("Updated default admin level to {0}. Please note that you have to use '/cfg save' to save it permanently.", Config.AdminLevel));
                break;

            case ConfigAction.NoGrindIndestructible:
                ChatCommandLogic.Instance.ServerCfg.SetNoGrindIndestructible(Config.NoGrindIndestructible);
                MessageClientTextMessage.SendMessage(SenderSteamId, "Server", string.Format("Set NoGrindIndestructible to {0}. ", Config.NoGrindIndestructible));
                break;

            case ConfigAction.Show:
                Config = ChatCommandLogic.Instance.ServerCfg.Config;
                ConnectionHelper.SendMessageToPlayer(SenderSteamId, this);
                break;
            }
        }
        public override void Load()
        {
            Config = new ServerConfigurationStruct();

            TextReader reader  = MyAPIGateway.Utilities.ReadFileInLocalStorage(Name, 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);
            }

            if (Config == null)
            {
                Config = new ServerConfigurationStruct();
            }

            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
                });
            }

            Config.MotdFileSuffix = Config.MotdFileSuffix.ReplaceForbiddenChars();
        }
 public override void Create()
 {
     Config = new ServerConfigurationStruct();
     Save();
 }