public static void Initialize() { if (Instance.TriggerValidator != null) { return; } char prefix; if (CommandPrefixes.Contains(prefix = ExecCommandPrefix) || CommandPrefixes.Contains(prefix = SelectCommandPrefix)) { throw new ArgumentException("Invalid Command-prefix may not be used as Command-prefix: " + prefix); } Instance.TriggerValidator = delegate(CmdTrigger <RealmServerCmdArgs> trigger, BaseCommand <RealmServerCmdArgs> cmd, bool silent) { var rootCmd = cmd.RootCmd; if (rootCmd is HelpCommand) { return(true); } if (!trigger.Args.Role.MayUse(rootCmd)) { if (!silent) { trigger.Reply(RealmLangKey.MustNotUseCommand, cmd.Name); } return(false); } else if (rootCmd is RealmServerCommand && !trigger.Args.CheckArgs(rootCmd)) { if (!silent) { OnInvalidArguments(trigger, (RealmServerCommand)rootCmd); } return(false); } // check whether we may do anything to the given target else if (trigger.Args.Target is Character) { if (((Character)trigger.Args.Target).Account.Role > trigger.Args.Role) { if (!silent) { trigger.Reply("Insufficient privileges."); } return(false); } } return(true); }; Instance.AddCmdsOfAsm(typeof(RealmCommandHandler).Assembly); Instance.UnknownCommand += (trigger) => { trigger.Reply("Unknown Command \"" + trigger.Alias + "\" - Type ? for help."); }; }
public static void Initialize() { if (Instance.TriggerValidator != null) { return; } char ch; if (CommandPrefixes.Contains(ch = ExecCommandPrefix) || CommandPrefixes.Contains(ch = SelectCommandPrefix)) { throw new ArgumentException("Invalid Command-prefix may not be used as Command-prefix: " + ch); } Instance.TriggerValidator = (trigger, cmd, silent) => { Command <RealmServerCmdArgs> rootCmd = cmd.RootCmd; if (rootCmd is HelpCommand) { return(true); } if (!trigger.Args.Role.MayUse(rootCmd)) { if (!silent) { trigger.Reply(RealmLangKey.MustNotUseCommand, (object)cmd.Name); } return(false); } if (rootCmd is RealmServerCommand && !trigger.Args.CheckArgs(rootCmd)) { if (!silent) { OnInvalidArguments(trigger, (RealmServerCommand)rootCmd); } return(false); } if (!(trigger.Args.Target is Character) || !(((Character)trigger.Args.Target).Account.Role > trigger.Args.Role)) { return(true); } if (!silent) { trigger.Reply("Insufficient privileges."); } return(false); }; Instance.AddCmdsOfAsm(typeof(RealmCommandHandler).Assembly); Instance.UnknownCommand += (UnknownCommandHandler)(trigger => trigger.Reply("Unknown Command \"" + trigger.Alias + "\" - Type ? for help.")); }