public static bool LoadCommands() { CommandMgr.m_cmds.Clear(); ArrayList arrayList = new ArrayList(ScriptMgr.Scripts); foreach (Assembly assembly in arrayList) { if (CommandMgr.log.IsDebugEnabled) { CommandMgr.log.Debug("ScriptMgr: Searching for commands in " + assembly.GetName()); } Type[] types = assembly.GetTypes(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; if (type.IsClass && type.GetInterface("Game.Base.ICommandHandler") != null) { try { object[] customAttributes = type.GetCustomAttributes(typeof(CmdAttribute), false); object[] array = customAttributes; for (int j = 0; j < array.Length; j++) { CmdAttribute cmdAttribute = (CmdAttribute)array[j]; bool flag = false; string[] disabledarray = CommandMgr.m_disabledarray; for (int k = 0; k < disabledarray.Length; k++) { string b = disabledarray[k]; if (cmdAttribute.Cmd.Replace('&', '/') == b) { flag = true; CommandMgr.log.Info("Will not load command " + cmdAttribute.Cmd + " as it is disabled in game properties"); break; } } if (!flag) { if (CommandMgr.m_cmds.ContainsKey(cmdAttribute.Cmd)) { CommandMgr.log.Info(string.Concat(new object[] { cmdAttribute.Cmd, " from ", assembly.GetName(), " has been suppressed, a command of that type already exists!" })); } else { if (CommandMgr.log.IsDebugEnabled) { CommandMgr.log.Debug("Load: " + cmdAttribute.Cmd + "," + cmdAttribute.Description); } GameCommand gameCommand = new GameCommand(); gameCommand.m_usage = cmdAttribute.Usage; gameCommand.m_cmd = cmdAttribute.Cmd; gameCommand.m_lvl = cmdAttribute.Level; gameCommand.m_desc = cmdAttribute.Description; gameCommand.m_cmdHandler = (ICommandHandler)Activator.CreateInstance(type); CommandMgr.m_cmds.Add(cmdAttribute.Cmd, gameCommand); if (cmdAttribute.Aliases != null) { string[] aliases = cmdAttribute.Aliases; for (int l = 0; l < aliases.Length; l++) { string key = aliases[l]; CommandMgr.m_cmds.Add(key, gameCommand); } } } } } } catch (Exception exception) { if (CommandMgr.log.IsErrorEnabled) { CommandMgr.log.Error("LoadCommands", exception); } } } } } CommandMgr.log.Info("Loaded " + CommandMgr.m_cmds.Count + " commands!"); return(true); }
public static bool LoadCommands() { CommandMgr.m_cmds.Clear(); ArrayList asms = new ArrayList(ScriptMgr.Scripts); foreach (Assembly script in asms) { CommandMgr.log.Debug("ScriptMgr: Searching for commands in " + script.GetName()); Type[] types = script.GetTypes(); for (int i = 0; i < types.Length; i++) { Type type = types[i]; if (type.IsClass) { if (type.GetInterface("Game.Base.ICommandHandler") != null) { try { object[] objs = type.GetCustomAttributes(typeof(CmdAttribute), false); object[] array = objs; for (int j = 0; j < array.Length; j++) { CmdAttribute attrib = (CmdAttribute)array[j]; bool disabled = false; string[] array2 = CommandMgr.m_disabledarray; for (int k = 0; k < array2.Length; k++) { string str = array2[k]; if (attrib.Cmd.Replace('&', '/') == str) { disabled = true; CommandMgr.log.Info("Will not load command " + attrib.Cmd + " as it is disabled in game properties"); break; } } if (!disabled) { if (CommandMgr.m_cmds.ContainsKey(attrib.Cmd)) { CommandMgr.log.Info(string.Concat(new object[] { attrib.Cmd, " from ", script.GetName(), " has been suppressed, a command of that type already exists!" })); } else { CommandMgr.log.Debug("Load: " + attrib.Cmd + "," + attrib.Description); GameCommand cmd = new GameCommand(); cmd.m_usage = attrib.Usage; cmd.m_cmd = attrib.Cmd; cmd.m_lvl = attrib.Level; cmd.m_desc = attrib.Description; cmd.m_cmdHandler = (ICommandHandler)Activator.CreateInstance(type); CommandMgr.m_cmds.Add(attrib.Cmd, cmd); if (attrib.Aliases != null) { array2 = attrib.Aliases; for (int k = 0; k < array2.Length; k++) { string alias = array2[k]; CommandMgr.m_cmds.Add(alias, cmd); } } } } } } catch (Exception e) { CommandMgr.log.Error("LoadCommands", e); } } } } } CommandMgr.log.Info("CommandMger:Loaded " + CommandMgr.m_cmds.Count + " commands!"); return(true); }