public MatchRequestListHandler() { try { geo = new GeoIPCountry("GeoIP.dat"); } catch {} }
public MatchRegisterHostingHandler() { try { geo = new GeoIPCountry("GeoIP.dat"); } catch {} }
private static void QueryReceived(IAsyncResult result) { try { var bytes = _connection.EndReceiveFrom(result, ref obtainedIP); var obtainedEP = (IPEndPoint)obtainedIP; Log.Info("Received packet from address " + obtainedEP.ToString()); if (PendingSessions.ContainsKey(obtainedEP)) { var strData = Encoding.ASCII.GetString(obtainedData, 0, bytes); Log.Debug("Received data: " + strData.Substring(4)); var lines = strData.Substring(4).Split('\n'); var xuid = PendingSessions[obtainedEP].XUID; var client = Client.Get(xuid); var gt = client.GamerTag; if (lines[0].StartsWith("statusResponse")) { Log.Info("Received a statusResponse."); if (lines.Length >= 2) { var dictionary = GetParams(lines[1].Split('\\')); if (!dictionary.ContainsKey("fs_game")) { dictionary.Add("fs_game", ""); } try { using (GeoIPCountry geo = new GeoIPCountry("GeoIP.dat")) { var countrycode = geo.GetCountryCode(obtainedEP.Address); Console.WriteLine("Country code of IP address " + obtainedEP.Address.ToString() + ": " + countrycode); dictionary.Add("countrycode", countrycode); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } dictionary.Add("xuid", xuid.ToString("X16")); lock (Servers) { /* if (Servers.ContainsKey(obtainedEP)) { Servers.Remove(obtainedEP); } */ ServerData info = null; if (!Servers.ContainsKey(obtainedEP)) { info = new ServerData(); Servers.Add(obtainedEP, info); } else { info = Servers[obtainedEP]; } info.GameData = dictionary; info.Address = obtainedEP; info.HostName = gt; info.HostXUID = xuid; info.LastUpdated = DateTime.UtcNow; Servers[obtainedEP] = info; /* Servers.Add(obtainedEP, new ServerData() { GameData = dictionary, Address = obtainedEP, HostName = gt, HostXUID = xuid, LastUpdated = DateTime.UtcNow }); */ } } } else if (lines[0].StartsWith("0hpong")) { Log.Info("Received a 0hpong."); var data = lines[0].Split(' '); var ingame = (data[3] == "1"); var players = int.Parse(data[4]); var maxPlayers = int.Parse(data[5]); if (ingame) { ServerData info = null; if (!Servers.ContainsKey(obtainedEP)) { info = new ServerData(); Servers.Add(obtainedEP, info); } else { info = Servers[obtainedEP]; } info.GameData = new Dictionary<string, string>(); //info.Address = obtainedEP; //info.HostName = gt; //info.HostXUID = xuid; //info.LastUpdated = DateTime.UtcNow; // hpong-exclusive data info.InGame = ingame; info.CurrentPlayers = players; info.MaxPlayers = maxPlayers; Servers[obtainedEP] = info; // send getstatus if in-game StartAdvancedQuery(PendingSessions[obtainedEP]); } } } } catch (Exception ex) { Log.Error(ex.ToString()); } _connection.BeginReceiveFrom(obtainedData, 0, obtainedData.Length, SocketFlags.None, ref obtainedIP, new AsyncCallback(QueryReceived), null); }