geoIP script for AC 1.2
#1
GeoIP script shows name of country, from where connected chosen player.
To use it, paste below code to config/autoexec.cfg in profile and unpack .txt files to that folder from this file:
geoip_GeoLite2_AC_attachments_20191224.zip

Usage: /geoip CN , where CN is client number, for example: /geoip 4
/geoipall - show countries of the all players

Notes: database has ~2,5 MB (it isn't added to saved.cfg), script checks only first 3 octets of IP, it uses binary search algorithm, database is from https://dev.maxmind.com/geoip/geoip2/geolite2/

// geoip script v. 4.2 by grenadier - date: 28.10.2018

// execute database of IPs
// this product includes GeoLite2 data created by MaxMind, available from http://www.maxmind.com
exec config/geoip_ipnum.txt
exec config/geoip_abbr.txt
exec config/geoip_countrylist.txt

alias geoip [
 if (= (isclient $arg1) 1) [
   if (!= (player $arg1 ip) (player1 ip)) [
     tmp_first_byte = (at (strreplace (player $arg1 ip) "." " ") 0)
     tmp_second_byte = (at (strreplace (player $arg1 ip) "." " ") 1)
     tmp_third_byte = (at (strreplace (player $arg1 ip) "." " ") 2)
     tmp_ipnum = ( + ( + ( * 65536 (tmp_first_byte) ) ( * 256 (tmp_second_byte) ) ) (tmp_third_byte) )
     
     //take IP of server for players with private IP
     if (|| (|| (&& (>= (tmp_ipnum) 655360) (<= (tmp_ipnum) 720895)) (&& (>= (tmp_ipnum) 11276288) (<= (tmp_ipnum) 11280383))) (&& (>= (tmp_ipnum) 12625920) (<= (tmp_ipnum) 12626175))) [              
       tmp_first_byte = (at (strreplace (curserver 1) "." " ") 0)
       tmp_second_byte = (at (strreplace (curserver 1) "." " ") 1)
       tmp_third_byte = (at (strreplace (curserver 1) "." " ") 2)
       tmp_ipnum = ( + ( + ( * 65536 (tmp_first_byte) ) ( * 256 (tmp_second_byte) ) ) (tmp_third_byte) )
echo 1
     ]

     i = 0
     j = 0

     persistidents 0
     alias tmp_geoip_ipnum [ getalias (concatword tmp_geoip_ipnum_ $tmp_first_byte) ]
     alias tmp_geoip_abbr [ getalias (concatword tmp_geoip_abbr_ $tmp_first_byte) ]
     persistidents 1
     
     alias tmp_length [ listlen (tmp_geoip_ipnum) ]
     alias tmp_search [ at (tmp_geoip_ipnum) (- $tmp_IP_position 1) ] //-1, because CubeScript starts from 0
     alias tmp_search_plus [ at (tmp_geoip_ipnum) $tmp_IP_position ]      

     //binary search algorithm
     while [&& (>= $i 0) (<= $j 19)][
       ++ j
       tmp_IP_position = (div (+ $i (tmp_length)) 2)  
       if (&& (>= $tmp_ipnum (tmp_search_plus)) (!= (- $tmp_IP_position $i) -1) )[ //find last country
         i = (+ $tmp_IP_position 1)
       ][
         if (< $tmp_ipnum (tmp_search))[
           tmp_length = (- $tmp_IP_position 1)        
         ][
           alias tmp_abbr (at (tmp_geoip_abbr) (- $tmp_IP_position 1)) //find country abbreviation                

           if (<= (strlen $tmp_abbr) 2)[ //if in this IP range is only 1 country
             tmp_player_country = (at $tmp_geoip_countrylist (+ (findlist $tmp_geoip_countrylist $tmp_abbr) 1) ) //find country name from abbreviation
           ][  //if in this IP range is more than 1 country
             if (= (strlen $tmp_abbr) 4)[
               tmp_player_country = ( concatword (at $tmp_geoip_countrylist (+ (findlist $tmp_geoip_countrylist (substr $tmp_abbr 0 2)) 1)) " or " (at $tmp_geoip_countrylist (+ (findlist $tmp_geoip_countrylist (substr $tmp_abbr 2 2)) 1)) )
             ][
               if (<= (strlen $tmp_abbr) 6)[
                 tmp_player_country = ( concatword (at $tmp_geoip_countrylist (+ (findlist $tmp_geoip_countrylist (substr $tmp_abbr 0 2)) 1)) " or " (at $tmp_geoip_countrylist (+ (findlist $tmp_geoip_countrylist (substr $tmp_abbr 2 2)) 1)) " or " (at $tmp_geoip_countrylist (+ (findlist $tmp_geoip_countrylist (substr $tmp_abbr 4 2)) 1)) )
               ][
                 tmp_player_country = (concatword "one of " (div (strlen $tmp_abbr) 2) " countries")
               ]
             ]
           ]          
           break          
         ]
       ]
     ] //end of binary search algorithm

     if (= $j 20) [tmp_player_country = "nowhere"]
     if (= $arg2 1) [tmp_player_ip = ""][tmp_player_ip = (concatword (c Y) "(" (player $arg1 ip) ")")]
     echo (c Y) (player $arg1 name) (c Y) (concatword "(" $arg1 ")") (c Y) "connected from" (c Y) $tmp_player_country $tmp_player_ip
   ][
     echo "geoIP info: this client number" $arg1 "is your number"
   ]
 ][
   echo "geoIP info: this client number" $arg1 "isn't valid"
 ]
]

alias "geoipall" [ loop i (curplayers) [if (&& (= (isclient $i) 1) (!= $i (player1 cn))) [ geoip $i $arg1]] ]

Note: if you want to use the last version of abandoned GeoLite database from https://dev.maxmind.com/geoip/legacy/geolite/ instead of newer GeoLite2 database, please use the attachments from the following package: geoip_AC_attachments_2018_03_27.zip
Thanks given by: D3M0NW0LF
#2
Instruction for preparing geoip database for geoip script (for Linux):

I. Instruction for GeoLite2 database by MaxMind:

II. Instruction for abandoned GeoLite database by MaxMind:
Thanks given by:
#3
I'm glad to see this being updated finally after all this time. Thank you grenadier! :)

Thanks given by:
#4
Only database is updated, but I posted the script here, because Akimbo is down, and it can help to recognize impersonators (btw impersonator can be also from the same country what "true" player).

PS. It seems to me that I used .txt extension for database intentionally, in order to they will be different than .cfg files with the scripts. :)
Thanks given by:
#5
I just updated the geoip database - it is now from GeoLite2 database from 23.10.2018.
You don't have to upgrade the script in autoexec.cfg, the only change in v. 4.2 are credits and colours when player can be from more than one country.

PS. Previously used GeoLite is abandoned by MaxMind (last version of GeoLite is from 27.03.2018), I left it in the first post.
Thanks given by:
#6
The geoip database became updated, it's is from GeoLite2 database from 24.12.2019.
You don't have to upgrade the script in autoexec.cfg.
Thanks given by: RandomPanda