Example #1
0
 /// <summary>
 /// Displays the argument length error.
 /// </summary>
 /// <param name="c">The cmd args.</param>
 public void DisplayArgLengthError(Cmd c)
 {
     _irc.SendIrcNotice(c.FromUser,
                        string.Format(
                            "\u0002[ERROR]\u0002 The correct usage is: \u0002{0}{1}\u0002 <start|stop|reset|status>",
                            IrcCommandList.IrcCommandPrefix, c.CmdName));
 }
Example #2
0
 /// <summary>
 /// Displays the argument length error.
 /// </summary>
 /// <param name="c">The cmd args.</param>
 public void DisplayArgLengthError(Cmd c)
 {
     _irc.SendIrcNotice(c.FromUser, string.Format("\u0002[ERROR]\u0002 The correct usage is: \u0002{0}{1}\u0002" +
                                                  " <sst command> <sst command args>",
                                                  IrcCommandList.IrcCommandPrefix, c.CmdName));
     _irc.SendIrcNotice(c.FromUser, string.Format("<sst command> is a cmd you'd normally issue in-game," +
                                                  " and <sst cmd args> are its arguments, if required, i.e: {0}{1} {2} syncore",
                                                  IrcCommandList.IrcCommandPrefix, c.CmdName, CommandList.CmdSeen));
 }
Example #3
0
        /// <summary>
        /// Executes the specified command.
        /// </summary>
        /// <param name="c">The cmd args.</param>
        /// <returns>
        /// <c>true</c> if the command was successfully executed, otherwise returns <c>false</c>.
        /// </returns>
        public bool Exec(Cmd c)
        {
            var cmds = _cmdList.Select(cmd =>
                                       string.Format("{0}{1}", IrcCommandList.IrcCommandPrefix, cmd.Key)).ToList();

            _irc.SendIrcNotice(c.FromUser,
                               string.Format(
                                   "\u0003[COMMANDS]: \u0002{0}\u0002 - for more information, visit: http://sst.syncore.org/help",
                                   string.Join(", ", cmds)));

            return(true);
        }
Example #4
0
        /// <summary>
        /// Executes the specified command.
        /// </summary>
        /// <param name="c">The cmd args.</param>
        /// <returns>
        /// <c>true</c> if the command was successfully executed, otherwise returns <c>false</c>.
        /// </returns>
        public bool Exec(Cmd c)
        {
            if (!c.FromUser.Equals(_irc.IrcSettings.ircAdminNickname, StringComparison.InvariantCultureIgnoreCase))
            {
                _irc.SendIrcNotice(c.FromUser,
                                   "\u0002[ERROR]\u0002 You do not have permission to access this command.");

                Log.Write(string.Format("{0} requested IRC operator status in {1}, but lacks permission. Ignoring.",
                                        c.FromUser, _irc.IrcSettings.ircChannel), _logClassType, _logPrefix);

                return(false);
            }

            _irc.OpUser(c.FromUser);

            Log.Write(string.Format("Giving operator status to {0} in {1}",
                                    c.FromUser, _irc.IrcSettings.ircChannel), _logClassType, _logPrefix);

            return(true);
        }
Example #5
0
        /// <summary>
        /// Processes the IRC command.
        /// </summary>
        /// <param name="fromUser">The user who sent the command.</param>
        /// <param name="msg">The full message text.</param>
        public async Task ProcessIrcCommand(string fromUser, string msg)
        {
            char[] sep     = { ' ' };
            var    args    = msg.Split(sep);
            var    cmdName = args[0].Substring(1);

            if (!CheckCommand(fromUser, cmdName, msg))
            {
                return;
            }

            // See if command requires active server monitoring
            var c = new Cmd(args, cmdName, fromUser, msg, true);

            if (_ircCmds.Commands[cmdName].RequiresMonitoring &&
                (((!_sst.IsMonitoringServer && !_sst.IsInitComplete))))
            {
                _irc.SendIrcNotice(fromUser,
                                   "\u0002[ERROR]\u0002 This command requires that a server be monitored; your server" +
                                   " is not currently being monitored.");

                Log.Write(string.Format(
                              "Could not execute IRC user {0}'s IRC command ({1}) because command requires active server" +
                              " monitoring and no server is being monitored at this time.",
                              c.FromUser, cmdName), _logClassType, _logPrefix);

                return;
            }
            // Check argument length
            var minArgs = _ircCmds.Commands[cmdName].IrcMinArgs;

            if (args.Length < minArgs)
            {
                _ircCmds.Commands[cmdName].DisplayArgLengthError(c);

                Log.Write(string.Format(
                              "IRC user {0} specified invalid # of args for {1}{2} command. Required: {3}," +
                              " specified: {4}, received: {5}. Ignoring.",
                              fromUser, IrcCommandList.IrcCommandPrefix, cmdName, minArgs, args.Length, msg),
                          _logClassType, _logPrefix);

                return;
            }
            // Execute
            if (_ircCmds.Commands[cmdName].IsAsync)
            {
                if (await _ircCmds.Commands[cmdName].ExecAsync(c))
                {
                    Log.Write(string.Format("Successfully executed IRC user {0}'s IRC command ({1}): {2}",
                                            fromUser, cmdName, msg), _logClassType, _logPrefix);
                }
                else
                {
                    Log.Write(string.Format(
                                  "Unsuccessful execution of IRC user {0}'s IRC command ({1}): {2}", fromUser,
                                  cmdName, msg), _logClassType, _logPrefix);
                }
            }
            else
            {
                if (_ircCmds.Commands[cmdName].Exec(c))
                {
                    Log.Write(string.Format("Successfully executed IRC user {0}'s IRC command ({1}): {2}",
                                            fromUser, cmdName, msg), _logClassType, _logPrefix);
                }
                else
                {
                    Log.Write(string.Format(
                                  "Unsuccessful execution of IRC user {0}'s IRC command ({1}): {2}", fromUser,
                                  cmdName, msg), _logClassType, _logPrefix);
                }
            }
        }