init
commit
812fbe9f4e
|
@ -0,0 +1,21 @@
|
|||
helloip country locator
|
||||
minetest 0.4.15+
|
||||
(c) 2017 rnd
|
||||
|
||||
|
||||
INSTRUCTIONS: uncompress 14mb data from dbip-country-2017-03.7z before use
|
||||
|
||||
---------------------------------------------------------------------
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
----------------------------------------------------------------------
|
|
@ -0,0 +1,249 @@
|
|||
Afghanistan AF AFG 004 ISO 3166-2:AF Yes
|
||||
Åland_Islands AX ALA 248 ISO 3166-2:AX No
|
||||
Albania AL ALB 008 ISO 3166-2:AL Yes
|
||||
Algeria DZ DZA 012 ISO 3166-2:DZ Yes
|
||||
American_Samoa AS ASM 016 ISO 3166-2:AS No
|
||||
Andorra AD AND 020 ISO 3166-2:AD Yes
|
||||
Angola AO AGO 024 ISO 3166-2:AO Yes
|
||||
Anguilla AI AIA 660 ISO 3166-2:AI No
|
||||
Antarctica AQ ATA 010 ISO 3166-2:AQ No
|
||||
Antigua_and_Barbuda AG ATG 028 ISO 3166-2:AG Yes
|
||||
Argentina AR ARG 032 ISO 3166-2:AR Yes
|
||||
Armenia AM ARM 051 ISO 3166-2:AM Yes
|
||||
Aruba AW ABW 533 ISO 3166-2:AW No
|
||||
Australia AU AUS 036 ISO 3166-2:AU Yes
|
||||
Austria AT AUT 040 ISO 3166-2:AT Yes
|
||||
Azerbaijan AZ AZE 031 ISO 3166-2:AZ Yes
|
||||
Bahamas BS BHS 044 ISO 3166-2:BS Yes
|
||||
Bahrain BH BHR 048 ISO 3166-2:BH Yes
|
||||
Bangladesh BD BGD 050 ISO 3166-2:BD Yes
|
||||
Barbados BB BRB 052 ISO 3166-2:BB Yes
|
||||
Belarus BY BLR 112 ISO 3166-2:BY Yes
|
||||
Belgium BE BEL 056 ISO 3166-2:BE Yes
|
||||
Belize BZ BLZ 084 ISO 3166-2:BZ Yes
|
||||
Benin BJ BEN 204 ISO 3166-2:BJ Yes
|
||||
Bermuda BM BMU 060 ISO 3166-2:BM No
|
||||
Bhutan BT BTN 064 ISO 3166-2:BT Yes
|
||||
Bolivia_(Plurinational_State_of) BO BOL 068 ISO 3166-2:BO Yes
|
||||
Bonaire,_Sint_Eustatius_and_Saba BQ BES 535 ISO 3166-2:BQ No
|
||||
Bosnia_and_Herzegovina BA BIH 070 ISO 3166-2:BA Yes
|
||||
Botswana BW BWA 072 ISO 3166-2:BW Yes
|
||||
Bouvet Island BV BVT 074 ISO 3166-2:BV No
|
||||
Brazil BR BRA 076 ISO 3166-2:BR Yes
|
||||
British_Indian_Ocean_Territory IO IOT 086 ISO 3166-2:IO No
|
||||
Brunei_Darussalam BN BRN 096 ISO 3166-2:BN Yes
|
||||
Bulgaria BG BGR 100 ISO 3166-2:BG Yes
|
||||
Burkina_Faso BF BFA 854 ISO 3166-2:BF Yes
|
||||
Burundi BI BDI 108 ISO 3166-2:BI Yes
|
||||
Cabo_Verde CV CPV 132 ISO 3166-2:CV Yes
|
||||
Cambodia KH KHM 116 ISO 3166-2:KH Yes
|
||||
Cameroon CM CMR 120 ISO 3166-2:CM Yes
|
||||
Canada CA CAN 124 ISO 3166-2:CA Yes
|
||||
Cayman_Islands KY CYM 136 ISO 3166-2:KY Yes
|
||||
Central_African_Republic CF CAF 140 ISO 3166-2:CF Yes
|
||||
Chad TD TCD 148 ISO 3166-2:TD Yes
|
||||
Chile CL CHL 152 ISO 3166-2:CL Yes
|
||||
China CN CHN 156 ISO 3166-2:CN Yes
|
||||
Christmas_Island CX CXR 162 ISO 3166-2:CX No
|
||||
Cocos_(Keeling)_Islands CC CCK 166 ISO 3166-2:CC No
|
||||
Colombia CO COL 170 ISO 3166-2:CO Yes
|
||||
Comoros KM COM 174 ISO 3166-2:KM Yes
|
||||
Congo CG COG 178 ISO 3166-2:CG Yes
|
||||
Congo_(Democratic_Republic_of_the) CD COD 180 ISO 3166-2:CD Yes
|
||||
Cook_Islands CK COK 184 ISO 3166-2:CK No
|
||||
Costa_Rica CR CRI 188 ISO 3166-2:CR Yes
|
||||
Côte_d'Ivoire CI CIV 384 ISO 3166-2:CI Yes
|
||||
Croatia HR HRV 191 ISO 3166-2:HR Yes
|
||||
Cuba CU CUB 192 ISO 3166-2:CU Yes
|
||||
Curaçao CW CUW 531 ISO 3166-2:CW No
|
||||
Cyprus CY CYP 196 ISO 3166-2:CY Yes
|
||||
Czechia CZ CZE 203 ISO 3166-2:CZ Yes
|
||||
Denmark DK DNK 208 ISO 3166-2:DK Yes
|
||||
Djibouti DJ DJI 262 ISO 3166-2:DJ Yes
|
||||
Dominica DM DMA 212 ISO 3166-2:DM Yes
|
||||
Dominican_Republic DO DOM 214 ISO 3166-2:DO Yes
|
||||
Ecuador EC ECU 218 ISO 3166-2:EC Yes
|
||||
Egypt EG EGY 818 ISO 3166-2:EG Yes
|
||||
El_Salvador SV SLV 222 ISO 3166-2:SV Yes
|
||||
Equatorial_Guinea GQ GNQ 226 ISO 3166-2:GQ Yes
|
||||
Eritrea ER ERI 232 ISO 3166-2:ER Yes
|
||||
Estonia EE EST 233 ISO 3166-2:EE Yes
|
||||
Ethiopia ET ETH 231 ISO 3166-2:ET Yes
|
||||
Falkland_Islands_(Malvinas) FK FLK 238 ISO 3166-2:FK No
|
||||
Faroe_Islands FO FRO 234 ISO 3166-2:FO No
|
||||
Fiji FJ FJI 242 ISO 3166-2:FJ Yes
|
||||
Finland FI FIN 246 ISO 3166-2:FI Yes
|
||||
France FR FRA 250 ISO 3166-2:FR Yes
|
||||
French_Guiana GF GUF 254 ISO 3166-2:GF No
|
||||
French_Polynesia PF PYF 258 ISO 3166-2:PF No
|
||||
French_Southern_Territories TF ATF 260 ISO 3166-2:TF No
|
||||
Gabon GA GAB 266 ISO 3166-2:GA Yes
|
||||
Gambia GM GMB 270 ISO 3166-2:GM Yes
|
||||
Georgia GE GEO 268 ISO 3166-2:GE Yes
|
||||
Germany DE DEU 276 ISO 3166-2:DE Yes
|
||||
Ghana GH GHA 288 ISO 3166-2:GH Yes
|
||||
Gibraltar GI GIB 292 ISO 3166-2:GI Yes
|
||||
Greece GR GRC 300 ISO 3166-2:GR Yes
|
||||
Greenland GL GRL 304 ISO 3166-2:GL No
|
||||
Grenada GD GRD 308 ISO 3166-2:GD Yes
|
||||
Guadeloupe GP GLP 312 ISO 3166-2:GP No
|
||||
Guam GU GUM 316 ISO 3166-2:GU No
|
||||
Guatemala GT GTM 320 ISO 3166-2:GT Yes
|
||||
Guernsey GG GGY 831 ISO 3166-2:GG No
|
||||
Guinea GN GIN 324 ISO 3166-2:GN Yes
|
||||
Guinea-Bissau GW GNB 624 ISO 3166-2:GW Yes
|
||||
Guyana GY GUY 328 ISO 3166-2:GY Yes
|
||||
Haiti HT HTI 332 ISO 3166-2:HT Yes
|
||||
Heard_Island_and_McDonald_Islands HM HMD 334 ISO 3166-2:HM No
|
||||
Holy_See VA VAT 336 ISO 3166-2:VA Yes
|
||||
Honduras HN HND 340 ISO 3166-2:HN Yes
|
||||
Hong_Kong HK HKG 344 ISO 3166-2:HK No
|
||||
Hungary HU HUN 348 ISO 3166-2:HU Yes
|
||||
Iceland IS ISL 352 ISO 3166-2:IS Yes
|
||||
India IN IND 356 ISO 3166-2:IN Yes
|
||||
Indonesia ID IDN 360 ISO 3166-2:ID Yes
|
||||
Iran_(Islamic_Republic_of) IR IRN 364 ISO 3166-2:IR Yes
|
||||
Iraq IQ IRQ 368 ISO 3166-2:IQ Yes
|
||||
Ireland IE IRL 372 ISO 3166-2:IE Yes
|
||||
Isle_of_Man IM IMN 833 ISO 3166-2:IM No
|
||||
Israel IL ISR 376 ISO 3166-2:IL Yes
|
||||
Italy IT ITA 380 ISO 3166-2:IT Yes
|
||||
Jamaica JM JAM 388 ISO 3166-2:JM Yes
|
||||
Japan JP JPN 392 ISO 3166-2:JP Yes
|
||||
Jersey JE JEY 832 ISO 3166-2:JE No
|
||||
Jordan JO JOR 400 ISO 3166-2:JO Yes
|
||||
Kazakhstan KZ KAZ 398 ISO 3166-2:KZ Yes
|
||||
Kenya KE KEN 404 ISO 3166-2:KE Yes
|
||||
Kiribati KI KIR 296 ISO 3166-2:KI Yes
|
||||
Korea_(Democratic_People's_Republic_of) KP PRK 408 ISO 3166-2:KP Yes
|
||||
Korea_(Republic_of) KR KOR 410 ISO 3166-2:KR Yes
|
||||
Kuwait KW KWT 414 ISO 3166-2:KW Yes
|
||||
Kyrgyzstan KG KGZ 417 ISO 3166-2:KG Yes
|
||||
Lao_People's_Democratic_Republic LA LAO 418 ISO 3166-2:LA Yes
|
||||
Latvia LV LVA 428 ISO 3166-2:LV Yes
|
||||
Lebanon LB LBN 422 ISO 3166-2:LB Yes
|
||||
Lesotho LS LSO 426 ISO 3166-2:LS Yes
|
||||
Liberia LR LBR 430 ISO 3166-2:LR Yes
|
||||
Libya LY LBY 434 ISO 3166-2:LY Yes
|
||||
Liechtenstein LI LIE 438 ISO 3166-2:LI Yes
|
||||
Lithuania LT LTU 440 ISO 3166-2:LT Yes
|
||||
Luxembourg LU LUX 442 ISO 3166-2:LU Yes
|
||||
Macao MO MAC 446 ISO 3166-2:MO No
|
||||
Macedonia_(the_former_Yugoslav_Republic_of) MK MKD 807 ISO 3166-2:MK Yes
|
||||
Madagascar MG MDG 450 ISO 3166-2:MG Yes
|
||||
Malawi MW MWI 454 ISO 3166-2:MW Yes
|
||||
Malaysia MY MYS 458 ISO 3166-2:MY Yes
|
||||
Maldives MV MDV 462 ISO 3166-2:MV Yes
|
||||
Mali ML MLI 466 ISO 3166-2:ML Yes
|
||||
Malta MT MLT 470 ISO 3166-2:MT Yes
|
||||
Marshall_Islands MH MHL 584 ISO 3166-2:MH Yes
|
||||
Martinique MQ MTQ 474 ISO 3166-2:MQ No
|
||||
Mauritania MR MRT 478 ISO 3166-2:MR Yes
|
||||
Mauritius MU MUS 480 ISO 3166-2:MU Yes
|
||||
Mayotte YT MYT 175 ISO 3166-2:YT No
|
||||
Mexico MX MEX 484 ISO 3166-2:MX Yes
|
||||
Micronesia_(Federated_States_of) FM FSM 583 ISO 3166-2:FM Yes
|
||||
Moldova_(Republic_of) MD MDA 498 ISO 3166-2:MD Yes
|
||||
Monaco MC MCO 492 ISO 3166-2:MC Yes
|
||||
Mongolia MN MNG 496 ISO 3166-2:MN Yes
|
||||
Montenegro ME MNE 499 ISO 3166-2:ME Yes
|
||||
Montserrat MS MSR 500 ISO 3166-2:MS No
|
||||
Morocco MA MAR 504 ISO 3166-2:MA Yes
|
||||
Mozambique MZ MOZ 508 ISO 3166-2:MZ Yes
|
||||
Myanmar MM MMR 104 ISO 3166-2:MM Yes
|
||||
Namibia NA NAM 516 ISO 3166-2:NA Yes
|
||||
Nauru NR NRU 520 ISO 3166-2:NR Yes
|
||||
Nepal NP NPL 524 ISO 3166-2:NP Yes
|
||||
Netherlands NL NLD 528 ISO 3166-2:NL Yes
|
||||
New_Caledonia NC NCL 540 ISO 3166-2:NC No
|
||||
New_Zealand NZ NZL 554 ISO 3166-2:NZ Yes
|
||||
Nicaragua NI NIC 558 ISO 3166-2:NI Yes
|
||||
Niger NE NER 562 ISO 3166-2:NE Yes
|
||||
Nigeria NG NGA 566 ISO 3166-2:NG Yes
|
||||
Niue NU NIU 570 ISO 3166-2:NU No
|
||||
Norfolk_Island NF NFK 574 ISO 3166-2:NF No
|
||||
Northern_Mariana_Islands MP MNP 580 ISO 3166-2:MP No
|
||||
Norway NO NOR 578 ISO 3166-2:NO Yes
|
||||
Oman OM OMN 512 ISO 3166-2:OM Yes
|
||||
Pakistan PK PAK 586 ISO 3166-2:PK Yes
|
||||
Palau PW PLW 585 ISO 3166-2:PW Yes
|
||||
Palestine,_State_of PS PSE 275 ISO 3166-2:PS No
|
||||
Panama PA PAN 591 ISO 3166-2:PA Yes
|
||||
Papua_New_Guinea PG PNG 598 ISO 3166-2:PG Yes
|
||||
Paraguay PY PRY 600 ISO 3166-2:PY Yes
|
||||
Peru PE PER 604 ISO 3166-2:PE Yes
|
||||
Philippines PH PHL 608 ISO 3166-2:PH Yes
|
||||
Pitcairn PN PCN 612 ISO 3166-2:PN No
|
||||
Poland PL POL 616 ISO 3166-2:PL Yes
|
||||
Portugal PT PRT 620 ISO 3166-2:PT Yes
|
||||
Puerto_Rico PR PRI 630 ISO 3166-2:PR No
|
||||
Qatar QA QAT 634 ISO 3166-2:QA Yes
|
||||
Réunion RE REU 638 ISO 3166-2:RE No
|
||||
Romania RO ROU 642 ISO 3166-2:RO Yes
|
||||
Russian_Federation RU RUS 643 ISO 3166-2:RU Yes
|
||||
Rwanda RW RWA 646 ISO 3166-2:RW Yes
|
||||
Saint_Barthélemy BL BLM 652 ISO 3166-2:BL No
|
||||
Saint_Helena,_Ascension_and_Tristan_da_Cunha SH SHN 654 ISO 3166-2:SH No
|
||||
Saint_Kitts_and_Nevis KN KNA 659 ISO 3166-2:KN Yes
|
||||
Saint_Lucia LC LCA 662 ISO 3166-2:LC Yes
|
||||
Saint_Martin_(French_part) MF MAF 663 ISO 3166-2:MF No
|
||||
Saint_Pierre_and_Miquelon PM SPM 666 ISO 3166-2:PM No
|
||||
Saint_Vincent_and_the_Grenadines VC VCT 670 ISO 3166-2:VC Yes
|
||||
Samoa WS WSM 882 ISO 3166-2:WS Yes
|
||||
San_Marino SM SMR 674 ISO 3166-2:SM Yes
|
||||
Sao_Tome_and_Principe ST STP 678 ISO 3166-2:ST Yes
|
||||
Saudi_Arabia SA SAU 682 ISO 3166-2:SA Yes
|
||||
Senegal SN SEN 686 ISO 3166-2:SN Yes
|
||||
Serbia RS SRB 688 ISO 3166-2:RS Yes
|
||||
Seychelles SC SYC 690 ISO 3166-2:SC Yes
|
||||
Sierra_Leone SL SLE 694 ISO 3166-2:SL Yes
|
||||
Singapore SG SGP 702 ISO 3166-2:SG Yes
|
||||
Sint_Maarten_(Dutch_part) SX SXM 534 ISO 3166-2:SX No
|
||||
Slovakia SK SVK 703 ISO 3166-2:SK Yes
|
||||
Slovenia SI SVN 705 ISO 3166-2:SI Yes
|
||||
Solomon_Islands SB SLB 090 ISO 3166-2:SB Yes
|
||||
Somalia SO SOM 706 ISO 3166-2:SO Yes
|
||||
South_Africa ZA ZAF 710 ISO 3166-2:ZA Yes
|
||||
South_Georgia_and_the_South_Sandwich_Islands GS SGS 239 ISO 3166-2:GS No
|
||||
South_Sudan SS SSD 728 ISO 3166-2:SS Yes
|
||||
Spain ES ESP 724 ISO 3166-2:ES Yes
|
||||
Sri_Lanka LK LKA 144 ISO 3166-2:LK Yes
|
||||
Sudan SD SDN 729 ISO 3166-2:SD Yes
|
||||
Suriname SR SUR 740 ISO 3166-2:SR Yes
|
||||
Svalbard_and_Jan_Mayen SJ SJM 744 ISO 3166-2:SJ No
|
||||
Swaziland SZ SWZ 748 ISO 3166-2:SZ Yes
|
||||
Sweden SE SWE 752 ISO 3166-2:SE Yes
|
||||
Switzerland CH CHE 756 ISO 3166-2:CH Yes
|
||||
Syrian_Arab_Republic SY SYR 760 ISO 3166-2:SY Yes
|
||||
Taiwan,_Province_of_China[a] TW TWN 158 ISO 3166-2:TW No
|
||||
Tajikistan TJ TJK 762 ISO 3166-2:TJ Yes
|
||||
Tanzania,_United_Republic_of TZ TZA 834 ISO 3166-2:TZ Yes
|
||||
Thailand TH THA 764 ISO 3166-2:TH Yes
|
||||
Timor-Leste TL TLS 626 ISO 3166-2:TL Yes
|
||||
Togo TG TGO 768 ISO 3166-2:TG Yes
|
||||
Tokelau TK TKL 772 ISO 3166-2:TK No
|
||||
Tonga TO TON 776 ISO 3166-2:TO Yes
|
||||
Trinidad_and_Tobago TT TTO 780 ISO 3166-2:TT Yes
|
||||
Tunisia TN TUN 788 ISO 3166-2:TN Yes
|
||||
Turkey TR TUR 792 ISO 3166-2:TR Yes
|
||||
Turkmenistan TM TKM 795 ISO 3166-2:TM Yes
|
||||
Turks_and_Caicos_Islands TC TCA 796 ISO 3166-2:TC No
|
||||
Tuvalu TV TUV 798 ISO 3166-2:TV Yes
|
||||
Uganda UG UGA 800 ISO 3166-2:UG Yes
|
||||
Ukraine UA UKR 804 ISO 3166-2:UA Yes
|
||||
United_Arab_Emirates AE ARE 784 ISO 3166-2:AE Yes
|
||||
United_Kingdom_of_Great_Britain_and_Northern_Ireland GB GBR 826 ISO 3166-2:GB Yes
|
||||
United_States_of_America US USA 840 ISO 3166-2:US Yes
|
||||
United_States_Minor_Outlying_Islands UM UMI 581 ISO 3166-2:UM No
|
||||
Uruguay UY URY 858 ISO 3166-2:UY Yes
|
||||
Uzbekistan UZ UZB 860 ISO 3166-2:UZ Yes
|
||||
Vanuatu VU VUT 548 ISO 3166-2:VU Yes
|
||||
Venezuela_(Bolivarian_Republic_of) VE VEN 862 ISO 3166-2:VE Yes
|
||||
Viet_Nam VN VNM 704 ISO 3166-2:VN Yes
|
||||
Virgin_Islands_(British) VG VGB 092 ISO 3166-2:VG No
|
||||
Virgin_Islands_(U.S.) VI VIR 850 ISO 3166-2:VI No
|
||||
Wallis_and_Futuna WF WLF 876 ISO 3166-2:WF No
|
||||
Western_Sahara EH ESH 732 ISO 3166-2:EH No
|
||||
Yemen YE YEM 887 ISO 3166-2:YE Yes
|
||||
Zambia ZM ZMB 894 ISO 3166-2:ZM Yes
|
||||
Zimbabwe ZW ZWE 716 ISO 3166-2:ZW Yes
|
Binary file not shown.
|
@ -0,0 +1,129 @@
|
|||
-- rnd 2017
|
||||
-- helloip country locator
|
||||
|
||||
helloip = {};
|
||||
local modpath = minetest.get_modpath("helloip")
|
||||
|
||||
-- load csv db
|
||||
local f = assert(io.open(modpath .. "\\dbip-country-2017-03.csv", "r"))
|
||||
local csv = f:read("*all")
|
||||
f:close()
|
||||
|
||||
|
||||
local ip2num = function(ip)
|
||||
local i1 = string.find(ip,".",1,true)
|
||||
local i2 = string.find(ip,".",i1+1,true)
|
||||
local i3 = string.find(ip,".",i2+1,true)
|
||||
local ip1 = tonumber(string.sub(ip,1,i1-1)) or 0
|
||||
local ip2 = tonumber(string.sub(ip,i1+1,i2-1)) or 0
|
||||
local ip3 = tonumber(string.sub(ip,i2+1,i3-1)) or 0
|
||||
local ip4 = tonumber(string.sub(ip,i3+1)) or 0
|
||||
return ip1*256^3+ip2*256^2+ ip3*256+ ip4
|
||||
end
|
||||
|
||||
local iplookup = function(ip) -- ip is as number, returns index of entry or 0
|
||||
local entry = 0
|
||||
local i1=1;
|
||||
local i3 = #helloip;
|
||||
local step = 0
|
||||
|
||||
while i3-i1>0 and step < 100 do
|
||||
step = step + 1
|
||||
local i2 = math.floor((i1+i3)/2)
|
||||
|
||||
local iplow = helloip[i2][1];
|
||||
local iphigh = helloip[i2][2];
|
||||
if ip>=iplow and ip <=iphigh then entry = i2; break; end
|
||||
if i3-i1 == 1 then break end
|
||||
|
||||
if ip > iphigh then -- right
|
||||
i1 = i2
|
||||
else -- left
|
||||
i3 = i2
|
||||
end
|
||||
end
|
||||
|
||||
return entry
|
||||
end
|
||||
|
||||
|
||||
print("#helloip: parsing csv")
|
||||
|
||||
-- parse csv into db
|
||||
local step = 0;
|
||||
local i = 0
|
||||
local i1,i2,i3
|
||||
|
||||
while i and step < 10^6 do
|
||||
step=step+1
|
||||
i1 = string.find(csv,",",i+1)
|
||||
i2 = string.find(csv,",",i1+1)
|
||||
i3 = string.find(csv, "\n", i2+1)
|
||||
if not i3 then break end
|
||||
|
||||
local ipmin = ip2num(string.sub(csv, i+2,i1-2))
|
||||
local ipmax = ip2num(string.sub(csv, i1+2,i2-2))
|
||||
local ccode = string.sub(csv, i2+2,i3-2);
|
||||
helloip[step] = {ipmin,ipmax,ccode};
|
||||
i=i3
|
||||
end
|
||||
print("#helloip: ".. step .. " ip range entries loaded.")
|
||||
|
||||
|
||||
|
||||
-- load country codelist from ccode.txt
|
||||
-- copied as text from https://en.wikipedia.org/wiki/ISO_3166-1
|
||||
|
||||
local f = assert(io.open(modpath .. "\\ccode.txt", "r"))
|
||||
local cc = f:read("*all");f:close()
|
||||
local ccodes = {}
|
||||
|
||||
local step = 0;
|
||||
local i = 0
|
||||
local i1,i2,i3
|
||||
|
||||
while i and step < 10^3 do
|
||||
step=step+1
|
||||
i1 = string.find(cc," ",i+1)
|
||||
i2 = string.find(cc," ",i1+1)
|
||||
i3 = string.find(cc, "\n", i1+1)
|
||||
if not i3 then break end
|
||||
|
||||
local cname = string.sub(cc, i+1,i1-1)
|
||||
local ccode = string.sub(cc, i1+2,i2-1)
|
||||
ccodes[ccode] = cname
|
||||
i=i3
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("ip", {
|
||||
description = "",
|
||||
privs = {
|
||||
privs = kick
|
||||
},
|
||||
func = function(name, param)
|
||||
|
||||
local ip = param or "0.0.0.0";
|
||||
local _, count = string.gsub(ip, "%.", "") -- how many dots
|
||||
if count ~= 3 then ip = "0.0.0.0" end
|
||||
|
||||
minetest.chat_send_player(name,"looking up ip " .. ip .. "=" .. ip2num(ip) )
|
||||
local entry = iplookup(ip2num(ip)) or 0
|
||||
if entry > 0 then
|
||||
local hentry = helloip[entry] or {0,0,"?"};
|
||||
minetest.chat_send_player(name, ccodes[hentry[3]] or "unknown")
|
||||
end
|
||||
end
|
||||
});
|
||||
|
||||
minetest.register_on_joinplayer(
|
||||
function(player)
|
||||
local name = player:get_player_name();
|
||||
local ip = minetest.get_player_ip(name);
|
||||
local entry = iplookup(ip2num(ip))
|
||||
if entry > 0 then
|
||||
local hentry = helloip[entry] or {0,0,"?"};
|
||||
local country = ccodes[hentry[3]] or "unknown";
|
||||
minetest.chat_send_all("welcome " .. name .. " from " .. country)
|
||||
end
|
||||
end
|
||||
)
|
Loading…
Reference in New Issue