@@ -1786,12 +1786,19 @@ static void IPInfoHandler( Player player, CommandReader cmd ) {
17861786 } else {
17871787 info = FindPlayerInfo ( player , cmd ) ;
17881788 }
1789+
17891790 if ( info == null ) return ;
1790- if ( info . GeoIP != info . LastIP . ToString ( ) ) {
1791- GetGeoip ( info ) ;
1791+ GetGeoipInfo ( info ) ;
1792+ PrintGeoIpInfo ( player , info ) ;
1793+ }
1794+
1795+ static void PrintGeoIpInfo ( Player player , PlayerInfo info ) {
1796+ if ( info . Name != null ) {
1797+ player . Message ( "Geo Info about: {0}&S ({1})" , info . ClassyName , info . GeoIP ?? "N/A" ) ;
1798+ } else {
1799+ player . Message ( "Geo Info about: &f{0}" , info . GeoIP ?? "N/A" ) ;
17921800 }
1793-
1794- player . Message ( "Geo Info about: {0}&S ({1})" , info . ClassyName , info . GeoIP ?? "N/A" ) ;
1801+
17951802 player . Message ( " Country: &f{1}&S ({0})" , info . CountryCode ?? "N/A" , info . CountryName ?? "N/A" ) ;
17961803 player . Message ( " Continent: &f{0}" , info . Continent ?? "N/A" ) ;
17971804 player . Message ( " Subdivisions: &f{0}" , info . Subdivision ) ;
@@ -1823,45 +1830,25 @@ private static void IPNPInfoHandler(Player player, CommandReader cmd) {
18231830 player . Message ( "Info: Invalid IP range format. Use CIDR notation." ) ;
18241831 return ;
18251832 }
1826- JsonObject result = null ;
1827- try {
1828- result = JsonObject . Parse ( Server . downloadDatastring ( "http://geoip.pw/api/" + ip ) ) ;
1829- if ( result . Get ( "message" ) != null ) {
1830- player . Message ( "No information found!" ) ;
1831- return ;
1832- }
1833- player . Message ( "Geo Info about: &f{0}" , result . Get ( "ip" ) ?? "N/A" ) ;
1834- player . Message ( " Country: &f{0}&S ({1})" , result . Get ( "country" ) ?? "N/A" , result . Get ( "country_abbr" ) ?? "N/A" ) ;
1835- player . Message ( " Continent: &f{0}" , result . Get ( "continent" ) ?? "N/A" ) ;
1836- player . Message ( " Subdivisions: &f{0}" , nan . Replace ( result . Get ( "subdivision" ) , "" ) . Split ( ',' ) . JoinToString ( ", " ) ) ;
1837- player . Message ( " Latitude: &f{0}" , result . Get ( "latitude" ) ?? "N/A" ) ;
1838- player . Message ( " Longitude: &f{0}" , result . Get ( "longitude" ) ?? "N/A" ) ;
1839- player . Message ( " Timezone: &f{0}" , result . Get ( "timezone" ) ?? "N/A" ) ;
1840- byte acc ;
1841- byte . TryParse ( result . Get ( "accuracy" ) , out acc ) ;
1842- player . Message ( " Hostname: &f{0}" , result . Get ( "host" ) ?? "N/A" ) ;
1843- player . Message ( " Accuracy: &f{0}" , acc ) ;
1844- player . Message ( "Geoip information by: &9http://geoip.pw/" ) ;
1845-
1846- } catch ( Exception ex ) {
1847- Logger . Log ( LogType . Warning , "Could not access GeoIP website (Ex: " + ex + ")" ) ;
1848- }
1833+
1834+ PlayerInfo tmp = new PlayerInfo ( 0 ) ; tmp . LastIP = ip ;
1835+ GetGeoipInfo ( tmp ) ;
1836+ PrintGeoIpInfo ( player , tmp ) ;
18491837 }
18501838
1851- public static void GetGeoip ( PlayerInfo info ) {
1839+ public static void GetGeoipInfo ( PlayerInfo info ) {
18521840 string ip = info . LastIP . ToString ( ) ;
18531841 if ( IPAddress . Parse ( ip ) . IsLocal ( ) && Server . ExternalIP != null ) {
18541842 ip = Server . ExternalIP . ToString ( ) ;
18551843 }
1856- if ( ip == info . GeoIP ) {
1857- return ;
1858- }
1844+ if ( ip == info . GeoIP ) return ;
1845+
18591846 JsonObject result = null ;
18601847 try {
1861- result = JsonObject . Parse ( Server . downloadDatastring ( "http://geoip.pw/api/" + ip ) ) ;
1862- if ( result . Get ( "message" ) != null ) {
1863- return ;
1864- }
1848+ string url = "http://geoip.pw/api/" + ip ;
1849+ result = JsonObject . Parse ( HttpUtil . DownloadString ( url , "get GeoIP info" , 10000 ) ) ;
1850+ if ( result . Get ( "message" ) != null ) return ;
1851+
18651852 info . CountryName = result . Get ( "country" ) ?? "N/A" ;
18661853 info . CountryCode = result . Get ( "country_abbr" ) ?? "N/A" ;
18671854 info . Continent = result . Get ( "continent" ) ?? "N/A" ;
@@ -1871,12 +1858,9 @@ public static void GetGeoip(PlayerInfo info) {
18711858 info . TimeZone = result . Get ( "timezone" ) ?? "N/A" ;
18721859 info . Hostname = result . Get ( "host" ) ?? "N/A" ;
18731860 info . GeoIP = result . Get ( "ip" ) ?? "N/A" ;
1874- return ;
1875-
18761861 } catch ( Exception ex ) {
18771862 Logger . Log ( LogType . Warning , "Could not access GeoIP website (Ex: " + ex + ")" ) ;
18781863 Logger . Log ( LogType . Debug , ex . ToString ( ) ) ;
1879- return ;
18801864 }
18811865 }
18821866
@@ -1927,7 +1911,8 @@ private static void APIPInfoHandler(Player player, CommandReader cmd) {
19271911 break ;
19281912 }
19291913
1930- string data = Server . downloadDatastring ( "http://www.classicube.net/api/" + value ) ;
1914+ string url = "http://www.classicube.net/api/" + value ;
1915+ string data = HttpUtil . DownloadString ( url , "get user info" , 10000 ) ;
19311916 if ( string . IsNullOrEmpty ( data ) || ! data . Contains ( "username" ) ) {
19321917 player . Message ( "Player not found!" ) ;
19331918 return ;
0 commit comments