#include <amxmod>
new origupdr[33], origrate[33], excl[33]
#define MAX_IP 32
new ignip[MAX_IP][32], ippos=0
#define MAX_steamID 128
new ignsteamid[MAX_steamID][32], steamidpos=0
public check_rr() {
new maxupdr=get_cvar_num("rm_maxupdr")
new minupdr=get_cvar_num("rm_minupdr")
new maxrate=get_cvar_num("rm_maxrate")
new minrate=get_cvar_num("rm_minrate")
new announce=get_cvar_num("rm_announce")
new players[32], np, i, playername[32]
new clupdr[8], clrt[16], msg[256]
new tmpupdr, tmprate, cmdexe[32]
get_players(players, np, "ac")
for(i=0; i<np; i++)
if ((players[i]!=0)&&(!is_user_hltv(players[i]))) {
get_user_ping(players[i], tmpupdr, tmprate)
if ((tmpupdr>get_cvar_num("rm_localping"))&&(excl[players[i]]==0)) {
get_user_info(players[i], "cl_updaterate", clupdr, 7)
get_user_info(players[i], "rate", clrt, 15)
tmpupdr=str_to_num(clupdr)
tmprate=str_to_num(clrt)
if (announce)
get_user_name(players[i],playername,31)
if (tmpupdr>maxupdr) {
origupdr[players[i]]=maxupdr
format(cmdexe, 31, "cl_updaterate %i", maxupdr)
client_cmd(players[i], cmdexe)
if (announce) {
format(msg, 255, "* [AMX_RM] %s set 'cl_updaterate' to '%i' (max '%i') - blocked by plugin !", playername, tmpupdr, maxupdr)
client_print(0, print_chat, msg)
}
}
if (tmpupdr<minupdr) {
origupdr[players[i]]=minupdr
format(cmdexe, 31, "cl_updaterate %i", minupdr)
client_cmd(players[i], cmdexe)
if (announce) {
format(msg, 255, "* [AMX_RM] %s set 'cl_updaterate' to '%i' (min '%i') - blocked by plugin !", playername, tmpupdr, minupdr)
client_print(0, print_chat, msg)
}
}
if (tmprate>maxrate) {
origrate[players[i]]=maxrate
format(cmdexe, 31, "rate %i", maxrate)
client_cmd(players[i], cmdexe)
format(cmdexe, 31, "cl_rate %i", maxrate)
client_cmd(players[i], cmdexe)
if (announce) {
format(msg, 255, "* [AMX_RM] %s set 'rate' to '%i' (max '%i') - blocked by plugin !", playername, tmprate, maxrate)
client_print(0, print_chat, msg)
}
}
if (tmprate<minrate) {
origrate[players[i]]=minrate
format(cmdexe, 31, "rate %i", minrate)
client_cmd(players[i], cmdexe)
format(cmdexe, 31, "cl_rate %i", minrate)
client_cmd(players[i], cmdexe)
if (announce) {
format(msg, 255, "* [AMX_RM] %s set 'rate' to '%i' (min '%i') - blocked by plugin !", playername, tmprate, minrate)
client_print(0, print_chat, msg)
}
}
}
}
new Float:freq=get_cvar_float("rm_delay")
if (freq > 0.0) set_task(freq, "check_rr")
return PLUGIN_CONTINUE
}
public alive_again(id) {
if ((is_user_bot(id))||(is_user_hltv(id)))
return PLUGIN_CONTINUE
if (excl[id]==1)
return PLUGIN_CONTINUE
new Float:ratio=get_cvar_float("rm_deadratio")
if (ratio==1.0)
return PLUGIN_CONTINUE
new ping, loss
get_user_ping(id, ping, loss)
if (ping>get_cvar_num("rm_localping")) {
new cmdexe[32]
format(cmdexe, 31, "cl_updaterate %i", origupdr[id])
client_cmd(id, cmdexe)
format(cmdexe, 31, "rate %i", origrate[id])
client_cmd(id, cmdexe)
format(cmdexe, 31, "cl_rate %i", origrate[id])
client_cmd(id, cmdexe)
if (get_cvar_num("rm_announce")) {
new msg[256]
format(msg, 255, "* [AMX_RM] Your net settings have been restored : 'cl_updaterate' = '%i', 'rate' = '%i'", origupdr[id], origrate[id])
client_print(id, print_chat, msg)
}
}
return PLUGIN_CONTINUE
}
public dead_now() {
new victim=read_data(2)
if ((is_user_bot(victim))||(is_user_hltv(victim)))
return PLUGIN_CONTINUE
if (excl[victim]==1)
return PLUGIN_CONTINUE
new Float:ratio=get_cvar_float("rm_deadratio")
if (ratio==1.0)
return PLUGIN_CONTINUE
new tmpupdr, tmprate
get_user_ping(victim, tmpupdr, tmprate)
if (tmpupdr>get_cvar_num("rm_localping")) {
new cmdexe[32]
tmpupdr=floatround(float(origupdr[victim])*ratio)
tmprate=floatround(float(origrate[victim])*ratio)
format(cmdexe, 31, "cl_updaterate %i", tmpupdr)
client_cmd(victim, cmdexe)
format(cmdexe, 31, "rate %i", tmprate)
client_cmd(victim, cmdexe)
format(cmdexe, 31, "cl_rate %i", tmprate)
client_cmd(victim, cmdexe)
if (get_cvar_num("rm_announce")) {
new msg[256]
format(msg, 255, "* [AMX_RM] Your net settings have been lowered : 'cl_updaterate' = '%i', 'rate' = '%i'", tmpupdr, tmprate)
client_print(victim, print_chat, msg)
}
}
return PLUGIN_CONTINUE
}
public ignore_ip(id) {
new argc=read_argc()
if (argc<2) {
console_print(id, "Usage: rm_ignoreip <IP> [IP] [IP] [IP] ...")
return PLUGIN_CONTINUE
}
for(new i=1; i<argc; i++)
if (ippos<MAX_IP) {
read_argv(i, ignip[ippos], 31)
ippos++
}
else {
console_print(id, "* [AMX_RM] Too many IP addresses added to the ignore IP list")
return PLUGIN_CONTINUE
}
return PLUGIN_CONTINUE
}
public ignore_steamid(id) {
new argc=read_argc()
if (argc<2) {
console_print(id, "Usage: rm_ignoresteamid <steamID> [steamID] [steamID] [steamID] ...")
return PLUGIN_CONTINUE
}
new tmp[32]
for(new i=1; i<argc; i++)
if (steamidpos<MAX_steamID) {
read_argv(i, tmp, 31)
copy(ignsteamid[steamidpos], 31, tmp)
steamidpos++
}
else {
console_print(id, "* [AMX_RM] Too many steamIDs added to the ignore steamID list")
return PLUGIN_CONTINUE
}
return PLUGIN_CONTINUE
}
public client_connect(id) {
if ((is_user_bot(id))||(is_user_hltv(id)))
return PLUGIN_CONTINUE
new clupdr[8], clrt[16]
get_user_info(id, "cl_updaterate", clupdr, 7)
get_user_info(id, "rate", clrt, 15)
origupdr[id]=str_to_num(clupdr)
origrate[id]=str_to_num(clrt)
excl[id]=0
new i
if (ippos>0) {
new userip[32]
get_user_ip(id, userip, 31)
copyc(userip, 31, userip, ':')
new len
for(i=0; i<ippos; i++) {
len=containi(ignip[i],".x")
if (len>-1) {
if (equal(userip, ignip[i], len)) {
excl[id]=1
break
}
}
else if (equal(userip, ignip[i])) {
excl[id]=1
break
}
}
}
if ((steamidpos>0)&&(excl[id]==0)) {
new steamid[32]
get_user_authid(id, steamid, 31)
for(i=0; i<steamidpos; i++)
if (equal(steamid,ignsteamid[i])) {
excl[id]=1
break
}
}
if (get_cvar_num("rm_hello")==0)
return PLUGIN_CONTINUE
new plgver[16]
get_cvar_string("rate_manager", plgver, 15)
client_cmd(id, "echo ======================================================================")
client_cmd(id,
"echo ^"* AMX Rate Manager v
%s by Marach,
marach@phreaker.net, ICQ
: 242122535 *^"", plgver
) new Float:freq=get_cvar_float("rm_delay")
if (freq>0.0) {
new maxupdr=get_cvar_num("rm_maxupdr")
new minupdr=get_cvar_num("rm_minupdr")
new maxrate=get_cvar_num("rm_maxrate")
new minrate=get_cvar_num("rm_minrate")
client_cmd(id, "echo ^" - allowed 'cl_updaterate' range : '%i' - '%i', you have '%i'^"", minupdr, maxupdr, origupdr[id])
client_cmd(id, "echo ^" - allowed 'rate' range : '%i' - '%i', you have '%i'^"", minrate, maxrate, origrate[id])
}
new Float:ratio=get_cvar_float("rm_deadratio")
if (ratio<1.0)
client_cmd(id, "echo ^" - dead players use %2.0f%%%% of their normal net settings^"", (ratio*100.0))
client_cmd(id, "echo ======================================================================")
return PLUGIN_CONTINUE
}
public client_disconnect(id) {
if ((is_user_bot(id))||(is_user_hltv(id)))
return PLUGIN_CONTINUE
origupdr[id]=get_cvar_num("rm_minupdr")
origrate[id]=get_cvar_num("rm_minrate")
excl[id]=0
return PLUGIN_CONTINUE
}
public set_servercvars() {
new tmp[16]
get_cvar_string("rm_exclmaxupdr", tmp, 15)
set_cvar_string("sv_maxupdaterate", tmp)
get_cvar_string("rm_exclminupdr", tmp, 15)
set_cvar_string("sv_minupdaterate", tmp)
get_cvar_string("rm_exclmaxrate", tmp, 15)
set_cvar_string("sv_maxrate", tmp)
get_cvar_string("rm_exclminrate", tmp, 15)
set_cvar_string("sv_minrate", tmp)
if (get_cvar_num("rm_announce"))
console_print(0, "* [AMX_RM] Bandwith limits for excluded players have been set")
return PLUGIN_CONTINUE
}
public plugin_init() {
register_plugin("Rate Manager", "1.2", "Marach")
register_cvar("rate_manager", "1.2", FCVAR_SERVER)
register_event("ResetHUD", "alive_again", "be","1=1")
register_event("DeathMsg","dead_now","a")
register_cvar("rm_maxupdr", "36")
register_cvar("rm_minupdr", "12")
register_cvar("rm_maxrate", "9216")
register_cvar("rm_minrate", "3072")
register_cvar("rm_exclmaxupdr", "60")
register_cvar("rm_exclminupdr", "24")
register_cvar("rm_exclmaxrate", "15360")
register_cvar("rm_exclminrate", "6144")
register_cvar("rm_delay", "20")
register_cvar("rm_deadratio", "0.4")
register_cvar("rm_localping", "0")
register_cvar("rm_announce", "1")
register_cvar("rm_hello", "1")
register_srvcmd("rm_ignoreip", "ignore_ip")
register_srvcmd("rm_ignoresteamid", "ignore_steamid")
new Float:freq=get_cvar_float("rm_delay")
if (freq>0.0) {
set_task(freq, "check_rr")
set_task(5.0, "set_servercvars")
}
return PLUGIN_CONTINUE
}