Example #1
0
        /// <summary>
        /// Locate
        /// </summary>
        /// <param name="host">Host</param>
        /// <returns>Geo location data</returns>
        public static GeoLocationData Locate(string host)
        {
            GeoLocationData ret = null;
            string          h   = host.Trim();

            if (cache.ContainsKey(h))
            {
                ret = cache[h];
            }
            else
            {
                foreach (GeoLocationProvider provider in providers)
                {
                    ret = provider.RequestData(h);
                    if (ret != null)
                    {
                        break;
                    }
                }
            }
            if (ret == null)
            {
                ret = new GeoLocationData(null);
            }
            return(ret);
        }
        /// <summary>
        /// Request data
        /// </summary>
        /// <param name="host">Host</param>
        /// <returns>Geo location data</returns>
        public GeoLocationData RequestData(string host)
        {
            GeoLocationData ret = null;

            try
            {
                WebClientEx wc = new WebClientEx(1000);
                wc.Headers.Set(HttpRequestHeader.Accept, "application/json");
                wc.Headers.Set(HttpRequestHeader.UserAgent, SAMPProvider.UserAgent);
                using (MemoryStream stream = new MemoryStream(wc.DownloadData(endpoint + host)))
                {
                    object result = serializer.ReadObject(stream);
                    if (result != null)
                    {
                        ret = new GeoLocationData(result);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }
            return(ret);
        }
Example #3
0
 /// <summary>
 /// Update timer tick event
 /// </summary>
 /// <param name="sender">Sender</param>
 /// <param name="e">Event arguments</param>
 private void updateTimer_Tick(object sender, EventArgs e)
 {
     lock (pingList)
     {
         pingChart.Series[0].Points.DataBindY(pingList);
         if (pingList.Count > 0)
         {
             pingLabel.Text = Translator.GetTranslation("PING") + ": " + pingList[pingList.Count - 1] + " ms";
         }
     }
     lock (hostname)
     {
         hostnameLabel.Text = Translator.GetTranslation("HOSTNAME") + ": " + hostname;
         playersLabel.Text  = Translator.GetTranslation("PLAYERS") + ": " + playerCount + "/" + maxPlayers;
     }
     lock (gamemode)
     {
         gamemodeLabel.Text = Translator.GetTranslation("GAMEMODE") + ": " + gamemode;
     }
     lock (gamemode)
     {
         languageLabel.Text = Translator.GetTranslation("LANGUAGE") + ": " + language;
     }
     lock (players)
     {
         int  si = -1;
         bool cs = false;
         foreach (DataGridViewRow dgvr in playersGridView.SelectedRows)
         {
             si = dgvr.Index;
             break;
         }
         playersDataTable.Clear();
         int i = 0;
         foreach (Player player in players)
         {
             DataRow  dr   = playersDataTable.NewRow();
             object[] data = new object[4];
             data[0]      = player.ID;
             data[1]      = player.Name;
             data[2]      = player.Score;
             data[3]      = player.Ping;
             dr.ItemArray = data;
             playersDataTable.Rows.Add(dr);
             if (i == si)
             {
                 cs = true;
             }
             ++i;
         }
         if (cs)
         {
             playersGridView.Rows[si].Selected = true;
         }
     }
     lock (rules)
     {
         int  si = -1;
         bool cs = false;
         foreach (DataGridViewRow dgvr in rulesGridView.SelectedRows)
         {
             si = dgvr.Index;
             break;
         }
         rulesDataTable.Clear();
         int i = 0;
         foreach (KeyValuePair <string, string> rule in rules)
         {
             DataRow  dr   = rulesDataTable.NewRow();
             object[] data = new object[2];
             data[0]      = rule.Key;
             data[1]      = rule.Value;
             dr.ItemArray = data;
             rulesDataTable.Rows.Add(dr);
             if (i == si)
             {
                 cs = true;
             }
             ++i;
         }
         if (cs)
         {
             rulesGridView.Rows[si].Selected = true;
         }
     }
     if ((geoLocation == null) && geoLocationAsync.IsCompleted)
     {
         geoLocation                 = geoLocationAsync.Result;
         countryLabel.Text           = Translator.GetTranslation("COUNTRY") + ": " + geoLocation.CountryName + " (" + geoLocation.CountryCode + ")";
         regionLabel.Text            = Translator.GetTranslation("REGION") + ": " + geoLocation.RegionName + " (" + geoLocation.RegionCode + ")";
         cityLabel.Text              = Translator.GetTranslation("CITY") + ": " + geoLocation.ZIPCode + " " + geoLocation.City;
         timeZoneLabel.Text          = Translator.GetTranslation("TIME_ZONE") + ": " + geoLocation.TimeZone;
         latitudeLongitudeLabel.Text = Translator.GetTranslation("LATITUDE_LONGITUDE") + ": " + geoLocation.Latitude + "; " + geoLocation.Longitude;
         metroCodeLabel.Text         = Translator.GetTranslation("METRO_CODE") + ": " + geoLocation.MetroCode;
     }
 }