mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-09 15:23:28 -04:00
Make /location show state, can be used on any IP, and alias of /geoip
This commit is contained in:
parent
766f3a20fb
commit
e64e16dbb9
@ -30,11 +30,12 @@ namespace MCGalaxy.Commands.Info {
|
||||
}
|
||||
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
string name;
|
||||
if (message.Length == 0) {
|
||||
if (p.IsSuper) { SuperRequiresArgs(p, "IP address"); return; }
|
||||
message = p.ip;
|
||||
} else {
|
||||
message = ModActionCmd.FindIP(p, message, "find alts of", "clones");
|
||||
message = ModActionCmd.FindIP(p, message, "Clones", out name);
|
||||
if (message == null) return;
|
||||
}
|
||||
|
||||
|
@ -33,22 +33,22 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (message.Length == 0) { Help(p); return; }
|
||||
string[] args = message.SplitSpaces(2);
|
||||
args[0] = ModActionCmd.FindIP(p, args[0], "IP ban", "banip");
|
||||
if (args[0] == null) return;
|
||||
string name, addr = ModActionCmd.FindIP(p, args[0], "BanIP", out name);
|
||||
if (addr == null) return;
|
||||
|
||||
IPAddress ip;
|
||||
if (!IPAddress.TryParse(args[0], out ip)) { p.Message("\"{0}\" is not a valid IP.", args[0]); return; }
|
||||
if (!IPAddress.TryParse(addr, out ip)) { p.Message("\"{0}\" is not a valid IP.", addr); return; }
|
||||
if (IPAddress.IsLoopback(ip)) { p.Message("You cannot IP ban the server."); return; }
|
||||
if (p.ip == args[0]) { p.Message("You cannot IP ban yourself."); return; }
|
||||
if (Server.bannedIP.Contains(args[0])) { p.Message("{0} is already IP banned.", args[0]); return; }
|
||||
if (p.ip == addr) { p.Message("You cannot IP ban yourself."); return; }
|
||||
if (Server.bannedIP.Contains(addr)) { p.Message("{0} is already IP banned.", addr); return; }
|
||||
// Check if IP is shared by any other higher ranked accounts
|
||||
if (!CheckIP(p, data, args[0])) return;
|
||||
if (!CheckIP(p, data, addr)) return;
|
||||
|
||||
string reason = args.Length > 1 ? args[1] : "";
|
||||
reason = ModActionCmd.ExpandReason(p, reason);
|
||||
if (reason == null) return;
|
||||
|
||||
ModAction action = new ModAction(args[0], p, ModActionType.BanIP, reason);
|
||||
ModAction action = new ModAction(addr, p, ModActionType.BanIP, reason);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
|
@ -17,48 +17,57 @@
|
||||
*/
|
||||
using System;
|
||||
using System.Net;
|
||||
using MCGalaxy.Config;
|
||||
using MCGalaxy.Network;
|
||||
|
||||
namespace MCGalaxy.Commands.Moderation {
|
||||
public class CmdLocation : Command2 {
|
||||
public override string name { get { return "Location"; } }
|
||||
public override string shortcut { get { return "lo"; } }
|
||||
public override string shortcut { get { return "GeoIP"; } }
|
||||
public override string type { get { return CommandTypes.Moderation; } }
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
||||
|
||||
class GeoInfo {
|
||||
[ConfigString] public string region;
|
||||
[ConfigString] public string country;
|
||||
}
|
||||
static ConfigElement[] elems;
|
||||
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (message.Length == 0) {
|
||||
if (p.IsSuper) { SuperRequiresArgs(p, "player name"); return; }
|
||||
if (p.IsSuper) { SuperRequiresArgs(p, "player name or IP"); return; }
|
||||
message = p.name;
|
||||
}
|
||||
|
||||
string ip = "";
|
||||
Player match = PlayerInfo.FindMatches(p, message);
|
||||
string target = message;
|
||||
|
||||
if (match == null) {
|
||||
p.Message("Searching PlayerDB for \"{0}\"..", message);
|
||||
target = PlayerInfo.FindOfflineIPMatches(p, message, out ip);
|
||||
if (target == null) return;
|
||||
} else {
|
||||
target = match.name; ip = match.ip;
|
||||
}
|
||||
string name, ip = ModActionCmd.FindIP(p, message, "Location", out name);
|
||||
if (ip == null) return;
|
||||
|
||||
if (HttpUtil.IsPrivateIP(ip)) {
|
||||
p.Message("%WPlayer has an internal IP, cannot trace"); return;
|
||||
}
|
||||
|
||||
string country = null;
|
||||
JsonContext ctx = new JsonContext();
|
||||
using (WebClient client = HttpUtil.CreateWebClient()) {
|
||||
country = client.DownloadString("http://ipinfo.io/" + ip + "/country");
|
||||
country = country.Replace("\n", "");
|
||||
ctx.Val = client.DownloadString("http://ipinfo.io/" + ip + "/geo");
|
||||
}
|
||||
p.Message("The IP of {0} %Shas been traced to: &b" + country, PlayerInfo.GetColoredName(p, target));
|
||||
|
||||
JsonObject obj = (JsonObject)Json.ParseStream(ctx);
|
||||
GeoInfo info = new GeoInfo();
|
||||
if (obj == null || !ctx.Success) {
|
||||
p.Message("%WError parsing GeoIP info"); return;
|
||||
}
|
||||
|
||||
if (elems == null) elems = ConfigElement.GetAll(typeof(GeoInfo));
|
||||
obj.Deserialise(elems, info);
|
||||
|
||||
string target = name == null ? ip : "of " + PlayerInfo.GetColoredName(p, name);
|
||||
p.Message("The IP {0} %Shas been traced to: &b{1}%S/&b{2}",
|
||||
target, info.region, info.country);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
p.Message("%T/Location [name]");
|
||||
p.Message("%HTracks down the country of the IP associated with [name].");
|
||||
p.Message("%T/Location [name/IP]");
|
||||
p.Message("%HTracks down location of the given IP, or IP player is on.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,19 +31,19 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (message.Length == 0) { Help(p); return; }
|
||||
string[] args = message.SplitSpaces(2);
|
||||
args[0] = ModActionCmd.FindIP(p, args[0], "un-IP ban", "unbanip");
|
||||
if (args[0] == null) return;
|
||||
string name, addr = ModActionCmd.FindIP(p, args[0], "UnbanIP", out name);
|
||||
if (addr == null) return;
|
||||
|
||||
IPAddress ip;
|
||||
if (!IPAddress.TryParse(args[0], out ip)) { p.Message("\"{0}\" is not a valid IP.", args[0]); return; }
|
||||
if (p.ip == args[0]) { p.Message("You cannot un-IP ban yourself."); return; }
|
||||
if (!Server.bannedIP.Contains(args[0])) { p.Message(args[0] + " is not a banned IP."); return; }
|
||||
if (!IPAddress.TryParse(addr, out ip)) { p.Message("\"{0}\" is not a valid IP.", addr); return; }
|
||||
if (p.ip == addr) { p.Message("You cannot un-IP ban yourself."); return; }
|
||||
if (!Server.bannedIP.Contains(addr)) { p.Message(addr + " is not a banned IP."); return; }
|
||||
|
||||
string reason = args.Length > 1 ? args[1] : "";
|
||||
reason = ModActionCmd.ExpandReason(p, reason);
|
||||
if (reason == null) return;
|
||||
|
||||
ModAction action = new ModAction(args[0], p, ModActionType.UnbanIP, reason);
|
||||
ModAction action = new ModAction(addr, p, ModActionType.UnbanIP, reason);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
|
@ -185,28 +185,29 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
/// or finds the IP of the account whose name matches the message. </summary>
|
||||
/// <remarks> "@input" can be used to always find IP by matching account name. <br/>
|
||||
/// Warns the player if the input matches both an IP and an account name. </remarks>
|
||||
internal static string FindIP(Player p, string message, string action, string cmd) {
|
||||
internal static string FindIP(Player p, string message, string cmd, out string name) {
|
||||
IPAddress ip;
|
||||
name = null;
|
||||
|
||||
// TryParse returns "0.0.0.123" for "123", we do not want that behaviour
|
||||
if (IPAddress.TryParse(message, out ip) && message.Split('.').Length == 4) {
|
||||
string account = ServerConfig.ClassicubeAccountPlus ? message + "+" : message;
|
||||
if (PlayerInfo.FindName(account) == null) return message;
|
||||
|
||||
// Some classicube.net accounts can be parsed as valid IPs, so warn in this case.
|
||||
p.Message("Note: \"{0}\" is an IP, but also an account name. "
|
||||
+ "If you meant to {1} the account, use %T/{2} @{0}",
|
||||
message, action, cmd);
|
||||
p.Message("Note: \"{0}\" is both an IP and an account name. "
|
||||
+ "If you meant the account, use %T/{1} @{0}", message, cmd);
|
||||
return message;
|
||||
}
|
||||
|
||||
if (message[0] == '@') message = message.Remove(0, 1);
|
||||
Player who = PlayerInfo.FindMatches(p, message);
|
||||
if (who != null) return who.ip;
|
||||
if (who != null) { name = who.name; return who.ip; }
|
||||
|
||||
p.Message("Searching PlayerDB..");
|
||||
string databaseIP;
|
||||
PlayerInfo.FindOfflineIPMatches(p, message, out databaseIP);
|
||||
return databaseIP;
|
||||
string dbIP;
|
||||
name = PlayerInfo.FindOfflineIPMatches(p, message, out dbIP);
|
||||
return dbIP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user