Fps protection.

Started by NumB
01/10/2007 22:54
Page 1 of 1
NumB01/10/2007 22:54

Some of you maybe are using "Long Jump Stats - eXtreme Modification" plugin that has client-fps control. But you can bug it with aliases. Any way i was thinking how to make realy good legal kz setting client syde (fps) protection. Once playing at kzm surf server with unlegal kz settings I got kicked with message that my fpses are 135, so i decided to make the same plugin only on public. :)

Anyway here you go.


#include
#include

new fps_protection;
new user_fps[33];
new user_fps_setted[33];
new kick_user[33];

#define PLUGIN "Fps test"
#define VERSION "1.1"
#define AUTHOR "NumB"


public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_PlayerPreThink, "fwdPlayerPreThink", 0);
register_clcmd("say /fps", "cmdFps", ADMIN_ALL, "- show all players fps usage");
fps_protection = register_cvar("kz_fps_protection", "1")
}

public client_putinserver(id)
{
if( task_exists(id+6651298) )
remove_task(id+6651298);

if( task_exists(id+7651298, 0) )
remove_task(id+7651298, 0);

if( task_exists(id+8651298, 0) )
remove_task(id+8651298, 0);

if( task_exists(id+9651298) )
remove_task(id+9651298);

user_fps[id] = 0;
user_fps_setted[id] = 0;
kick_user[id] = -1;
set_task(1.0, "fps_test", id+7651298, "", 0, "b", 0);
}

public fps_test(id)
{
id -= 7651298;
if( get_pcvar_num(fps_protection) )
{
if( is_user_connected(id) )
{
if( user_fps[id] > 101 && !task_exists(id+6651298) )
{
set_task(0.2, "event_kick_user", id+6651298);
kick_user[id] = 9;
}
else if( user_fps[id] < 102 && task_exists(id+6651298) )
{
remove_task(id+6651298);
kick_user[id] = -1;
}
}
user_fps_setted[id] = user_fps[id];
if( user_fps_setted[id] == 101 )
user_fps_setted[id] -= 1;
}
else if( task_exists(id+6651298) )
{
remove_task(id+6651298);
kick_user[id] = -1;
}
user_fps[id] = 0;
}

public event_kick_user(id)
{
id -= 6651298;
if( kick_user[id] > -1 )
{
kick_user[id] += 1;
set_hudmessage(255, 0, 0, -1.0, 0.30, 0, 1.0, 1.1, 0.0, 0.0, 2);
show_hudmessage(id, "You have %d %s to disable your fps-boost^nor be kicked from the server^nyour fps usage: %d, allowed fps limit: 100", kick_user[id], (kick_user[id]==1) ? "second" : "seconds", user_fps_setted[id]);
set_task(1.0, "event_kick_user", id+6651298);
kick_user[id] -= 2;
}
else
{
static name[32];
get_user_info(id, "name", name, 31);
server_cmd("kick #%d ^"Your fps usage (%d) is over the limit (100)^"", get_user_userid(id), user_fps_setted[id]);
client_print(0, print_chat, "[FPS] %s was kicked due to high fps usage (%d)", name, user_fps_setted[id]);
user_fps_setted[id] = 0;
user_fps[id] = 0;
kick_user[id] = -1;
}
}

public fwdPlayerPreThink(id)
{
if( get_pcvar_num(fps_protection) )
{
if( user_fps[id] < 999 )
user_fps[id] += 1;
else
{
static name[32];
get_user_info(id, "name", name, 31);
server_cmd("kick #%d ^"Your fps usage (999+) is way over the limit (100)^"", get_user_userid(id));
client_print(0, print_chat, "[FPS] %s was kicked due to uber-high fps usage (999+)", name);
user_fps_setted[id] = 0;
user_fps[id] = 0;
kick_user[id] = -1;
}
}
}

public cmdFps(id)
{
if( get_pcvar_num(fps_protection) )
{
if( get_user_time(id, 0) > 3 && user_fps_setted[id] )
{
if( task_exists(id+8651298, 0) )
remove_task(id+8651298, 0);

if( task_exists(id+9651298) )
remove_task(id+9651298);

show_fpshud(id+8651298);
set_task(0.5, "show_fpshud", id+8651298, "", 0, "b", 0);
set_task(14.7, "disable_hud", id+9651298);
client_print(id, print_chat, "[FPS] Your fps usage is %s (%d)", (user_fps_setted[id]<30) ? "criticaly low" : ((user_fps_setted[id]<75) ? "low" : ((user_fps_setted[id]>100) ? "over the limit" : "in good standing")), user_fps_setted[id]);
}
else
client_print(id, print_chat, "[FPS] Please wait 3 seconds to let us get your fps settings");
}
else
client_print(id, print_chat, "[FPS] Fps-protection plugin disabled");
}


public show_fpshud(id)
{
id -= 8651298;
if( user_fps_setted[id] < 30 )
set_hudmessage(255, 127, 0, 0.02, 0.20, 0, 1.0, 0.6, 0.0, 0.0, 2);
else if( user_fps_setted[id] < 75 )
set_hudmessage(0, 127, 255, 0.02, 0.20, 0, 1.0, 0.6, 0.0, 0.0, 2);
else if( user_fps_setted[id] > 100 )
set_hudmessage(255, 0, 0, 0.02, 0.20, 0, 1.0, 0.6, 0.0, 0.0, 2);
else
set_hudmessage(0, 255, 0, 0.02, 0.20, 0, 1.0, 0.6, 0.0, 0.0, 2);

static i, name[32], message[1254];
message = "Players fps stats:";

for( i = 1; i < 33; i++ )
{
if( pev_valid(i) )
{
if( is_user_connected(i) && user_fps_setted && !is_user_bot(i) && !is_user_hltv(i) )
{
get_user_info(i, "name", name, 31);
format( message, 1253, "%s^n%s (%d)", message, name, user_fps_setted);
}
}
}

show_hudmessage(id, "%s", message);
}

public disable_hud(taskid)
{
taskid -= 1000000;
if( task_exists(taskid) )
remove_task(taskid);
}

public client_disconnect(id)
{
if( task_exists(id+6651298) )
remove_task(id+6651298);

if( task_exists(id+7651298, 0) )
remove_task(id+7651298, 0);

if( task_exists(id+8651298, 0) )
remove_task(id+8651298, 0);

if( task_exists(id+9651298) )
remove_task(id+9651298);

user_fps_setted[id] = 0;
user_fps[id] = 0;
kick_user[id] = -1;
}



P.S. If you want to disable it - set cvar kz_fps_protection to 0.
[ Edited ]

Fatalis02/10/2007 03:18

PreThink is NOT client fps.
Use query_client_cvar and query fps_max.

NumB02/10/2007 08:18

but somewhy prethinks in second is the as client_fps number (i tested). =P
[ Edited 10/02/07 - 08:24:14 ]

Fatalis04/10/2007 15:58

PreThink is NOT client fps.

Fatalis

Bibo05/10/2007 08:04

!?!??! 1st time and last time im reading this category.

doktor07/10/2007 16:31

You may start with this :

#include

#define TASKID1 1987654

public plugin_init() {
register_plugin("Check fps", "1.0", "DokTor")
}

public client_putinserver(id) {
set_task(1.0, "fps_check", id+TASKID1, _, _, "b")
}

public client_disconnect(id) {
remove_task(id+TASKID1)
}

public fps_check(id) {
id -= TASKID1

query_client_cvar(id , "fps_max" , "cvar_result")
query_client_cvar(id , "developer" , "cvar_result")
}

public cvar_result(id, const cvar[], const value[])
{
if(equal(value, "Bad CVAR request"))
{
// player has blocked the cvar with an alias
}

new iValue = str_to_num(value)
if(equal(cvar,"fps_max"))
{

if(iValue < 100 || iValue > 101)
{
}
}
else if(equal(cvar,"developer"))
{
if(iValue)
{
//developer is higher than 0
}
}
}



[ Edited 10/07/07 - 16:39:23 ]

colix mapper07/10/2007 17:15

zomg how can u understand these ... :confused:

SchlumPF07/10/2007 17:44

its ez if u know the basics and some commandsthen u easily understand what which does etc ^^

Page 1 of 1

Please log in to post replies.