public static void Initialize() { if (Enabled) { RegionPopularityWatcher.Load(true); } }
public static List <RegionWatcherObject> Load(bool autoStart) { RegionPopularityWatcher watcher = new RegionPopularityWatcher(); watcher.Regions = new List <RegionWatcherObject>(); watcher.TotalChecks = 0; if (File.Exists(PersistancePath)) { XmlDocument doc = new XmlDocument(); XmlElement root; RegionWatcherObject obj; try { doc.Load(PersistancePath); root = doc[RootElementName]; watcher.TotalChecks = Convert.ToInt32(root.GetAttribute("totalChecks")); foreach (XmlElement node in root.GetElementsByTagName(ChildElementName)) { obj = new RegionWatcherObject(node["name"].InnerText, Util.GetMapByName(node["map"].InnerText)); obj.Count = Convert.ToInt32(node["count"].InnerText); obj.PopularityPercent = Convert.ToInt32(node["popularityPercentage"].InnerText); if (IgnoreMap(obj.Map)) { watcher.TotalChecks -= obj.Count; } else { watcher.Regions.Add(obj); } } } catch (Exception e) { ExceptionManager.LogException("RegionPopularityWatcher", e); } } SortStats(watcher.Regions); if (autoStart) { watcher.Start(); } return(watcher.Regions); }
public static string BuildStatus() { StringBuilder resultsBuilder = new StringBuilder("<status>"); List <NetState> userList = new List <NetState>(NetState.Instances); userList.Sort(NetStateComparer.Instance); Mobile m; int serial; string name, guild, accessLevel, mapName, fullName, profile; for (int i = 0; i < userList.Count; i++) { m = userList[i].Mobile; name = guild = accessLevel = mapName = fullName = profile = ""; if (m == null) { continue; } serial = m.Serial; name = Encode(m.RawName); if (((Guild)m.Guild) != null) { guild = Encode(((Guild)m.Guild).Abbreviation); } if (m.AccessLevel > AccessLevel.Player) { accessLevel = Encode(m.AccessLevel.ToString()); } if (IsHidden(m)) { mapName = "unknown"; } else { Region reg = Region.Find(m.Location, m.Map); if (reg != null) { if (reg.Name != null && reg.Name != "world") { mapName = Encode(Util.SplitString(reg.Name)); } else if (reg is HouseRegion && Server.Multis.BaseHouse.FindHouseAt(m) != null) { mapName = "inside a house"; } } } if (String.IsNullOrEmpty(mapName)) { mapName = Encode(String.Format("somewhere in {0}", m.Map.Name)); } fullName = Encode(String.Format("{0}\n{1}", Titles.GetNameTitle(m, m), Titles.GetSkillTitle(m))); profile = Encode(m.Profile); resultsBuilder.AppendFormat("<mobile name='{0}' guild='{1}' access='{2}' map='{3}' fullName='{4}' profile='{5}' serial='{6}'/>", name, guild, accessLevel, mapName, fullName, profile, serial); } userList.Clear(); Dictionary <string, uint> colorList = LoadRegionColors(); List <RegionWatcherObject> regionWatchList = RegionPopularityWatcher.Load(false); RegionWatcherObject obj; regionWatchList.Sort( delegate(RegionWatcherObject x, RegionWatcherObject y) { return(GetRegionColor(x, colorList).CompareTo(GetRegionColor(y, colorList))); }); for (int i = 0; i < regionWatchList.Count; i++) { obj = regionWatchList[i]; resultsBuilder.AppendFormat("<region name='{0}' map='{1}' popularity='{2}' color='{3}'/>", Encode(Util.SplitString(obj.Name)), obj.Map == Map.Ilshenar ? Encode(Map.Backtrol.Name) : Encode(obj.Map.Name), obj.PopularityPercent, GetRegionColor(obj, colorList)); } string uptime = Util.FormatLongTimeSpan(DateTime.Now - Server.Items.Clock.ServerStart); string ramUsage = Util.FormatByteAmount(System.Diagnostics.Process.GetCurrentProcess().WorkingSet64); string cycles = Core.AverageCPS.ToString("N2"); resultsBuilder.AppendFormat("<stats uptime='{0}' ram='{1}' cycles='{2}'/>", uptime, ramUsage, cycles); resultsBuilder.Append("</status>"); return(resultsBuilder.ToString()); }
public static List<RegionWatcherObject> Load( bool autoStart ) { RegionPopularityWatcher watcher = new RegionPopularityWatcher(); watcher.Regions = new List<RegionWatcherObject>(); watcher.TotalChecks = 0; if( File.Exists( PersistancePath ) ) { XmlDocument doc = new XmlDocument(); XmlElement root; RegionWatcherObject obj; try { doc.Load( PersistancePath ); root = doc[RootElementName]; watcher.TotalChecks = Convert.ToInt32( root.GetAttribute( "totalChecks" ) ); foreach( XmlElement node in root.GetElementsByTagName( ChildElementName ) ) { obj = new RegionWatcherObject( node["name"].InnerText, Util.GetMapByName( node["map"].InnerText ) ); obj.Count = Convert.ToInt32( node["count"].InnerText ); obj.PopularityPercent = Convert.ToInt32( node["popularityPercentage"].InnerText ); if( IgnoreMap( obj.Map ) ) watcher.TotalChecks -= obj.Count; else watcher.Regions.Add( obj ); } } catch( Exception e ) { ExceptionManager.LogException( "RegionPopularityWatcher", e ); } } SortStats( watcher.Regions ); if( autoStart ) watcher.Start(); return watcher.Regions; }