mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-16 18:57:26 -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;
|
||||
}
|
||||
|
||||
string json, region = null, country = null;
|
||||
using (WebClient client = HttpUtil.CreateWebClient()) {
|
||||
json = client.DownloadString("http://ipinfo.io/" + ip + "/geo");
|
||||
string json;
|
||||
try {
|
||||
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);
|
||||
reader.OnMember = (obj, key, value) => {
|
||||
if (key == "region") region = (string)value;
|
||||
if (key == "country") country = (string)value;
|
||||
};
|
||||
JsonObject obj = (JsonObject)reader.Parse();
|
||||
if (obj == null) { p.Message("&WError parsing GeoIP info"); return; }
|
||||
|
||||
reader.Parse();
|
||||
if (reader.Failed) { p.Message("&WError parsing GeoIP info"); return; }
|
||||
object region = null, country = null;
|
||||
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 nick = name == null ? ip : "of " + p.FormatNick(name);
|
||||
|
@ -153,7 +153,7 @@ namespace MCGalaxy.Commands.Building {
|
||||
public override void Help(Player p) {
|
||||
p.Message("&T/MB [block] [message]");
|
||||
p.Message("&HPlaces a message in your next block.");
|
||||
List<string> names = SupportedBlocks(p);
|
||||
List<string> names = SupportedBlocks(p);
|
||||
p.Message("&H Supported blocks: &S{0}", names.Join());
|
||||
p.Message("&H Use | to separate commands, e.g. /say 1 |/say 2");
|
||||
p.Message("&H Note: \"@p\" is a placeholder for player who clicked.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user