Skip to content

Commit

Permalink
Refactor/Naming
Browse files Browse the repository at this point in the history
  • Loading branch information
d3agle committed Aug 18, 2015
1 parent c566174 commit 5f84b24
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
4 changes: 2 additions & 2 deletions Client/Core/Commands/ConnectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static void HandleGetAuthentication(Packets.ServerPackets.GetAuthenticati
{
GeoLocationHelper.Initialize();
new Packets.ClientPackets.GetAuthenticationResponse(Settings.VERSION, SystemCore.OperatingSystem, SystemCore.AccountType,
GeoLocationHelper.GeoInformation.country, GeoLocationHelper.GeoInformation.country_code,
GeoLocationHelper.GeoInformation.region, GeoLocationHelper.GeoInformation.city, GeoLocationHelper.ImageIndex,
GeoLocationHelper.GeoInfo.country, GeoLocationHelper.GeoInfo.country_code,
GeoLocationHelper.GeoInfo.region, GeoLocationHelper.GeoInfo.city, GeoLocationHelper.ImageIndex,
SystemCore.GetId(), SystemCore.GetUsername(), SystemCore.GetPcName(), Settings.TAG).Execute(client);
}

Expand Down
52 changes: 23 additions & 29 deletions Client/Core/Helper/GeoLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static class GeoLocationHelper
};

public static int ImageIndex { get; set; }
public static GeoInfo GeoInformation { get; private set; }
public static GeoInformation GeoInfo { get; private set; }
public static DateTime LastLocated { get; private set; }
public static bool LocationCompleted { get; private set; }

Expand All @@ -57,15 +57,15 @@ public static void Initialize()
{
TryLocate();

if (GeoInformation.country_code == "-" || GeoInformation.country == "Unknown")
if (GeoInfo.country_code == "-" || GeoInfo.country == "Unknown")
{
ImageIndex = 247; // question icon
return;
}

for (int i = 0; i < ImageList.Length; i++)
{
if (ImageList[i].Contains(GeoInformation.country_code.ToLower()))
if (ImageList[i].Contains(GeoInfo.country_code.ToLower()))
{
ImageIndex = i;
break;
Expand All @@ -78,7 +78,7 @@ private static void TryLocate()
{
try
{
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GeoInfo));
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(GeoInformation));

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://telize.com/geoip");
request.UserAgent = "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0";
Expand All @@ -95,12 +95,12 @@ private static void TryLocate()

using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(responseString)))
{
GeoInformation = (GeoInfo)jsonSerializer.ReadObject(ms);
GeoInfo = (GeoInformation)jsonSerializer.ReadObject(ms);
}
}
}
}
SystemCore.WanIp = GeoInformation.ip;
SystemCore.WanIp = GeoInfo.ip;
LastLocated = DateTime.UtcNow;
LocationCompleted = true;
}
Expand All @@ -112,13 +112,7 @@ private static void TryLocate()

private static void TryLocateFallback()
{
string xmlIp;
string xmlCountry;
string xmlCountryCode;
string xmlRegion;
string xmlCity;

GeoInformation = new GeoInfo();
GeoInfo = new GeoInformation();

try
{
Expand All @@ -138,40 +132,40 @@ private static void TryLocateFallback()
XmlDocument doc = new XmlDocument();
doc.LoadXml(responseString);

xmlIp = doc.SelectSingleNode("Response//IP").InnerXml;
xmlCountry = doc.SelectSingleNode("Response//CountryName").InnerXml;
xmlCountryCode = doc.SelectSingleNode("Response//CountryCode").InnerXml;
xmlRegion = doc.SelectSingleNode("Response//RegionName").InnerXml;
xmlCity = doc.SelectSingleNode("Response//City").InnerXml;
string xmlIp = doc.SelectSingleNode("Response//IP").InnerXml;
string xmlCountry = doc.SelectSingleNode("Response//CountryName").InnerXml;
string xmlCountryCode = doc.SelectSingleNode("Response//CountryCode").InnerXml;
string xmlRegion = doc.SelectSingleNode("Response//RegionName").InnerXml;
string xmlCity = doc.SelectSingleNode("Response//City").InnerXml;

GeoInformation.ip = (!string.IsNullOrEmpty(xmlIp))
GeoInfo.ip = (!string.IsNullOrEmpty(xmlIp))
? xmlIp
: "-";
GeoInformation.country = (!string.IsNullOrEmpty(xmlCountry))
GeoInfo.country = (!string.IsNullOrEmpty(xmlCountry))
? xmlCountry
: "Unknown";
GeoInformation.country_code = (!string.IsNullOrEmpty(xmlCountryCode))
GeoInfo.country_code = (!string.IsNullOrEmpty(xmlCountryCode))
? xmlCountryCode
: "-";
GeoInformation.region = (!string.IsNullOrEmpty(xmlRegion))
GeoInfo.region = (!string.IsNullOrEmpty(xmlRegion))
? xmlRegion
: "Unknown";
GeoInformation.city = (!string.IsNullOrEmpty(xmlCity))
GeoInfo.city = (!string.IsNullOrEmpty(xmlCity))
? xmlCity
: "Unknown";
}
}
}
SystemCore.WanIp = GeoInformation.ip;
SystemCore.WanIp = GeoInfo.ip;
LastLocated = DateTime.UtcNow;
LocationCompleted = true;
}
catch
{
GeoInformation.country = "Unknown";
GeoInformation.country_code = "-";
GeoInformation.region = "Unknown";
GeoInformation.city = "Unknown";
GeoInfo.country = "Unknown";
GeoInfo.country_code = "-";
GeoInfo.region = "Unknown";
GeoInfo.city = "Unknown";
LocationCompleted = false;
}

Expand Down Expand Up @@ -210,7 +204,7 @@ private static void TryGetWanIp()
}

[DataContract]
public class GeoInfo
public class GeoInformation
{
[DataMember]
public double longitude { get; set; }
Expand Down

0 comments on commit 5f84b24

Please sign in to comment.