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:
This obviously requires mysql running and configured (see level.mysql var in mysql_wrapper()), and libcod.Code: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; }
Database (import this in your favorite tool, be it heidiSQL or phpmyadmin):
(see attachment)



Reply With Quote