示例#1
0
        /// <summary>
        /// </summary>
        public void AddScriptMembers()
        {
            this.scriptList.Clear();
            foreach (Assembly assembly in this.multipleDllList)
            {
                foreach (Type t in assembly.GetTypes())
                {
                    if (t.GetInterface("IAOScript") != null)
                    {
                        if (t.Name != "IAOScript")
                        {
                            foreach (MemberInfo mi in t.GetMembers())
                            {
                                if ((mi.Name == "GetType") || (mi.Name == ".ctor") || (mi.Name == "GetHashCode") ||
                                    (mi.Name == "ToString") || (mi.Name == "Equals"))
                                {
                                    continue;
                                }

                                if (mi.MemberType == MemberTypes.Method)
                                {
                                    if (!this.scriptList.ContainsKey(t.Namespace + "." + t.Name + ":" + mi.Name))
                                    {
                                        this.scriptList.Add(t.Namespace + "." + t.Name + ":" + mi.Name, t);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            this.chatCommands.Clear();
            Assembly wholeassembly = Assembly.GetExecutingAssembly();

            foreach (Type t in wholeassembly.GetTypes())
            {
                if (t.Namespace == "ZoneEngine.ChatCommands")
                {
                    if (t.Name != "AOChatCommand")
                    {
                        if (!this.chatCommands.ContainsKey(t.Namespace + "." + t.Name))
                        {
                            AOChatCommand aoc = (AOChatCommand)wholeassembly.CreateInstance(t.Namespace + "." + t.Name);
                            List <string> acceptedcommands = aoc.ListCommands();
                            foreach (string command in acceptedcommands)
                            {
                                this.chatCommands.Add(t.Namespace + "." + t.Name + ":" + command, t);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        public int AddScriptMembers()
        {
            this.scriptList.Clear();
            foreach (Assembly assembly in this.multipleDllList)
            {
                foreach (Type t in assembly.GetTypes())
                {
                    // returns all public types in the asembly
                    foreach (Type iface in t.GetInterfaces())
                    {
                        if (iface.FullName == typeof(IAOScript).FullName)
                        {
                            if (t.Name != "IAOScript")
                            {
                                foreach (MemberInfo mi in t.GetMembers())
                                {
                                    if ((mi.Name == "GetType") || (mi.Name == ".ctor") || (mi.Name == "GetHashCode") ||
                                        (mi.Name == "ToString") || (mi.Name == "Equals"))
                                    {
                                        continue;
                                    }

                                    if (mi.MemberType == MemberTypes.Method)
                                    {
                                        if (!this.scriptList.ContainsKey(t.Namespace + "." + t.Name + ":" + mi.Name))
                                        {
                                            this.scriptList.Add(t.Namespace + "." + t.Name + ":" + mi.Name, t);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            this.chatCommands.Clear();
            Assembly wholeassembly = Assembly.GetExecutingAssembly();
            int      chatCommands  = 0;

            foreach (Type t in wholeassembly.GetTypes().Where(x => x.IsSubclassOf(typeof(AOChatCommand))))
            {
                chatCommands++;
                AOChatCommand aoc = (AOChatCommand)wholeassembly.CreateInstance(t.FullName);
                List <string> acceptedcommands = aoc.ListCommands();
                foreach (string command in acceptedcommands)
                {
                    this.chatCommands.Add(t.FullName + ":" + command, t);
                }
            }

            return(chatCommands);
        }
        /// <summary>
        /// </summary>
        /// <param name="commandName">
        /// </param>
        /// <param name="client">
        /// </param>
        /// <param name="target">
        /// </param>
        /// <param name="commandArguments">
        /// </param>
        public void CallChatCommand(string commandName, ZoneClient client, Identity target, string[] commandArguments)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            if (commandName.ToUpperInvariant() != "LISTCOMMANDS")
            {
                foreach (KeyValuePair <string, Type> kv in this.chatCommands)
                {
                    if (kv.Key.Substring(kv.Key.IndexOf(":", StringComparison.Ordinal) + 1).ToUpperInvariant()
                        == commandName.ToUpperInvariant())
                    {
                        AOChatCommand aoc =
                            (AOChatCommand)
                            assembly.CreateInstance(
                                kv.Key.Substring(0, kv.Key.IndexOf(":", StringComparison.Ordinal)));
                        if (aoc != null)
                        {
                            // Check GM Level bitwise
                            if ((client.Character.Stats[StatIds.gmlevel].Value < aoc.GMLevelNeeded()) &&
                                (aoc.GMLevelNeeded() > 0))
                            {
                                client.Character.Playfield.Publish(
                                    ChatText.CreateIM(
                                        client.Character,
                                        "You are not authorized to use this command!. This incident will be recorded."));

                                // It is not yet :)
                                return;
                            }

                            // Check if only one argument has been passed for "help"
                            if (commandArguments.Length == 2)
                            {
                                if (commandArguments[1].ToUpperInvariant() == "HELP")
                                {
                                    aoc.CommandHelp(client.Character);
                                    return;
                                }
                            }

                            // Execute the command with the given command arguments, if CheckCommandArguments is true else print command help
                            if (aoc.CheckCommandArguments(commandArguments))
                            {
                                aoc.ExecuteCommand(client.Character, target, commandArguments);
                            }
                            else
                            {
                                aoc.CommandHelp(client.Character);
                            }
                        }
                    }
                }
            }
            else
            {
                client.Character.Playfield.Publish(ChatText.CreateIM(client.Character, "Available Commands:"));
                string[] scriptNames = this.chatCommands.Keys.ToArray();
                for (int i = 0; i < scriptNames.Length; i++)
                {
                    scriptNames[i] = scriptNames[i].Substring(scriptNames[i].IndexOf(":", StringComparison.Ordinal) + 1)
                                     + ":"
                                     + scriptNames[i].Substring(
                        0,
                        scriptNames[i].IndexOf(":", StringComparison.Ordinal));
                }

                Array.Sort(scriptNames);

                foreach (string scriptName in scriptNames)
                {
                    string        typename = scriptName.Substring(scriptName.IndexOf(":", StringComparison.Ordinal) + 1);
                    AOChatCommand aoc      = (AOChatCommand)assembly.CreateInstance(typename);
                    if (aoc != null)
                    {
                        if (client.Character.Stats[StatIds.gmlevel].Value >= aoc.GMLevelNeeded())
                        {
                            client.Character.Playfield.Publish(
                                ChatText.CreateIM(
                                    client.Character,
                                    scriptName.Substring(0, scriptName.IndexOf(":", StringComparison.Ordinal))));
                        }
                    }
                }
            }
        }