示例#1
0
        public override void Execute(string commandArgs)
        {
            string playerName;
            string reason;

            CommandSystemHelperMethods.SplitCommand(commandArgs, out playerName, out reason);
            reason = string.IsNullOrEmpty(reason) ? "No reason specified" : reason;

            if (playerName != "")
            {
                var player = ClientRetriever.GetClientByName(playerName);
                if (player != null)
                {
                    LunaLog.Normal($"Kicking {playerName} from the server");
                    MessageQueuer.SendConnectionEnd(player, $"Kicked from the server: {reason}");
                }
                else
                {
                    LunaLog.Normal($"Player: {playerName} not found");
                }
            }
            else
            {
                LunaLog.Error("Syntax error. Usage: /kick playername [reason]");
            }
        }
示例#2
0
        public override void HandleCommand(string commandArgs)
        {
            string playerName;
            string func;

            CommandSystemHelperMethods.SplitCommand(commandArgs, out func, out playerName);

            switch (func)
            {
            default:
                LunaLog.Normal("Undefined function. Usage: /admin [add|del] playername or /admin show");
                break;

            case "add":
                AdminAddCommand.Execute(playerName);
                break;

            case "del":
                AdminRemoveCommand.Execute(playerName);
                break;

            case "show":
                AdminShowCommand.Execute("");
                break;
            }
        }
示例#3
0
        public override void Execute(string commandArgs)
        {
            string playerName;
            string reason;

            CommandSystemHelperMethods.SplitCommand(commandArgs, out playerName, out reason);
            reason = string.IsNullOrEmpty(reason) ? "No reason specified" : reason;

            if (!string.IsNullOrEmpty(playerName))
            {
                var player = ClientRetriever.GetClientByName(playerName);

                if (player != null)
                {
                    MessageQueuer.SendConnectionEnd(player, $"You were banned from the server: {reason}");
                }

                Add(playerName);
                LunaLog.Normal($"Player '{playerName}' was banned from the server: {reason}");
            }
            else
            {
                LunaLog.Normal($"Player: {playerName} not found");
            }
        }
示例#4
0
        public override bool Execute(string commandArgs)
        {
            CommandSystemHelperMethods.SplitCommandParamArray(commandArgs, out var parameters);

            if (!ValidateParameters(parameters))
            {
                return(false);
            }

            var settingsFile = parameters[0];
            var settingName  = parameters[1];
            var newValue     = parameters[2];

            var settingsPath = GetSettingsFilePath(settingsFile);

            if (string.IsNullOrEmpty(settingsPath))
            {
                LunaLog.Error($"Syntax error. Could not find a settings file called '{settingsFile}'");
                return(false);
            }

            try
            {
                ChangeServerSettings(settingName, newValue, settingsPath);
            }
            catch (Exception e)
            {
                LunaLog.Error($"Error while changing settings: {e}");
            }

            return(true);
        }
        public override bool Execute(string commandArgs)
        {
            CommandSystemHelperMethods.SplitCommand(commandArgs, out var playerName, out var reason);
            reason = string.IsNullOrEmpty(reason) ? "No reason specified" : reason;

            if (!string.IsNullOrEmpty(playerName))
            {
                var player = ClientRetriever.GetClientByName(playerName);

                if (player != null)
                {
                    MessageQueuer.SendConnectionEnd(player, $"You were banned from the server: {reason}");
                    Add(player.UniqueIdentifier);
                    LunaLog.Normal($"Player '{playerName}' was banned from the server: {reason}");
                    return(true);
                }
                else
                {
                    LunaLog.Normal($"Player '{playerName}' not found");
                }
            }
            else
            {
                LunaLog.Normal("Undefined function. Usage: /ban [username] [reason]");
            }

            return(false);
        }
示例#6
0
        public override void Execute(string commandArgs)
        {
            string ip;
            string reason;

            CommandSystemHelperMethods.SplitCommand(commandArgs, out ip, out reason);
            reason = string.IsNullOrEmpty(reason) ? "No reason specified" : reason;

            IPAddress ipAddress;

            if (IPAddress.TryParse(ip, out ipAddress))
            {
                var player = ClientRetriever.GetClientByIp(ipAddress);

                if (player != null)
                {
                    MessageQueuer.SendConnectionEnd(player, $"You were banned from the server: {reason}");
                }

                Add(ipAddress.ToString());
                LunaLog.Normal($"IP Address '{ip}' was banned from the server: {reason}");
            }
            else
            {
                LunaLog.Normal($"{ip} is not a valid IP address");
            }
        }
        public override void HandleCommand(string commandArgs)
        {
            string playerName;
            string func;

            CommandSystemHelperMethods.SplitCommand(commandArgs, out func, out playerName);

            switch (func)
            {
            default:
                LunaLog.Debug("Undefined function. Usage: /whitelist [add|del] playername or /whitelist show");
                break;

            case "add":
                WhitelistAddCommand.Add(playerName);
                break;

            case "del":
                WhitelistRemoveCommand.Remove(playerName);
                break;

            case "show":
                WhitelistShowCommand.Retrieve();
                break;
            }
        }
示例#8
0
        public override void Execute(string commandArgs)
        {
            CommandSystemHelperMethods.SplitCommand(commandArgs, out var publicKey, out var reason);
            reason = string.IsNullOrEmpty(reason) ? "No reason specified" : reason;

            var player = ClientRetriever.GetClientByPublicKey(publicKey);

            if (player != null)
            {
                MessageQueuer.SendConnectionEnd(player, $"You were banned from the server: {reason}");
            }

            Add(publicKey);
            LunaLog.Normal($"Public key '{publicKey}' was banned from the server: {reason}");
        }
        //Executes the ClearVesselsCommand
        public override bool Execute(string commandArgs)
        {
            CommandSystemHelperMethods.SplitCommandParamArray(commandArgs, out var parameters);

            var msgUsage = $"{Environment.NewLine}{Environment.NewLine}" +
                           $"Usage:{Environment.NewLine}" +
                           "/clearvessels vesselType vesselSituation vesselSplashed vesselName";

            var msgDescription = $"{Environment.NewLine}{Environment.NewLine}" +
                                 $"Description:{Environment.NewLine}" +
                                 $"You can use * on a search param to accept all possible values.{Environment.NewLine}" +
                                 $"Using * for all params like in the following example{Environment.NewLine}" +
                                 $"will clear every vessel from universe.{Environment.NewLine}" +
                                 $"/clearvessels * * * * *{Environment.NewLine}" +
                                 $"vesselType can be ship, plane, debris, spaceobject etc.{Environment.NewLine}" +
                                 $"vesselSituation can be orbiting, flying, landed.{Environment.NewLine}" +
                                 $"vesselSplashed can be true or false.{Environment.NewLine}" +
                                 $"vesselName is the given vessel name.{Environment.NewLine}" +
                                 $"Example: /clearvessels plane orbiting * aeris{Environment.NewLine}" +
                                 $"Clears all vessels that are planes and have{Environment.NewLine}" +
                                 "name containing the word aeris.";

            try
            {
                if (parameters.Length == 4)
                {
                    var vesselType      = string.IsNullOrEmpty(parameters[0]) ? "" : parameters[0];
                    var vesselSituation = string.IsNullOrEmpty(parameters[1]) ? "" : parameters[1];
                    var vesselSplashed  = string.IsNullOrEmpty(parameters[2]) ? "" : parameters[2];
                    var vesselName      = string.IsNullOrEmpty(parameters[3]) ? "" : parameters[3];

                    RunRemove(vesselType, vesselSituation, vesselSplashed, vesselName);
                }
                else
                {
                    LunaLog.Error($"{Environment.NewLine}Syntax error. Wrong number of parameters.{msgUsage}{msgDescription}");
                    return(false);
                }
            }
            catch (Exception)
            {
                LunaLog.Error($"{Environment.NewLine}Syntax error.{msgUsage}{msgDescription}");
                return(false);
            }

            return(true);
        }
        //Executes the SetFundsCommand
        public override bool Execute(string commandArgs)
        {
            //Check parameter
            CommandSystemHelperMethods.SplitCommandParamArray(commandArgs, out var parameters);
            if (!CheckParameter(parameters))
            {
                return(false);
            }
            var funds    = parameters[0];
            var isDouble = double.TryParse(funds, out var dFunds);

            if (isDouble)
            {
                //Set funds
                SetFunds(dFunds);
                return(true);
            }
            else
            {
                LunaLog.Error($"Syntax error. Use valid number as parameter!");
                return(false);
            }
        }
示例#11
0
        //Executes the SetScienceCommand
        public override bool Execute(string commandArgs)
        {
            //Check parameter
            CommandSystemHelperMethods.SplitCommandParamArray(commandArgs, out var parameters);
            if (!CheckParameter(parameters))
            {
                return(false);
            }
            var science = parameters[0];
            var isFloat = float.TryParse(science, out var fScience);

            if (isFloat)
            {
                //Set science
                SetScience(fScience);
                return(true);
            }
            else
            {
                LunaLog.Error($"Syntax error. Use valid number as parameter!");
                return(false);
            }
        }
示例#12
0
        //Executes the ChangeSettingsCommand
        public override bool Execute(string commandArgs)
        {
            //Set messages
            var msgUsage = Environment.NewLine
                           + Environment.NewLine + "Usage:"
                           + Environment.NewLine + "/changesettings settingsFile settingName newValue";

            var msgSettingFileInfo = Environment.NewLine + "Parameter settingsFile can be settings, gameplaysettings or debugsettings.";

            var msgDescription = Environment.NewLine
                                 + Environment.NewLine + "Description:"
                                 + msgSettingFileInfo
                                 + Environment.NewLine + "Parameter settingName corresponds to the names inside the settings xml files."
                                 + Environment.NewLine + "Parameter settingName is case sensitive."
                                 + Environment.NewLine + "Parameter newValue is the new value."
                                 + Environment.NewLine + "Use '-' to set the new value as empty."
                                 + Environment.NewLine + Environment.NewLine + "Examples:"
                                 + Environment.NewLine + "This will change server password to empty ..."
                                 + Environment.NewLine + "/changesettings settings Password -"
                                 + Environment.NewLine + "This will change MaxPlayers to 8 ..."
                                 + Environment.NewLine + "/changesettings settings MaxPlayers 8";

            //Get param array from command
            CommandSystemHelperMethods.SplitCommandParamArray(commandArgs, out var parameters);

            //Check parameters
            if (parameters == null)
            {
                LunaLog.Error(Environment.NewLine + "Syntax error. No parameters found." + msgUsage + msgDescription);
                return(false);
            }
            if (parameters.Length != 3)
            {
                LunaLog.Error(Environment.NewLine + "Syntax error. Wrong number of parameters." + msgUsage + msgDescription);
                return(false);
            }
            if (parameters[0] == "")
            {
                LunaLog.Error(Environment.NewLine + "Syntax error. First parameter not found." + msgUsage + msgDescription);
                return(false);
            }
            if (parameters[1] == "")
            {
                LunaLog.Error(Environment.NewLine + "Syntax error. Second parameter not found." + msgUsage + msgDescription);
                return(false);
            }
            if (parameters[2] == "")
            {
                LunaLog.Error(Environment.NewLine + "Syntax error. Third parameter not found." + msgUsage + msgDescription);
                return(false);
            }

            //Get param values
            var settingsFile     = parameters[0];
            var settingsFileName = "Settings.xml";
            var settingName      = parameters[1];
            var newValue         = parameters[2];

            //Check setting file
            var settingsFileLowered = settingsFile.ToLower();

            if (settingsFileLowered == "settings")
            {
                settingsFileName = "Settings.xml";
            }
            else if (settingsFileLowered == "gameplaysettings")
            {
                settingsFileName = "GameplaySettings.xml";
            }
            else if (settingsFileLowered == "debugsettings")
            {
                settingsFileName = "DebugSettings.xml";
            }
            else
            {
                LunaLog.Error(Environment.NewLine + "Syntax error. First parameter (settingsFile) wrong use." + Environment.NewLine + msgSettingFileInfo + msgUsage + msgDescription);
                return(false);
            }

            //Define settings xml path
            var settingsPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\Config\\" + settingsFileName;

            //Define stream reader and xml document
            var streamReader = new StreamReader(settingsPath);
            var document     = new XmlDocument();

            //Try to change the settings
            try
            {
                //Change server settings
                ChangeServerSettings(settingName, newValue, streamReader, document, settingsPath);
            }
            catch (Exception e)
            {
                LunaLog.Error(Environment.NewLine + "Exception error: " + Environment.NewLine + e.ToString());
            }
            finally
            {
                //Close and Dispose streamReader if not already done
                CloseDisposeStreamReader(streamReader);
            }

            return(true);
        }
示例#13
0
        //Executes the ClearVesselsCommand
        public override bool Execute(string commandArgs)
        {
            //Get param array from command
            CommandSystemHelperMethods.SplitCommandParamArray(commandArgs, out var parameters);

            //Declare variables
            var paramCount = 5;

            var msgUsage = Environment.NewLine
                           + Environment.NewLine + "Usage:"
                           + Environment.NewLine + "/clearvessels vesselType vesselSituation vesselSplashed vesselName orbName";

            var msgDescription = Environment.NewLine
                                 + Environment.NewLine + "Description:"
                                 + Environment.NewLine + "You can use * on a search param to accept all possible values."
                                 + Environment.NewLine + "Using * for all params like in the following example"
                                 + Environment.NewLine + "will clear every vessel from universe."
                                 + Environment.NewLine + "/clearvessels * * * * *"
                                 + Environment.NewLine + "vesselType can be ship, plane, debris, spaceobject etc."
                                 + Environment.NewLine + "vesselSituation can be orbiting, flying, landed."
                                 + Environment.NewLine + "vesselSplashed can be true or false."
                                 + Environment.NewLine + "vesselName is the given vessel name."
                                 + Environment.NewLine + "Checks if the name contains the given vesselName."
                                 + Environment.NewLine + "orbName is the name of the orb the vessel is close to."
                                 + Environment.NewLine + "For example kerbin or duna."
                                 + Environment.NewLine + "Checks if the orb name contains the given orbName."
                                 + Environment.NewLine + "The following command clears all vessels from"
                                 + Environment.NewLine + "kerbin orbit that are planes and have"
                                 + Environment.NewLine + "name containing the word aeris."
                                 + Environment.NewLine + "/clearvessels plane orbiting * aeris kerbin";

            var vesselType      = "";
            var vesselSituation = "";
            var vesselSplashed  = "";
            var vesselName      = "";
            var orbName         = "";

            try
            {
                //Check number of parameters and if they are null or empty
                if (parameters != null && !string.IsNullOrEmpty(parameters[0]) && parameters.Length == paramCount)
                {
                    //Get params
                    if (!string.IsNullOrEmpty(parameters[0]))
                    {
                        vesselType = parameters[0];
                    }
                    if (!string.IsNullOrEmpty(parameters[1]))
                    {
                        vesselSituation = parameters[1];
                    }
                    if (!string.IsNullOrEmpty(parameters[2]))
                    {
                        vesselSplashed = parameters[2];
                    }
                    if (!string.IsNullOrEmpty(parameters[3]))
                    {
                        vesselName = parameters[3];
                    }
                    if (!string.IsNullOrEmpty(parameters[4]))
                    {
                        orbName = parameters[4];
                    }

                    //Check params
                    vesselType      = string.IsNullOrEmpty(vesselType) ? "" : vesselType;
                    vesselSituation = string.IsNullOrEmpty(vesselSituation) ? "" : vesselSituation;
                    vesselSplashed  = string.IsNullOrEmpty(vesselSplashed) ? "" : vesselSplashed;
                    vesselName      = string.IsNullOrEmpty(vesselName) ? "" : vesselName;
                    orbName         = string.IsNullOrEmpty(orbName) ? "" : orbName;

                    //Remove vessels
                    RunRemove(vesselType, vesselSituation, vesselSplashed, vesselName, orbName);
                }
                else
                {
                    LunaLog.Error($"{Environment.NewLine}Syntax error. Wrong number of parameters.{msgUsage}{msgDescription}");
                    return(false);
                }
            }
            catch (Exception)
            {
                LunaLog.Error($"{Environment.NewLine}Syntax error.{msgUsage}{msgDescription}");
                return(false);
            }

            return(true);
        }