public static void Register( string command, AccessLevel access, CommandEventHandler handler ) { m_Entries[command] = new CommandEntry( command, handler, access ); }
public static bool Handle(Mobile from, string text, MessageType type) { if (text.StartsWith(m_Prefix) || type == MessageType.Command) { if (type != MessageType.Command) { text = text.Substring(m_Prefix.Length); } int indexOf = text.IndexOf(' '); string command; string[] args; string argString; if (indexOf >= 0) { argString = text.Substring(indexOf + 1); command = text.Substring(0, indexOf); args = Split(argString); } else { argString = ""; command = text.ToLower(); args = new string[0]; } CommandEntry entry = null; m_Entries.TryGetValue(command, out entry); if (entry != null) { if (from.AccessLevel >= entry.AccessLevel) { if (entry.Handler != null) { CommandEventArgs e = new CommandEventArgs(from, command, argString, args); entry.Handler(e); EventSink.InvokeCommand(e); } } else { if (from.AccessLevel <= m_BadCommandIngoreLevel) { return(false); } from.SendMessage("You do not have access to that command."); } } else { if (from.AccessLevel <= m_BadCommandIngoreLevel) { return(false); } from.SendMessage("That is not a valid command."); } return(true); } return(false); }
public static void FillTable() { List <CommandEntry> commands = new(CommandSystem.Entries.Values); List <CommandInfo> list = new(); commands.Sort(); commands.Reverse(); Docs.Clean(commands); for (int i = 0; i < commands.Count; ++i) { CommandEntry e = commands[i]; MethodInfo mi = e.Handler.Method; object[] attrs = mi.GetCustomAttributes(typeof(UsageAttribute), false); if (attrs.Length == 0) { continue; } attrs = mi.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attrs.Length == 0) { continue; } if (attrs[0] is not UsageAttribute usage || attrs[0] is not DescriptionAttribute desc) { continue; } attrs = mi.GetCustomAttributes(typeof(AliasesAttribute), false); AliasesAttribute aliases = (attrs.Length == 0 ? null : attrs[0] as AliasesAttribute); string descString = desc.Description.Replace("<", "(").Replace(">", ")"); if (aliases == null) { list.Add(new CommandInfo(e.AccessLevel, e.Command, null, usage.Usage, descString)); } else { list.Add(new CommandInfo(e.AccessLevel, e.Command, aliases.Aliases, usage.Usage, descString)); for (int j = 0; j < aliases.Aliases.Length; j++) { string[] newAliases = new string[aliases.Aliases.Length]; aliases.Aliases.CopyTo(newAliases, 0); newAliases[j] = e.Command; list.Add(new CommandInfo(e.AccessLevel, aliases.Aliases[j], newAliases, usage.Usage, descString)); } } } for (int i = 0; i < TargetCommands.AllCommands.Count; ++i) { BaseCommand command = TargetCommands.AllCommands[i]; string usage = command.Usage; string desc = command.Description; if (usage == null || desc == null) { continue; } string[] cmds = command.Commands; string cmd = cmds[0]; string[] aliases = new string[cmds.Length - 1]; for (int j = 0; j < aliases.Length; ++j) { aliases[j] = cmds[j + 1]; } desc = desc.Replace("<", "(").Replace(">", ")"); if (command.Supports != CommandSupport.Single) { StringBuilder sb = new(50 + desc.Length); sb.Append("Modifiers: "); if ((command.Supports & CommandSupport.Global) != 0) { sb.Append("<i>Global</i>, "); } if ((command.Supports & CommandSupport.Online) != 0) { sb.Append("<i>Online</i>, "); } if ((command.Supports & CommandSupport.Region) != 0) { sb.Append("<i>Region</i>, "); } if ((command.Supports & CommandSupport.Contained) != 0) { sb.Append("<i>Contained</i>, "); } if ((command.Supports & CommandSupport.Multi) != 0) { sb.Append("<i>Multi</i>, "); } if ((command.Supports & CommandSupport.Area) != 0) { sb.Append("<i>Area</i>, "); } if ((command.Supports & CommandSupport.Self) != 0) { sb.Append("<i>Self</i>, "); } sb.Remove(sb.Length - 2, 2); sb.Append("<br>"); sb.Append(desc); desc = sb.ToString(); } list.Add(new CommandInfo(command.AccessLevel, cmd, aliases, usage, desc)); for (int j = 0; j < aliases.Length; j++) { string[] newAliases = new string[aliases.Length]; aliases.CopyTo(newAliases, 0); newAliases[j] = cmd; list.Add(new CommandInfo(command.AccessLevel, aliases[j], newAliases, usage, desc)); } } List <BaseCommandImplementor> commandImpls = BaseCommandImplementor.Implementors; for (int i = 0; i < commandImpls.Count; ++i) { BaseCommandImplementor command = commandImpls[i]; string usage = command.Usage; string desc = command.Description; if (usage == null || desc == null) { continue; } string[] cmds = command.Accessors; string cmd = cmds[0]; string[] aliases = new string[cmds.Length - 1]; for (int j = 0; j < aliases.Length; ++j) { aliases[j] = cmds[j + 1]; } desc = desc.Replace("<", ")").Replace(">", ")"); list.Add(new CommandInfo(command.AccessLevel, cmd, aliases, usage, desc)); for (int j = 0; j < aliases.Length; j++) { string[] newAliases = new string[aliases.Length]; aliases.CopyTo(newAliases, 0); newAliases[j] = cmd; list.Add(new CommandInfo(command.AccessLevel, aliases[j], newAliases, usage, desc)); } } list.Sort(new CommandInfoSorter()); SortedHelpInfo = list; foreach (CommandInfo c in SortedHelpInfo) { if (!HelpInfos.ContainsKey(c.Name.ToLower())) { HelpInfos.Add(c.Name.ToLower(), c); } } }
public static void Register(string command, AccessLevel access, CommandEventHandler handler) { m_Entries[command] = new CommandEntry(command, handler, access); }
public static void DoCommands(int[] selections, GumpType type, Mobile from) { World.Broadcast(0x35, false, "The world is generating. This may take some time..."); string prefix = CommandSystem.Prefix; string error = null; WorldCreating = true; for (var index = 0; index < selections.Length; index++) { int sel = selections[index]; for (var i = 0; i < Commands.Count; i++) { CommandEntry entry = Commands[i]; if (entry.CheckID == sel) { switch (type) { case GumpType.Create: from.Say("Generating " + entry.Name); if (CanGenerate(entry, ref error)) { if (entry.Delay > 0) { DoDelayedCommand(from, TimeSpan.FromMinutes(entry.Delay), prefix + entry.CreateCommand); } else { CommandSystem.Handle(from, prefix + entry.CreateCommand); } if (CreateWorldData.CreateTable.ContainsKey(sel)) { CreateWorldData.CreateTable[sel] = true; } } break; case GumpType.Delete: if (!string.IsNullOrEmpty(entry.DeleteCommand)) { from.Say("Deleting " + entry.Name); CommandSystem.Handle(from, prefix + entry.DeleteCommand); if (CreateWorldData.CreateTable.ContainsKey(sel)) { CreateWorldData.CreateTable[sel] = false; } } break; } } } } if (error != null) { from.SendGump(new BasicInfoGump(error, "World Generation Error")); } WorldCreating = false; World.Broadcast(0x35, false, "World generation complete."); }