Results 1 to 10 of 33

Thread: [advanced] Find player's country-of-origin

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts

    [advanced] Find player's country-of-origin

    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:
    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;
    }
    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)
    Attached Files Attached Files
    Last edited by IzNoGoD; 29th December 2013 at 20:45.

  2. The Following 4 Users Say Thank You to IzNoGoD For This Useful Post:

    kung foo man (29th December 2013),maxdamage99 (8th August 2016),RobsoN (20th February 2014),smect@ (5th February 2014)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •