Exemplo n.º 1
0
        internal void ExecuteByPlayer(string cmd, Player player)
        {
            string command = "";

            CommandObject[] args = new CommandObject[0];
            if (cmd.Contains(" "))
            {
                command = cmd.Substring(0, cmd.IndexOf(' '));
                args    = SplitCommand(cmd.Substring(cmd.IndexOf(' ') + 1));
            }
            else
            {
                command = cmd;
            }
            IForgetiveCommand desc = ForgetiveCommandCenter.PreInvoke(command, !player.IsOp);

            if (desc == null)
            {
                player.SendChat("找不到指令或没有权限调用该指令。输入@help查看更多帮助", "Forgetive");
                return;
            }
            desc.invoker = player;
            try
            {
                desc.OnInvoke(args);
            }
            catch
            {
                player.SendChat("<" + command + "> 执行命令时出现内部错误", "Forgetive");
            }
        }
Exemplo n.º 2
0
        internal void Execute(string cmd, bool needRepeatCommand = false)
        {
            string command = "";

            if (needRepeatCommand)
            {
                Logger.WriteLine(LogLevel.Info, "Server> " + cmd);
            }
            CommandObject[] args = new CommandObject[0];
            if (cmd.Contains(" "))
            {
                command = cmd.Substring(0, cmd.IndexOf(' '));
                args    = SplitCommand(cmd.Substring(cmd.IndexOf(' ') + 1));
            }
            else
            {
                command = cmd;
            }
            IForgetiveCommand desc = ForgetiveCommandCenter.PreInvoke(command);

            if (desc == null)
            {
                Logger.WriteLine(LogLevel.Warning, "<{0}> {1}", command, "找不到指令。输入help查看更多帮助");
                return;
            }
            desc.invoker = null;
#if !DEBUG
            try
            {
                desc.OnInvoke(args);
            }
            catch
            {
                Logger.WriteLine(LogLevel.Warning, "<{0}> {1}", command, "执行命令时出现内部错误");
            }
#else
            desc.OnInvoke(args);
#endif
        }
Exemplo n.º 3
0
        internal static void FindCommands(Assembly[] asses)
        {
            Type basicType = typeof(IForgetiveCommand);

            for (int i = 0; i < asses.Length; i++)
            {
                Assembly current = asses[i];
                Type[]   ltype   = current.GetTypes();
                for (int j = 0; j < ltype.Length; j++)
                {
                    if (ltype[j].IsSubclassOf(basicType))
                    {
                        IForgetiveCommand command = null;
                        try
                        {
                            command = (IForgetiveCommand)Activator.CreateInstance(ltype[j]);
                        }
                        catch
                        {
                            Logger.WriteLine("尝试初始化指令时出现错误。类型{0}", ltype[j].FullName);
                        }
                        if (command.Info.CommandNames != null && command.Info.HelpText != null)
                        {
                            if (command != null)
                            {
                                AddCommand(command);
                            }
                        }
                        else
                        {
                            Logger.WriteLine("类型{0}已正确加载,但是它并不包含完整的信息表", ltype[j].FullName);
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 static void AddCommand(IForgetiveCommand body)
 {
     body.OnInit();
     cmds.Add(body);
 }