Example #1
0
        public static void ExecuteCommandLine(ToolCommandHandler.ConsoleCmdTrigger trigger, string line)
        {
            var text = new StringStream(line);

            trigger.Text = text;

            var isSelect = text.ConsumeNext(RealmCommandHandler.SelectCommandPrefix);

            if (isSelect)
            {
                var cmd = ToolCommandHandler.Instance.SelectCommand(text);
                if (cmd != null)
                {
                    Console.WriteLine("Selected: " + cmd);
                    trigger.SelectedCommand = cmd;
                    return;
                }
                else if (trigger.SelectedCommand != null)
                {
                    Console.WriteLine("Cleared Command selection.");
                    trigger.SelectedCommand = null;
                    return;
                }
            }
            ToolCommandHandler.Instance.Execute(trigger);
        }
Example #2
0
        public static void ExecFileFor(string file, Character user, CmdTrigger <RealmServerCmdArgs> trigger)
        {
            if (!File.Exists(file))
            {
                return;
            }
            bool mayExec = true;
            Func <CmdTrigger <RealmServerCmdArgs>, int, bool> cmdValidator =
                (Func <CmdTrigger <RealmServerCmdArgs>, int, bool>)((trig, line) =>
            {
                StringStream text = trigger.Text;
                if (text.ConsumeNext('+'))
                {
                    string str1 = text.NextWord();
                    if (str1 == "char" || str1 == "name")
                    {
                        string str2 = text.NextWord();
                        mayExec = str2.Length <= 0 ||
                                  user.Name.IndexOf(str2, StringComparison.InvariantCultureIgnoreCase) > -1;
                        return(false);
                    }

                    if (str1 == "class")
                    {
                        string expr  = text.Remainder.Trim();
                        long val     = 0;
                        object error = (object)null;
                        if (!StringParser.Eval(typeof(ClassMask), ref val, expr, ref error, false))
                        {
                            CommandMgr <RealmServerCmdArgs> .log.Warn(
                                "Invalid Class restriction in file {0} (line {1}): {2}", (object)file,
                                (object)line, error);
                        }
                        else
                        {
                            ClassMask otherFlags = (ClassMask)val;
                            mayExec = otherFlags == ClassMask.None || user.ClassMask.HasAnyFlag(otherFlags);
                        }

                        return(false);
                    }

                    trig.Reply("Invalid statement in file {0} (line: {1}): " + text.String.Substring(1).Trim(),
                               (object)file, (object)line);
                }

                if (mayExec && !trig.InitTrigger())
                {
                    mayExec = false;
                }
                return(mayExec);
            });

            RealmCommandHandler.Instance.ExecFile(file, trigger, cmdValidator);
        }
Example #3
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)
        {
            var c = str.PeekChar();

            if (IsCommandPrefix(c))
            {
                str.Position++;
                dbl = str.ConsumeNext(c);
                return(true);
            }
            dbl = false;
            return(false);
        }
Example #4
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);
        }
Example #5
0
            public override void Process(CmdTrigger <C> trigger)
            {
                StringStream text = trigger.Text;

                if (!text.HasNext)
                {
                    trigger.Reply("Invalid arguments - " + this.CreateInfo(trigger));
                }
                else
                {
                    IExecutable executable1;
                    if (text.ConsumeNext('-'))
                    {
                        if (!text.HasNext)
                        {
                            trigger.Reply("Invalid arguments - " + this.CreateInfo(trigger));
                            return;
                        }

                        if (char.ToLower(text.Remainder[0]) == 'l')
                        {
                            ++text.Position;
                            string[] strArray = text.Remainder.Split(new char[1]
                            {
                                ' '
                            }, StringSplitOptions.RemoveEmptyEntries);
                            ToolMgr toolMgr = ((CommandMgr <C> .CallCommand) this.RootCmd).ToolMgr;
                            trigger.Reply("Callable functions ({0}):", (object)toolMgr.Executables.Count);
                            for (int index = 0; index < toolMgr.ExecutableList.Count; ++index)
                            {
                                IExecutable executable2 = toolMgr.ExecutableList[index];
                                if (strArray.Length != 0)
                                {
                                    bool flag = false;
                                    foreach (string str in strArray)
                                    {
                                        if (executable2.Name.IndexOf(str, StringComparison.InvariantCultureIgnoreCase) >
                                            -1)
                                        {
                                            flag = true;
                                            break;
                                        }
                                    }

                                    if (!flag)
                                    {
                                        continue;
                                    }
                                }

                                trigger.Reply(" {0}: {1}", (object)index, (object)executable2);
                            }

                            return;
                        }

                        uint num = text.NextUInt(uint.MaxValue);
                        executable1 = (long)num >= (long)this.ToolMgr.ExecutableList.Count
                            ? (IExecutable)null
                            : this.ToolMgr.ExecutableList[(int)num];
                    }
                    else
                    {
                        executable1 = this.ToolMgr.Get(text.NextWord());
                    }

                    if (executable1 == null)
                    {
                        trigger.Reply("Could not find specified Executable.");
                    }
                    else
                    {
                        int      length   = executable1.ParameterTypes.Length;
                        object[] objArray = new object[length];
                        object   obj      = (object)null;
                        for (int index = 0; index < length; ++index)
                        {
                            Type parameterType = executable1.ParameterTypes[index];
                            StringParser.Parse(index == length - 1 ? text.Remainder : text.NextWord(), parameterType,
                                               ref obj);
                            objArray[index] = obj;
                        }

                        executable1.Exec(objArray);
                    }
                }
            }
Example #6
0
		internal static void Run()
		{
			//DatabaseUtil.ReleaseConsole(); TODO: Work out why the database util would ever have such a ridiculous console binding..
			var server = RealmServ.Instance;

			if (!server.IsRunning)
			{
				Thread.Sleep(300);
				Console.WriteLine("Press any key to exit...");
				Console.ReadKey();
			}
			else
			{
				Console.WriteLine("Console ready. Type ? for help");

				DefaultTrigger = new DefaultCmdTrigger
				{
					Args = new RealmServerCmdArgs(null, false, null)
				};

				while (RealmServ.Instance.IsRunning)
				{
					string line;
					try
					{
						while (!Console.KeyAvailable && RealmServ.Instance.IsRunning)
						{
							Thread.Sleep(100);
						}
						if (!RealmServ.Instance.IsRunning)
						{
							break;
						}
						line = Console.ReadLine();
					}
					catch
					{
						// console shutdown
						break;
					}
					if (line == null || !RealmServ.Instance.IsRunning)
					{
						break;
					}
					try
					{
						/*if (DatabaseUtil.IsWaiting) TODO: More odd database blocking...
						{
							DatabaseUtil.Input.Write(line);
						}
						else
						{*/
						var text = new StringStream(line);
						DefaultTrigger.Text = text;
						if (!DefaultTrigger.InitTrigger())
						{
							continue;
						}

						var isSelect = text.ConsumeNext(RealmCommandHandler.SelectCommandPrefix);
						if (isSelect)
						{
							var cmd = RealmCommandHandler.Instance.SelectCommand(text);
							if (cmd != null)
							{
								Console.WriteLine(@"Selected: {0}", cmd);
								DefaultTrigger.SelectedCommand = cmd;
							}
							else if (DefaultTrigger.SelectedCommand != null)
							{
								Console.WriteLine(@"Cleared Command selection.");
								DefaultTrigger.SelectedCommand = null;
							}
						}
						else
						{
							bool dbl;
							RealmCommandHandler.ConsumeCommandPrefix(text, out dbl);
							DefaultTrigger.Args.Double = dbl;

							RealmCommandHandler.Instance.ExecuteInContext(DefaultTrigger,
																		  OnExecuted,
																		  OnFail);
						}
						//}
					}
					catch (Exception e)
					{
						LogUtil.ErrorException(e, false, "Failed to execute Command.");
					}
				}
			}
		}
Example #7
0
        internal static void Run()
        {
            DatabaseUtil.ReleaseConsole();
            var server = RealmServ.Instance;

            if (!server.IsRunning)
            {
                Thread.Sleep(300);
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Console ready. Type ? for help");

                DefaultTrigger = new DefaultCmdTrigger
                {
                    Args = new RealmServerCmdArgs(null, false, null)
                };

                while (RealmServ.Instance.IsRunning)
                {
                    string line;
                    try
                    {
                        while (!Console.KeyAvailable && RealmServ.Instance.IsRunning)
                        {
                            Thread.Sleep(100);
                        }
                        if (!RealmServ.Instance.IsRunning)
                        {
                            break;
                        }
                        line = Console.ReadLine();
                    }
                    catch
                    {
                        // console shutdown
                        break;
                    }
                    if (line == null || !RealmServ.Instance.IsRunning)
                    {
                        break;
                    }
                    try
                    {
                        if (DatabaseUtil.IsWaiting)
                        {
                            DatabaseUtil.Input.Write(line);
                        }
                        else
                        {
                            var text = new StringStream(line);
                            DefaultTrigger.Text = text;
                            if (!DefaultTrigger.InitTrigger())
                            {
                                continue;
                            }

                            var isSelect = text.ConsumeNext(RealmCommandHandler.SelectCommandPrefix);
                            if (isSelect)
                            {
                                var cmd = RealmCommandHandler.Instance.SelectCommand(text);
                                if (cmd != null)
                                {
                                    Console.WriteLine(@"Selected: {0}", cmd);
                                    DefaultTrigger.SelectedCommand = cmd;
                                }
                                else if (DefaultTrigger.SelectedCommand != null)
                                {
                                    Console.WriteLine(@"Cleared Command selection.");
                                    DefaultTrigger.SelectedCommand = null;
                                }
                            }
                            else
                            {
                                bool dbl;
                                RealmCommandHandler.ConsumeCommandPrefix(text, out dbl);
                                DefaultTrigger.Args.Double = dbl;

                                RealmCommandHandler.Instance.ExecuteInContext(DefaultTrigger,
                                                                              OnExecuted,
                                                                              OnFail);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        LogUtil.ErrorException(e, false, "Failed to execute Command.");
                    }
                }
            }
        }