PDA

View Full Version : [advanced] Find player's country-of-origin



IzNoGoD
29th December 2013, 21:42
Hey all,

Another part of the JumpersHeaven mod is here: !country [player], but in a different form.

What this script will do is determine a player's ip-address using libcod, then execute a mysql command to search a table containing ip-country linked items.

Script:


getcountry()
{
ip = self std\player::getip();
ip_parts = [];
part = 0;
ip_parts[part] = "";
prev_found = 0;
for(i = 0; i < ip.size; i++)
{
if(ip[i] != ".")
ip_parts[part] += ip[i];
else
{
part++;
ip_parts[part] = "";
}
}
multi = 1;
num = 0;
for(i = ip_parts.size - 1; i >= 0; i--)
{
num += int(ip_parts[i]) * multi;
multi *= 256;
}
result = mysql_wrapper("SELECT country FROM countries WHERE ip < " + num + " ORDER BY ip DESC LIMIT 1", true);
if(isdefined(result))
{
rowcount = mysql_num_rows(result);
if(rowcount)
{
row = mysql_fetch_row(result);
if(isdefined(row[0]))
self.country = row[0];
}
mysql_free_result(result);
}
}

mysql_wrapper(query, save)
{
ret = mysql_query(level.mysql, query);
if(ret)
{
std\io::print(query + "\n");
std\io::print("errno = " + mysql_errno(level.mysql) + " error = " + mysql_error(level.mysql) + "\n");
mysql_close(level.mysql);
return undefined;
}
if(save)
{
result = mysql_store_result(level.mysql);
return result;
}
else
return undefined;
}

This obviously requires mysql running and configured (see level.mysql var in mysql_wrapper()), and libcod.

Database (import this in your favorite tool, be it heidiSQL or phpmyadmin):
(see attachment)

IzNoGoD
22nd April 2014, 21:20
Updated the database, for anyone thats interested.

php
23rd April 2014, 10:46
Not sure if this can be done easier, but I generated a small list of a website which had the shortcodes and full names.



get_country_full() {
if(!isdefined(level.countries)) {
list = [];
list["AD"] = "Andorra";
list["AE"] = "United Arab Emirates";
list["AF"] = "Afghanistan";
list["AG"] = "Antigua and Barbuda";
list["AI"] = "Anguilla";
list["AL"] = "Albania";
list["AM"] = "Armenia";
list["AO"] = "Angola";
list["AQ"] = "Antarctica";
list["AR"] = "Argentina";
list["AS"] = "American Samoa";
list["AT"] = "Austria";
list["AU"] = "Australia";
list["AW"] = "Aruba";
list["AX"] = "Åland Islands";
list["AZ"] = "Azerbaijan";
list["BA"] = "Bosnia and Herzegovina";
list["BB"] = "Barbados";
list["BD"] = "Bangladesh";
list["BE"] = "Belgium";
list["BF"] = "Burkina Faso";
list["BG"] = "Bulgaria";
list["BH"] = "Bahrain";
list["BI"] = "Burundi";
list["BJ"] = "Benin";
list["BL"] = "Saint Barthélemy";
list["BM"] = "Bermuda";
list["BN"] = "Brunei Darussalam";
list["BO"] = "Bolivia, Plurinational State of";
list["BQ"] = "Bonaire, Sint Eustatius and Saba";
list["BR"] = "Brazil";
list["BS"] = "Bahamas";
list["BT"] = "Bhutan";
list["BV"] = "Bouvet Island";
list["BW"] = "Botswana";
list["BY"] = "Belarus";
list["BZ"] = "Belize";
list["CA"] = "Canada";
list["CC"] = "Cocos (Keeling) Islands";
list["CD"] = "Congo, the Democratic Republic of the";
list["CF"] = "Central African Republic";
list["CG"] = "Congo";
list["CH"] = "Switzerland";
list["CI"] = "Côte d'Ivoire";
list["CK"] = "Cook Islands";
list["CL"] = "Chile";
list["CM"] = "Cameroon";
list["CN"] = "China";
list["CO"] = "Colombia";
list["CR"] = "Costa Rica";
list["CU"] = "Cuba";
list["CV"] = "Cape Verde";
list["CW"] = "Curaçao";
list["CX"] = "Christmas Island";
list["CY"] = "Cyprus";
list["CZ"] = "Czech Republic";
list["DE"] = "Germany";
list["DJ"] = "Djibouti";
list["DK"] = "Denmark";
list["DM"] = "Dominica";
list["DO"] = "Dominican Republic";
list["DZ"] = "Algeria";
list["EC"] = "Ecuador";
list["EE"] = "Estonia";
list["EG"] = "Egypt";
list["EH"] = "Western Sahara";
list["ER"] = "Eritrea";
list["ES"] = "Spain";
list["ET"] = "Ethiopia";
list["FI"] = "Finland";
list["FJ"] = "Fiji";
list["FK"] = "Falkland Islands (Malvinas)";
list["FM"] = "Micronesia, Federated States of";
list["FO"] = "Faroe Islands";
list["FR"] = "France";
list["GA"] = "Gabon";
list["GB"] = "United Kingdom";
list["GD"] = "Grenada";
list["GE"] = "Georgia";
list["GF"] = "French Guiana";
list["GG"] = "Guernsey";
list["GH"] = "Ghana";
list["GI"] = "Gibraltar";
list["GL"] = "Greenland";
list["GM"] = "Gambia";
list["GN"] = "Guinea";
list["GP"] = "Guadeloupe";
list["GQ"] = "Equatorial Guinea";
list["GR"] = "Greece";
list["GS"] = "South Georgia and the South Sandwich Islands";
list["GT"] = "Guatemala";
list["GU"] = "Guam";
list["GW"] = "Guinea-Bissau";
list["GY"] = "Guyana";
list["HK"] = "Hong Kong";
list["HM"] = "Heard Island and McDonald Islands";
list["HN"] = "Honduras";
list["HR"] = "Croatia";
list["HT"] = "Haiti";
list["HU"] = "Hungary";
list["ID"] = "Indonesia";
list["IE"] = "Ireland";
list["IL"] = "Israel";
list["IM"] = "Isle of Man";
list["IN"] = "India";
list["IO"] = "British Indian Ocean Territory";
list["IQ"] = "Iraq";
list["IR"] = "Iran, Islamic Republic of";
list["IS"] = "Iceland";
list["IT"] = "Italy";
list["JE"] = "Jersey";
list["JM"] = "Jamaica";
list["JO"] = "Jordan";
list["JP"] = "Japan";
list["KE"] = "Kenya";
list["KG"] = "Kyrgyzstan";
list["KH"] = "Cambodia";
list["KI"] = "Kiribati";
list["KM"] = "Comoros";
list["KN"] = "Saint Kitts and Nevis";
list["KP"] = "Korea, Democratic People's Republic of";
list["KR"] = "Korea, Republic of";
list["KW"] = "Kuwait";
list["KY"] = "Cayman Islands";
list["KZ"] = "Kazakhstan";
list["LA"] = "Lao People's Democratic Republic";
list["LB"] = "Lebanon";
list["LC"] = "Saint Lucia";
list["LI"] = "Liechtenstein";
list["LK"] = "Sri Lanka";
list["LR"] = "Liberia";
list["LS"] = "Lesotho";
list["LT"] = "Lithuania";
list["LU"] = "Luxembourg";
list["LV"] = "Latvia";
list["LY"] = "Libyan Arab Jamahiriya";
list["MA"] = "Morocco";
list["MC"] = "Monaco";
list["MD"] = "Moldova, Republic of";
list["ME"] = "Montenegro";
list["MF"] = "Saint Martin (French part)";
list["MG"] = "Madagascar";
list["MH"] = "Marshall Islands";
list["MK"] = "Macedonia, the former Yugoslav Republic of";
list["ML"] = "Mali";
list["MM"] = "Myanmar";
list["MN"] = "Mongolia";
list["MO"] = "Macao";
list["MP"] = "Northern Mariana Islands";
list["MQ"] = "Martinique";
list["MR"] = "Mauritania";
list["MS"] = "Montserrat";
list["MT"] = "Malta";
list["MU"] = "Mauritius";
list["MV"] = "Maldives";
list["MW"] = "Malawi";
list["MX"] = "Mexico";
list["MY"] = "Malaysia";
list["MZ"] = "Mozambique";
list["NA"] = "Namibia";
list["NC"] = "New Caledonia";
list["NE"] = "Niger";
list["NF"] = "Norfolk Island";
list["NG"] = "Nigeria";
list["NI"] = "Nicaragua";
list["NL"] = "Netherlands";
list["NO"] = "Norway";
list["NP"] = "Nepal";
list["NR"] = "Nauru";
list["NU"] = "Niue";
list["NZ"] = "New Zealand";
list["OM"] = "Oman";
list["PA"] = "Panama";
list["PE"] = "Peru";
list["PF"] = "French Polynesia";
list["PG"] = "Papua New Guinea";
list["PH"] = "Philippines";
list["PK"] = "Pakistan";
list["PL"] = "Poland";
list["PM"] = "Saint Pierre and Miquelon";
list["PN"] = "Pitcairn";
list["PR"] = "Puerto Rico";
list["PS"] = "Palestinian Territory, Occupied";
list["PT"] = "Portugal";
list["PW"] = "Palau";
list["PY"] = "Paraguay";
list["QA"] = "Qatar";
list["RE"] = "Réunion";
list["RO"] = "Romania";
list["RS"] = "Serbia";
list["RU"] = "Russian Federation";
list["RW"] = "Rwanda";
list["SA"] = "Saudi Arabia";
list["SB"] = "Solomon Islands";
list["SC"] = "Seychelles";
list["SD"] = "Sudan";
list["SE"] = "Sweden";
list["SG"] = "Singapore";
list["SH"] = "Saint Helena, Ascension and Tristan da Cunha";
list["SI"] = "Slovenia";
list["SJ"] = "Svalbard and Jan Mayen";
list["SK"] = "Slovakia";
list["SL"] = "Sierra Leone";
list["SM"] = "San Marino";
list["SN"] = "Senegal";
list["SO"] = "Somalia";
list["SR"] = "Suriname";
list["ST"] = "Sao Tome and Principe";
list["SV"] = "El Salvador";
list["SX"] = "Sint Maarten (Dutch part)";
list["SY"] = "Syrian Arab Republic";
list["SZ"] = "Swaziland";
list["TC"] = "Turks and Caicos Islands";
list["TD"] = "Chad";
list["TF"] = "French Southern Territories";
list["TG"] = "Togo";
list["TH"] = "Thailand";
list["TJ"] = "Tajikistan";
list["TK"] = "Tokelau";
list["TL"] = "Timor-Leste";
list["TM"] = "Turkmenistan";
list["TN"] = "Tunisia";
list["TO"] = "Tonga";
list["TR"] = "Turkey";
list["TT"] = "Trinidad and Tobago";
list["TV"] = "Tuvalu";
list["TW"] = "Taiwan, Province of China";
list["TZ"] = "Tanzania, United Republic of";
list["UA"] = "Ukraine";
list["UG"] = "Uganda";
list["UM"] = "United States Minor Outlying Islands";
list["US"] = "United States";
list["UY"] = "Uruguay";
list["UZ"] = "Uzbekistan";
list["VA"] = "Holy See (Vatican City State)";
list["VC"] = "Saint Vincent and the Grenadines";
list["VE"] = "Venezuela, Bolivarian Republic of";
list["VG"] = "Virgin Islands, British";
list["VI"] = "Virgin Islands, U.S.";
list["VN"] = "Viet Nam";
list["VU"] = "Vanuatu";
list["WF"] = "Wallis and Futuna";
list["WS"] = "Samoa";
list["YE"] = "Yemen";
list["YT"] = "Mayotte";
list["ZA"] = "South Africa";
list["ZM"] = "Zambia";
list["ZW"] = "Zimbabwe";
level.countries = list;
}
c = self get_country();
if(isdefined(c)) {
if(isdefined(level.countries[c]))
return level.countries[c];
}
return undefined;
}

Jeplaa
23rd April 2014, 14:31
Also wrote full list-of-countries with their codes if someone need it: countries_array.js (https://github.com/Jeplaa/JavaScript/blob/master/countries_array.js)

IzNoGoD
23rd April 2014, 18:29
getlongcountry(c)
{
switch(c)
{
case "AD": return "Andorra";
case "AE": return "United Arab Emirates";
case "AF": return "Afghanistan";
case "AG": return "Antigua and Barbuda";
case "AL": return "Albania";
case "AM": return "Armenia";
case "AN": return "Netherlands Antilles";
case "AO": return "Angola";
case "AR": return "Argentina";
case "AT": return "Austria";
case "AU": return "Australia";
case "AW": return "Aruba";
case "AZ": return "Azerbaijan";
case "BA": return "Bosnia and Herzegowina";
case "BB": return "Barbados";
case "BD": return "Bangladesh";
case "BE": return "Belgium";
case "BF": return "Burkina Faso";
case "BG": return "Bulgaria";
case "BH": return "Bahrain";
case "BJ": return "Benin";
case "BM": return "Bermuda";
case "BN": return "Brunei Darussalam";
case "BO": return "Bolivia";
case "BR": return "Brazil";
case "BS": return "Bahamas";
case "BT": return "Bhutan";
case "BW": return "Botswana";
case "BY": return "Belarus";
case "BZ": return "Belize";
case "CA": return "Canada";
case "CD": return "Congo The Democratic Republic of The";
case "CF": return "Central African Republic";
case "CG": return "Congo";
case "CH": return "Switzerland";
case "CI": return "Cote D\'ivoire";
case "CL": return "Chile";
case "CM": return "Cameroon";
case "CN": return "China";
case "CO": return "Colombia";
case "CR": return "Costa Rica";
case "CU": return "Cuba";
case "CV": return "Cape Verde";
case "CY": return "Cyprus";
case "CZ": return "Czech Republic";
case "DE": return "Germany";
case "DJ": return "Djibouti";
case "DK": return "Denmark";
case "DO": return "Dominican Republic";
case "DZ": return "Algeria";
case "EC": return "Ecuador";
case "EE": return "Estonia";
case "EG": return "Egypt";
case "ES": return "Spain";
case "EU": return "European Union";
case "FI": return "Finland";
case "FJ": return "Fiji";
case "FM": return "Micronesia Federated States of";
case "FO": return "Faroe Islands";
case "FR": return "France";
case "GA": return "Gabon";
case "GB": return "United Kingdom";
case "GD": return "Grenada";
case "GE": return "Georgia";
case "GG": return "Guernsey";
case "GH": return "Ghana";
case "GI": return "Gibraltar";
case "GL": return "Greenland";
case "GM": return "Gambia";
case "GN": return "Guinea";
case "GQ": return "Equatorial Guinea";
case "GR": return "Greece";
case "GT": return "Guatemala";
case "GU": return "Guam";
case "GY": return "Guyana";
case "HK": return "Hong Kong";
case "HN": return "Honduras";
case "HR": return "Croatia (LOCAL Name: Hrvatska)";
case "HT": return "Haiti";
case "HU": return "Hungary";
case "ID": return "Indonesia";
case "IE": return "Ireland";
case "IL": return "Israel";
case "IM": return "Isle of Man";
case "IN": return "India";
case "IQ": return "Iraq";
case "IR": return "Iran (ISLAMIC Republic Of)";
case "IS": return "Iceland";
case "IT": return "Italy";
case "JE": return "Jersey";
case "JM": return "Jamaica";
case "JO": return "Jordan";
case "JP": return "Japan";
case "KE": return "Kenya";
case "KG": return "Kyrgyzstan";
case "KH": return "Cambodia";
case "KP": return "Korea Democratic People\'s Republic of";
case "KR": return "Korea Republic of";
case "KW": return "Kuwait";
case "KY": return "Cayman Islands";
case "KZ": return "Kazakhstan";
case "LA": return "Lao People\'s Democratic Republic";
case "LB": return "Lebanon";
case "LI": return "Liechtenstein";
case "LK": return "Sri Lanka";
case "LR": return "Liberia";
case "LS": return "Lesotho";
case "LT": return "Lithuania";
case "LU": return "Luxembourg";
case "LV": return "Latvia";
case "LY": return "Libyan Arab Jamahiriya";
case "MA": return "Morocco";
case "MC": return "Monaco";
case "MD": return "Moldova Republic of";
case "ME": return "Montenegro";
case "MF": return "Saint Martin";
case "MG": return "Madagascar";
case "MH": return "Marshall Islands";
case "MK": return "Macedonia";
case "ML": return "Mali";
case "MM": return "Myanmar";
case "MN": return "Mongolia";
case "MO": return "Macau";
case "MR": return "Mauritania";
case "MT": return "Malta";
case "MU": return "Mauritius";
case "MV": return "Maldives";
case "MW": return "Malawi";
case "MX": return "Mexico";
case "MY": return "Malaysia";
case "MZ": return "Mozambique";
case "NA": return "Namibia";
case "NC": return "New Caledonia";
case "NE": return "Niger";
case "NG": return "Nigeria";
case "NI": return "Nicaragua";
case "NL": return "Netherlands";
case "NO": return "Norway";
case "NP": return "Nepal";
case "NU": return "Niue";
case "NZ": return "New Zealand";
case "OM": return "Oman";
case "PA": return "Panama";
case "PE": return "Peru";
case "PF": return "French Polynesia";
case "PG": return "Papua New Guinea";
case "PH": return "Philippines";
case "PK": return "Pakistan";
case "PL": return "Poland";
case "PM": return "St. Pierre and Miquelon";
case "PR": return "Puerto Rico";
case "PS": return "Palestinian Territory Occupied";
case "PT": return "Portugal";
case "PY": return "Paraguay";
case "QA": return "Qatar";
case "RE": return "Reunion";
case "RO": return "Romania";
case "RS": return "Serbia";
case "RU": return "Russian Federation";
case "RW": return "Rwanda";
case "SA": return "Saudi Arabia";
case "SC": return "Seychelles";
case "SD": return "Sudan";
case "SE": return "Sweden";
case "SG": return "Singapore";
case "SI": return "Slovenia";
case "SK": return "Slovakia (SLOVAK Republic)";
case "SL": return "Sierra Leone";
case "SM": return "San Marino";
case "SN": return "Senegal";
case "SO": return "Somalia";
case "SR": return "Suriname";
case "SV": return "El Salvador";
case "SY": return "Syrian Arab Republic";
case "SZ": return "Swaziland";
case "TC": return "Turks and Caicos Islands";
case "TD": return "Chad";
case "TG": return "Togo";
case "TH": return "Thailand";
case "TJ": return "Tajikistan";
case "TK": return "Tokelau";
case "TL": return "Timor-leste";
case "TM": return "Turkmenistan";
case "TN": return "Tunisia";
case "TO": return "Tonga";
case "TR": return "Turkey";
case "TT": return "Trinidad and Tobago";
case "TW": return "Taiwan; Republic of China (ROC)";
case "TZ": return "Tanzania United Republic of";
case "UA": return "Ukraine";
case "UG": return "Uganda";
case "US": return "United States";
case "UY": return "Uruguay";
case "UZ": return "Uzbekistan";
case "VC": return "Saint Vincent and The Grenadines";
case "VE": return "Venezuela";
case "VG": return "Virgin Islands (BRITISH)";
case "VI": return "Virgin Islands (U.S.)";
case "VN": return "Viet Nam";
case "VU": return "Vanuatu";
case "WF": return "Wallis and Futuna Islands";
case "WS": return "Samoa";
case "YE": return "Yemen";
case "ZA": return "South Africa";
case "ZM": return "Zambia";
case "ZW": return "Zimbabwe";
case "ZZ": return "Reserved";
default: return "Unknown";
}
}

already had one

Ni3ls
26th March 2016, 10:42
So I want that an admin can check to see where a player is from based on his IP.
Im getting stuck on showing the message to the admin with the players name + location
(credits to izno for the script)

getcountry(player)
{
//self = admin
//player = who u want to know
ip = player getip();
ip_parts = [];
part = 0;
ip_parts[part] = "";
prev_found = 0;
for(i = 0; i < ip.size; i++)
{
if(ip[i] != ".")
ip_parts[part] += ip[i];
else
{
part++;
ip_parts[part] = "";
}
}
multi = 1;
num = 0;
for(i = ip_parts.size - 1; i >= 0; i--)
{
num += int(ip_parts[i]) * multi;
multi *= 256;
}
maps\mp\gametypes\_mysql::asyncQuery("SELECT country FROM countries WHERE ip < " + num + " ORDER BY ip DESC LIMIT 1", ::showLocation);
}

showLocation(rows, args)
{
realcountry = "";
if(isDefined(rows) && isDefined(rows[0]) && isDefined(rows[0]["country"]))
realcountry = getlongcountry(rows[0]["country"]);
}
How the hell can I make an iprint to the admin that says "player.name is from: realcountry"?
I have to set

realcountry = ""; in the beginning and then after running the thread it still return a blank realcountry.
The output looks like this then. "Niels is from: );

IzNoGoD
26th March 2016, 11:56
args = [];
args[0] = player;
self maps\mp\gametypes\_mysql::asyncquery(yourquery, ::showlocation, args);



showlocation(rows, args)
{
if(!isdefined(args[0]))
return;
if(isdefiend(rows) && isdefined(rows[0]) && isdefined(rows[0]["country"]))
self iprintln(args[0].name + " is from " + rows[0]["country"]);
}

Ni3ls
26th March 2016, 12:06
Working! 10 char

voron00
30th March 2016, 05:18
Maybe someone will be intersted: just for lulz built a little C geolocation app to use with execute() (https://killtube.org/showthread.php?2486-String-output-for-system()) (since the way with Perl was not fast enough)
its an implentation of https://github.com/maxmind/geoip-api-c (had to do make some changes to compile it on linux)

Just put the GeoLityCity.dat http://dev.maxmind.com/geoip/legacy/geolite/ where the app is and use it something like like:

result = execute("cd /home/voron/GeoIP && ./geoiplookup -f GeoLiteCity.dat -l " + self GetIP());

The returned result (ip 8.8.8.8):
1048

You can split it using strtok or edit the source for your printing pleasure, well, you know the drill.
App:
1046

Source:
1047

thOuMta
2nd April 2016, 11:37
args = [];
args[0] = player;
self maps\mp\gametypes\_mysql::asyncquery(yourquery, ::showlocation, args);



showlocation(rows, args)
{
if(!isdefined(args[0]))
return;
if(isdefiend(rows) && isdefined(rows[0]) && isdefined(rows[0]["country"]))
self iprintln(args[0].name + " is from " + rows[0]["country"]);
}


Using this but got error:

in cod2 console


^8idk^7: !location
script runtime error: potential infinite loop in script - killing thread.
(file 'maps/mp/gametypes/_callbacksetup.gsc', line 466)
for(i = 0; i < ip.size; i++)
*
Hitch warning: 5007 msec frame time


Script:


getcountry(player)
{
//self = admin
//player = who u want to know
ip = player getip();
ip_parts = [];
part = 0;
ip_parts[part] = "";
prev_found = 0;
for(i = 0; i < ip.size; i++)
{
if(ip[i] != ".")
ip_parts[part] += ip[i];
else
{
part++;
ip_parts[part] = "";
}
}
multi = 1;
num = 0;
for(i = ip_parts.size - 1; i >= 0; i--)
{
num += int(ip_parts[i]) * multi;
multi *= 256;
}
args = [];
args[0] = player;
maps\mp\gametypes\_mysql::asyncQuery("SELECT country FROM countries WHERE ip < " + num + " ORDER BY ip DESC LIMIT 1", ::showLocation, args);
}

showlocation(rows, args)
{
if(!isdefined(args[0]))
return;
if(isdefined(rows) && isdefined(rows[0]) && isdefined(rows[0]["country"]))
self iprintln(args[0].name + " is from " + rows[0]["country"]);
self iprintln("test");
}

getlongcountry(c)
{
switch(c)
{
case "AD": return "Andorra";
case "AE": return "United Arab Emirates";
case "AF": return "Afghanistan";
case "AG": return "Antigua and Barbuda";
case "AL": return "Albania";
case "AM": return "Armenia";
case "AN": return "Netherlands Antilles";
case "AO": return "Angola";
case "AR": return "Argentina";
case "AT": return "Austria";
case "AU": return "Australia";
case "AW": return "Aruba";
case "AZ": return "Azerbaijan";
case "BA": return "Bosnia and Herzegowina";
case "BB": return "Barbados";
case "BD": return "Bangladesh";
case "BE": return "Belgium";
case "BF": return "Burkina Faso";
case "BG": return "Bulgaria";
case "BH": return "Bahrain";
case "BJ": return "Benin";
case "BM": return "Bermuda";
case "BN": return "Brunei Darussalam";
case "BO": return "Bolivia";
case "BR": return "Brazil";
case "BS": return "Bahamas";
case "BT": return "Bhutan";
case "BW": return "Botswana";
case "BY": return "Belarus";
case "BZ": return "Belize";
case "CA": return "Canada";
case "CD": return "Congo The Democratic Republic of The";
case "CF": return "Central African Republic";
case "CG": return "Congo";
case "CH": return "Switzerland";
case "CI": return "Cote D\'ivoire";
case "CL": return "Chile";
case "CM": return "Cameroon";
case "CN": return "China";
case "CO": return "Colombia";
case "CR": return "Costa Rica";
case "CU": return "Cuba";
case "CV": return "Cape Verde";
case "CY": return "Cyprus";
case "CZ": return "Czech Republic";
case "DE": return "Germany";
case "DJ": return "Djibouti";
case "DK": return "Denmark";
case "DO": return "Dominican Republic";
case "DZ": return "Algeria";
case "EC": return "Ecuador";
case "EE": return "Estonia";
case "EG": return "Egypt";
case "ES": return "Spain";
case "EU": return "European Union";
case "FI": return "Finland";
case "FJ": return "Fiji";
case "FM": return "Micronesia Federated States of";
case "FO": return "Faroe Islands";
case "FR": return "France";
case "GA": return "Gabon";
case "GB": return "United Kingdom";
case "GD": return "Grenada";
case "GE": return "Georgia";
case "GG": return "Guernsey";
case "GH": return "Ghana";
case "GI": return "Gibraltar";
case "GL": return "Greenland";
case "GM": return "Gambia";
case "GN": return "Guinea";
case "GQ": return "Equatorial Guinea";
case "GR": return "Greece";
case "GT": return "Guatemala";
case "GU": return "Guam";
case "GY": return "Guyana";
case "HK": return "Hong Kong";
case "HN": return "Honduras";
case "HR": return "Croatia (LOCAL Name: Hrvatska)";
case "HT": return "Haiti";
case "HU": return "Hungary";
case "ID": return "Indonesia";
case "IE": return "Ireland";
case "IL": return "Israel";
case "IM": return "Isle of Man";
case "IN": return "India";
case "IQ": return "Iraq";
case "IR": return "Iran (ISLAMIC Republic Of)";
case "IS": return "Iceland";
case "IT": return "Italy";
case "JE": return "Jersey";
case "JM": return "Jamaica";
case "JO": return "Jordan";
case "JP": return "Japan";
case "KE": return "Kenya";
case "KG": return "Kyrgyzstan";
case "KH": return "Cambodia";
case "KP": return "Korea Democratic People\'s Republic of";
case "KR": return "Korea Republic of";
case "KW": return "Kuwait";
case "KY": return "Cayman Islands";
case "KZ": return "Kazakhstan";
case "LA": return "Lao People\'s Democratic Republic";
case "LB": return "Lebanon";
case "LI": return "Liechtenstein";
case "LK": return "Sri Lanka";
case "LR": return "Liberia";
case "LS": return "Lesotho";
case "LT": return "Lithuania";
case "LU": return "Luxembourg";
case "LV": return "Latvia";
case "LY": return "Libyan Arab Jamahiriya";
case "MA": return "Morocco";
case "MC": return "Monaco";
case "MD": return "Moldova Republic of";
case "ME": return "Montenegro";
case "MF": return "Saint Martin";
case "MG": return "Madagascar";
case "MH": return "Marshall Islands";
case "MK": return "Macedonia";
case "ML": return "Mali";
case "MM": return "Myanmar";
case "MN": return "Mongolia";
case "MO": return "Macau";
case "MR": return "Mauritania";
case "MT": return "Malta";
case "MU": return "Mauritius";
case "MV": return "Maldives";
case "MW": return "Malawi";
case "MX": return "Mexico";
case "MY": return "Malaysia";
case "MZ": return "Mozambique";
case "NA": return "Namibia";
case "NC": return "New Caledonia";
case "NE": return "Niger";
case "NG": return "Nigeria";
case "NI": return "Nicaragua";
case "NL": return "Netherlands";
case "NO": return "Norway";
case "NP": return "Nepal";
case "NU": return "Niue";
case "NZ": return "New Zealand";
case "OM": return "Oman";
case "PA": return "Panama";
case "PE": return "Peru";
case "PF": return "French Polynesia";
case "PG": return "Papua New Guinea";
case "PH": return "Philippines";
case "PK": return "Pakistan";
case "PL": return "Poland";
case "PM": return "St. Pierre and Miquelon";
case "PR": return "Puerto Rico";
case "PS": return "Palestinian Territory Occupied";
case "PT": return "Portugal";
case "PY": return "Paraguay";
case "QA": return "Qatar";
case "RE": return "Reunion";
case "RO": return "Romania";
case "RS": return "Serbia";
case "RU": return "Russian Federation";
case "RW": return "Rwanda";
case "SA": return "Saudi Arabia";
case "SC": return "Seychelles";
case "SD": return "Sudan";
case "SE": return "Sweden";
case "SG": return "Singapore";
case "SI": return "Slovenia";
case "SK": return "Slovakia (SLOVAK Republic)";
case "SL": return "Sierra Leone";
case "SM": return "San Marino";
case "SN": return "Senegal";
case "SO": return "Somalia";
case "SR": return "Suriname";
case "SV": return "El Salvador";
case "SY": return "Syrian Arab Republic";
case "SZ": return "Swaziland";
case "TC": return "Turks and Caicos Islands";
case "TD": return "Chad";
case "TG": return "Togo";
case "TH": return "Thailand";
case "TJ": return "Tajikistan";
case "TK": return "Tokelau";
case "TL": return "Timor-leste";
case "TM": return "Turkmenistan";
case "TN": return "Tunisia";
case "TO": return "Tonga";
case "TR": return "Turkey";
case "TT": return "Trinidad and Tobago";
case "TW": return "Taiwan; Republic of China (ROC)";
case "TZ": return "Tanzania United Republic of";
case "UA": return "Ukraine";
case "UG": return "Uganda";
case "US": return "United States";
case "UY": return "Uruguay";
case "UZ": return "Uzbekistan";
case "VC": return "Saint Vincent and The Grenadines";
case "VE": return "Venezuela";
case "VG": return "Virgin Islands (BRITISH)";
case "VI": return "Virgin Islands (U.S.)";
case "VN": return "Viet Nam";
case "VU": return "Vanuatu";
case "WF": return "Wallis and Futuna Islands";
case "WS": return "Samoa";
case "YE": return "Yemen";
case "ZA": return "South Africa";
case "ZM": return "Zambia";
case "ZW": return "Zimbabwe";
case "ZZ": return "Reserved";
default: return "Unknown";
}
}


In db


CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` varchar(15) DEFAULT NULL,
`name` varchar(55) CHARACTER SET utf32 NOT NULL,
`country` varchar(55) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=10 ;


Ofc i put developer 1 to see the prob
And trying to put countries_april_2014.sql too but idk.. maybe im wrong ?

IzNoGoD
2nd April 2016, 12:23
Update:
MySQL has a built-in ip to (unsigned)int32 function, so here's the updated codscript stuff:


getcountry(player)
{
args = [];
args[0] = player;
maps\mp\gametypes\_mysql::asyncQuery("SELECT country FROM countries WHERE ip < INET_ATON('" + stripstring(player getip()) + "') ORDER BY ip DESC LIMIT 1", ::showLocation, args);
}

showlocation(rows, args)
{
if(!isDefined(args[0]))
return;
if(isDefined(rows) && isdefined(rows[0]) && isdefined(rows[0]["country"]))
self iprintln(args[0].name + " is from " + rows[0]["country"]);
}


with sql table:
1063

This table does have an updated layout, so make sure you delete your old table before inserting the new one

suck000
6th July 2016, 12:33
Hi i know this is an old topic, but i tried to make it.

getcountry(player)
{
//self = admin
//player = who u want to know
ip = player getip();
ip_parts = [];
part = 0;
ip_parts[part] = "";
prev_found = 0;
for(i = 0; i < ip.size; i++)
{
if(ip[i] != ".")
ip_parts[part] += ip[i];
else
{
part++;
ip_parts[part] = "";
}
}
multi = 1;
num = 0;
for(i = ip_parts.size - 1; i >= 0; i--)
{
num += int(ip_parts[i]) * multi;
multi *= 256;
}
args = [];
args[0] = player;
maps\mp\gametypes\_mysql::asyncQuery("SELECT country FROM countries WHERE ip < " + num + " ORDER BY ip DESC LIMIT 1", ::showLocation, args);
}

showlocation(rows, args)
{
if(!isdefined(args[0]))
return;
if(isdefined(rows) && isdefined(rows[0]) && isdefined(rows[0]["country"]))
self iprintln(args[0].name + " is from " + rows[0]["country"]);
self iprintln("test");
}

Then when i added a case "country" , i try to !country 0, server crashes giving me this error.

script runtime error: potential infinite loop in script - killing thread.


with developer 1

******* script runtime error *******
undefined is not an entity: (file 'maps/mp/gametypes/_callbacksetup.gsc', line 214)
ip = player getIP();
*
called from:
(file 'maps/mp/gametypes/_callbacksetup.gsc', line 1739)
thread getcountry();
*
started from:
(file 'maps/mp/gametypes/_callbacksetup.gsc', line 926)
CodeCallback_PlayerCommand(args)
*


I'm working with april 2014 countries list. Any help ?

Ni3ls
6th July 2016, 13:00
Read the error.


undefined is not an entity: (file 'maps/mp/gametypes/_callbacksetup.gsc', line 214)
ip = player getIP();

suck000
6th July 2016, 13:07
how can i fix it ?

Ni3ls
6th July 2016, 13:15
Define player

suck000
6th July 2016, 14:40
I failed to know how to define it. Can you please give full script with player defined please ?

suck000
6th July 2016, 17:04
Sorry for spam. I defined the player. I get the message telling me that the player is from COUNTRYHERE.
But how to make for example : the player is from TN to the player is from Tunisia. Long cut i mean.

Ni3ls
6th July 2016, 18:28
You are a pro mod maker you said, so this is easy for you

suck000
6th July 2016, 18:31
want to help ? ok np , you don't want ? ok np too ..

suck000
6th July 2016, 18:57
Indeed resolved it. want help ask it guys

suck000
7th July 2016, 00:16
Hmm sry for coming back again but i managed to show the message but for example im num 0 ingame .. when i do !locate 0 everything is cool but when i write !locate 1 to see another player country it shows my Nick instead of his and my country instead of his.. asked à player to connect to the srv before me .. he got 0 id and when i do !locate 0 everything is cool but same problème comes again if i do !locate 1 to see my self i still have iprintlnbold that tells the 0 id player country and name. Any fix please ?

IzNoGoD
7th July 2016, 00:26
Hmm sry for coming back again but i managed to show the message but for example im num 0 ingame .. when i do !locate 0 everything is cool but when i write !locate 1 to see another player country it shows my Nick instead of his and my country instead of his.. asked à player to connect to the srv before me .. he got 0 id and when i do !locate 0 everything is cool but same problème comes again if i do !locate 1 to see my self i still have iprintlnbold that tells the 0 id player country and name. Any fix please ?

Yes, inside your code.


"Hey my car isnt working it wont start can you please fix it?"
"Do you have your car here?"
"Nope"
"What brand+type is your car?"
"Its a red car"

suck000
7th July 2016, 00:43
case "locate":
if(!(self checkIfAdmin()))
return;
if (isDefined(args[2]) && isint(args[2]))
{
args[2] = int(args[2]);
if(!checkIfExist(args[2]))
{
self thread tellMessage("Couldn\'t find a player with this number.");
return;
}
player = getplayerbyid();
ip = player getip();
ip_parts = [];
part = 0;
ip_parts[part] = "";
prev_found = 0;
for(i = 0; i < ip.size; i++)
{
if(ip[i] != ".")
ip_parts[part] += ip[i];
else
{
part++;
ip_parts[part] = "";
}
}
multi = 1;
num = 0;
for(i = ip_parts.size - 1; i >= 0; i--)
{
num += int(ip_parts[i]) * multi;
multi *= 256;
}
args = [];
args[0] = player;
maps\mp\gametypes\_mysql::asyncQuery("SELECT country FROM countries WHERE ip < " + num + " ORDER BY ip DESC LIMIT 1", ::showLocation, args);
return;
}
thread tellmessage("Usage : !locate playernum");
return;

suck000
7th July 2016, 00:45
showlocation(rows, args)
{
if(!isdefined(args[0]))
return;
if(isdefined(rows) && isdefined(rows[0]) && isdefined(rows[0]["country"]))
self iprintlnbold(args[0].name + "^7 is from ^2" + getlongcountry(rows[0]["country"]));
}


Sorry for posting two Times in à row cuz im on phone :P

IzNoGoD
7th July 2016, 00:56
player = getplayerbyid();

There's your problem.

suck000
7th July 2016, 01:16
And how can i fix it sir ?

Whiskas
7th July 2016, 01:25
And how can i fix it sir ?

If you copied my code, at least you could read it. It's not that ugly (hopefully).


getPlayerById(number)
{
number = Int(number);
players = getentarray("player", "classname");
for(i = 0; i < players.size; i++)
{
if(players[i] getEntityNumber() == number)
return players[i];
}
return undefined;
}

Read it again (if you did it) and spot the part you missed.

Ni3ls
7th July 2016, 07:50
If you had developer 1 on it would gave you the error

suck000
7th July 2016, 15:45
case "locate":
if(!(self checkIfAdmin()))
return;
if (isDefined(args[2]) && isint(args[2]))
{
args[2] = int(args[2]);
if(!checkIfExist(args[2]))
{
self thread tellMessage("Couldn\'t find a player with this number.");
return;
}
player = getplayerbyid();
ip = player getip();
ip_parts = [];
part = 0;
ip_parts[part] = "";
prev_found = 0;
for(i = 0; i < ip.size; i++)
{
if(ip[i] != ".")
ip_parts[part] += ip[i];
else
{
part++;
ip_parts[part] = "";
}
}
multi = 1;
num = 0;
for(i = ip_parts.size - 1; i >= 0; i--)
{
num += int(ip_parts[i]) * multi;
multi *= 256;
}
args = [];
args[0] = player;
maps\mp\gametypes\_mysql::asyncQuery("SELECT country FROM countries WHERE ip < " + num + " ORDER BY ip DESC LIMIT 1", ::showLocation, args);
return;
}
thread tellmessage("Usage : !locate playernum");
return;


showlocation(rows, args)
{
if(!isdefined(args[0]))
return;
if(isdefined(rows) && isdefined(rows[0]) && isdefined(rows[0]["country"]))
self iprintlnbold(args[0].name + "^7 is from ^2" + getlongcountry(rows[0]["country"]));
}

failed to notice the problem. can you fix the code please ?

I got the car here and his model

Whiskas
7th July 2016, 16:10
case "locate":
if(!(self checkIfAdmin()))
return;
if (isDefined(args[2]) && isint(args[2]))
{
args[2] = int(args[2]);
if(!checkIfExist(args[2]))
{
self thread tellMessage("Couldn\'t find a player with this number.");
return;
}
player = getplayerbyid();
ip = player getip();
ip_parts = [];
part = 0;
ip_parts[part] = "";
prev_found = 0;
for(i = 0; i < ip.size; i++)
{
if(ip[i] != ".")
ip_parts[part] += ip[i];
else
{
part++;
ip_parts[part] = "";
}
}
multi = 1;
num = 0;
for(i = ip_parts.size - 1; i >= 0; i--)
{
num += int(ip_parts[i]) * multi;
multi *= 256;
}
args = [];
args[0] = player;
maps\mp\gametypes\_mysql::asyncQuery("SELECT country FROM countries WHERE ip < " + num + " ORDER BY ip DESC LIMIT 1", ::showLocation, args);
return;
}
thread tellmessage("Usage : !locate playernum");
return;


showlocation(rows, args)
{
if(!isdefined(args[0]))
return;
if(isdefined(rows) && isdefined(rows[0]) && isdefined(rows[0]["country"]))
self iprintlnbold(args[0].name + "^7 is from ^2" + getlongcountry(rows[0]["country"]));
}

failed to notice the problem. can you fix the code please ?

I got the car here and his model



player = getplayerbyid();

There's your problem.


Just use CTRL + F player = getplayerbyid(); maybe?

suck000
7th July 2016, 16:19
how i can define player then ? player = what ?

suck000
7th July 2016, 16:38
Oki here is the fix guys.

player = getplayerbyid(secondArgument(args));

it's working now fine :P

IzNoGoD
7th July 2016, 16:52
You're replying to a thread that has [advanced] in its title with basic programming questions, without providing any error logs.

Dont. Do. That.