static ActionCams() { _PersistenceFile = IOUtility.EnsureFile(VitaNexCore.SavesDirectory + "/ActionCams/Cameras.bin"); #region Non-Persisting Variables CurrentlyViewing = new Dictionary <PlayerMobile, PlayerMobile>(); DeathCams = new Dictionary <PlayerMobile, DateTime>(); DeathCamsEvents = new Dictionary <PlayerMobile, DateTime>(); #endregion PlayerMurderers = new Dictionary <PlayerMobile, int>(); MonsterMurderers = new Dictionary <BaseCreature, int>(); GumpWhitelist = new List <Type> { typeof(ActionCamUI), typeof(BattleResultsGump), typeof(NotifyGump), typeof(PropertiesGump), typeof(WhoGump), typeof(ScoutGump) }; RegionBlackList = new List <string> { "Jail", "Trinsic-Delucia Passage" }; }
public static void OnExportBounds3D(Mobile m, string speech, string comment) { if (m == null || m.Deleted || !(m is PlayerMobile)) { return; } if (String.IsNullOrWhiteSpace(speech)) { speech = "Bounds"; } BoundingBoxPicker.Begin( m, (from, map, start, end, state) => { var r = new Rectangle3D(start, end.Clone3D(1, 1)); IOUtility.EnsureFile( VitaNexCore.DataDirectory + "/Exported Bounds/3D/" + IOUtility.GetSafeFileName(speech) + ".txt") .AppendText( false, String.Format( "new Rectangle3D({0}, {1}, {2}, {3}, {4}, {5}), //{6}", // r.Start.X, r.Start.Y, r.Start.Z, r.Width, r.Height, r.Depth, comment ?? String.Empty)); }, null); }
public static void OnExportBounds3D(Mobile m, string speech) { if (m == null || m.Deleted || !(m is PlayerMobile)) { return; } if (String.IsNullOrWhiteSpace(speech)) { speech = TimeStamp.UtcNow.ToString(); } BoundingBoxPicker.Begin( m, (from, map, start, end, state) => { var r = new Rectangle3D(start, end.Clone3D(1, 1)); using ( StreamWriter w = IOUtility.EnsureFile( VitaNexCore.DataDirectory + "/Exported Bounds/3D/" + IOUtility.GetSafeFileName(speech) + ".txt").AppendText()) { w.WriteLine( "new Rectangle3D({0}, {1}, {2}, {3}, {4}, {5}),", r.Start.X, r.Start.Y, r.Start.Z, r.Width, r.Height, r.Depth); w.Close(); } }, null); }
public void SaveOptions() { IOUtility.EnsureFile(VitaNexCore.CacheDirectory + "/Options/" + _TypeOf.FullName + ".opt", true) .Serialize( writer => { var version = writer.SetVersion(0); switch (version) { case 0: { writer.WriteType( Options, t => { if (t != null) { Options.Serialize(writer); } }); } break; } }); }
public void LoadState() { IOUtility.EnsureFile(VitaNexCore.CacheDirectory + "/States/" + _TypeOf.FullName + ".state").Deserialize( reader => { if (reader.End()) { return; } var version = reader.GetVersion(); switch (version) { case 0: { _Enabled = reader.ReadBool(); _Name = reader.ReadString(); _Priority = reader.ReadInt(); _Debug = reader.ReadBool(); _Quiet = reader.ReadBool(); Deferred = !_Enabled; } break; } }); }
private static bool Backup(bool restore) { if (restore) { return(VitaNexCore.TryCatchGet( () => { World.Save(false, false); //World.WaitForWriteCompletion(); return true; }, CSOptions.ToConsole)); } return(VitaNexCore.TryCatchGet( () => { DirectoryInfo target = IOUtility.EnsureDirectory(BackupTarget + "/" + _Stamp.ToSimpleString("D d M y - t@h-m@")); Parallel.ForEach( GetFiles(BackupSource), file => VitaNexCore.TryCatch( () => file.CopyTo(IOUtility.EnsureFile(file.FullName.Replace(BackupSource.FullName, target.FullName)).FullName, true), CSOptions.ToConsole)); return true; }, CSOptions.ToConsole)); }
public void LoadOptions() { IOUtility.EnsureFile(VitaNexCore.CacheDirectory + "/Options/" + _TypeOf.FullName + ".opt").Deserialize( reader => { if (reader.End()) { return; } var version = reader.GetVersion(); switch (version) { case 0: { if (reader.ReadType() != null) { Options.Deserialize(reader); } } break; } }); }
public static void Log(this StringBuilder sb, string file) { var root = String.IsNullOrWhiteSpace(file) ? VitaNexCore.LogFile : IOUtility.EnsureFile(VitaNexCore.LogsDirectory + "/" + file); Log(sb, root); }
static VitaNexCore() { _INITQueue = new Queue <Tuple <string, string> >(); _INITHandlers = new Dictionary <string, Action <string> >(); _INITVersion = "2.2.0.0"; Version = null; if (!Directory.Exists(IOUtility.GetSafeDirectoryPath(Core.BaseDirectory + "/VitaNexCore"))) { FirstBoot = true; } BaseDirectory = IOUtility.EnsureDirectory(Core.BaseDirectory + "/VitaNexCore"); if (!File.Exists(BaseDirectory + "/FirstBoot.vnc")) { FirstBoot = true; IOUtility.EnsureFile(BaseDirectory + "/FirstBoot.vnc") .AppendText( true, "This file serves no other purpose than to identify if", "the software has been initialized for the first time. ", "To re-initialize 'First-Boot' mode, simply delete this", "file before starting the application."); } // HACK: See FindRootDirectory summary. var root = FindRootDirectory(Core.BaseDirectory + "/Scripts/VitaNex"); if (root == null || !root.Exists) { return; } RootDirectory = root; ParseVersion(); ParseINIT(); RegisterINITHandler( "ROOT_DIR", path => { root = FindRootDirectory(path); if (root == null || !root.Exists) { return; } RootDirectory = root; ParseVersion(); }); }
private static bool Report() { return(VitaNexCore.TryCatchGet( () => { _Report = IOUtility.EnsureFile( ReportTarget + "/" + IOUtility.GetSafeFileName("Crash " + _Stamp.ToSimpleString("D d M y - t@h-m@") + ".log")); Version ver = Core.Version; int clients = NetState.Instances.Count; var lines = new List <string> { String.Format("{0} Crash Report", ServerList.ServerName), String.Format("{0}=============", new String('=', ServerList.ServerName.Length)), String.Empty, String.Format("RunUO Version {0}.{1}, Build {2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision), String.Format("Operating System: {0}", Environment.OSVersion), String.Format(".NET Framework: {0}", Environment.Version), String.Format("Date: {0}", _Stamp.ToSimpleString("D d M y - t@h-m@")), String.Format("Mobiles: {0:#,#}", VitaNexCore.TryCatchGet(() => World.Mobiles.Count)), String.Format("Items: {0:#,#}", VitaNexCore.TryCatchGet(() => World.Items.Count)), String.Empty, String.Format("Exception:"), String.Format("{0}", _Event != null ? _Event.Exception : null), String.Empty, String.Format("Clients: {0:#,#}", clients), String.Empty }; var breaker = new[] { lines[2], lines[2], lines[1], lines[2], lines[2] }; lines.AddRange(breaker); int i = 0; lines.AddRange( NetState.Instances.Where(ns => ns != null && ns.Socket != null && ns.Mobile != null && ns.Account != null) .Select( ns => String.Format( "{0:#,#}:\t [{1}]: \tAccount: '{2}' -> '{3}' (0x{4:X})", ++i, ns, ns.Account.Username, ns.Mobile.RawName, ns.Mobile.Serial.Value))); lines.AddRange(breaker); _Report.AppendText(false, lines.ToArray()); return true; }, CSOptions.ToConsole)); }
/// <summary> /// Copies the contents of the specified directory to the specified target directory, only including files that meet the mask criteria /// </summary> /// <param name="source">Directory to copy</param> /// <param name="dest">Directory to copy to</param> /// <param name="mask">String mask to use to filter file names</param> /// <param name="option">Search options</param> public static void CopyDirectory(this DirectoryInfo source, DirectoryInfo dest, string mask, SearchOption option) { VitaNexCore.TryCatch( () => Parallel.ForEach( AllFiles(source, mask, option), file => VitaNexCore.TryCatch( () => file.CopyTo(IOUtility.EnsureFile(file.FullName.Replace(source.FullName, dest.FullName)).FullName, true)))); }
static UOFCentral() { EntryTypes = typeof(Entry).GetConstructableChildren(); CMOptions = new UOFCentralOptions(); StateFile = IOUtility.EnsureFile(VitaNexCore.SavesDirectory + "/UOFCentral/State.bin"); State = new State(); }
public static void Log(string path, params string[] lines) { // Redirect file writes to the Logs/Custom/ directory if the path doesn't begin with // or <drive>: if (!Path.IsPathRooted(path) && !Insensitive.StartsWith(path, @"Logs/Custom/") && !Insensitive.StartsWith(path, @"Logs\Custom\")) { path = "Logs" + IOUtility.SEPARATOR + "Custom" + IOUtility.SEPARATOR + path; } FileInfo file = IOUtility.EnsureFile(path); Log(file, lines); }
private static void CSConfig() { Core.CrashedHandler = OnServerCrashed; EventSink.Crashed += e => { if (!World.Loading && !World.Saving) { NotifyPlayers(); } }; BackupSource = IOUtility.EnsureDirectory(Core.BaseDirectory + "/Saves/"); BackupTarget = IOUtility.EnsureDirectory(Core.BaseDirectory + "/Backups/Crashed/"); ReportTarget = IOUtility.EnsureDirectory(Core.BaseDirectory + "/Reports/"); _CrashState = IOUtility.EnsureFile(VitaNexCore.CacheDirectory + "/CrashState.bin"); _LastOnline = new List <PlayerMobile>(); _CrashNotes = new List <CrashNote>(); CommandUtility.Register( "CrashGuard", Access, e => { if (e.Mobile is PlayerMobile) { SuperGump.Send(new CrashNoteListGump((PlayerMobile)e.Mobile)); } }); CommandUtility.Register( "Crash", AccessLevel.Administrator, e => { if (e.Mobile is PlayerMobile) { SuperGump.Send( new ConfirmDialogGump((PlayerMobile)e.Mobile) { Title = "Force Crash", Html = "Click OK to force the server to crash.", AcceptHandler = b => { throw new Exception("Forced Crash Exception"); } }); } }); }
static Instances() { _BounceRestore = new Dictionary <PlayerMobile, MapPoint>(0x100); _ItemRestore = new Dictionary <Item, IEntity>(0x1000); CSOptions = new InstanceMapsOptions(); IndexFile = IOUtility.EnsureFile(VitaNexCore.SavesDirectory + "/InstanceMaps/Maps.idx"); RestoreFile = IOUtility.EnsureFile(VitaNexCore.CacheDirectory + "/InstanceMaps/Restore.bin"); RestoreFile.SetHidden(true); Lockouts = new BinaryDataStore <PlayerMobile, LockoutState>(VitaNexCore.SavesDirectory + "/InstanceMaps", "Lockouts") { Async = true, OnSerialize = SerializeLockouts, OnDeserialize = DeserializeLockouts }; Maps = new BinaryDirectoryDataStore <InstanceMapSerial, InstanceMap>(VitaNexCore.SavesDirectory + "/InstanceMaps", "Maps", "bin") { Async = true, OnSerialize = SerializeMap, OnDeserialize = DeserializeMap }; Dungeons = new BinaryDirectoryDataStore <DungeonSerial, Dungeon>(VitaNexCore.SavesDirectory + "/InstanceMaps", "Dungeons", "bin") { Async = true, OnSerialize = SerializeDungeon, OnDeserialize = DeserializeDungeon }; DungeonTypes = typeof(Dungeon).GetConstructableChildren(); var instances = DungeonTypes .Select(t => t.CreateInstanceSafe <Dungeon>()) .Where(d => d != null && d.ID != DungeonID.None && d.GroupMax > 0) .Where(d => d.MapParent != null && !(d.MapParent is InstanceMap)) .ToList(); DungeonInfo = instances.Select(d => new DungeonInfo(d)).ToArray(); instances.ForEach(d => d.Delete()); instances.Free(true); DefragmentTimer = PollTimer.FromMinutes(10.0, Defragment, () => !_Defragmenting, false); }
public void LogToFile() { var file = IOUtility.EnsureFile(VitaNexCore.LogsDirectory + "/Donations/" + ID + ".log"); var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine(new String('*', 80)); sb.AppendLine(); sb.AppendLine("{0}: {1}", file.Exists ? "UPDATED" : "CREATED", DateTime.Now); sb.AppendLine(); sb.AppendLine("ID: {0}", ID); sb.AppendLine("State: {0}", State); sb.AppendLine("Time: {0}", Time.Value); sb.AppendLine("Version: {0:#,0}", Version); sb.AppendLine(); sb.AppendLine("Account: {0}", Account); sb.AppendLine("Email: {0}", Email); sb.AppendLine(); sb.AppendLine("Total: {0}{1} {2}", AutoDonate.CMOptions.MoneySymbol, Total, AutoDonate.CMOptions.MoneyAbbr); sb.AppendLine("Credit: {0:#,0} {1}", Credit, AutoDonate.CMOptions.CurrencyName); sb.AppendLine("Bonus: {0:#,0} {1}", Bonus, AutoDonate.CMOptions.CurrencyName); if (DeliveredTo != null) { sb.AppendLine(); sb.AppendLine("Delivered: {0}", DeliveryTime.Value); sb.AppendLine("Recipient: {0}", DeliveredTo); } if (!String.IsNullOrWhiteSpace(Notes)) { sb.AppendLine(); sb.AppendLine("Notes:"); sb.AppendLine(Notes); } if (!String.IsNullOrWhiteSpace(Extra)) { sb.AppendLine(); sb.AppendLine("Extra:"); sb.AppendLine(Extra); } sb.Log(file); }
public void SaveState() { IOUtility.EnsureFile(VitaNexCore.CacheDirectory + "/States/" + _TypeOf.FullName + ".state", true).Serialize( writer => { int version = writer.SetVersion(0); switch (version) { case 0: { writer.Write(_Name); writer.Write(_Debug); writer.Write(_QuietMode); } break; } }); }
public static void Log(this string text, string file) { FileInfo root; if (String.IsNullOrWhiteSpace(file)) { root = VitaNexCore.LogFile; } else if (Path.IsPathRooted(file)) { root = IOUtility.EnsureFile(file); } else { root = IOUtility.EnsureFile(VitaNexCore.LogsDirectory + "/" + file); } Log(text, root); }
public static void OnExportPoint3D(Mobile m, string speech, string comment) { if (m == null || m.Deleted || !(m is PlayerMobile)) { return; } if (String.IsNullOrWhiteSpace(speech)) { speech = "Points"; } GenericSelectTarget <IPoint3D> .Begin( m, (from, p) => IOUtility.EnsureFile( VitaNexCore.DataDirectory + "/Exported Points/3D/" + IOUtility.GetSafeFileName(speech) + ".txt") .AppendText(false, String.Format("new Point3D({0}, {1}, {2}), //{3}", p.X, p.Y, p.Z, comment ?? String.Empty)), null, -1, true); }
public void ToConsole(Exception e) { if (e == null) { return; } lock (VitaNexCore.ConsoleLock) { Console.Write('['); Utility.PushColor(ConsoleColor.Green); Console.Write(Name); Utility.PopColor(); Console.Write("]: "); Utility.PushColor(ConsoleColor.DarkRed); Console.WriteLine((Quiet && !Debug) ? e.Message : e.ToString()); Utility.PopColor(); } if (Debug) { e.Log(IOUtility.EnsureFile(VitaNexCore.LogsDirectory + "/Debug/" + TypeOf.FullName + ".log")); } }
public void LoadState() { IOUtility.EnsureFile(VitaNexCore.CacheDirectory + "/States/" + _TypeOf.FullName + ".state").Deserialize( reader => { if (reader.End()) { return; } int version = reader.GetVersion(); switch (version) { case 0: { _Name = reader.ReadString(); _Debug = reader.ReadBool(); _QuietMode = reader.ReadBool(); } break; } }); }
static Filters() { _Filters = new Dictionary <PlayerMobile, List <IFilter> >(); _Persistence = IOUtility.EnsureFile(VitaNexCore.SavesDirectory + "/Filters/Profiles.bin"); }
public static void RestoreState( PlayerMobile m, Serial serial, bool moveExisting, bool logging, out int created, out int deleted, out int ignored, out int moved) { var pack = m.Backpack; if (pack == null || pack.Deleted) { m.AddItem( pack = new Backpack { Movable = false }); } var bank = m.BankBox; if (bank == null || bank.Deleted) { m.AddItem( bank = new BankBox(m) { Movable = false }); } if (serial == Serial.MinusOne) { serial = m.Serial; } var root = VitaNexCore.DataDirectory + "/PlayerBackup/" + m.Account.Username + "/" + serial; var idxFile = IOUtility.EnsureFile(root + ".idx"); var binFile = IOUtility.EnsureFile(root + ".bin"); var logFile = logging ? IOUtility.EnsureFile(root + ".log") : null; var log = logging ? new StringBuilder() : null; if (log != null) { log.AppendLine(); log.AppendLine(new String('*', 10)); log.AppendLine(); log.AppendLine("RESTORE:\tDate[{0}]\tMobile[{1}]", DateTime.UtcNow, m); log.AppendLine(); } int idxCreated = 0, idxDeleted = 0, idxIgnored = 0, idxMoved = 0; idxFile.Deserialize( idx => { idx.GetVersion(); var ser = idx.ReadInt(); if (ser != m.Serial.Value) { if (log != null) { log.AppendLine("INVALID:\tSerial[{0:X8}]", ser); } return; } long idxLength; int idxCount; ReadLength(idx, false, out idxLength, out idxCount); if (log != null) { log.AppendLine("INDEX:\tCount[{0}]\tLength[{1}]", idxCount, idxLength); } var items = new Tuple <Item, Serial, long, long, string> [idxCount]; binFile.Deserialize( bin => { bin.GetVersion(); var restored = new Dictionary <Item, Serial>(); Backpack oldPack = null; BankBox oldBank = null; for (var i = 0; i < idxCount; i++) { Type type; Serial s, parent; long binIndex, binLength; ReadIndex(idx, out type, out s, out parent, out binIndex, out binLength); var valid = s.IsValid && s.IsItem; var exists = World.Items.ContainsKey(s); Item item = null; if (exists) { item = World.Items[s]; if (item == null || item.Deleted) { World.Items.Remove(s); exists = false; } } object logItem; string status; if (!exists && valid && type.IsEqualOrChildOf <Item>()) { item = type.CreateInstanceSafe <Item>(s); if (item == null) { ++idxIgnored; logItem = s; status = "NULL"; } else if (item.Deleted) { ++idxDeleted; item = null; logItem = s; status = "DELETED"; } else { ++idxCreated; World.AddItem(item); logItem = item; status = "CREATED"; } } else if (exists && valid && moveExisting && item.RootParent != m) { ++idxMoved; logItem = item; status = "MOVE"; } else { ++idxIgnored; item = null; logItem = s; status = exists ? "EXISTS" : "INVALID"; } if (log != null) { log.AppendLine( "DATA:\tIndex[{0}]\t\tLength[{1}]\tStatus[{2}]\tItem[{3}]\t\t\tParent[{4}]", // binIndex, binLength, status, logItem, parent); } items[i] = Tuple.Create(item, parent, binIndex, binLength, status); } foreach (var t in items) { var item = t.Item1; var parent = t.Item2; var index = t.Item3; var length = t.Item4; var status = t.Item5; bin.Seek(index, SeekOrigin.Begin); if (item == null) { bin.Seek(index + length, SeekOrigin.Begin); continue; } Exception x = null; if (status == "MOVE") { bin.Seek(index + length, SeekOrigin.Begin); status = "IGNORED"; } else { try { item.Deserialize(bin); status = "LOADED"; } catch (Exception e) { --idxCreated; ++idxDeleted; item.Delete(); x = e; status = "ERROR"; } } if (log != null) { log.AppendLine( "READ:\tIndex[{0}]\tLength[{1}]\tStatus[{2}]\tItem[{3}]\t\t\tParent[{4}]", index, length, status, item, parent); if (x != null) { log.AppendLine(); log.AppendLine(new String('*', 10)); log.AppendLine(x.ToString()); log.AppendLine(new String('*', 10)); log.AppendLine(); } } if (parent == m.Serial) { if (item is BankBox) { oldBank = (BankBox)item; } else if (item is Backpack) { oldPack = (Backpack)item; } } restored.Add(item, parent); } if (log != null) { log.AppendLine(); } Point3D p; foreach (var kv in restored.Where(kv => !kv.Key.Deleted).OrderBy(kv => kv.Value)) { var item = kv.Key; if ((item == oldPack || item == oldBank) && item != pack && item != bank) { if (item.Parent is Item) { ((Item)item.Parent).RemoveItem(item); } else if (item.Parent is Mobile) { ((Mobile)item.Parent).RemoveItem(item); } item.Parent = null; continue; } var parent = World.FindEntity(kv.Value); if (item != pack && item != bank && (item.Parent == oldPack || item.Parent == oldBank)) { ((Item)item.Parent).RemoveItem(item); } if (parent != null) { if (item == pack || item == bank) { m.AddItem(item); } else if (parent == pack || parent == oldPack) { p = item.Location; pack.DropItem(item); item.Location = p; } else if (parent == bank || parent == oldBank) { p = item.Location; bank.DropItem(item); item.Location = p; } else if (parent is Container) { if (parent.Deleted) { bank.DropItem(item); } else { p = item.Location; ((Container)parent).DropItem(item); item.Location = p; } } else if (parent is Mobile) { if (!m.EquipItem(item)) { pack.DropItem(item); } } else { bank.DropItem(item); } item.SetLastMoved(); item.UpdateTotals(); item.Delta(ItemDelta.Update); } else if (Cleanup.IsBuggable(item)) { --idxCreated; ++idxDeleted; item.Delete(); } else { item.Internalize(); } } if (oldPack != null && oldPack != pack && !restored.ContainsKey(oldPack)) { oldPack.Delete(); } if (oldBank != null && oldBank != bank && !restored.ContainsKey(oldBank)) { oldBank.Delete(); } if (log != null) { log.AppendLine(); } foreach (var kv in restored) { if (kv.Key.Deleted) { if (log != null) { log.AppendLine("DELETED:\tItem[{0}]\t\tParent[{1}]", kv.Key, kv.Value); } } else if (kv.Key.RootParent == m && kv.Key.Map == Map.Internal && kv.Key.Location == Point3D.Zero) { if (log != null) { log.AppendLine("INTERNAL:\tItem[{0}]\t\tParent[{1}]", kv.Key, kv.Value); } } else if (kv.Key.RootParent != m) { if (log != null) { log.AppendLine("IGNORED:\tItem[{0}]\t\tParent[{1}]", kv.Key, kv.Value); } } else { if (log != null) { log.AppendLine("RESTORED:\tItem[{0}]\t\tParent[{1}]", kv.Key, kv.Key.Parent); } } } restored.Clear(); m.SendEverything(); }); }); created = idxCreated; deleted = idxDeleted; ignored = idxIgnored; moved = idxMoved; if (log == null) { return; } log.AppendLine(); log.AppendLine( "RESULT:\tCreated[{0}]\t\tDeleted[{1}]\t\tIgnored[{2}]\t\tMoved[{3}]", created, deleted, ignored, moved); logFile.AppendText(false, log.ToString()); }
public static void BackupState(PlayerMobile m, bool logging, out int count, out int fails) { var root = VitaNexCore.DataDirectory + "/PlayerBackup/" + m.Account.Username + "/" + m.Serial; var idxFile = IOUtility.EnsureFile(root + ".idx", true); var binFile = IOUtility.EnsureFile(root + ".bin", true); var logFile = logging ? IOUtility.EnsureFile(root + ".log") : null; var log = logging ? new StringBuilder() : null; if (log != null) { log.AppendLine(); log.AppendLine(new String('*', 10)); log.AppendLine(); log.AppendLine("BACKUP:\tDate[{0}]\tMobile[{1}]", DateTime.UtcNow, m); log.AppendLine(); } var idxlen = 0L; var idxCount = 0; var idxFails = 0; idxFile.Serialize( idx => { idx.SetVersion(0); idx.Write(m.Serial.Value); WriteLength(idx, false, idxlen, idxCount); binFile.Serialize( bin => { bin.SetVersion(0); var items = m.FindItemsByType <Item>(true, i => i != null && !i.Deleted); foreach (var item in items) { #if NEWPARENT var parent = item.Parent != null ? item.Parent.Serial : Serial.MinusOne; var logParent = item.Parent ?? (object)Serial.MinusOne; #else var parent = item.ParentEntity != null ? item.ParentEntity.Serial : Serial.MinusOne; var logParent = item.ParentEntity ?? (object)Serial.MinusOne; #endif var pos = bin.Position; Exception x = null; string status; try { item.Serialize(bin); status = "SAVED"; } catch (Exception e) { ++idxFails; x = e; status = "ERROR"; } var len = bin.Position - pos; if (log != null) { log.AppendLine( "WRITE:\tIndex[{0}]\t\tLength[{1}]\tStatus[{2}]\tItem[{3}]\t\t\tParent[{4}]", // pos, len, status, item, logParent); if (x != null) { log.AppendLine(); log.AppendLine(new String('*', 10)); log.AppendLine(x.ToString()); log.AppendLine(new String('*', 10)); log.AppendLine(); } } WriteIndex(idx, item.GetType(), item.Serial, parent, pos, len); idxlen += len; ++idxCount; } }); WriteLength(idx, true, idxlen, idxCount); }); count = idxCount; fails = idxFails; if (log == null) { return; } log.AppendLine(); log.AppendLine("RESULT:\tCount[{0}]\tFails[{1}]\tLength[{2}]", count - fails, fails, idxlen); log.AppendLine(); logFile.AppendText(false, log.ToString()); }
static PokerPersistance() { _PersistenceFile = IOUtility.EnsureFile(VitaNexCore.SavesDirectory + "/ActionCams/Cameras.bin"); }
public static void Log(this string text, string file) { Log( text, String.IsNullOrWhiteSpace(file) ? VitaNexCore.LogFile : IOUtility.EnsureFile(VitaNexCore.LogsDirectory + "/" + file)); }
public static void Configure() { Is64Bit = (IntPtr.Size == 8); KnownInstallationRegistryKeys = new[] { @"Electronic Arts\EA Games\Ultima Online Classic", @"Electronic Arts\EA Games\Ultima Online Stygian Abyss Classic", @"Origin Worlds Online\Ultima Online\KR Legacy Beta", @"EA Games\Ultima Online: Mondain's Legacy\1.00.0000", @"Origin Worlds Online\Ultima Online\1.0", @"Origin Worlds Online\Ultima Online Third Dawn\1.0", @"EA GAMES\Ultima Online Samurai Empire", @"EA Games\Ultima Online: Mondain's Legacy", @"EA GAMES\Ultima Online Samurai Empire\1.0", @"EA GAMES\Ultima Online Samurai Empire\1.00.0000", @"EA GAMES\Ultima Online: Samurai Empire\1.0", @"EA GAMES\Ultima Online: Samurai Empire\1.00.0000", @"EA Games\Ultima Online: Mondain's Legacy\1.0", @"EA Games\Ultima Online: Mondain's Legacy\1.00.0000", @"Origin Worlds Online\Ultima Online Samurai Empire BETA\2d\1.0", @"Origin Worlds Online\Ultima Online Samurai Empire BETA\3d\1.0", @"Origin Worlds Online\Ultima Online Samurai Empire\2d\1.0", @"Origin Worlds Online\Ultima Online Samurai Empire\3d\1.0" }; KnownRegistryKeyValueNames = new[] { @"ExePath", @"InstallDir", @"Install Dir", @"GameExecutionPath" }; Console.WriteLine("Searching for Ultima Online installations..."); var paths = new List <string>(); var dpCustom = typeof(DataPath).GetField("CustomPath", BindingFlags.NonPublic | BindingFlags.Static); if (dpCustom != null) { string custom = dpCustom.GetValue(null) as string; if (!String.IsNullOrWhiteSpace(custom) && !paths.Contains(custom)) { paths.Add(custom); } } var cache = IOUtility.EnsureFile(VitaNexCore.BaseDirectory + "/DataPath.bin"); cache.Deserialize( r => { var l = r.ReadArray(r.ReadString); paths.AddRange( l.Not(paths.Contains).Where(path => File.Exists(IOUtility.GetSafeFilePath(path + "/client.exe", true)))); }); paths.AddRange(Locate().Not(paths.Contains)); DetectedPaths = paths.ToArray(); if (DetectedPaths.Length > 0) { Console.WriteLine("Found {0:#,0} Ultima Online installations:", DetectedPaths.Length); DetectedPaths.ForEach(Console.WriteLine); Core.DataDirectories.AddRange(DetectedPaths); } else { Console.WriteLine("Could not find any Ultima Online installations."); if (!Core.Service && Core.DataDirectories.Count == 0) { int attempt = 0; string path = IOUtility.GetSafeDirectoryPath(GetConsoleInput()); while (String.IsNullOrWhiteSpace(path) && attempt < 3) { path = IOUtility.GetSafeDirectoryPath(GetConsoleInput()); if (Directory.Exists(path)) { break; } Console.WriteLine("The directory could not be found."); path = null; attempt++; } if (attempt < 3) { Core.DataDirectories.Add(path); } } } cache.Serialize(w => w.WriteArray(Core.DataDirectories.ToArray(), w.Write)); }
private static void PickerCallback(Mobile m, Map map, Point3D start, Point3D end, object state) { var args = state as object[]; if (args == null) { return; } if (start.X > end.X) { var x = start.X; start.X = end.X; end.X = x; } if (start.Y > end.Y) { var y = start.Y; start.Y = end.Y; end.Y = y; } var bounds = new Rectangle2D(start, end); var name = args[0] as string; var namesplit = name; if (name != null) { namesplit = name.SpaceWords().ToUpperWords(); name = namesplit.Replace(" ", String.Empty); } var ns = args[1] as string; var getStatics = (bool)args[2]; var getItems = (bool)args[3]; var getTiles = (bool)args[4]; var includeStaticRange = (bool)args[5]; var includeItemRange = (bool)args[6]; var includeTileRange = (bool)args[7]; var includeZRange = (bool)args[8]; var generateTest = (bool)args[17]; int minZ, maxZ, minStaticID, maxStaticID, minItemID, maxItemID, minTileID, maxTileID; if (!Int32.TryParse(args[9] as string, out minZ)) { minZ = Region.MinZ; } if (!Int32.TryParse(args[10] as string, out maxZ)) { maxZ = Region.MaxZ; } if (!Int32.TryParse(args[11] as string, out minStaticID)) { minStaticID = 2; } if (!Int32.TryParse(args[12] as string, out maxStaticID)) { maxStaticID = UInt16.MaxValue; } if (!Int32.TryParse(args[13] as string, out minItemID)) { minItemID = 2; } if (!Int32.TryParse(args[14] as string, out maxItemID)) { maxItemID = UInt16.MaxValue; } if (!Int32.TryParse(args[15] as string, out minTileID)) { minTileID = 2; } if (!Int32.TryParse(args[16] as string, out maxTileID)) { maxTileID = UInt16.MaxValue; } var cList = GetComponents( bounds, map, getTiles, getStatics, getItems, includeZRange, minZ, maxZ, includeTileRange, minTileID, maxTileID, includeStaticRange, minStaticID, maxStaticID, includeItemRange, minItemID, maxItemID); if (cList == null || cList.Count == 0) { m.SendMessage(0x40, "No components have been selected."); m.SendGump(new InternalGump(m, args)); return; } var list = String.Join( "\n\t\t\t", cList.Select((s, i) => s + (i < cList.Count - 1 ? "," : String.Empty) + " // " + (i + 1))); var fileOut = new StringBuilder(_Template); var useref = "using System;"; if (!ns.StartsWith("Server")) { useref += "\nusing Server;"; useref += "\nusing Server.Items;"; } else if (!ns.StartsWith("Server.Items")) { useref += "\nusing Server.Items;"; } fileOut.Replace("~USING~", useref); fileOut.Replace("~NAMESPACE~", ns); fileOut.Replace("~NAME~", name); fileOut.Replace("~NAMESPLIT~", namesplit); fileOut.Replace("~LIST~", list); var path = Path.IsPathRooted(OutputDirectory) ? OutputDirectory : Path.Combine(Core.BaseDirectory, OutputDirectory); var file = IOUtility.EnsureFile(path + "/" + name + "Addon.cs", true); try { file.AppendText(true, fileOut.ToString()); } catch (Exception ex) { ex.ToConsole(true, true); m.SendMessage(0x40, "An error occurred while writing the Addon file."); return; } m.SendMessage(0x40, "Addon saved to {0}", file); m.SendMessage(0x40, "Total components in Addon: {0}", cList.Count); if (!generateTest) { return; } var ia = new CEOIdentifyAddon(); for (var i = 0; i < cList.Count; i++) { AddTestComponent(ia, cList[i], i + 1); } m.SendMessage(0x37, "Target a location to place the test Addon..."); var target = m.Target = new GenericSelectTarget <IPoint3D>( (u, t) => ia.MoveToWorld(t.ToPoint3D(), u.Map), u => ia.Delete(), -1, true, TargetFlags.None); Timer timer = null; timer = Timer.DelayCall( TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0), () => { if (m.Target == target) { return; } if (ia.Map == null || ia.Map == Map.Internal) { ia.Delete(); } if (timer != null) { timer.Stop(); } }); timer.Start(); }
static VitaNexCore() { _INITVersion = "5.2.0.0"; _INITQueue = new Queue <Tuple <string, string> >(); _INITHandlers = new Dictionary <string, Action <string> >(); var basePath = IOUtility.GetSafeDirectoryPath(Core.BaseDirectory + "/VitaNexCore"); if (!Directory.Exists(basePath)) { FirstBoot = true; } BaseDirectory = IOUtility.EnsureDirectory(basePath); var first = IOUtility.GetSafeFilePath(BaseDirectory + "/FirstBoot.vnc", true); if (!File.Exists(first)) { FirstBoot = true; IOUtility.EnsureFile(first) .AppendText( true, "This file serves no other purpose than to identify if", "the software has been initialized for the first time. ", "To re-initialize 'First-Boot' mode, simply delete this", "file before starting the application."); } var root = FindRootDirectory(Core.BaseDirectory + "/Scripts/VitaNex"); if (root != null && root.Exists) { RootDirectory = root; ParseVersion(); ParseINIT(); RegisterINITHandler( "ROOT_DIR", path => { root = FindRootDirectory(path); if (root == null || !root.Exists) { return; } RootDirectory = root; ParseVersion(); }); } BackupExpireAge = TimeSpan.FromDays(7); RegisterINITHandler( "BACKUP_EXPIRE", time => { TimeSpan ts; if (TimeSpan.TryParse(time, out ts)) { BackupExpireAge = ts; } }); Core.Slice += Slice; }
static VitaNexCore() { _INITVersion = "2.2.0.0"; #if MONO Version = _INITVersion; #endif _INITQueue = new Queue <Tuple <string, string> >(); _INITHandlers = new Dictionary <string, Action <string> >(); //ensuring simply "VitaNexCore" exists causes Mono to look in system root folder "/", so we // concatenate to give path relative to Server. --sith if (!Directory.Exists(Core.BaseDirectory + "/VitaNexCore")) { FirstBoot = true; } BaseDirectory = IOUtility.EnsureDirectory(Core.BaseDirectory + "/VitaNexCore"); if (!File.Exists(BaseDirectory + "/FirstBoot.vnc")) { FirstBoot = true; IOUtility.EnsureFile(BaseDirectory + "/FirstBoot.vnc") .AppendText( true, "This file serves no other purpose than to identify if", "the software has been initialized for the first time. ", "To re-initialize 'First-Boot' mode, simply delete this", "file before starting the application."); } #if MONO // Someone moved VitaNex from Scripts/VitaNex to Scripts/Custom Systems/VitaNex/Core // but this path was not updated... does this cause problems on Windows? --Sith var root = FindRootDirectory("Scripts/VitaNex"); #else var root = new DirectoryInfo(Core.BaseDirectory + @"\Scripts\Custom Systems\VitaNex\Core"); #endif if (root == null || !root.Exists) { return; } RootDirectory = root; ParseVersion(); ParseINIT(); RegisterINITHandler( "ROOT_DIR", path => { root = FindRootDirectory(path); if (root == null || !root.Exists) { return; } RootDirectory = root; ParseVersion(); }); }