Пример #1
0
 public bool Execute(CmdTrigger <RealmServerCmdArgs> trigger, bool checkForCall)
 {
     if (checkForCall && trigger.Text.ConsumeNext(RealmCommandHandler.ExecCommandPrefix))
     {
         return(RealmCommandHandler.Call(trigger));
     }
     return(base.Execute(trigger));
 }
Пример #2
0
        /// <summary>Default Command-Handling method</summary>
        /// <returns>Whether the given msg triggered a command</returns>
        public static bool HandleCommand(IUser user, string msg, IGenericChatTarget target)
        {
            if (msg.Length > 0 && user.Role.Commands.Count > 0)
            {
                char ch1;
                bool isCall;
                if (!(isCall = !RealmCommandHandler.IsCommandPrefix(ch1 = msg[0])) ||
                    (int)ch1 == (int)RealmCommandHandler.ExecCommandPrefix)
                {
                    if (msg.Length != 2 || msg[1] != '?')
                    {
                        bool flag = false;
                        foreach (char ch2 in msg)
                        {
                            if (ch2 >= 'A')
                            {
                                flag = true;
                                break;
                            }
                        }

                        if (!flag)
                        {
                            return(false);
                        }
                    }

                    bool dbl        = false;
                    int  startIndex = 1;
                    if ((int)msg[1] == (int)ch1)
                    {
                        if (!user.Role.CanUseCommandsOnOthers)
                        {
                            user.SendMessage("You are not allowed to use Commands on others.");
                            return(true);
                        }

                        if (user.Target == null)
                        {
                            user.SendMessage("Invalid target.");
                            return(true);
                        }

                        dbl = true;
                        ++startIndex;
                    }

                    IngameCmdTrigger trigger =
                        new IngameCmdTrigger(new StringStream(msg.Substring(startIndex)), user, target, dbl);
                    if (trigger.InitTrigger())
                    {
                        if (trigger.Args.Context != null)
                        {
                            trigger.Args.Context.ExecuteInContext((Action)(() =>
                            {
                                if (!isCall)
                                {
                                    RealmCommandHandler.Instance.Execute((CmdTrigger <RealmServerCmdArgs>)trigger,
                                                                         false);
                                }
                                else
                                {
                                    RealmCommandHandler.Call((CmdTrigger <RealmServerCmdArgs>)trigger);
                                }
                            }));
                        }
                        else if (!isCall)
                        {
                            RealmCommandHandler.Instance.Execute((CmdTrigger <RealmServerCmdArgs>)trigger, false);
                        }
                        else
                        {
                            RealmCommandHandler.Call((CmdTrigger <RealmServerCmdArgs>)trigger);
                        }
                    }

                    return(true);
                }

                if ((int)ch1 == (int)RealmCommandHandler.SelectCommandPrefix && user.Role.IsStaff)
                {
                    return(RealmCommandHandler.SelectCommand(user, msg.Substring(1)));
                }
            }

            return(false);
        }