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) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
|
string name;
|
||||||
if (message.Length == 0) {
|
if (message.Length == 0) {
|
||||||
if (p.IsSuper) { SuperRequiresArgs(p, "IP address"); return; }
|
if (p.IsSuper) { SuperRequiresArgs(p, "IP address"); return; }
|
||||||
message = p.ip;
|
message = p.ip;
|
||||||
} else {
|
} else {
|
||||||
message = ModActionCmd.FindIP(p, message, "find alts of", "clones");
|
message = ModActionCmd.FindIP(p, message, "Clones", out name);
|
||||||
if (message == null) return;
|
if (message == null) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,22 +33,22 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (message.Length == 0) { Help(p); return; }
|
if (message.Length == 0) { Help(p); return; }
|
||||||
string[] args = message.SplitSpaces(2);
|
string[] args = message.SplitSpaces(2);
|
||||||
args[0] = ModActionCmd.FindIP(p, args[0], "IP ban", "banip");
|
string name, addr = ModActionCmd.FindIP(p, args[0], "BanIP", out name);
|
||||||
if (args[0] == null) return;
|
if (addr == null) return;
|
||||||
|
|
||||||
IPAddress ip;
|
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 (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 (p.ip == addr) { 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 (Server.bannedIP.Contains(addr)) { p.Message("{0} is already IP banned.", addr); return; }
|
||||||
// Check if IP is shared by any other higher ranked accounts
|
// 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] : "";
|
string reason = args.Length > 1 ? args[1] : "";
|
||||||
reason = ModActionCmd.ExpandReason(p, reason);
|
reason = ModActionCmd.ExpandReason(p, reason);
|
||||||
if (reason == null) return;
|
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);
|
OnModActionEvent.Call(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,48 +17,57 @@
|
|||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using MCGalaxy.Config;
|
||||||
using MCGalaxy.Network;
|
using MCGalaxy.Network;
|
||||||
|
|
||||||
namespace MCGalaxy.Commands.Moderation {
|
namespace MCGalaxy.Commands.Moderation {
|
||||||
public class CmdLocation : Command2 {
|
public class CmdLocation : Command2 {
|
||||||
public override string name { get { return "Location"; } }
|
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 string type { get { return CommandTypes.Moderation; } }
|
||||||
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
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) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (message.Length == 0) {
|
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;
|
message = p.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ip = "";
|
string name, ip = ModActionCmd.FindIP(p, message, "Location", out name);
|
||||||
Player match = PlayerInfo.FindMatches(p, message);
|
if (ip == null) return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (HttpUtil.IsPrivateIP(ip)) {
|
if (HttpUtil.IsPrivateIP(ip)) {
|
||||||
p.Message("%WPlayer has an internal IP, cannot trace"); return;
|
p.Message("%WPlayer has an internal IP, cannot trace"); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string country = null;
|
JsonContext ctx = new JsonContext();
|
||||||
using (WebClient client = HttpUtil.CreateWebClient()) {
|
using (WebClient client = HttpUtil.CreateWebClient()) {
|
||||||
country = client.DownloadString("http://ipinfo.io/" + ip + "/country");
|
ctx.Val = client.DownloadString("http://ipinfo.io/" + ip + "/geo");
|
||||||
country = country.Replace("\n", "");
|
|
||||||
}
|
}
|
||||||
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) {
|
public override void Help(Player p) {
|
||||||
p.Message("%T/Location [name]");
|
p.Message("%T/Location [name/IP]");
|
||||||
p.Message("%HTracks down the country of the IP associated with [name].");
|
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) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
if (message.Length == 0) { Help(p); return; }
|
if (message.Length == 0) { Help(p); return; }
|
||||||
string[] args = message.SplitSpaces(2);
|
string[] args = message.SplitSpaces(2);
|
||||||
args[0] = ModActionCmd.FindIP(p, args[0], "un-IP ban", "unbanip");
|
string name, addr = ModActionCmd.FindIP(p, args[0], "UnbanIP", out name);
|
||||||
if (args[0] == null) return;
|
if (addr == null) return;
|
||||||
|
|
||||||
IPAddress ip;
|
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 (p.ip == args[0]) { p.Message("You cannot un-IP ban yourself."); return; }
|
if (p.ip == addr) { 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 (!Server.bannedIP.Contains(addr)) { p.Message(addr + " is not a banned IP."); return; }
|
||||||
|
|
||||||
string reason = args.Length > 1 ? args[1] : "";
|
string reason = args.Length > 1 ? args[1] : "";
|
||||||
reason = ModActionCmd.ExpandReason(p, reason);
|
reason = ModActionCmd.ExpandReason(p, reason);
|
||||||
if (reason == null) return;
|
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);
|
OnModActionEvent.Call(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,28 +185,29 @@ namespace MCGalaxy.Commands.Moderation {
|
|||||||
/// or finds the IP of the account whose name matches the message. </summary>
|
/// 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/>
|
/// <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>
|
/// 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;
|
IPAddress ip;
|
||||||
|
name = null;
|
||||||
|
|
||||||
// TryParse returns "0.0.0.123" for "123", we do not want that behaviour
|
// TryParse returns "0.0.0.123" for "123", we do not want that behaviour
|
||||||
if (IPAddress.TryParse(message, out ip) && message.Split('.').Length == 4) {
|
if (IPAddress.TryParse(message, out ip) && message.Split('.').Length == 4) {
|
||||||
string account = ServerConfig.ClassicubeAccountPlus ? message + "+" : message;
|
string account = ServerConfig.ClassicubeAccountPlus ? message + "+" : message;
|
||||||
if (PlayerInfo.FindName(account) == null) return message;
|
if (PlayerInfo.FindName(account) == null) return message;
|
||||||
|
|
||||||
// Some classicube.net accounts can be parsed as valid IPs, so warn in this case.
|
// 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. "
|
p.Message("Note: \"{0}\" is both an IP and an account name. "
|
||||||
+ "If you meant to {1} the account, use %T/{2} @{0}",
|
+ "If you meant the account, use %T/{1} @{0}", message, cmd);
|
||||||
message, action, cmd);
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message[0] == '@') message = message.Remove(0, 1);
|
if (message[0] == '@') message = message.Remove(0, 1);
|
||||||
Player who = PlayerInfo.FindMatches(p, message);
|
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..");
|
p.Message("Searching PlayerDB..");
|
||||||
string databaseIP;
|
string dbIP;
|
||||||
PlayerInfo.FindOfflineIPMatches(p, message, out databaseIP);
|
name = PlayerInfo.FindOfflineIPMatches(p, message, out dbIP);
|
||||||
return databaseIP;
|
return dbIP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user