bool FindTokenCommand(string prefix, out CommandInfo info)
        {
            info = null;

            foreach (var plugin in PluginManager.EnumeratePlugins)
            {
                lock (plugin.commands)
                {
                    if (plugin.IsEnabled && plugin.commands.TryGetValue (prefix, out info) && info.tokenCallback != null)
                        return true;
                }
            }

            if (serverCommands.TryGetValue (prefix, out info) && info.tokenCallback != null)
                return true;

            return false;
        }
        /// <summary>
        /// Permissions checking for registered commands.
        /// </summary>
        /// <param name="sender">Entity to check permissions for</param>
        /// <param name="cmd">Command to check for permissions on</param>
        /// <returns>True if entity can use command.  False if not.</returns>
        public static bool CheckPermissions(ISender sender, CommandInfo cmd)
        {
            /*
             *  [TODO] Should a node return false, Since there is three possibilites, should it return false if permissions
             *  is enabled and allow the normal OP system work or no access at all?
             */
            if (cmd.node == null || sender is ConsoleSender || sender.Op)
                return true;

            if (sender is Player && Program.permissionManager.IsPermittedImpl != null && Statics.PermissionsEnabled)
                return Program.permissionManager.IsPermittedImpl(cmd.node, sender as Player);

            return false;
        }
        /// <summary>
        /// Registers new command
        /// </summary>
        /// <param name="prefix">The text attached to the / that will be registered as the command.</param>
        /// <returns>CommandInfo for new command</returns>
        public CommandInfo AddCommand(string prefix)
        {
            if (serverCommands.ContainsKey (prefix)) throw new ApplicationException ("AddCommand: duplicate command: " + prefix);

            var cmd = new CommandInfo ();
            serverCommands[prefix] = cmd;
            serverCommands["." + prefix] = cmd;

            return cmd;
        }
 /// <summary>
 /// Determines entity's ability to use command. Used when permissions plugin is running.
 /// </summary>
 /// <param name="cmd">Command to check</param>
 /// <param name="sender">Sender entity to check against</param>
 /// <returns>True if sender can use command, false if not</returns>
 public static bool CheckAccessLevel(CommandInfo cmd, ISender sender)
 {
     return CheckPermissions(sender, cmd) ? true : CheckAccessLevel(cmd.accessLevel, sender);
 }
 internal void InitFrom(CommandInfo other)
 {
     description = other.description;
     helpText = other.helpText;
     accessLevel = other.accessLevel;
     tokenCallback = other.tokenCallback;
     stringCallback = other.stringCallback;
     ClearEvents ();
 }
        bool FindTokenCommand(string prefix, out CommandInfo info)
        {
            info = null;

            foreach (var plugin in server.PluginManager.Plugins.Values)
            {
                if (plugin.commands.TryGetValue (prefix, out info) && info.tokenCallback != null)
                    return true;
            }

            if (serverCommands.TryGetValue (prefix, out info) && info.tokenCallback != null)
                return true;

            return false;
        }
 public static bool CheckAccessLevel(CommandInfo cmd, ISender sender)
 {
     if (sender is Player) return cmd.accessLevel == AccessLevel.PLAYER || (cmd.accessLevel == AccessLevel.OP && sender.Op);
     if (sender is RConSender) return cmd.accessLevel <= AccessLevel.REMOTE_CONSOLE;
     if (sender is ConsoleSender) return true;
     throw new NotImplementedException ("Unexpected ISender implementation");
 }
        /// <summary>
        /// Adds new command to the server's command list
        /// </summary>
        /// <param name="prefix">Command text</param>
        /// <returns>New Command</returns>
        protected CommandInfo AddCommand(string prefix)
        {
            if (commands.ContainsKey (prefix)) throw new ApplicationException ("AddCommand: duplicate command: " + prefix);

            var cmd = new CommandInfo ();
            commands[prefix] = cmd;
            commands[string.Concat (Name.ToLower(), ".", prefix)] = cmd;

            return cmd;
        }