public override void Process(Mobile from, object target, BaseCommand command, string[] args) { if (command.ValidateArgs(this, new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args))) { if (target == null) { from.BeginTarget(-1, command.ObjectTypes == ObjectTypes.All, TargetFlags.None, new TargetStateCallback(OnTarget), new object[] { command, args }); } else { OnTarget(from, target, new object[] { command, args }); } } }
public void Redirect(CommandEventArgs e) { BaseCommand command = (BaseCommand)Commands[e.Command]; if (command == null) { e.Mobile.SendMessage("That is either an invalid command name or one that does not support this modifier."); } else if (e.Mobile.AccessLevel < command.AccessLevel) { e.Mobile.SendMessage("You do not have access to that command."); } else if (command.ValidateArgs(this, e)) { Process(e.Mobile, e.Target, command, e.Arguments); } }
public override void ExecuteList(CommandEventArgs e, ArrayList list) { if (list.Count == 0) { LogFailure("Nothing was found to use this command on."); return; } try { BaseCommand[] commands = new BaseCommand[BatchCommands.Count]; CommandEventArgs[] eventArgs = new CommandEventArgs[BatchCommands.Count]; for (int i = 0; i < BatchCommands.Count; ++i) { BatchCommand bc = (BatchCommand)BatchCommands[i]; string commandString, argString; string[] args; bc.GetDetails(out commandString, out argString, out args); BaseCommand command = Scope.Commands[commandString]; commands[i] = command; eventArgs[i] = new CommandEventArgs(e.Mobile, commandString, argString, args); if (command == null) { e.Mobile.SendMessage("That is either an invalid command name or one that does not support this modifier: {0}.", commandString); return; } else if (e.Mobile.AccessLevel < command.AccessLevel) { e.Mobile.SendMessage("You do not have access to that command: {0}.", commandString); return; } else if (!command.ValidateArgs(Scope, eventArgs[i])) { return; } } for (int i = 0; i < commands.Length; ++i) { BaseCommand command = commands[i]; BatchCommand bc = (BatchCommand)BatchCommands[i]; if (list.Count > 20) { CommandLogging.Enabled = false; } ArrayList usedList; if (Utility.InsensitiveCompare(bc.Object, "Current") == 0) { usedList = list; } else { Hashtable propertyChains = new Hashtable(); usedList = new ArrayList(list.Count); for (int j = 0; j < list.Count; ++j) { object obj = list[j]; if (obj == null) { continue; } Type type = obj.GetType(); PropertyInfo[] chain = (PropertyInfo[])propertyChains[type]; string failReason = ""; if (chain == null && !propertyChains.Contains(type)) { propertyChains[type] = chain = Properties.GetPropertyInfoChain(e.Mobile, type, bc.Object, PropertyAccess.Read, ref failReason); } if (chain == null) { continue; } PropertyInfo endProp = Properties.GetPropertyInfo(ref obj, chain, ref failReason); if (endProp == null) { continue; } try { obj = endProp.GetValue(obj, null); if (obj != null) { usedList.Add(obj); } } catch { } } } command.ExecuteList(eventArgs[i], usedList); if (list.Count > 20) { CommandLogging.Enabled = true; } command.Flush(e.Mobile, list.Count > 20); } } catch (Exception ex) { e.Mobile.SendMessage(ex.Message); } }
public override void ExecuteList(CommandEventArgs e, List <object> list) { if (list.Count == 0) { LogFailure("Nothing was found to use this command on."); return; } try { BaseCommand[] commands = new BaseCommand[BatchCommands.Count]; CommandEventArgs[] eventArgs = new CommandEventArgs[BatchCommands.Count]; for (int i = 0; i < BatchCommands.Count; ++i) { BatchCommand bc = BatchCommands[i]; bc.GetDetails(out string commandString, out string argString, out string[] args); BaseCommand command = Scope.Commands[commandString]; commands[i] = command; eventArgs[i] = new CommandEventArgs(e.Mobile, commandString, argString, args); if (command == null) { e.Mobile.SendMessage( "That is either an invalid command name or one that does not support this modifier: {0}.", commandString); return; } if (e.Mobile.AccessLevel < command.AccessLevel) { e.Mobile.SendMessage("You do not have access to that command: {0}.", commandString); return; } if (!command.ValidateArgs(Scope, eventArgs[i])) { return; } } for (int i = 0; i < commands.Length; ++i) { BaseCommand command = commands[i]; BatchCommand bc = BatchCommands[i]; if (list.Count > 20) { CommandLogging.Enabled = false; } List <object> usedList; if (Utility.InsensitiveCompare(bc.Object, "Current") == 0) { usedList = list; } else { Dictionary <Type, PropertyInfo[]> propertyChains = new Dictionary <Type, PropertyInfo[]>(); usedList = new List <object>(list.Count); for (int j = 0; j < list.Count; ++j) { object obj = list[j]; if (obj == null) { continue; } Type type = obj.GetType(); string failReason = ""; if (!propertyChains.TryGetValue(type, out PropertyInfo[] chain))
public void RunCommand(Mobile from, object obj, BaseCommand command, string[] args) { try { CommandEventArgs e = new CommandEventArgs(from, command.Commands[0], GenerateArgString(args), args); if (!command.ValidateArgs(this, e)) { return; } bool flushToLog = false; if (obj is ArrayList) { ArrayList list = (ArrayList)obj; if (list.Count > 20) { CommandLogging.Enabled = false; } else if (list.Count == 0) { command.LogFailure("Nothing was found to use this command on."); } command.Begin(e); command.ExecuteList(e, list); command.End(e); if (list.Count > 20) { flushToLog = true; CommandLogging.Enabled = true; } } else if (obj != null) { if (command.ListOptimized) { ArrayList list = new ArrayList(); list.Add(obj); command.Begin(e); command.ExecuteList(e, list); command.End(e); } else { command.Begin(e); command.Execute(e, obj); command.End(e); } } command.Flush(from, flushToLog); } catch (Exception ex) { LogHelper.LogException(ex); from.SendMessage(ex.Message); } }