Esempio n. 1
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 /// <param name="flags">Options for command.</param>
 /// <param name="parent">Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested.</param>
 /// <param name="Arg">Custom argument to pass to function handler. This way you can register multiple commands to a same
 /// function handler only differentiating them with this custom argument.</param>
 /// <param name="AuthMask">Mask of allowed auth levels to access this command. Default ulong.MaxValue (meaning all auth levels are allowed).
 /// Enter 3 for example to allow only auth level 1 and 2 to access this command.</param>
 /// <param name="MinLength">Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour.</param>
 protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength, CMDFlags flags, string parent, int Arg, ulong AuthMask)
 {
     InputHandler.RegisterCommand(Cmd, Args, f, flags, parent, Arg, AuthMask, Keyword.ToLower().Trim(), MinLength);
 }
Esempio n. 2
0
 public Command(string cmd_name, Privileges priv, CmdFunction action)
 {
     Name      = cmd_name;
     Privilege = priv;
     Action    = action;
 }
Esempio n. 3
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 /// <param name="MinLength">Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour.</param>
 /// <param name="flags">Options for command.</param>
 /// <param name="parent">Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested.</param>
 protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength, CMDFlags flags, string parent)
 {
     RegisterCommand(Cmd, Args, f, MinLength, flags, parent, 0);
 }
Esempio n. 4
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 /// <param name="MinLength">Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour.</param>
 /// <param name="flags">Options for command.</param>
 /// <param name="parent">Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested.</param>
 /// <param name="Arg">Custom argument to pass to function handler. This way you can register multiple commands to a same
 /// function handler only differentiating them with this custom argument.</param>
 protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength, CMDFlags flags, string parent, int Arg)
 {
     RegisterCommand(Cmd, Args, f, MinLength, flags, parent, Arg, ulong.MaxValue);
 }
Esempio n. 5
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 protected void RegisterCommand(string Cmd, string Args, CmdFunction f)
 {
     RegisterCommand(Cmd, Args, f, 0);
 }
Esempio n. 6
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 /// <param name="MinLength">Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't. Enter 0 to disable this behaviour.</param>
 protected void RegisterCommand(string Cmd, string Args, CmdFunction f, int MinLength)
 {
     RegisterCommand(Cmd, Args, f, MinLength, CMDFlags.None);
 }
Esempio n. 7
0
        /// <summary>
        /// Register a new command or overwrite a previous one.
        /// </summary>
        /// <param name="Cmd">Command to register.</param>
        /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
        /// if you don't want to capture anything or plan to do so in the function yourself.</param>
        /// <param name="f">Function of command.</param>
        /// <param name="flags">Options for command.</param>
        /// <param name="parent">Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested.</param>
        /// <param name="Arg">Custom argument to pass to function handler. This way you can register multiple commands to a same
        /// function handler only differentiating them with this custom argument.</param>
        /// <param name="AuthMask">Mask of allowed auth levels to access this command. Default ulong.MaxValue (meaning all auth levels are allowed).
        /// Enter 3 for example to allow only auth level 1 and 2 to access this command.</param>
        /// <param name="Plugin">From which plugin did this come.</param>
        /// <param name="ReqMinLength">Minimum length of command typed required to activate. For example if command is "plugins" and this is 6 then "plugin" and "plugins" both activate this command but "plugi" won't.</param>
        internal static void RegisterCommand(string Cmd, string Args, CmdFunction f, CMDFlags flags, string parent, int Arg, ulong AuthMask, string Plugin, int ReqMinLength)
        {
            if (string.IsNullOrEmpty(Cmd))
            {
                return;
            }

            Cmd = Cmd.ToLower().Trim();
            if (string.IsNullOrEmpty(Cmd))
            {
                return;
            }

            if (Cmd.Contains(' '))
            {
                Cmd = Cmd.Substring(0, Cmd.IndexOf(' '));
            }

            InputEntry p = null;

            if (!string.IsNullOrEmpty(parent))
            {
                string[] pc = parent.ToLower().Trim().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                if (pc.Length == 0)
                {
                    return;
                }

                if (Commands.ContainsKey(pc[0]))
                {
                    p = Commands[pc[0]];
                    for (int i = 1; i < pc.Length; i++)
                    {
                        if (p.Subcommands != null && p.Subcommands.ContainsKey(pc[i]))
                        {
                            p = p.Subcommands[pc[i]];
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                else
                {
                    return;
                }
            }

            InputEntry c = new InputEntry()
            {
                Command   = Cmd,
                CustomArg = Arg,
                Flags     = flags,
                Func      = f,
                Parent    = p,
                Plugin    = Plugin,
                MinLength = ReqMinLength,
                AuthMask  = AuthMask
            };

            try
            {
                c.ArgumentsPattern = new Regex(Args, RegexOptions.IgnoreCase);
            }
            catch
            {
                c.ArgumentsPattern = null;
            }

            if (p != null)
            {
                if (p.Subcommands == null)
                {
                    p.Subcommands = new SortedDictionary <string, InputEntry>();
                }
                p.Subcommands[Cmd] = c;
                p.Flags           |= CMDFlags.IsParent;
            }
            else
            {
                Commands[Cmd] = c;
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 /// <param name="flags">Options for command.</param>
 /// <param name="parent">Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested.</param>
 /// <param name="Arg">Custom argument to pass to function handler. This way you can register multiple commands to a same
 /// function handler only differentiating them with this custom argument.</param>
 internal static void RegisterCommand(string Cmd, string Args, CmdFunction f, CMDFlags flags, string parent, int Arg)
 {
     RegisterCommand(Cmd, Args, f, flags, parent, Arg, ulong.MaxValue, "core", 0);
 }
Esempio n. 9
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 /// <param name="flags">Options for command.</param>
 /// <param name="parent">Parent command (if you want to create a subcommand). You can enter commands separated with space if it's nested.</param>
 internal static void RegisterCommand(string Cmd, string Args, CmdFunction f, CMDFlags flags, string parent)
 {
     RegisterCommand(Cmd, Args, f, flags, parent, 0);
 }
Esempio n. 10
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 /// <param name="flags">Options for command.</param>
 internal static void RegisterCommand(string Cmd, string Args, CmdFunction f, CMDFlags flags)
 {
     RegisterCommand(Cmd, Args, f, flags, null);
 }
Esempio n. 11
0
 /// <summary>
 /// Register a new command or overwrite a previous one.
 /// </summary>
 /// <param name="Cmd">Command to register.</param>
 /// <param name="Args">Arguments to match (regex pattern). This can be set to null or empty string
 /// if you don't want to capture anything or plan to do so in the function yourself.</param>
 /// <param name="f">Function of command.</param>
 internal static void RegisterCommand(string Cmd, string Args, CmdFunction f)
 {
     RegisterCommand(Cmd, Args, f, CMDFlags.None);
 }