Beispiel #1
0
        public override void Use(Player p, string message, CommandData data) {
            if (message.Length == 0) {
                if (p.IsSuper) { SuperRequiresArgs(p, "player name or IP"); return; }
                message = p.name;
            }
            
            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;
            }

            JsonContext ctx = new JsonContext();
            using (WebClient client = HttpUtil.CreateWebClient()) {
                ctx.Val = client.DownloadString(https://geoip.pw/" + ip);
            }
            
            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);
        }
Beispiel #2
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                if (p.IsSuper)
                {
                    SuperRequiresArgs(p, "player name or IP"); return;
                }
                message = p.name;
            }

            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;
            }

            JsonContext ctx = new JsonContext();

            using (WebClient client = HttpUtil.CreateWebClient())
            {
                ctx.Val = client.DownloadString("http://geoip.pw/api/" + ip);
            }

            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: ", target);
            p.Message("  Continent: &f{1}&S ({0})", info.continent_abbr, info.continent);
            p.Message("  Country: &f{1}&S ({0})", info.country_abbr, info.country);
            p.Message("  Region/State: &f{0}", info.subdivision);
            p.Message("  City: &f{0}", info.city);
            p.Message("  Time Zone: &f{0}", info.timezone);
            p.Message("  Hostname: &f{0}", info.host);
            p.Message("  Is using proxy: &f{0}", info.proxy);
            p.Message("Geoip information by: &9http://geoip.pw/");
        }
Beispiel #3
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                if (p.IsSuper)
                {
                    SuperRequiresArgs(p, "player name or IP"); return;
                }
                message = p.name;
            }

            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 json, region = null, country = null;

            using (WebClient client = HttpUtil.CreateWebClient()) {
                json = client.DownloadString("http://ipinfo.io/" + ip + "/geo");
            }

            JsonReader reader = new JsonReader(json);

            reader.OnMember = (obj, key, value) => {
                if (key == "region")
                {
                    region = (string)value;
                }
                if (key == "country")
                {
                    country = (string)value;
                }
            };

            reader.Parse();
            if (reader.Failed)
            {
                p.Message("&WError parsing GeoIP info"); return;
            }

            string suffix = HasExtraPerm(p, data.Rank, 1) ? "&b{1}%S/&b{2}" : "&b{2}";
            string nick   = name == null ? ip : "of " + p.FormatNick(name);

            p.Message("The IP {0} %Straces to: " + suffix, nick, region, country);
        }
Beispiel #4
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                if (p.IsSuper)
                {
                    SuperRequiresArgs(p, "player name or IP"); return;
                }
                message = p.name;
            }

            string name, ip = ModActionCmd.FindIP(p, message, "Location", out name);

            if (ip == null)
            {
                return;
            }

            if (IPUtil.IsPrivate(IPAddress.Parse(ip)))
            {
                p.Message("&WPlayer has an internal IP, cannot trace"); return;
            }

            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);
            JsonObject obj    = (JsonObject)reader.Parse();

            if (obj == null)
            {
                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);

            p.Message("The IP {0} &Straces to: " + suffix, nick, region, country);
        }
Beispiel #5
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                Help(p); return;
            }
            string[] args = message.SplitSpaces(2);
            string   name, addr = ModActionCmd.FindIP(p, args[0], "BanIP", out name);

            if (addr == null)
            {
                return;
            }

            IPAddress ip;

            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 (ip.Equals(p.IP))
            {
                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, addr))
            {
                return;
            }

            string reason = args.Length > 1 ? args[1] : "";

            reason = ModActionCmd.ExpandReason(p, reason);
            if (reason == null)
            {
                return;
            }

            ModAction action = new ModAction(addr, p, ModActionType.BanIP, reason);

            OnModActionEvent.Call(action);
        }
Beispiel #6
0
        public override void Use(Player p, string message)
        {
            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;
            }

            IPAddress ip;

            if (!IPAddress.TryParse(args[0], out ip))
            {
                Player.Message(p, "\"{0}\" is not a valid IP.", args[0]); return;
            }
            if (IPAddress.IsLoopback(ip))
            {
                Player.Message(p, "You cannot IP ban the server."); return;
            }
            if (p != null && p.ip == args[0])
            {
                Player.Message(p, "You cannot IP ban yourself."); return;
            }
            if (Server.bannedIP.Contains(args[0]))
            {
                Player.Message(p, "{0} is already IP banned.", args[0]); return;
            }
            // Check if IP is shared by any other higher ranked accounts
            if (!CheckIP(p, args[0]))
            {
                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);

            OnModActionEvent.Call(action);
        }
Beispiel #7
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                if (p.IsSuper)
                {
                    SuperRequiresArgs(p, "player name or IP"); return;
                }
                message = p.name;
            }

            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;
            }

            bool   success;
            string ipInfo;

            using (WebClient client = HttpUtil.CreateWebClient()) {
                ipInfo = client.DownloadString("http://ipinfo.io/" + ip + "/geo");
            }

            JsonObject obj  = (JsonObject)Json.Parse(ipInfo, out success);
            GeoInfo    info = new GeoInfo();

            if (obj == null || !success)
            {
                p.Message("%WError parsing GeoIP info"); return;
            }

            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(GeoInfo));
            }
            obj.Deserialise(elems, info);

            string suffix = HasExtraPerm(p, data.Rank, 1) ? "&b{1}%S/&b{2}" : "&b{2}";
            string nick   = name == null ? ip : "of " + p.FormatNick(name);

            p.Message("The IP {0} %Straces to: " + suffix, nick, info.region, info.country);
        }
Beispiel #8
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                Help(p); return;
            }
            string[] args = message.SplitSpaces(2);
            string   name, addr = ModActionCmd.FindIP(p, args[0], "UnbanIP", out name);

            if (addr == null)
            {
                return;
            }

            IPAddress ip;

            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(addr, p, ModActionType.UnbanIP, reason);

            OnModActionEvent.Call(action);
        }
Beispiel #9
0
        public override void Use(Player p, string message)
        {
            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;
            }

            IPAddress ip;

            if (!IPAddress.TryParse(args[0], out ip))
            {
                Player.Message(p, "\"{0}\" is not a valid IP.", args[0]); return;
            }
            if (p != null && p.ip == args[0])
            {
                Player.Message(p, "You cannot un-IP ban yourself."); return;
            }
            if (!Server.bannedIP.Contains(args[0]))
            {
                Player.Message(p, args[0] + " 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);

            OnModActionEvent.Call(action);
        }