private static void Load(string filePath) { XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlElement root = doc["names"]; foreach (XmlElement element in root.GetElementsByTagName("namelist")) { string type = element.GetAttribute("type"); if (type == null || type == String.Empty) { continue; } try { NameList list = new NameList(type, element); m_Table[type] = list; } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } }
public static void PopColor() { try { Console.ForegroundColor = m_ConsoleColors.Pop(); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } }
public Item Construct() { try { Item item; if (m_Type == typeof(BaseRanged)) { item = Loot.RandomRangedWeapon(); } else if (m_Type == typeof(BaseWeapon)) { item = Loot.RandomWeapon(); } else if (m_Type == typeof(BaseArmor)) { item = Loot.RandomArmor(); } else if (m_Type == typeof(BaseShield)) { item = Loot.RandomShield(); } else if (m_Type == typeof(BaseJewel)) { item = Core.AOS ? Loot.RandomJewelry() : Loot.RandomArmorOrShieldOrWeapon(); } else if (m_Type == typeof(BaseInstrument)) { item = Loot.RandomInstrument(); } else if (m_Type == typeof(Amber)) // gem { item = Loot.RandomGem(); } else if (m_Type == typeof(ClumsyScroll)) // low scroll { item = RandomScroll(0, 1, 3); } else if (m_Type == typeof(ArchCureScroll)) // med scroll { item = RandomScroll(1, 4, 7); } else if (m_Type == typeof(SummonAirElementalScroll)) // high scroll { item = RandomScroll(2, 8, 8); } else { item = Activator.CreateInstance(m_Type) as Item; } return(item); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } return(null); }
public static void PushColor(ConsoleColor color) { try { m_ConsoleColors.Push(Console.ForegroundColor); Console.ForegroundColor = color; } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } }
public static void Slice() { lock (m_Queue) { m_QueueCountAtSlice = m_Queue.Count; int index = 0; DateTime start = DateTime.MinValue; DateTime breakTime = DateTime.Now + m_BreakTime; while (index < m_BreakCount && DateTime.Now < breakTime && m_Queue.Count != 0) { Timer t = (Timer)m_Queue.Dequeue(); TimerProfile prof = t.GetProfile(); if (prof != null) { start = DateTime.Now; } // Adam: See comments at top of file regarding timer.Flush() if (t.Eat == true) { t.Eat = false; } else { try { t.OnTick(); } catch (Exception e) { // Log an exception EventSink.InvokeLogException(new LogExceptionEventArgs(e)); } } t.m_Queued = false; ++index; if (prof != null) { prof.RegTicked(DateTime.Now - start); } } //while !empty if (index >= m_BreakCount) { Console.WriteLine("Timer.Slice: index >= m_BreakCount"); } if (DateTime.Now >= breakTime) { Console.WriteLine("Timer.Slice: DateTime.Now >= breakTime"); } } }
private static void DeleteFiles(string mask) { try { string[] files = Directory.GetFiles(Path.Combine(Core.BaseDirectory, "Scripts/Output"), mask); foreach (string file in files) { try { File.Delete(file); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } }
public static void Pathfind(object state) { object[] states = (object[])state; Mobile from = (Mobile)states[0]; Direction d = (Direction)states[1]; try { from.Direction = d; from.NetState.BlockAllPackets = true; from.Move(d); from.NetState.BlockAllPackets = false; from.ProcessDelta(); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } }
public static Poison Parse(string value) { Poison p = null; try { p = GetPoison(Convert.ToInt32(value)); } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } if (p == null) { p = GetPoison(value); } return(p); }
private static void Load() { string path = Path.Combine(Core.BaseDirectory, "Data/shrink.cfg"); if (!File.Exists(path)) { m_Table = new int[0]; return; } m_Table = new int[1000]; using (StreamReader ip = new StreamReader(path)) { string line; while ((line = ip.ReadLine()) != null) { line = line.Trim(); if (line.Length == 0 || line.StartsWith("#")) { continue; } try { string[] split = line.Split('\t'); if (split.Length >= 2) { int body = Utility.ToInt32(split[0]); int item = Utility.ToInt32(split[1]); if (body >= 0 && body < m_Table.Length) { m_Table[body] = item; } } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { Console.WriteLine(e.IsTerminating ? "Error:" : "Warning:"); Console.WriteLine(e.ExceptionObject); if (e.IsTerminating) { m_Crashed = true; bool close = false; try { CrashedEventArgs args = new CrashedEventArgs(e.ExceptionObject as Exception); EventSink.InvokeCrashed(args); close = args.Close; } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } if (!close && !m_Service) { try { for (int i = 0; i < m_MessagePump.Listeners.Length; i++) { m_MessagePump.Listeners[i].Dispose(); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } if (SocketPool.Created) { SocketPool.Destroy(); } Console.WriteLine("This exception is fatal, press return to exit"); Console.ReadLine(); } m_Closing = true; } }
public static void Initialize() { string filePath = Path.Combine(Core.BaseDirectory, "Data/treasure.cfg"); int i = 0, x = 0, y = 0; if (File.Exists(filePath)) { using (StreamReader ip = new StreamReader(filePath)) { string line; while ((line = ip.ReadLine()) != null) { i++; try { string[] split = line.Split(' '); x = Convert.ToInt32(split[0]); y = Convert.ToInt32(split[1]); try { Region.AddRegion(new TreasureRegion(x, y, Map.Felucca)); // Region.AddRegion( new TreasureRegion( x, y, Map.Trammel ) ); } catch (Exception e) { LogHelper.LogException(e); Console.WriteLine("{0} {1} {2} {3}", i, x, y, e); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } } }
private static void VerifySerialization(Assembly a) { if (a == null) { return; } Type[] ctorTypes = new Type[] { typeof(Serial) }; foreach (Type t in a.GetTypes()) { bool isItem = t.IsSubclassOf(typeof(Item)); bool isSerializableObject = t.IsSubclassOf(typeof(SerializableObject)); bool isMobile = t.IsSubclassOf(typeof(Mobile)); if (isItem || isMobile || isSerializableObject) { if (isItem) { ++m_ItemCount; } else if (isMobile) { ++m_MobileCount; } else { ++m_SerializableObjectCount; } bool warned = false; try { if (isSerializableObject == false) { if (t.GetConstructor(ctorTypes) == null) { if (!warned) { Console.WriteLine("Warning: {0}", t); } warned = true; Console.WriteLine(" - No serialization constructor"); } } if (t.GetMethod("Serialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) == null) { if (!warned) { Console.WriteLine("Warning: {0}", t); } warned = true; Console.WriteLine(" - No Serialize() method"); } if (t.GetMethod("Deserialize", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) == null) { if (!warned) { Console.WriteLine("Warning: {0}", t); } warned = true; Console.WriteLine(" - No Deserialize() method"); } if (warned) { Console.WriteLine(); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } }
public static void Main(string[] args) { #if !DEBUG AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); #endif AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit); for (int i = 0; i < args.Length; ++i) { if (Insensitive.Equals(args[i], "-debug")) { m_Debug = true; } else if (Insensitive.Equals(args[i], "-service")) { m_Service = true; } else if (Insensitive.Equals(args[i], "-profile")) { Profiling = true; } else if (Insensitive.Equals(args[i], "-nocache")) { m_Cache = false; } else if (Insensitive.Equals(args[i], "-haltonwarning")) { m_HaltOnWarning = true; } else if (Insensitive.Equals(args[i], "-vb")) { m_VBdotNET = true; } } try { if (m_Service) { if (!Directory.Exists("Logs")) { Directory.CreateDirectory("Logs"); } Console.SetOut(m_MultiConOut = new MultiTextWriter(Console.Out, new FileLogger("Logs/Console.log"))); } else { Console.SetOut(m_MultiConOut = new MultiTextWriter(Console.Out)); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } m_Thread = Thread.CurrentThread; m_Process = Process.GetCurrentProcess(); m_Assembly = Assembly.GetEntryAssembly(); if (m_Thread != null) { m_Thread.Name = "Core Thread"; } if (BaseDirectory.Length > 0) { Directory.SetCurrentDirectory(BaseDirectory); } Timer.TimerThread ttObj = new Timer.TimerThread(); timerThread = new Thread(new ThreadStart(ttObj.TimerMain)); timerThread.Name = "Timer Thread"; Version ver = m_Assembly.GetName().Version; // Added to help future code support on forums, as a 'check' people can ask for to it see if they recompiled core or not Console.WriteLine("Angel Island - [www.game-master.net] Version {0}.{1}.{3}, Build {2}", ver.Major, ver.Minor, ver.Revision, ver.Build); #if DEBUG Console.WriteLine("[Debug Build Enabled]"); #endif string s = Arguments; if (s.Length > 0) { Console.WriteLine("Core: Running with arguments: {0}", s); } m_ProcessorCount = Environment.ProcessorCount; if (m_ProcessorCount > 1) { m_MultiProcessor = true; } if (m_MultiProcessor || Is64Bit) { Console.WriteLine("Core: Optimizing for {0} {2}processor{1}", m_ProcessorCount, m_ProcessorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : ""); } int platform = (int)Environment.OSVersion.Platform; if ((platform == 4) || (platform == 128)) { // MS 4, MONO 128 m_Unix = true; Console.WriteLine("Core: Unix environment detected"); } else { m_ConsoleEventHandler = new ConsoleEventHandler(OnConsoleEvent); SetConsoleCtrlHandler(m_ConsoleEventHandler, true); } while (!ScriptCompiler.Compile(m_Debug)) { if (m_Quiet) //abort and exit if compile scripts failed { return; } Console.WriteLine("Scripts: One or more scripts failed to compile or no script files were found."); Console.WriteLine(" - Press return to exit, or R to try again."); string line = Console.ReadLine(); if (line == null || line.ToLower() != "r") { return; } } // adam: I believe the new startup logic is nore robust as it attempts to prevents timers from firing // before the shard is fully up and alive. Region.Load(); SocketPool.Create(); MessagePump ms = m_MessagePump = new MessagePump(); timerThread.Start(); for (int i = 0; i < Map.AllMaps.Count; ++i) { ((Map)Map.AllMaps[i]).Tiles.Force(); } NetState.Initialize(); EventSink.InvokeServerStarted(); #if !DEBUG try { #endif while (m_Signal.WaitOne()) { Mobile.ProcessDeltaQueue(); Item.ProcessDeltaQueue(); Timer.Slice(); m_MessagePump.Slice(); NetState.FlushAll(); NetState.ProcessDisposedQueue(); if (Slice != null) { Slice(); } } #if !DEBUG } catch (Exception e) { CurrentDomain_UnhandledException(null, new UnhandledExceptionEventArgs(e, true)); } #endif }
public void Cancel() { if (!m_Valid) { return; } List <Item> list = new List <Item>(); try { for (int i = 0; i < m_From.Container.Items.Count; i++) { try { Item it = m_From.Container.Items[i] as Item; if (it != null) { list.Add(it); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } for (int i = list.Count - 1; i >= 0; --i) { if (i < list.Count) { Item item = list[i]; item.OnSecureTrade(m_From.Mobile, m_To.Mobile, m_From.Mobile, false); if (!item.Deleted) { m_From.Mobile.AddToBackpack(item); } } } //list = m_To.Container.Items; list = new List <Item>(); try { for (int i = 0; i < m_To.Container.Items.Count; i++) { try { Item it = m_To.Container.Items[i] as Item; if (it != null) { list.Add(it); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } for (int i = list.Count - 1; i >= 0; --i) { if (i < list.Count) { Item item = list[i]; item.OnSecureTrade(m_To.Mobile, m_From.Mobile, m_To.Mobile, false); if (!item.Deleted) { m_To.Mobile.AddToBackpack(item); } } } Close(); }
public void Update() { if (!m_Valid) { return; } if (m_From.Accepted && m_To.Accepted) { //List<Item> list = m_From.Container.Items; List <Item> list = new List <Item>(); try { for (int i = 0; i < m_From.Container.Items.Count; i++) { try { Item it = m_From.Container.Items[i] as Item; if (it != null) { list.Add(it); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } bool allowed = true; for (int i = list.Count - 1; allowed && i >= 0; --i) { if (i < list.Count) { Item item = list[i]; if (!item.AllowSecureTrade(m_From.Mobile, m_To.Mobile, m_To.Mobile, true)) { allowed = false; } } } //list = m_To.Container.Items; list = new List <Item>(); try { for (int i = 0; i < m_To.Container.Items.Count; i++) { try { Item it = m_To.Container.Items[i] as Item; if (it != null) { list.Add(it); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } for (int i = list.Count - 1; allowed && i >= 0; --i) { if (i < list.Count) { Item item = list[i]; if (!item.AllowSecureTrade(m_To.Mobile, m_From.Mobile, m_From.Mobile, true)) { allowed = false; } } } if (!allowed) { m_From.Accepted = false; m_To.Accepted = false; m_From.Mobile.Send(new UpdateSecureTrade(m_From.Container, m_From.Accepted, m_To.Accepted)); m_To.Mobile.Send(new UpdateSecureTrade(m_To.Container, m_To.Accepted, m_From.Accepted)); return; } //list = m_From.Container.Items; list = new List <Item>(); try { for (int i = 0; i < m_From.Container.Items.Count; i++) { try { Item it = m_From.Container.Items[i] as Item; if (it != null) { list.Add(it); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } for (int i = list.Count - 1; i >= 0; --i) { if (i < list.Count) { Item item = list[i]; item.OnSecureTrade(m_From.Mobile, m_To.Mobile, m_To.Mobile, true); if (!item.Deleted) { m_To.Mobile.AddToBackpack(item); } } } //list = m_To.Container.Items; list = new List <Item>(); try { for (int i = 0; i < m_To.Container.Items.Count; i++) { try { Item it = m_To.Container.Items[i] as Item; if (it != null) { list.Add(it); } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } } } catch (Exception ex) { EventSink.InvokeLogException(new LogExceptionEventArgs(ex)); } for (int i = list.Count - 1; i >= 0; --i) { if (i < list.Count) { Item item = list[i]; item.OnSecureTrade(m_To.Mobile, m_From.Mobile, m_From.Mobile, true); if (!item.Deleted) { m_From.Mobile.AddToBackpack(item); } } } Close(); } else { m_From.Mobile.Send(new UpdateSecureTrade(m_From.Container, m_From.Accepted, m_To.Accepted)); m_To.Mobile.Send(new UpdateSecureTrade(m_To.Container, m_To.Accepted, m_From.Accepted)); } }