mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-18 11:48:33 -04:00
Tidy up /location code
This commit is contained in:
parent
7cf4748fb3
commit
2bf9593bbf
@ -43,19 +43,23 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
p.Message("&WPlayer has an internal IP, cannot trace"); return;
|
p.Message("&WPlayer has an internal IP, cannot trace"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string json, region = null, country = null;
|
string json;
|
||||||
using (WebClient client = HttpUtil.CreateWebClient()) {
|
try {
|
||||||
json = client.DownloadString("http://ipinfo.io/" + ip + "/geo");
|
WebRequest req = HttpUtil.CreateRequest("http://ipinfo.io/" + ip + "/geo");
|
||||||
|
WebResponse res = req.GetResponse();
|
||||||
|
json = HttpUtil.GetResponseText(res);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
HttpUtil.DisposeErrorResponse(ex);
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonReader reader = new JsonReader(json);
|
JsonReader reader = new JsonReader(json);
|
||||||
reader.OnMember = (obj, key, value) => {
|
JsonObject obj = (JsonObject)reader.Parse();
|
||||||
if (key == "region") region = (string)value;
|
if (obj == null) { p.Message("&WError parsing GeoIP info"); return; }
|
||||||
if (key == "country") country = (string)value;
|
|
||||||
};
|
|
||||||
|
|
||||||
reader.Parse();
|
object region = null, country = null;
|
||||||
if (reader.Failed) { p.Message("&WError parsing GeoIP info"); return; }
|
obj.TryGetValue("region", out region);
|
||||||
|
obj.TryGetValue("country", out country);
|
||||||
|
|
||||||
string suffix = HasExtraPerm(p, data.Rank, 1) ? "&b{1}&S/&b{2}" : "&b{2}";
|
string suffix = HasExtraPerm(p, data.Rank, 1) ? "&b{1}&S/&b{2}" : "&b{2}";
|
||||||
string nick = name == null ? ip : "of " + p.FormatNick(name);
|
string nick = name == null ? ip : "of " + p.FormatNick(name);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user