Esempio n. 1
0
        Command GetCommand(ref string cmd, ref string cmdArgs)
        {
            if (!CheckCommand(cmd))
            {
                return(null);
            }
            Command.Search(ref cmd, ref cmdArgs);

            byte bindIndex;

            if (byte.TryParse(cmd, out bindIndex) && bindIndex < CmdBindings.Length)
            {
                if (CmdArgsBindings[bindIndex] == null)
                {
                    SendMessage("No command is bound to: /" + cmd); return(null);
                }
                cmd     = CmdBindings[bindIndex];
                cmdArgs = CmdArgsBindings[bindIndex] + " " + cmdArgs;
                cmdArgs = cmdArgs.TrimEnd(' ');
            }

            OnPlayerCommandEvent.Call(this, cmd, cmdArgs);
            if (cancelcommand)
            {
                cancelcommand = false; return(null);
            }

            Command command = Command.all.Find(cmd);

            if (command == null)
            {
                if (Block.Byte(cmd) != Block.Invalid)
                {
                    cmdArgs = cmd.ToLower(); cmd = "mode";
                    command = Command.all.FindByName("Mode");
                }
                else
                {
                    Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmd, cmdArgs);
                    SendMessage("Unknown command \"" + cmd + "\"."); return(null);
                }
            }

            if (!group.CanExecute(command))
            {
                CommandPerms.Find(command.name).MessageCannotUse(this);
                return(null);
            }

            string reason = Command.GetDisabledReason(command.Enabled);

            if (reason != null)
            {
                SendMessage("Command is disabled as " + reason); return(null);
            }
            if (level.IsMuseum && !command.museumUsable)
            {
                SendMessage("Cannot use this command while in a museum."); return(null);
            }
            return(command);
        }
Esempio n. 2
0
        Command GetCommand(ref string cmdName, ref string cmdArgs, CommandData data)
        {
            if (!CheckCommand(cmdName))
            {
                return(null);
            }

            string bound;
            byte   bindIndex;

            if (CmdBindings.TryGetValue(cmdName, out bound))
            {
                // user defined command shortcuts take priority
                bound.Separate(out cmdName, out cmdArgs);
            }
            else if (byte.TryParse(cmdName, out bindIndex) && bindIndex < 10)
            {
                // backwards compatibility for old /cmdbind behaviour
                Message("No command is bound to: &T/" + cmdName);
                return(null);
            }

            Command.Search(ref cmdName, ref cmdArgs);
            OnPlayerCommandEvent.Call(this, cmdName, cmdArgs, data);
            if (cancelcommand)
            {
                cancelcommand = false; return(null);
            }

            Command command = Command.Find(cmdName);

            if (command == null)
            {
                if (Block.Parse(this, cmdName) != Block.Invalid)
                {
                    cmdArgs = cmdName; cmdName = "mode";
                    command = Command.Find("Mode");
                }
                else
                {
                    Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmdName, cmdArgs);
                    Message("Unknown command \"{0}\".", cmdName); return(null);
                }
            }

            if (!CanUse(command))
            {
                CommandPerms.Find(command.name).MessageCannotUse(this);
                return(null);
            }

            string reason = Command.GetDisabledReason(command.Enabled);

            if (reason != null)
            {
                Message("Command is disabled as " + reason); return(null);
            }
            if (level != null && level.IsMuseum && !command.museumUsable)
            {
                Message("Cannot use &T/{0} &Swhile in a museum.", command.name); return(null);
            }
            if (frozen && !command.UseableWhenFrozen)
            {
                Message("Cannot use &T/{0} &Swhile frozen.", command.name); return(null);
            }
            return(command);
        }
Esempio n. 3
0
        Command GetCommand(ref string cmdName, ref string cmdArgs, CommandData data)
        {
            if (!CheckCommand(cmdName))
            {
                return(null);
            }
            Command.Search(ref cmdName, ref cmdArgs);

            byte bindIndex;

            if (byte.TryParse(cmdName, out bindIndex) && bindIndex < CmdBindings.Length)
            {
                if (CmdBindings[bindIndex] == null)
                {
                    Message("No command is bound to: %T/" + cmdName); return(null);
                }

                CmdBindings[bindIndex].Separate(out cmdName, out cmdArgs);
                Command.Search(ref cmdName, ref cmdArgs);
            }

            OnPlayerCommandEvent.Call(this, cmdName, cmdArgs, data);
            if (cancelcommand)
            {
                cancelcommand = false; return(null);
            }

            Command command = Command.Find(cmdName);

            if (command == null)
            {
                if (Block.Parse(this, cmdName) != Block.Invalid)
                {
                    cmdArgs = cmdName; cmdName = "mode";
                    command = Command.Find("Mode");
                }
                else
                {
                    Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmdName, cmdArgs);
                    Message("Unknown command \"" + cmdName + "\"."); return(null);
                }
            }

            if (!CanUse(command))
            {
                CommandPerms.Find(command.name).MessageCannotUse(this);
                return(null);
            }

            string reason = Command.GetDisabledReason(command.Enabled);

            if (reason != null)
            {
                Message("Command is disabled as " + reason); return(null);
            }
            if (level != null && level.IsMuseum && !command.museumUsable)
            {
                Message("Cannot use %T/{0} %Swhile in a museum.", command.name); return(null);
            }
            if (frozen && !command.UseableWhenFrozen)
            {
                Message("Cannot use %T/{0} %Swhile frozen.", command.name); return(null);
            }
            return(command);
        }
Esempio n. 4
0
        Command GetCommand(ref string cmd, ref string cmdArgs)
        {
            Command.Search(ref cmd, ref cmdArgs);

            byte bindIndex;

            if (byte.TryParse(cmd, out bindIndex) && bindIndex < 10)
            {
                if (messageBind[bindIndex] == null)
                {
                    SendMessage("No command is bound to: /" + cmd); return(null);
                }
                cmd     = cmdBind[bindIndex];
                cmdArgs = messageBind[bindIndex] + " " + cmdArgs;
                cmdArgs = cmdArgs.TrimEnd(' ');
            }

            if (OnCommand != null)
            {
                OnCommand(cmd, this, cmdArgs);
            }
            if (PlayerCommand != null)
            {
                PlayerCommand(cmd, this, cmdArgs);
            }
            OnPlayerCommandEvent.Call(cmd, this, cmdArgs);
            if (cancelcommand)
            {
                cancelcommand = false; return(null);
            }

            Command command = Command.all.Find(cmd);

            if (command == null)
            {
                if (Block.Byte(cmd) != Block.Invalid)
                {
                    cmdArgs = cmd.ToLower(); cmd = "mode";
                    command = Command.all.Find("mode");
                }
                else
                {
                    SendMessage("Unknown command \"" + cmd + "\"."); return(null);
                }
            }

            if (!group.CanExecute(command))
            {
                command.MessageCannotUse(this); return(null);
            }
            string reason = Command.GetDisabledReason(command.Enabled);

            if (reason != null)
            {
                SendMessage("Command is disabled as " + reason); return(null);
            }
            if (level.IsMuseum && !command.museumUsable)
            {
                SendMessage("Cannot use this command while in a museum."); return(null);
            }
            return(command);
        }