public static void CheckLOS_OnCommand(CommandEventArgs e) { if (e.Mobile.AccessLevel == AccessLevel.Player && TestCenter.Enabled == false) { // Players can only test this on Test Center e.Mobile.SendMessage("Not available here."); return; } if (e.Mobile.AccessLevel > AccessLevel.Player) { // you will not get good results if you test this with AccessLevel > Player e.Mobile.SendMessage("You should test this with AccessLevel.Player."); return; } try { e.Mobile.Target = new LOSTarget(); e.Mobile.SendMessage("Check LOS to which object?"); } catch (Exception ex) { LogHelper.LogException(ex); } }
public override void Execute(CommandEventArgs e, object obj) { int found = 0; int visited = 0; try { Item item = obj as Item; if (e.Arguments.Length == 0) { e.Mobile.SendMessage("Usage: FindItemInArea ItemID"); return; } int ItemID = 0; if (int.TryParse(e.Arguments[0], out ItemID) == false) { e.Mobile.SendMessage("Usage: FindItemInArea decimal-ItemID"); return; } visited++; if (item.ItemID == ItemID) { found++; AddResponse(String.Format("Found Item {0} at {1}", item.ItemID, item.Location)); } } catch (Exception exe) { LogHelper.LogException(exe); e.Mobile.SendMessage(exe.Message); } AddResponse(String.Format("{0} items visited, {1} items found.", visited, found)); }
public static void RetargetRunes_OnCommand(CommandEventArgs e) { ArrayList regionList = new ArrayList(); if (HaveRegions(e, regionList)) { try { LogHelper Logger = new LogHelper("retarget.log", e.Mobile, true); foreach (Item item in World.Items.Values) { if (item is RecallRune) { RecallRune rune = (RecallRune)item; for (int ix = 0; ix < regionList.Count; ix++) { if (rune.Marked && rune.TargetMap != null && (regionList[ix] as Region).Contains(rune.Target)) { object root = item.RootParent; if (root is Mobile) { if (((Mobile)root).AccessLevel < AccessLevel.GameMaster) { Logger.Log(LogType.Item, rune, rune.Description); rune.Target = new Point3D(0, 0, 0); } } else { Logger.Log(LogType.Item, rune, rune.Description); rune.Target = new Point3D(0, 0, 0); } } } } else if (item is Moonstone) { Moonstone stone = (Moonstone)item; for (int ix = 0; ix < regionList.Count; ix++) { if (stone.Marked && (regionList[ix] as Region).Contains(stone.Destination)) { object root = item.RootParent; if (root is Mobile) { if (((Mobile)root).AccessLevel < AccessLevel.GameMaster) { Logger.Log(LogType.Item, stone, stone.Description); stone.Destination = new Point3D(0, 0, 0); } } else { Logger.Log(LogType.Item, stone, stone.Description); stone.Destination = new Point3D(0, 0, 0); } } } } else if (item is Runebook) { Runebook book = (Runebook)item; for (int ix = 0; ix < regionList.Count; ix++) { for (int i = 0; i < book.Entries.Count; ++i) { RunebookEntry entry = (RunebookEntry)book.Entries[i]; if (entry.Map != null && (regionList[ix] as Region).Contains(entry.Location)) { object root = item.RootParent; if (root is Mobile) { if (((Mobile)root).AccessLevel < AccessLevel.GameMaster) { Logger.Log(LogType.Item, item, string.Format("{0}:{1}:{2}", i, entry.Description, book.Description)); entry.Location = new Point3D(0, 0, 0); } } else { Logger.Log(LogType.Item, item, string.Format("{0}:{1}:{2}", i, entry.Description, book.Description)); entry.Location = new Point3D(0, 0, 0); } } } } } } Logger.Finish(); e.Mobile.SendMessage("DONE search for runes."); return; } catch (Exception exc) { LogHelper.LogException(exc); e.Mobile.SendMessage("Exception in [Retarget -- see console."); System.Console.WriteLine("Exception in [Retarget: {0}", exc.Message); System.Console.WriteLine(exc.StackTrace); return; } } else { e.Mobile.SendMessage("Usage: [Retarget <-regionName|-type|-point|-RegionUID> <name|type|point|uid>"); } }
public static void SaveSpawners_OnCommand(CommandEventArgs e) { if (e.Arguments.Length == 5) { int count = 0; int x1, y1, x2, y2; string FileName = e.Arguments[0].ToString(); try { x1 = Int32.Parse(e.Arguments[1]); y1 = Int32.Parse(e.Arguments[2]); x2 = Int32.Parse(e.Arguments[3]); y2 = Int32.Parse(e.Arguments[4]); } catch { Usage(e.Mobile); return; } //adjust rect if (x1 > x2) { int x3 = x1; x1 = x2; x2 = x3; } if (y1 > y2) { int y3 = y1; y1 = y2; y2 = y3; } string itemIdxPath = Path.Combine("Saves/Spawners/", FileName + ".idx"); string itemBinPath = Path.Combine("Saves/Spawners/", FileName + ".bin"); try { ArrayList list = new ArrayList(); foreach (Item item in Server.World.Items.Values) { if (item is Spawner) { if (item.X >= x1 && item.Y >= y1 && item.X < x2 && item.Y < y2 && item.Map == e.Mobile.Map) { list.Add(item); } } } if (list.Count > 0) { try { string folder = Path.GetDirectoryName(itemIdxPath); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } catch { e.Mobile.SendMessage("An error occured while trying to create Spawner folder."); } count = list.Count; GenericWriter idx; GenericWriter bin; idx = new BinaryFileWriter(itemIdxPath, false); bin = new BinaryFileWriter(itemBinPath, true); idx.Write((int)list.Count); for (int i = 0; i < list.Count; ++i) { long start = bin.Position; Spawner temp = new Spawner(); CopyProperties(temp, (Spawner)list[i]); idx.Write((long)start); //dont save template data as we cant load it back properly temp.TemplateItem = null; temp.TemplateMobile = null; temp.CreaturesName = ((Spawner)list[i]).CreaturesName; temp.Serialize(bin); idx.Write((int)(bin.Position - start)); temp.Delete(); } idx.Close(); bin.Close(); } } catch (Exception ex) { LogHelper.LogException(ex); System.Console.WriteLine("Exception Caught in SaveSpawner code: " + ex.Message); System.Console.WriteLine(ex.StackTrace); } e.Mobile.SendMessage("{0} Spawners Saved.", count); } else { Usage(e.Mobile); } }
public static void LoadSpawners_OnCommand(CommandEventArgs e) { int count = 0; int itemCount = 0; Hashtable m_Items; if (e.Arguments.Length == 1) { string FileName = e.Arguments[0].ToString(); string itemIdxPath = Path.Combine("Saves/Spawners/", FileName + ".idx"); string itemBinPath = Path.Combine("Saves/Spawners/", FileName + ".bin"); try { ArrayList items = new ArrayList(); if (File.Exists(itemIdxPath)) { using (FileStream idx = new FileStream(itemIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryReader idxReader = new BinaryReader(idx); itemCount = idxReader.ReadInt32(); count = itemCount; m_Items = new Hashtable(itemCount); for (int i = 0; i < itemCount; ++i) { long pos = idxReader.ReadInt64(); int length = idxReader.ReadInt32(); Item item = null; try { item = new Spawner(); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } if (item != null) { items.Add(new ItemEntry(item, pos, length)); World.AddItem(item); } } idxReader.Close(); } } else { e.Mobile.SendMessage("File Not Found {0}.idx", FileName); } if (File.Exists(itemBinPath)) { using (FileStream bin = new FileStream(itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin)); for (int i = 0; i < items.Count; ++i) { ItemEntry entry = (ItemEntry)items[i]; Item item = (Item)entry.Object; if (item != null) { reader.Seek(entry.Position, SeekOrigin.Begin); try { item.Deserialize(reader); if (reader.Position != (entry.Position + entry.Length)) { throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType())); } item.MoveToWorld(item.Location, item.Map); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } reader.Close(); } } else { e.Mobile.SendMessage("File Not Found {0}.bin", FileName); } } catch (Exception ex) { LogHelper.LogException(ex); System.Console.WriteLine("Exception Caught in LoadSpawner code: " + ex.Message); System.Console.WriteLine(ex.StackTrace); } e.Mobile.SendMessage("{0} Spawners Loaded.", count); } else { e.Mobile.SendMessage("[Usage <FileName>"); } }
public static void DeactivateSpawners_OnCommand(CommandEventArgs e) { if (e.Arguments.Length == 4) { int count = 0; int x1, y1, x2, y2; try { x1 = Int32.Parse(e.Arguments[0]); y1 = Int32.Parse(e.Arguments[1]); x2 = Int32.Parse(e.Arguments[2]); y2 = Int32.Parse(e.Arguments[3]); } catch { Usage(e.Mobile); return; } //adjust rect if (x1 > x2) { int x3 = x1; x1 = x2; x2 = x3; } if (y1 > y2) { int y3 = y1; y1 = y2; y2 = y3; } try { ArrayList list = new ArrayList(); foreach (Item item in Server.World.Items.Values) { if (item is Spawner) { if (item.X >= x1 && item.Y >= y1 && item.X < x2 && item.Y < y2 && item.Map == e.Mobile.Map) { list.Add(item); } } } if (list.Count > 0) { count = list.Count; for (int i = 0; i < list.Count; ++i) { ((Spawner)list[i]).Running = false; ((Spawner)list[i]).RemoveCreatures(); } } } catch (Exception ex) { LogHelper.LogException(ex); System.Console.WriteLine("Exception Caught in DeactivateSpawner code: " + ex.Message); System.Console.WriteLine(ex.StackTrace); } e.Mobile.SendMessage("{0} Spawners Deactivated.", count); } else { Usage(e.Mobile); } }
public void OnTarget(Mobile from, object targeted, object state) { if (!BaseCommand.IsAccessible(from, targeted)) { from.SendMessage("That is not accessible."); return; } object[] states = (object[])state; BaseCommand command = (BaseCommand)states[0]; string[] args = (string[])states[1]; if (command.ObjectTypes == ObjectTypes.Mobiles) { return; // sanity check } if (!(targeted is Container)) { from.SendMessage("That is not a container."); } else { try { ObjectConditional cond = ObjectConditional.Parse(from, ref args); bool items, mobiles; if (!CheckObjectTypes(command, cond, out items, out mobiles)) { return; } if (!items) { from.SendMessage("This command only works on items."); return; } Container cont = (Container)targeted; Item[] found; if (cond.Type == null) { found = cont.FindItemsByType(typeof(Item), true); } else { found = cont.FindItemsByType(cond.Type, true); } ArrayList list = new ArrayList(); for (int i = 0; i < found.Length; ++i) { if (cond.CheckCondition(found[i])) { list.Add(found[i]); } } RunCommand(from, list, command, args); } catch (Exception e) { LogHelper.LogException(e); from.SendMessage(e.Message); } } }
protected override void OnTarget(Mobile from, object o) { try { if (from == null) { return; } if (o == null) { from.SendMessage("Target does not exist."); return; } if (o is BaseContainer == false) { from.SendMessage("That is not a container."); return; } BaseContainer bc = o as BaseContainer; if (Misc.Diagnostics.Assert(from.Backpack != null, "from.Backpack == null") == false) { from.SendMessage("You cannot use this deed without a backpack."); return; } // mobile backpacks may not be used if (bc == from.Backpack || bc.Parent is Mobile) { from.SendMessage("You may not use that container."); return; } // must not be locked down if (bc.IsLockedDown == true || bc.IsSecure == true) { from.SendMessage("That container is locked down."); return; } // if it's in your bankbox, or it's in YOUR house, you can deed it if ((bc.IsChildOf(from.BankBox) || CheckAccess(from)) == false) { from.SendMessage("The container must be in your bankbox, or a home you own."); return; } // cannot be in another container if (bc.RootParent is BaseContainer && bc.IsChildOf(from.BankBox) == false) { from.SendMessage("You must remove it from that container first."); return; } // okay, done with target checking, now deed the container. // place a special deed to reclaim the container in the players backpack PlayerQuestDeed deed = new PlayerQuestDeed(bc); if (from.Backpack.CheckHold(from, deed, true, false, 0, 0)) { bc.PlayerQuest = true; // mark as special bc.MoveToWorld(from.Location, Map.Internal); // put it on the internal map bc.SetLastMoved(); // record the move (will use this in Heartbeat cleanup) //while (deed.Expires.Hours + deed.Expires.Minutes == 0) //Console.WriteLine("Waiting..."); //int hours = deed.Expires.Hours; //int minutes = deed.Expires.Minutes; //string text = String.Format("{0} {1}, and {2} {3}", hours, hours == 1 ? "hour" : "hours", minutes, minutes == 1 ? "minute" : "minutes"); from.Backpack.DropItem(deed); from.SendMessage("A deed for the container has been placed in your backpack."); //from.SendMessage( "This quest will expire in {0}.", text); } else { from.SendMessage("Your backpack is full and connot hold the deed."); deed.Delete(); } } catch (Exception e) { LogHelper.LogException(e); } }
private static void ProcessMatch(Mobile from, bool highOnly, PlayerMobile pm1, PlayerMobile pm2) { try { // sanity if (from == null || pm1 == null || pm2 == null) { return; // wtf } NetState ns1 = pm1.NetState; NetState ns2 = pm2.NetState; if (ns1 == null || ns2 == null) { return; // logged out / disconnected } if (ns1.Address == null || ns1.Mobile == null || ns2.Address == null || ns2.Mobile == null) { return; // still logging in? } if (ns1.Account == null || ns2.Account == null) { return; // error state .. ignore this account } if (ns1.Account as Server.Accounting.Account == null || ns2.Account as Server.Accounting.Account == null) { return; // error state .. ignore this account } Server.Accounting.Account pm1Account = (Server.Accounting.Account)ns1.Account; HardwareInfo pm1HWInfo = pm1Account.HardwareInfo; string pm1Name = string.Format("{0}/{1}", pm1Account.Username, ns1.Mobile.Name); Server.Accounting.Account pm2Account = (Server.Accounting.Account)ns2.Account; HardwareInfo pm2HWInfo = pm2Account.HardwareInfo; string pm2Name = string.Format("{0}/{1}", pm2Account.Username, ns2.Mobile.Name); alert alarm = alert.LOW; if (pm1HWInfo == null && pm2HWInfo == null && ns1.Version == ns2.Version) { // unknown hardware if (LineOfSight(pm1, pm2)) { alarm = alert.MEDIUM; } } else if (pm1HWInfo == null || pm2HWInfo == null && ns1.Version == ns2.Version) { // unknown hardware if (LineOfSight(pm1, pm2)) { alarm = alert.MEDIUM; } } else if ((pm1HWInfo != null && pm2HWInfo != null) && (pm1HWInfo.CpuClockSpeed == 0 || pm1HWInfo.OSMajor == 0 || pm2HWInfo.CpuClockSpeed == 0 || pm2HWInfo.OSMajor == 0)) { // unknown hardware if (LineOfSight(pm1, pm2)) { alarm = alert.MEDIUM; } } else if ((pm1HWInfo != null && pm2HWInfo != null) && Server.Scripts.Commands.MultiClientCommand.IsSameHWInfo(pm1HWInfo, pm2HWInfo)) { // same hardware alarm = alert.MEDIUM; if (LineOfSight(pm1, pm2) && ns1.Version == ns2.Version) { alarm = alert.HIGH; } } else { // different hardware if (LineOfSight(pm1, pm2) && ns1.Version == ns2.Version) { alarm = alert.MEDIUM; } } // caller wants to filter to HIGH alarms only if (highOnly == true && alarm != alert.HIGH) { return; } from.SendMessage(String.Format("{0}, {1}, Alarm({2})", pm1Name, pm2Name, alarm.ToString())); } catch (Exception ex) { LogHelper.LogException(ex); } }
public static void Announcement_OnCommand(CommandEventArgs e) { Mobile from = e.Mobile; // check arguments if (e.Length != 3) { Usage(from); return; } // can only be run on Test Center if (TestCenter.Enabled == false) { from.SendMessage("This command may only be executed on Test Center."); return; } int iChecked = 0; int Reminders = 0; try { // loop through the accouints looking for current users ArrayList results = new ArrayList(); int days = 0; try { days = Convert.ToInt32(e.GetString(0)); } catch { Usage(from); return; } foreach (Account acct in Accounts.Table.Values) { iChecked++; // logged in the last n days. if (Server.Engines.CronScheduler.EmailHelpers.RecentLogin(acct, days) == true) { Reminders++; results.Add(acct.EmailAddress); } } if (Reminders > 0) { from.SendMessage("Sending {0} email announcement(s).", Reminders); string subject = String.Format(e.GetString(1)); string body = null; try { // create reader & open file TextReader tr = new StreamReader(String.Format("Msgs/{0}", e.GetString(2))); // read it body = tr.ReadToEnd(); // close the stream tr.Close(); } catch (Exception ex) { LogHelper.LogException(ex); from.SendMessage(ex.Message); Usage(from); return; } // okay, now hand the list of users off to our mailer daemon new Emailer().SendEmail(results, subject, body, false); } } catch (Exception ex) { LogHelper.LogException(ex); System.Console.WriteLine("Exception Caught in generic emailer: " + ex.Message); System.Console.WriteLine(ex.StackTrace); } return; }
public static void ClientMon_OnCommand(CommandEventArgs e) { try { if (e.Arguments.Length == 0) { e.Mobile.SendMessage("Usage: ClientMon -ui|-ma|-mc|-hi|-ho"); e.Mobile.SendMessage("Where: -ui ... Unique IP addresses"); e.Mobile.SendMessage("Where: -ma ... total multi accounts"); e.Mobile.SendMessage("Where: -mc ... total multi clients"); e.Mobile.SendMessage("Where: -hi ... clients that have hardware info"); e.Mobile.SendMessage("Where: -ho ... HIGH only. use with -mc"); return; } if (e.ArgString.Contains("-hi")) { int clients = 0; int hardwareInfo = 0; int badHardwareInfo = 0; int nullHardwareInfo = 0; foreach (DictionaryEntry de in ClientMon.list) { ArrayList al = de.Value as ArrayList; if (al == null) { continue; } foreach (Account acct in al) { if (acct == null) { continue; // bogus } PlayerMobile pm = GetActiveCharacter(acct); if (pm == null) { continue; // no longer logged in? } NetState ns = pm.NetState; if (ns == null || ns.Address == null || ns.Mobile == null) { continue; // still logging in? } Server.Accounting.Account pmAccount = (Server.Accounting.Account)ns.Account; HardwareInfo pmHWInfo = pmAccount.HardwareInfo; clients++; if (pmHWInfo == null) { nullHardwareInfo++; } else { if (pmHWInfo.CpuClockSpeed == 0 || pmHWInfo.OSMajor == 0) { badHardwareInfo++; } else { hardwareInfo++; } } } } e.Mobile.SendMessage(String.Format("{0} total clients, {1} with hardware info", clients, hardwareInfo)); e.Mobile.SendMessage(String.Format("{0} with null hardware info, {1} with bad hardware info", nullHardwareInfo, badHardwareInfo)); } if (e.ArgString.Contains("-mc")) { bool highOnly = false; if (e.ArgString.Contains("-ho")) { highOnly = true; } foreach (DictionaryEntry de in ClientMon.list) { ArrayList al = de.Value as ArrayList; if (al == null) // bogus { continue; } if (al.Count < 2) // no more than 1 account for this IP { continue; } PlayerMobile pm1 = null; PlayerMobile pm2 = null; ArrayList seen = new ArrayList(); foreach (Account acct1 in al) { if (acct1 == null) { continue; // bogus } if (!TestCenter.Enabled && acct1.GetAccessLevel() > AccessLevel.Player) { continue; // ignore staff } pm1 = GetActiveCharacter(acct1); if (pm1 == null) { continue; // logged out maybe? } seen.Add(acct1); foreach (Account acct2 in al) { if (acct2 == null) { continue; // bogus } if (seen.Contains(acct2)) { continue; // already processed } if (!TestCenter.Enabled && acct2.GetAccessLevel() > AccessLevel.Player) { continue; // ignore staff } pm2 = GetActiveCharacter(acct2); if (pm2 == null) { continue; // logged out maybe? } // okay check the hardware and report ProcessMatch(e.Mobile, highOnly, pm1, pm2); } } } } if (e.ArgString.Contains("-ma")) { int clients = 0; int ipaddresses = 0; foreach (DictionaryEntry de in ClientMon.list) { ArrayList al = de.Value as ArrayList; if (al == null) { continue; } if (al.Count > 1) { clients += al.Count; ipaddresses++; } } if (clients == 0) { e.Mobile.SendMessage("There are no shared IP addresses"); } else { e.Mobile.SendMessage(String.Format("There {2} {0} client{3} sharing {1} IP address{4}", clients, ipaddresses, clients == 1 ? "is" : "are", clients == 1 ? "" : "s", ipaddresses == 1 ? "" : "es" )); } } if (e.ArgString.Contains("-ui")) { e.Mobile.SendMessage(String.Format("There {1} {0} unique IP address{2}", ClientMon.list.Count, ClientMon.list.Count == 1 ? "is" : "are", ClientMon.list.Count == 1 ? "" : "es" )); } } catch (Exception ex) { LogHelper.LogException(ex); } e.Mobile.SendMessage("done."); }
public static void AddressDump_OnCommand(CommandEventArgs e) { Mobile from = e.Mobile; // check arguments if (e.Length < 1) { Usage(from); return; } int iChecked = 0; int Reminders = 0; try { // loop through the accouints looking for current users ArrayList results = new ArrayList(); // assume DaysActive if (e.Length == 1 && LooksLikeInt(e.GetString(0))) { int days = 0; try { days = Convert.ToInt32(e.GetString(0)); } catch { Usage(from); return; } foreach (Account acct in Accounts.Table.Values) { iChecked++; // logged in the last n days. if (Server.Engines.CronScheduler.EmailHelpers.RecentLogin(acct, days) == true) { if (ValidEmail(acct.EmailAddress)) { Reminders++; results.Add(acct.EmailAddress); } } } } // assume activations since date else { string buff = null; for (int ix = 0; ix < e.Length; ix++) { buff += e.GetString(ix) + " "; } DateTime Since; try { Since = DateTime.Parse(buff); } catch { Usage(from); return; } foreach (Account acct in Accounts.Table.Values) { iChecked++; // account created since... if (acct.Created >= Since && acct.EmailAddress != null) { if (ValidEmail(acct.EmailAddress)) { Reminders++; results.Add(acct.EmailAddress); } } } } if (Reminders > 0) { from.SendMessage("Logging {0} email address(es).", Reminders); LogHelper Logger = new LogHelper("accountEmails.log", true); foreach (object ox in results) { string address = ox as string; if (address == null) { continue; } Logger.Log(LogType.Text, address); } Logger.Finish(); } } catch (Exception ex) { LogHelper.LogException(ex); System.Console.WriteLine("Exception Caught in generic emailer: " + ex.Message); System.Console.WriteLine(ex.StackTrace); } return; }
public static void On_RHFile(CommandEventArgs e) { if (e.Arguments.Length != 1) { e.Mobile.SendMessage("Usage: [LoadCont <filename>"); return; } try { int loaded = 0; int count; LogHelper log = new LogHelper(e.Arguments[0] + " LoadCont.log"); log.Log(LogType.Text, String.Format("Reload process initiated by {0}, with {1} as backup data.", e.Mobile, e.Arguments[0])); using (FileStream idxfs = new FileStream(e.Arguments[0] + ".idx", FileMode.Open, FileAccess.Read)) { using (FileStream binfs = new FileStream(e.Arguments[0] + ".bin", FileMode.Open, FileAccess.Read)) { GenericReader bin = new BinaryFileReader(new BinaryReader(binfs)); GenericReader idx = new BinaryFileReader(new BinaryReader(idxfs)); count = idx.ReadInt(); if (count == -1) { log.Log(LogType.Text, "No item data to reload."); // do nothing } else { ArrayList items = new ArrayList(count); log.Log(LogType.Text, String.Format("Attempting to reload {0} items.", count)); Type[] ctortypes = new Type[] { typeof(Serial) }; object[] ctorargs = new object[1]; for (int i = 0; i < count; i++) { string type = idx.ReadString(); Serial serial = (Serial)idx.ReadInt(); long position = idx.ReadLong(); int length = idx.ReadInt(); Type t = ScriptCompiler.FindTypeByFullName(type); if (t == null) { Console.WriteLine("Warning: Tried to load nonexistent type {0}. Ignoring item.", type); log.Log(String.Format("Warning: Tried to load nonexistent type {0}. Ignoring item.", type)); continue; } ConstructorInfo ctor = t.GetConstructor(ctortypes); if (ctor == null) { Console.WriteLine("Warning: Tried to load type {0} which has no serialization constructor. Ignoring item.", type); log.Log(String.Format("Warning: Tried to load type {0} which has no serialization constructor. Ignoring item.", type)); continue; } Item item = null; try { if (World.FindItem(serial) != null) { log.Log(LogType.Item, World.FindItem(serial), "Serial already in use!! Loading of saved item failed."); } else if (!World.IsReserved(serial)) { log.Log(String.Format("Serial {0} is not reserved!! Loading of saved item failed.", serial)); } else { ctorargs[0] = serial; item = (Item)(ctor.Invoke(ctorargs)); } } catch (Exception ex) { LogHelper.LogException(ex); Console.WriteLine("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName); Console.WriteLine(ex.ToString()); log.Log(String.Format("An exception occurred while trying to invoke {0}'s serialization constructor.", t.FullName)); log.Log(ex.ToString()); } if (item != null) { World.FreeSerial(serial); World.AddItem(item); items.Add(new object[] { item, position, length }); log.Log(String.Format("Successfully created item {0}", item)); } } for (int i = 0; i < items.Count; i++) { object[] entry = (object[])items[i]; Item item = entry[0] as Item; long position = (long)entry[1]; int length = (int)entry[2]; if (item != null) { bin.Seek(position, SeekOrigin.Begin); try { item.Deserialize(bin); // take care of parent hierarchy object p = item.Parent; if (p is Item) { ((Item)p).RemoveItem(item); item.Parent = null; ((Item)p).AddItem(item); } else if (p is Mobile) { ((Mobile)p).RemoveItem(item); item.Parent = null; ((Mobile)p).AddItem(item); } else { item.Delta(ItemDelta.Update); } item.ClearProperties(); object rp = item.RootParent; if (rp is Item) { ((Item)rp).UpdateTotals(); } else if (rp is Mobile) { ((Mobile)rp).UpdateTotals(); } else { item.UpdateTotals(); } if (bin.Position != (position + length)) { throw new Exception(String.Format("Bad serialize on {0}", item)); } log.Log(LogType.Item, item, "Successfully loaded."); loaded++; } catch (Exception ex) { LogHelper.LogException(ex); Console.WriteLine("Caught exception while deserializing {0}:", item); Console.WriteLine(ex.ToString()); Console.WriteLine("Deleting item."); log.Log(String.Format("Caught exception while deserializing {0}:", item)); log.Log(ex.ToString()); log.Log("Deleting item."); item.Delete(); } } } } idx.Close(); bin.Close(); } } Console.WriteLine("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded); log.Log(String.Format("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded)); e.Mobile.SendMessage("Attempted to load {0} items: {1} loaded, {2} failed.", count, loaded, count - loaded); log.Finish(); } catch (Exception ex) { LogHelper.LogException(ex); Console.WriteLine(ex.ToString()); e.Mobile.SendMessage("Exception: {0}", ex.Message); } }
public static int Build(Mobile from, Point3D start, Point3D end, ConstructorInfo ctor, object[] values, string[,] props, PropertyInfo[] realProps, ArrayList packs) { try { Map map = from.Map; int objectCount = (packs == null ? (((end.X - start.X) + 1) * ((end.Y - start.Y) + 1)) : packs.Count); if (objectCount >= 20) { from.SendMessage("Constructing {0} objects, please wait.", objectCount); } bool sendError = true; if (packs != null) { for (int i = 0; i < packs.Count; ++i) { object built = Build(from, ctor, values, props, realProps, ref sendError); if (built is Item) { Container pack = (Container)packs[i]; pack.DropItem((Item)built); } else if (built is Mobile) { Mobile m = (Mobile)built; m.MoveToWorld(new Point3D(start.X, start.Y, start.Z), map); } } } else { for (int x = start.X; x <= end.X; ++x) { for (int y = start.Y; y <= end.Y; ++y) { object built = Build(from, ctor, values, props, realProps, ref sendError); if (built is Item) { Item item = (Item)built; item.MoveToWorld(new Point3D(x, y, start.Z), map); AddItemEventArgs e = new AddItemEventArgs(built as Item, from); EventSink.InvokeAddItem(e); // erl: stores person adding it if Spawner // or ChestItemSpawner type + calls change log if (built is Spawner) { Spawner sp = (Spawner)built; sp.LastProps = from; sp.LogChange("Spawner added"); } else if (built is ChestItemSpawner) { ChestItemSpawner sp = (ChestItemSpawner)built; sp.LastProps = from; sp.LogChange("ChestItemSpawner added"); } } else if (built is Mobile) { Mobile m = (Mobile)built; m.MoveToWorld(new Point3D(x, y, start.Z), map); } } } } return(objectCount); } catch (Exception ex) { LogHelper.LogException(ex); Console.WriteLine(ex); return(0); } }
public override void Execute(CommandEventArgs e, object obj) { try { Item item = obj as Item; if (!RareFactory.InUse) { if (e.Arguments.Length == 4) { int iRarity = 0; if (int.TryParse(e.Arguments[1], out iRarity) == true && iRarity >= 0 && iRarity <= 10) { DODGroup match; if ((match = FindGroup(e.Arguments[0], iRarity)) != null) { int iStartIndex = 0; if (int.TryParse(e.Arguments[2], out iStartIndex) == true && iStartIndex > 0 && iStartIndex <= 255) { int iLastIndex = 0; if (int.TryParse(e.Arguments[3], out iLastIndex) == true && iLastIndex > 0 && iLastIndex <= 255) { if (item != null) { LogHelper Logger = null; try { DODInstance di = RareFactory.AddRare(match, item); // rarity is defined by the group di.LastIndex = (short)iLastIndex; di.StartIndex = (short)iStartIndex; di.StartDate = DateTime.MinValue; // valid now di.EndDate = DateTime.MaxValue; // valid forever // default the name to the name of the item if (item.Name != null && item.Name != "") { di.Name = item.Name; } else { di.Name = item.GetType().Name; } AddResponse("Sucessfully defined new rare '" + di.Name + "'!"); } catch (Exception ex) { LogHelper.LogException(ex); e.Mobile.SendMessage(ex.Message); } finally { if (Logger != null) { Logger.Finish(); } } } else { LogFailure("Only an item may be converted into a rare."); } } else { LogFailure("The LastIndex must be a numeric value between 1 and 255 inclusive."); } } else { LogFailure("The StartIndex must be a numeric value between 1 and 255 inclusive."); } } else { LogFailure(String.Format("Could not find the group \"{0}\" with a rarity of {1}", e.Arguments[0], iRarity)); } } else { LogFailure("The rarity must be a numeric value between 0 and 10 inclusive."); } } else { LogFailure("AddRare sGroup iRarity iStartIndex iLastIndex"); } } else { LogFailure("Rare Factory is currently being configured by another administrator! Please wait. "); } } catch (Exception exe) { LogHelper.LogException(exe); e.Mobile.SendMessage(exe.Message); } }
public void OnTarget(Mobile from, Map map, Point3D start, Point3D end, object state) { try { object[] states = (object[])state; BaseCommand command = (BaseCommand)states[0]; string[] args = (string[])states[1]; ObjectConditional cond = ObjectConditional.Parse(from, ref args); Rectangle2D rect = new Rectangle2D(start.X, start.Y, end.X - start.X + 1, end.Y - start.Y + 1); bool items, mobiles; if (!CheckObjectTypes(command, cond, out items, out mobiles)) { return; } IPooledEnumerable eable; if (items && mobiles) { eable = map.GetObjectsInBounds(rect); } else if (items) { eable = map.GetItemsInBounds(rect); } else if (mobiles) { eable = map.GetMobilesInBounds(rect); } else { return; } ArrayList objs = new ArrayList(); foreach (object obj in eable) { if (mobiles && obj is Mobile && !BaseCommand.IsAccessible(from, obj)) { continue; } if (cond.CheckCondition(obj)) { objs.Add(obj); } } eable.Free(); RunCommand(from, objs, command, args); } catch (Exception ex) { LogHelper.LogException(ex); from.SendMessage(ex.Message); } }
public override void Execute(CommandEventArgs e, object obj) { PlayerMobile pm = obj as PlayerMobile; Mobile from = e.Mobile; try { if (pm != null) { NetState ns = pm.NetState; if (ns == null) { from.SendMessage("That player is no longer online."); return; } Server.Accounting.Account pmAccount = (Server.Accounting.Account)pm.Account; HardwareInfo pmHWInfo = pmAccount.HardwareInfo; from.SendMessage("{0}/{1}: Finding possible multi-clients (IP: {2}, CV: {3})", pmAccount.Username, pm.Name, ns.Address.ToString(), ns.Version.ToString()); //ArrayList netStates = NetState.Instances; List <NetState> netStates = NetState.Instances; for (int i = 0; i < netStates.Count; i++) { NetState compState = netStates[i]; //guard against NetStates which haven't completely logged in yet if (compState == null || compState.Address == null || compState.Mobile == null) { continue; } if (ns.Address.Equals(compState.Address)) { if (compState.Mobile != pm) { Server.Accounting.Account compAcct = (Server.Accounting.Account)compState.Mobile.Account; string clientName = string.Format("{0}/{1}", compAcct.Username, compState.Mobile.Name); HardwareInfo compHWInfo = compAcct.HardwareInfo; from.SendMessage("{0}: Same IP Address ({1})", clientName, compState.Address.ToString()); //Found another client from same IP, check client version if (ns.Version.CompareTo(compState.Version) == 0) { from.SendMessage("{0}: Same Client Version: {1}", clientName, compState.Version.ToString()); } else { from.SendMessage("{0}: Different Client Version: {1}", clientName, compState.Version.ToString()); } //Check HWInfo if (pmHWInfo == null && compHWInfo == null) { from.SendMessage("{0}+{1}: BOTH Hardware UNKNOWN", pm.Name, clientName); } else if (pmHWInfo == null || (pmHWInfo.CpuClockSpeed == 0 && pmHWInfo.OSMajor == 0)) { from.SendMessage("{0}: Hardware UNKNOWN, {1} Known", pm.Name, clientName); } else if (compHWInfo == null || (compHWInfo.CpuClockSpeed == 0 && compHWInfo.OSMajor == 0)) { from.SendMessage("{0}: Hardware UNKNOWN, {1} Known", clientName, pm.Name); } else if (IsSameHWInfo(pmHWInfo, compHWInfo)) { from.SendMessage("{0}: Same Hardware", clientName); } else { from.SendMessage("{0}: Different Hardware", clientName); } } } } } else { AddResponse("Please target a player."); } } catch (Exception ex) { LogHelper.LogException(ex); from.SendMessage("ERROR: Caught exception: " + ex.Message); } }
public Item Construct() { Item item; try { if (m_Type == typeofStatic) { item = new Static(m_ItemID); } else if (m_Type == typeofLocalizedStatic) { int labelNumber = 0; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("LabelNumber")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { labelNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); break; } } } item = new LocalizedStatic(m_ItemID, labelNumber); } else if (m_Type == typeofLocalizedSign) { int labelNumber = 0; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("LabelNumber")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { labelNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); break; } } } item = new LocalizedSign(m_ItemID, labelNumber); } else if (m_Type == typeofAnkhWest || m_Type == typeofAnkhEast) { bool bloodied = false; for (int i = 0; !bloodied && i < m_Params.Length; ++i) { bloodied = (m_Params[i] == "Bloodied"); } if (m_Type == typeofAnkhWest) { item = new AnkhWest(bloodied); } else { item = new AnkhEast(bloodied); } } else if (m_Type == typeofMarkContainer) { bool bone = false; bool locked = false; Map map = Map.Malas; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i] == "Bone") { bone = true; } else if (m_Params[i] == "Locked") { locked = true; } else if (m_Params[i].StartsWith("TargetMap")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { map = Map.Parse(m_Params[i].Substring(++indexOf)); } } } MarkContainer mc = new MarkContainer(bone, locked); mc.TargetMap = map; mc.Description = "strange location"; item = mc; } else if (m_Type == typeofHintItem) { int range = 0; int messageNumber = 0; string messageString = null; int hintNumber = 0; string hintString = null; TimeSpan resetDelay = TimeSpan.Zero; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Range")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("WarningString")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { messageString = m_Params[i].Substring(++indexOf); } } else if (m_Params[i].StartsWith("WarningNumber")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { messageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("HintString")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { hintString = m_Params[i].Substring(++indexOf); } } else if (m_Params[i].StartsWith("HintNumber")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { hintNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("ResetDelay")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { resetDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); } } } HintItem hi = new HintItem(m_ItemID, range, messageNumber, hintNumber); hi.WarningString = messageString; hi.HintString = hintString; hi.ResetDelay = resetDelay; item = hi; } else if (m_Type == typeofWarningItem) { int range = 0; int messageNumber = 0; string messageString = null; TimeSpan resetDelay = TimeSpan.Zero; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Range")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("WarningString")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { messageString = m_Params[i].Substring(++indexOf); } } else if (m_Params[i].StartsWith("WarningNumber")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { messageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("ResetDelay")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { resetDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); } } } WarningItem wi = new WarningItem(m_ItemID, range, messageNumber); wi.WarningString = messageString; wi.ResetDelay = resetDelay; item = wi; } else if (m_Type == typeofCannon) { CannonDirection direction = CannonDirection.North; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("CannonDirection")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { direction = (CannonDirection)Enum.Parse(typeof(CannonDirection), m_Params[i].Substring(++indexOf), true); } } } item = new Cannon(direction); } else if (m_Type.IsSubclassOf(typeofBeverage)) { BeverageType content = BeverageType.Liquor; bool fill = false; for (int i = 0; !fill && i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Content")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { content = (BeverageType)Enum.Parse(typeof(BeverageType), m_Params[i].Substring(++indexOf), true); fill = true; } } } if (fill) { item = (Item)Activator.CreateInstance(m_Type, new object[] { content }); } else { item = (Item)Activator.CreateInstance(m_Type); } } else if (m_Type.IsSubclassOf(typeofBaseDoor)) { DoorFacing facing = DoorFacing.WestCW; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Facing")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { facing = (DoorFacing)Enum.Parse(typeof(DoorFacing), m_Params[i].Substring(++indexOf), true); break; } } } item = (Item)Activator.CreateInstance(m_Type, new object[] { facing }); } else { item = (Item)Activator.CreateInstance(m_Type); } } catch (Exception e) { LogHelper.LogException(e); throw new Exception(String.Format("Bad type: {0}", m_Type), e); } if (item is BaseAddon) { if (item is MaabusCoffin) { MaabusCoffin coffin = (MaabusCoffin)item; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("SpawnLocation")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { coffin.SpawnLocation = Point3D.Parse(m_Params[i].Substring(++indexOf)); } } } } else if (m_ItemID > 0) { ArrayList comps = ((BaseAddon)item).Components; for (int i = 0; i < comps.Count; ++i) { AddonComponent comp = (AddonComponent)comps[i]; if (comp.Offset == Point3D.Zero) { comp.ItemID = m_ItemID; } } } } else if (item is BaseLight) { bool unlit = false; for (int i = 0; !unlit && i < m_Params.Length; ++i) { unlit = (m_Params[i] == "Unlit"); } if (!unlit) { ((BaseLight)item).Ignite(); } ((BaseLight)item).Protected = true; if (m_ItemID > 0) { item.ItemID = m_ItemID; } } else if (item is Server.Mobiles.Spawner) { Server.Mobiles.Spawner sp = (Server.Mobiles.Spawner)item; sp.NextSpawn = TimeSpan.Zero; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Spawn")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.CreaturesName.Add(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("MinDelay")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.MinDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("MaxDelay")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.MaxDelay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("NextSpawn")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.NextSpawn = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Count")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.Count = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Team")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.Team = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("HomeRange")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.HomeRange = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Running")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.Running = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Group")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { sp.Group = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } } } else if (item is RecallRune) { RecallRune rune = (RecallRune)item; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Description")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { rune.Description = m_Params[i].Substring(++indexOf); } } else if (m_Params[i].StartsWith("Marked")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { rune.Marked = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("TargetMap")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { rune.TargetMap = Map.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Target")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { rune.Target = Point3D.Parse(m_Params[i].Substring(++indexOf)); } } } } else if (item is SkillTeleporter) { SkillTeleporter tp = (SkillTeleporter)item; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Skill")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Skill = (SkillName)Enum.Parse(typeof(SkillName), m_Params[i].Substring(++indexOf), true); } } else if (m_Params[i].StartsWith("RequiredFixedPoint")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Required = Utility.ToInt32(m_Params[i].Substring(++indexOf)) * 0.01; } } else if (m_Params[i].StartsWith("Required")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Required = Utility.ToDouble(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("MessageString")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.MessageString = m_Params[i].Substring(++indexOf); } } else if (m_Params[i].StartsWith("MessageNumber")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.MessageNumber = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("PointDest")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("MapDest")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Creatures")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("SourceEffect")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("DestEffect")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("SoundID")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Delay")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); } } } if (m_ItemID > 0) { item.ItemID = m_ItemID; } } else if (item is KeywordTeleporter) { KeywordTeleporter tp = (KeywordTeleporter)item; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Substring")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Substring = m_Params[i].Substring(++indexOf); } } else if (m_Params[i].StartsWith("Keyword")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Keyword = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Range")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Range = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("PointDest")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("MapDest")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Creatures")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("SourceEffect")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("DestEffect")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("SoundID")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Delay")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); } } } if (m_ItemID > 0) { item.ItemID = m_ItemID; } } else if (item is Teleporter) { Teleporter tp = (Teleporter)item; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("PointDest")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.PointDest = Point3D.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("MapDest")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.MapDest = Map.Parse(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Creatures")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Creatures = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("SourceEffect")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.SourceEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("DestEffect")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.DestEffect = Utility.ToBoolean(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("SoundID")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.SoundID = Utility.ToInt32(m_Params[i].Substring(++indexOf)); } } else if (m_Params[i].StartsWith("Delay")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { tp.Delay = TimeSpan.Parse(m_Params[i].Substring(++indexOf)); } } } if (m_ItemID > 0) { item.ItemID = m_ItemID; } } else if (m_ItemID > 0) { item.ItemID = m_ItemID; } item.Movable = false; for (int i = 0; i < m_Params.Length; ++i) { if (m_Params[i].StartsWith("Light")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { item.Light = (LightType)Enum.Parse(typeof(LightType), m_Params[i].Substring(++indexOf), true); } } else if (m_Params[i].StartsWith("Hue")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { int hue = Utility.ToInt32(m_Params[i].Substring(++indexOf)); if (item is DyeTub) { ((DyeTub)item).DyedHue = hue; } else { item.Hue = hue; } } } else if (m_Params[i].StartsWith("Name")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { item.Name = m_Params[i].Substring(++indexOf); } } else if (m_Params[i].StartsWith("Amount")) { int indexOf = m_Params[i].IndexOf('='); if (indexOf >= 0) { // Must supress stackable warnings bool wasStackable = item.Stackable; item.Stackable = true; item.Amount = Utility.ToInt32(m_Params[i].Substring(++indexOf)); item.Stackable = wasStackable; } } } return(item); }
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[m_BatchCommands.Count]; CommandEventArgs[] eventArgs = new CommandEventArgs[m_BatchCommands.Count]; for (int i = 0; i < m_BatchCommands.Count; ++i) { BatchCommand bc = (BatchCommand)m_BatchCommands[i]; string commandString, argString; string[] args; bc.GetDetails(out commandString, out argString, out args); BaseCommand command = (BaseCommand)m_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(m_Scope, eventArgs[i])) { return; } } for (int i = 0; i < commands.Length; ++i) { BaseCommand command = commands[i]; BatchCommand bc = (BatchCommand)m_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, true, 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 (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } command.ExecuteList(eventArgs[i], usedList); if (list.Count > 20) { CommandLogging.Enabled = true; } command.Flush(e.Mobile, list.Count > 20); } } catch (Exception ex) { LogHelper.LogException(ex); e.Mobile.SendMessage(ex.Message); } }
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); } }