public static void ExecFileFor(string file, Character user, CmdTrigger <RealmServerCmdArgs> trigger) { if (!File.Exists(file)) { return; } bool mayExec = true; Func <CmdTrigger <RealmServerCmdArgs>, int, bool> cmdValidator = (Func <CmdTrigger <RealmServerCmdArgs>, int, bool>)((trig, line) => { StringStream text = trigger.Text; if (text.ConsumeNext('+')) { string str1 = text.NextWord(); if (str1 == "char" || str1 == "name") { string str2 = text.NextWord(); mayExec = str2.Length <= 0 || user.Name.IndexOf(str2, StringComparison.InvariantCultureIgnoreCase) > -1; return(false); } if (str1 == "class") { string expr = text.Remainder.Trim(); long val = 0; object error = (object)null; if (!StringParser.Eval(typeof(ClassMask), ref val, expr, ref error, false)) { CommandMgr <RealmServerCmdArgs> .log.Warn( "Invalid Class restriction in file {0} (line {1}): {2}", (object)file, (object)line, error); } else { ClassMask otherFlags = (ClassMask)val; mayExec = otherFlags == ClassMask.None || user.ClassMask.HasAnyFlag(otherFlags); } return(false); } trig.Reply("Invalid statement in file {0} (line: {1}): " + text.String.Substring(1).Trim(), (object)file, (object)line); } if (mayExec && !trig.InitTrigger()) { mayExec = false; } return(mayExec); }); RealmCommandHandler.Instance.ExecFile(file, trigger, cmdValidator); }
/// <summary> /// Returns the SubCommand, following the given set of aliases through the SubCommand structure. /// </summary> public BaseCommand <C> .SubCommand SelectSubCommand(StringStream cmdString) { BaseCommand <C> .SubCommand subCommand = this.SelectSubCommand(cmdString.NextWord()); if (subCommand != null && subCommand.SubCommands.Count > 0 && cmdString.HasNext) { return(subCommand.SelectSubCommand(cmdString)); } return(subCommand); }
public BaseCommand <C> SelectCommand(StringStream cmdString) { Command <C> command = this.Get(cmdString.NextWord()); if (command != null && cmdString.HasNext) { return((BaseCommand <C>)command.SelectSubCommand(cmdString)); } return((BaseCommand <C>)command); }
public BaseCommand <C> SelectCommand(StringStream cmdString) { var cmd = Get(cmdString.NextWord()); if (cmd != null && cmdString.HasNext) { return(cmd.SelectSubCommand(cmdString)); } return(cmd); }
/// <summary> /// Returns the SubCommand, following the given set of aliases through the SubCommand structure. /// </summary> public SubCommand SelectSubCommand(StringStream cmdString) { var cmd = SelectSubCommand(cmdString.NextWord()); if (cmd != null && cmd.SubCommands.Count > 0 && cmdString.HasNext) { return(cmd.SelectSubCommand(cmdString)); } return(cmd); }
private void ReceivedNotify(ByteBuffer buf) { if (InternalBytesReceived != null) { InternalBytesReceived(this, buf); buf.offset = 0; } if (BytesReceived != null) { BytesReceived(this, buf); } else if (RawTextReceived != null || LineReceived != null) { string text = lastLine + encoding.GetString(buf.Data, 0, buf.length); if (RawTextReceived != null) { RawTextReceived(this, new StringStream(text)); } if (LineReceived != null) { var ss = new StringStream(text); while (ss.HasNext) { if (BytesReceived != null) { // Handler might change int count; if (encoding.IsSingleByte) { count = ss.Position; } else { count = encoding.GetByteCount(ss.String.Substring(0, ss.Position)); } buf.offset = count; buf.length -= count; BytesReceived(this, buf); break; } if (LineReceived != null) { string line = ss.NextWord(lineTerminator); if (!ss.HasNext && !text.EndsWith(lineTerminator)) { lastLine += line; return; } LineReceived(this, new StringStream(line)); } } lastLine = ""; } } }
/// <summary> /// Returns the SubCommand, following the given set of aliases through the SubCommand structure. /// </summary> public void GetSubCommands(StringStream cmdString, List <BaseCommand <C> > list) { var str = cmdString.NextWord(); var cmds = m_subCommandSet.Where(comd => comd.Aliases.Where(alias => alias.IndexOf(str, StringComparison.InvariantCultureIgnoreCase) > -1).Count() > 0); if (cmdString.HasNext && cmds.Count() == 1) { cmds.First().GetSubCommands(cmdString, list); } else { foreach (var cmd in cmds) { list.Add(cmd); } } }
public void GetCommands(StringStream cmdString, List <BaseCommand <C> > list) { string str = cmdString.NextWord(); IEnumerable <Command <C> > source = this.commandsByName.Values.Where <Command <C> >( (Func <Command <C>, bool>)(comd => ((IEnumerable <string>)comd.Aliases).Where <string>((Func <string, bool>)(alias => alias.IndexOf(str, StringComparison.InvariantCultureIgnoreCase) > -1)).Count <string>() > 0)); if (cmdString.HasNext && source.Count <Command <C> >() == 1) { source.First <Command <C> >().GetSubCommands(cmdString, list); } else { foreach (Command <C> command in source) { list.Add((BaseCommand <C>)command); } } }
/// <summary> /// Returns the SubCommand, following the given set of aliases through the SubCommand structure. /// </summary> public void GetSubCommands(StringStream cmdString, List <BaseCommand <C> > list) { string str = cmdString.NextWord(); IEnumerable <SubCommand> source = m_subCommandSet.Where( comd => comd.Aliases.Where(alias => alias.IndexOf(str, StringComparison.InvariantCultureIgnoreCase) > -1).Count() > 0); if (cmdString.HasNext && source.Count() == 1) { source.First().GetSubCommands(cmdString, list); } else { foreach (SubCommand subCommand in source) { list.Add(subCommand); } } }
public override void Process(CmdTrigger <C> trigger) { StringStream text = trigger.Text; if (!text.HasNext) { trigger.Reply("Invalid arguments - " + this.CreateInfo(trigger)); } else { IExecutable executable1; if (text.ConsumeNext('-')) { if (!text.HasNext) { trigger.Reply("Invalid arguments - " + this.CreateInfo(trigger)); return; } if (char.ToLower(text.Remainder[0]) == 'l') { ++text.Position; string[] strArray = text.Remainder.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries); ToolMgr toolMgr = ((CommandMgr <C> .CallCommand) this.RootCmd).ToolMgr; trigger.Reply("Callable functions ({0}):", (object)toolMgr.Executables.Count); for (int index = 0; index < toolMgr.ExecutableList.Count; ++index) { IExecutable executable2 = toolMgr.ExecutableList[index]; if (strArray.Length != 0) { bool flag = false; foreach (string str in strArray) { if (executable2.Name.IndexOf(str, StringComparison.InvariantCultureIgnoreCase) > -1) { flag = true; break; } } if (!flag) { continue; } } trigger.Reply(" {0}: {1}", (object)index, (object)executable2); } return; } uint num = text.NextUInt(uint.MaxValue); executable1 = (long)num >= (long)this.ToolMgr.ExecutableList.Count ? (IExecutable)null : this.ToolMgr.ExecutableList[(int)num]; } else { executable1 = this.ToolMgr.Get(text.NextWord()); } if (executable1 == null) { trigger.Reply("Could not find specified Executable."); } else { int length = executable1.ParameterTypes.Length; object[] objArray = new object[length]; object obj = (object)null; for (int index = 0; index < length; ++index) { Type parameterType = executable1.ParameterTypes[index]; StringParser.Parse(index == length - 1 ? text.Remainder : text.NextWord(), parameterType, ref obj); objArray[index] = obj; } executable1.Exec(objArray); } } }