public int CompareToEx(AreaInfo other, string field, bool ascending) { int returnVal = 0; if (field == "Name") returnVal = PublicName.CompareTo(other.PublicName); else if (field == "Servers") { returnVal = this.Servers.CompareTo(other.Servers); } else if (field == "Load") { Int64 bwCur1 = 2 * (this.Bandwidth * 8) / (1000 * 1000); Int64 bwMax1 = this.BandwidthMax; int v1 = Convert.ToInt32((bwCur1 * 100) / bwMax1); Int64 bwCur2 = 2 * (other.Bandwidth * 8) / (1000 * 1000); Int64 bwMax2 = other.BandwidthMax; int v2 = Convert.ToInt32((bwCur2 * 100) / bwMax2); returnVal = v1.CompareTo(v2); } else if (field == "Users") { returnVal = this.Users.CompareTo(other.Users); } if (returnVal == 0) // Second order, Name returnVal = this.PublicName.CompareTo(other.PublicName); // Invert the value returned by String.Compare. if (ascending == false) returnVal *= -1; return returnVal; }
public int CompareToEx(AreaInfo other, string field, bool ascending) { int returnVal = 0; if (field == "Name") { returnVal = PublicName.CompareTo(other.PublicName); } else if (field == "Servers") { returnVal = this.Servers.CompareTo(other.Servers); } else if (field == "Load") { Int64 bwCur1 = 2 * (this.Bandwidth * 8) / (1000 * 1000); Int64 bwMax1 = this.BandwidthMax; int v1 = Convert.ToInt32((bwCur1 * 100) / bwMax1); Int64 bwCur2 = 2 * (other.Bandwidth * 8) / (1000 * 1000); Int64 bwMax2 = other.BandwidthMax; int v2 = Convert.ToInt32((bwCur2 * 100) / bwMax2); returnVal = v1.CompareTo(v2); } else if (field == "Users") { returnVal = this.Users.CompareTo(other.Users); } if (returnVal == 0) // Second order, Name { returnVal = this.PublicName.CompareTo(other.PublicName); } // Invert the value returned by String.Compare. if (ascending == false) { returnVal *= -1; } return(returnVal); }
public void PostManifestUpdate() { if (Storage.Manifest.Attributes["front_message"] != null) { string msg = Storage.Manifest.Attributes["front_message"].Value; if (FrontMessages.Contains(msg) == false) { OnFrontMessage(msg); FrontMessages.Add(msg); } } lock (m_servers) { foreach (ServerInfo infoServer in m_servers.Values) { infoServer.Deleted = true; } List<string> whiteList = Storage.GetList("servers.whitelist"); List<string> blackList = Storage.GetList("servers.blacklist"); if (Storage.Manifest != null) { lock (Storage.Manifest) { foreach (XmlNode nodeServer in Storage.Manifest.SelectNodes("//servers/server")) { string name = nodeServer.Attributes["name"].Value; ServerInfo infoServer = null; if (m_servers.ContainsKey(name)) infoServer = m_servers[name]; if (infoServer == null) { // Create infoServer = new ServerInfo(); infoServer.Name = name; m_servers[name] = infoServer; } { // Update info infoServer.Deleted = false; infoServer.PublicName = Utils.XmlGetAttributeString(nodeServer, "public_name", ""); infoServer.IpEntry = Utils.XmlGetAttributeString(nodeServer, "ip_entry", ""); ; infoServer.IpEntry2 = Utils.XmlGetAttributeString(nodeServer, "ip_entry2", ""); infoServer.IpExit = Utils.XmlGetAttributeString(nodeServer, "ip_exit", ""); infoServer.CountryCode = Utils.XmlGetAttributeString(nodeServer, "country_code", ""); infoServer.CountryName = Utils.XmlGetAttributeString(nodeServer, "country_name", ""); infoServer.Location = Utils.XmlGetAttributeString(nodeServer, "location", ""); infoServer.ScoreBase = Utils.XmlGetAttributeInt64(nodeServer, "scorebase", 0); infoServer.Bandwidth = Utils.XmlGetAttributeInt64(nodeServer, "bw", 0); infoServer.BandwidthMax = Utils.XmlGetAttributeInt64(nodeServer, "bw_max", 1); infoServer.Users = Utils.XmlGetAttributeInt64(nodeServer, "users", 0); infoServer.WarningOpen = Utils.XmlGetAttributeString(nodeServer, "warning_open", ""); infoServer.WarningClosed = Utils.XmlGetAttributeString(nodeServer, "warning_closed", ""); infoServer.ServerType = Utils.XmlGetAttributeInt64(nodeServer, "server_type", -1); infoServer.Public = Utils.XmlGetAttributeBool(nodeServer, "public", false); } } } } // TOOPEN - Add custom profiles for (; ; ) { bool restart = false; foreach (ServerInfo infoServer in m_servers.Values) { if (infoServer.Deleted) { m_servers.Remove(infoServer.Name); restart = true; break; } } if (restart == false) break; } // White/black list foreach (ServerInfo infoServer in m_servers.Values) { string name = infoServer.Name; if (whiteList.Contains(name)) infoServer.UserList = ServerInfo.UserListType.WhiteList; else if (blackList.Contains(name)) infoServer.UserList = ServerInfo.UserListType.BlackList; else infoServer.UserList = ServerInfo.UserListType.None; } } lock (m_areas) { foreach (AreaInfo infoArea in m_areas.Values) { infoArea.Deleted = true; } List<string> whiteList = Storage.GetList("areas.whitelist"); List<string> blackList = Storage.GetList("areas.blacklist"); if (Storage.Manifest != null) { lock (Storage.Manifest) { foreach (XmlNode nodeServer in Storage.Manifest.SelectNodes("//areas/area")) { string code = nodeServer.Attributes["code"].Value; AreaInfo infoArea = null; if (m_areas.ContainsKey(code)) infoArea = m_areas[code]; if (infoArea == null) { // Create infoArea = new AreaInfo(); infoArea.Code = code; m_areas[code] = infoArea; } { // Update info infoArea.Deleted = false; infoArea.PublicName = Utils.XmlGetAttributeString(nodeServer, "public_name", ""); infoArea.Bandwidth = Utils.XmlGetAttributeInt64(nodeServer, "bw", 0); infoArea.BandwidthMax = Utils.XmlGetAttributeInt64(nodeServer, "bw_max", 1); infoArea.Users = Utils.XmlGetAttributeInt64(nodeServer, "users", 0); infoArea.Servers = Utils.XmlGetAttributeInt64(nodeServer, "servers", 0); } } } } // TOOPEN - Add countries of custom profiles for (; ; ) { bool restart = false; foreach (AreaInfo infoArea in m_areas.Values) { if (infoArea.Deleted) { m_areas.Remove(infoArea.Code); break; } } if (restart == false) break; } // White/black list foreach (AreaInfo infoArea in m_areas.Values) { string code = infoArea.Code; if (whiteList.Contains(code)) infoArea.UserList = AreaInfo.UserListType.WhiteList; else if (blackList.Contains(code)) infoArea.UserList = AreaInfo.UserListType.BlackList; else infoArea.UserList = AreaInfo.UserListType.None; } } if (m_networkLockManager != null) m_networkLockManager.OnUpdateIps(); OnRefreshUi(Core.Engine.RefreshUiMode.Full); OnPostManifestUpdate(); }