вообщем вот готовый вариант.
/***********************************************
* Access.ini for players (example: "nick or ip" "pass" "flags")
* Denied.ini for subnets (example: "ip" "mask" "flags")
*
* if #define SUBNET_REVERSE is comment then
* Access.ini list of nicks,who can join from banned subnets
* Denied.ini list of banned subnets
*
* if #define SUBNET_REVERSE is uncomment then
* Access.ini list of nicks,who can't join from access subnets
* Denied.ini list of access subnets,others are banned
*
* ATTENTION!!! HELP for BAN (for that who don't know)
* http://ipcalc.dewil.ru/
*
***********************************************/ // uncomment if subnet only
#define SUBNET_REVERSE
#include <amxmodx>
#include <amxmisc>
// Variables
new DeniedFile[64]
new Subipaddr[16], Bitmask[16], Subipmask[16]
#if defined SUBNET_REVERSE
new SFlags[22]
#endif
new bool:PlayerFound[32]
new bool:SubnetFound[32]
new bool:PassNick[32]
new ip[16]
// Options // default value of amx or amxx access password
new BanSubMSG[] = "%s Your subnet was limited on server. Info %s" // Show this message when players from banned subnets was kicked
new WrongPassMSG[] = "%s Wrong Password on Nick" // Show this message if password on nick not right
new WEBRESOURCE[] = "<URL is HERE =)>" // Site of Server for communicate with admins
// Strings Messages
new Tag[] = "[BanSubnets]" // Plugin Tag
public plugin_init() {
register_plugin("BanSubnets","4.0f","Z@C,NO PASARAN,RUNET")
new confdir[64]
get_configsdir(confdir, 63)
format(DeniedFile, 63, "%s/BanSubnets/Denied.ini", confdir)
}
public client_putinserver(id) {
new authid[32]
get_user_authid(id,authid,31)
if(!containi(authid,"STEAM_0:")) {
return PLUGIN_HANDLED
}
else if(access(id, ADMIN_LEVEL_H)) {
return PLUGIN_HANDLED
}
else Denied(id)
return PLUGIN_HANDLED
}
public Denied(id) {
get_user_ip(id, ip, 15, 1)
new Dreaddata[61], Dlen, Dpos = 0
while(read_file(DeniedFile, Dpos++, Dreaddata, 60, Dlen)) {
if (Dreaddata[0] == ';' || !Dlen)
continue
#if defined SUBNET_REVERSE
parse(Dreaddata, Subipaddr, 16, Bitmask, 16, SFlags ,21)
#else
parse(Dreaddata, Subipaddr, 16, Bitmask, 16)
#endif
check_sub(id)
}
action(id)
}
check_sub(id) {
SubnetFound[id] = false
if (strlen(Bitmask) > 2) {
Subipmask = Bitmask
}
if (strlen(Bitmask) < 3) {
bitmask_to_mask(Bitmask)
}
if (net_belongs(ip_to_number(ip), ip_to_number("255.255.255.255"), ip_to_number(Subipaddr), ip_to_number(Subipmask)) == 1) {
SubnetFound[id] = true
}
#if defined SUBNET_REVERSE
if (strlen(SFlags) > 0) {
remove_user_flags(id)
set_user_flags(id, read_flags(SFlags))
}
#endif
}
bitmask_to_mask(Bitmask[]) {
if (equal(Bitmask, "1")) format(Subipmask, 15, "128.0.0.0")
if (equal(Bitmask, "2")) format(Subipmask, 15, "192.0.0.0")
if (equal(Bitmask, "3")) format(Subipmask, 15, "224.0.0.0")
if (equal(Bitmask, "4")) format(Subipmask, 15, "240.0.0.0")
if (equal(Bitmask, "5")) format(Subipmask, 15, "248.0.0.0")
if (equal(Bitmask, "6")) format(Subipmask, 15, "252.0.0.0")
if (equal(Bitmask, "7")) format(Subipmask, 15, "254.0.0.0")
if (equal(Bitmask, "8")) format(Subipmask, 15, "255.0.0.0")
if (equal(Bitmask, "9")) format(Subipmask, 15, "255.128.0.0")
if (equal(Bitmask, "10")) format(Subipmask, 15, "255.192.0.0")
if (equal(Bitmask, "11")) format(Subipmask, 15, "255.224.0.0")
if (equal(Bitmask, "12")) format(Subipmask, 15, "255.240.0.0")
if (equal(Bitmask, "13")) format(Subipmask, 15, "255.248.0.0")
if (equal(Bitmask, "14")) format(Subipmask, 15, "255.252.0.0")
if (equal(Bitmask, "15")) format(Subipmask, 15, "255.254.0.0")
if (equal(Bitmask, "16")) format(Subipmask, 15, "255.255.0.0")
if (equal(Bitmask, "17")) format(Subipmask, 15, "255.255.128.0")
if (equal(Bitmask, "18")) format(Subipmask, 15, "255.255.192.0")
if (equal(Bitmask, "19")) format(Subipmask, 15, "255.255.224.0")
if (equal(Bitmask, "20")) format(Subipmask, 15, "255.255.240.0")
if (equal(Bitmask, "21")) format(Subipmask, 15, "255.255.248.0")
if (equal(Bitmask, "22")) format(Subipmask, 15, "255.255.252.0")
if (equal(Bitmask, "23")) format(Subipmask, 15, "255.255.254.0")
if (equal(Bitmask, "24")) format(Subipmask, 15, "255.255.255.0")
if (equal(Bitmask, "25")) format(Subipmask, 15, "255.255.255.128")
if (equal(Bitmask, "26")) format(Subipmask, 15, "255.255.255.192")
if (equal(Bitmask, "27")) format(Subipmask, 15, "255.255.255.224")
if (equal(Bitmask, "28")) format(Subipmask, 15, "255.255.255.240")
if (equal(Bitmask, "29")) format(Subipmask, 15, "255.255.255.248")
if (equal(Bitmask, "30")) format(Subipmask, 15, "255.255.255.252")
if (equal(Bitmask, "31")) format(Subipmask, 15, "255.255.255.254")
}
action(id) {
new Reason[255]
#if defined SUBNET_REVERSE
if (!SubnetFound[id] && !PlayerFound[id])
#else
if (SubnetFound[id] && !PlayerFound[id])
#endif
{
format(Reason, 254, BanSubMSG, Tag, WEBRESOURCE)
kick(id, Reason)
}
if (PassNick[id]) {
format(Reason, 254, WrongPassMSG, Tag)
kick(id, Reason)
}
}
kick(id, Reason[]) {
server_cmd("kick #%d %s", get_user_userid(id), Reason)
}
// Functions
stock ip_to_number(userip[16]) {
new ipb1[12], ipb2[12], ipb3[12], ipb4[12], ip, nipb1, nipb2, nipb3, nipb4, uip[16]
copy(uip, 16, userip)
while(replace(uip, 16, ".", " ")) {}
parse(uip, ipb1, 12, ipb2, 12, ipb3, 12, ipb4, 12)
nipb1 = str_to_num(ipb1)
nipb2 = str_to_num(ipb2)
nipb3 = str_to_num(ipb3)
nipb4 = str_to_num(ipb4)
ip = ((((nipb1 * 256) + nipb2) * 256) + nipb3) + ((((((nipb1 * 256) + nipb2) * 256) + nipb3) * 255) + nipb4)
return ip
}
stock net_hi_num(addr, mask) {
return addr+4294967296-mask
}
stock net_belongs(ipaddr, ipmask, ipaddrin, ipmaskin) {
if (ipaddr >= ipaddrin && net_hi_num(ipaddr, ipmask) <= net_hi_num(ipaddrin, ipmaskin)) {
return 1
}
return 0
}