Ejemplo n.º 1
0
        void Listener_OnPrivate(UserInfo user, string message)
        {
            message = Colors.IrcToMinecraftColors(message);
            message = CP437Reader.ConvertToRaw(message);
            string[] parts   = message.SplitSpaces(2);
            string   cmdName = parts[0].ToLower();
            string   cmdArgs = parts.Length > 1 ? parts[1] : "";

            if (HandleWhoCommand(user.Nick, cmdName, false))
            {
                return;
            }
            Command.Search(ref cmdName, ref cmdArgs);

            string error;
            string chan = String.IsNullOrEmpty(channel) ? opchannel : channel;

            if (!CheckIRCCommand(user, cmdName, chan, out error))
            {
                if (error != null)
                {
                    Pm(user.Nick, error);
                }
                return;
            }
            HandleIRCCommand(user.Nick, user.Nick, cmdName, cmdArgs);
        }
Ejemplo n.º 2
0
        bool HandlePublicCommand(UserInfo user, string channel, string message,
                                 string[] parts, bool opchat)
        {
            string cmdName = parts.Length > 1 ? parts[1].ToLower() : "";
            string cmdArgs = parts.Length > 2 ? parts[2] : "";

            Command.Search(ref cmdName, ref cmdArgs);

            string error;

            if (!CheckIRCCommand(user, cmdName, channel, out error))
            {
                if (error != null)
                {
                    Say(error, opchat);
                }
                return(false);
            }

            string nick = opchat ? "#@private@#" : "#@public@#";

            return(HandleIRCCommand(nick, user.Nick, cmdName, cmdArgs));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }