|
发表于 2004-6-4 16:32:09
|
显示全部楼层
来自 中国–福建–福州
这个是country.sma
/* AMXMOD script.
*
* (c) Copyright 2000-2002, Rich - This file is provided as is (no warranties).
*
* Player Country 1.0 - Converts IP Address to Country Code via a database.
*
* - Must put the country.dat /addons/amx/ folder.
*
* - amx_showcountry 0/1 cvar for turning it on or off.
*
* - Thanks goes to:
*
* http://www.ip-to-country.com/ for providing original csv database.
*
* http://amxmod.net/forums/viewtopic.php?t=10117 spectating code by ST4life.
*
*/
#include <amxmod>
new filepath[32] = "addons/amx/country.dat"
new country[32][3]
public plugin_init()
{
register_plugin("Show Country","1.0","Rich")
register_event("StatusValue","show_country","bd","1=2")
register_clcmd("say /country","show_owncountry")
register_cvar("amx_showcountry","1")
}
public client_connect(id)
{
if (!(get_cvar_num("amx_showcountry")))
{
return PLUGIN_CONTINUE
}
new ipcode[11], ccode[3], playerip[17], ipta[4], iptb[4], iptc[4], iptd[4], text[256]
new line, ipna, ipnb, ipnc, ipnd, ipnuma, ipnumb, textlen, startline, endline = 32000
get_user_ip(id, playerip, 16, 1)
replace(playerip, 16, ".", " ")
replace(playerip, 16, ".", " ")
replace(playerip, 16, ".", " ")
replace(playerip, 16, ".", " ")
parse(playerip, ipta, 3, iptb, 3, iptc, 3, iptd, 3)
ipna = strtonum(ipta)
ipnb = strtonum(iptb)
ipnc = strtonum(iptc)
ipnd = strtonum(iptd)
//127 for slow/accurate or 60 for fast/approximate
if (ipna > 60)
{
ipnuma = (ipna * 1677721) + (ipnb * 6553) + ( ipnc * 26 ) + ipnd
}
else
{
ipnuma = (ipna * 16777216) + (ipnb * 65536) + ( ipnc * 256 ) + ipnd
numtostr(ipnuma, ipcode, textlen)
copy(ipcode,9,ipcode)
ipnuma = strtonum(ipcode)
}
for (new i = 0; i < 16; i++)
{
line = startline + ((endline - startline) / 2)
if (i == 15)
{
++line
}
read_file(filepath, line, text, 255, textlen)
parse(text, ipcode, 9, ccode, 2)
ipnumb = strtonum(ipcode)
//Diagnostic:
//client_print(0,print_chat,"Line: %i Start: %i End: %i PlayerCode: %i FileCode: %i", line, startline, endline, ipnuma, ipnumb)
if (ipnuma > ipnumb)
{
startline = line
}
else
{
endline = line
}
}
//Show Country on Connect - Only use if you know what your doing:
//client_print(0,print_chat,"Connecting IP: %i - Code: %i File: %i Country: %s", playerip, ipnuma, ipnumb, ccode)
country[id] = ccode
return PLUGIN_CONTINUE
}
public show_country(id)
{
if (!(get_cvar_num("amx_showcountry")))
{
return PLUGIN_CONTINUE
}
new target = read_data(2)
if (target != id && target != 0)
{
set_hudmessage(255,255,255,0.02,0.88,0, 0.5, 1.0, 0.0, 0.0, 27)
show_hudmessage(id,"Country Code: %s",country[target])
}
return PLUGIN_CONTINUE
}
public show_owncountry(id)
{
client_print(id,print_chat,"Your Country Code: %s",country[id])
return PLUGIN_HANDLED
} |
|