Ejemplo n.º 1
0
        /// <summary>Executes the trigger in Context</summary>
        public void ExecuteInContext(CmdTrigger <RealmServerCmdArgs> trigger,
                                     Action <CmdTrigger <RealmServerCmdArgs> > doneCallback, Action <CmdTrigger <RealmServerCmdArgs> > failCalback)
        {
            BaseCommand <RealmServerCmdArgs> cmd = this.GetCommand(trigger);

            if (cmd == null)
            {
                return;
            }
            if (cmd.GetRequiresContext())
            {
                if (trigger.Args.Context == null)
                {
                    RealmCommandHandler.OnInvalidArguments(trigger, (RealmServerCommand)cmd.RootCmd);
                }
                else
                {
                    trigger.Args.Context.ExecuteInContext((Action)(() =>
                                                                   this.Execute(trigger, cmd, doneCallback, failCalback)));
                }
            }
            else
            {
                this.Execute(trigger, cmd, doneCallback, failCalback);
            }
        }
Ejemplo n.º 2
0
 public bool Execute(CmdTrigger <RealmServerCmdArgs> trigger, bool checkForCall)
 {
     if (checkForCall && trigger.Text.ConsumeNext(RealmCommandHandler.ExecCommandPrefix))
     {
         return(RealmCommandHandler.Call(trigger));
     }
     return(base.Execute(trigger));
 }
Ejemplo n.º 3
0
 public static void ExecFileFor(Character user)
 {
     if (RealmCommandHandler.AutoExecDir == null)
     {
         return;
     }
     RealmCommandHandler.ExecFileFor(
         Path.Combine(RealmCommandHandler.AutoExecDir, "Chars/" + user.Account.Name + ".txt"), user);
 }
Ejemplo n.º 4
0
        public static void Initialize()
        {
            if (RealmCommandHandler.Instance.TriggerValidator != null)
            {
                return;
            }
            char ch;

            if (RealmCommandHandler.CommandPrefixes.Contains <char>(ch = RealmCommandHandler.ExecCommandPrefix) ||
                RealmCommandHandler.CommandPrefixes.Contains <char>(ch = RealmCommandHandler.SelectCommandPrefix))
            {
                throw new ArgumentException("Invalid Command-prefix may not be used as Command-prefix: " + (object)ch);
            }
            RealmCommandHandler.Instance.TriggerValidator =
                (CommandMgr <RealmServerCmdArgs> .TriggerValidationHandler)((trigger, cmd, silent) =>
            {
                Command <RealmServerCmdArgs> rootCmd = cmd.RootCmd;
                if (rootCmd is CommandMgr <RealmServerCmdArgs> .HelpCommand)
                {
                    return(true);
                }
                if (!trigger.Args.Role.MayUse(rootCmd))
                {
                    if (!silent)
                    {
                        trigger.Reply(RealmLangKey.MustNotUseCommand, (object)cmd.Name);
                    }
                    return(false);
                }

                if (rootCmd is RealmServerCommand && !trigger.Args.CheckArgs(rootCmd))
                {
                    if (!silent)
                    {
                        RealmCommandHandler.OnInvalidArguments(trigger, (RealmServerCommand)rootCmd);
                    }
                    return(false);
                }

                if (!(trigger.Args.Target is Character) ||
                    !(((Character)trigger.Args.Target).Account.Role > trigger.Args.Role))
                {
                    return(true);
                }
                if (!silent)
                {
                    trigger.Reply("Insufficient privileges.");
                }
                return(false);
            });
            RealmCommandHandler.Instance.AddCmdsOfAsm(typeof(RealmCommandHandler).Assembly);
            RealmCommandHandler.Instance.UnknownCommand +=
                (CommandMgr <RealmServerCmdArgs> .UnknownCommandHandler)(trigger =>
                                                                         trigger.Reply("Unknown Command \"" + trigger.Alias + "\" - Type ? for help."));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Removes the next char if it's a Command Prefix, and
        /// sets dbl = true, if it is double.
        /// </summary>
        public static bool ConsumeCommandPrefix(StringStream str, out bool dbl)
        {
            char c = str.PeekChar();

            if (RealmCommandHandler.IsCommandPrefix(c))
            {
                ++str.Position;
                dbl = str.ConsumeNext(c);
                return(true);
            }

            dbl = false;
            return(false);
        }
Ejemplo n.º 6
0
 public override void ExecFile(string filename, CmdTrigger <RealmServerCmdArgs> trigger)
 {
     if (trigger.Args.Character != null)
     {
         if (File.Exists(filename))
         {
             RealmCommandHandler.ExecFileFor(filename, trigger.Args.Character, trigger);
         }
         else
         {
             trigger.Reply("File to execute does not exist: " + filename);
         }
     }
     else
     {
         base.ExecFile(filename, trigger);
     }
 }
Ejemplo n.º 7
0
 public static void ExecFileFor(string file, Character user)
 {
     RealmCommandHandler.ExecFileFor(file, user,
                                     (CmdTrigger <RealmServerCmdArgs>) new IngameCmdTrigger(new RealmServerCmdArgs((IUser)user, false,
                                                                                                                   (IGenericChatTarget)null)));
 }
Ejemplo n.º 8
0
 public static void ExecAllCharsFileFor(Character user)
 {
     RealmCommandHandler.ExecFileFor(RealmCommandHandler.AutoExecDir + RealmCommandHandler.AutoExecAllCharsFile,
                                     user);
 }
Ejemplo n.º 9
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);
        }