Veteran Member
Join Date: Jul 2006
Location: France (95)
|
03-11-2008
, 05:25
Re: Hooking a client's cvar change
|
#11
|
Wilson's plugin doesn't check client cvar values (query_client_cvar), so clients can just block cvars before joining the server, then the plugin is inefficient.
I would stick with cvar_checker.
I'm using this on my server but i may not be a good way, and it's a bit tricky and hardcoded.
PHP Code:
/* AMX Mod X Plugin
*
* (c) Copyright 2008, ConnorMcLeod
* This file is provided as is (no warranties).
*
*/
#include <amxmodx>
#define MAX_PLAYERS 32
#define MAX_RECIDIVE 5
#define MSG_LEN 256
#define TASKID1 16468731465
#define MAX_CVAR_LEN 14
#define MIN_RATE 20000
#define MIN_CMDRATE 101
#define MIN_UPDATERATE 75
// | | | | -----
#define TOTAL_CVARS 3
new const g_szCvars[TOTAL_CVARS][MAX_CVAR_LEN] = { "rate", "cl_cmdrate", "cl_updaterate" }
new const g_iCvarsValues[TOTAL_CVARS] = { MIN_RATE, MIN_CMDRATE, MIN_UPDATERATE }
new g_iRecidive[MAX_PLAYERS+1]
new bool:g_bRestartAttempt[MAX_PLAYERS+1]
new g_szKickMsg[MSG_LEN+1]
new g_iMaxPlayers
public plugin_init()
{
register_plugin("Good Rates", "0.2", "connor")
register_event("TextMsg", "eRestartAttempt", "a", "2=#Game_will_restart_in")
register_event("ResetHUD", "eResetHUD", "be")
register_clcmd("fullupdate", "fullupdateCmd")
}
public plugin_cfg()
{
g_iMaxPlayers = get_maxplayers()
new n = formatex(g_szKickMsg, MSG_LEN, "Server failed to set your rates to acceptable values, ")
n += formatex(g_szKickMsg[n], MSG_LEN-n, "min values for this server are : ")
for(new j; j<TOTAL_CVARS; j++)
{
n += formatex(g_szKickMsg[n], MSG_LEN-n, "- %s %i", g_szCvars[j], g_iCvarsValues[j])
}
}
public client_putinserver(id)
{
g_iRecidive[id] = 0
g_bRestartAttempt[id] = false
}
public client_disconnect(id)
{
g_bRestartAttempt[id] = false
}
public eRestartAttempt()
{
static id
for(id=1; id<=g_iMaxPlayers; id++)
{
if(is_user_alive(id))
g_bRestartAttempt[id] = true
}
}
public eResetHUD(id)
{
if (g_bRestartAttempt[id])
{
g_bRestartAttempt[id] = false
return
}
new parms[2]
query_client_cvar(id , "rate" , "cvar_result", 2, parms)
query_client_cvar(id , "cl_cmdrate" , "cvar_result", 2, parms)
query_client_cvar(id , "cl_updaterate" , "cvar_result", 2, parms)
}
public fullupdateCmd(id)
{
return PLUGIN_HANDLED_MAIN
}
public cvar_result(id, const cvar[], const value[], parm[])
{
if(!is_user_connected(id))
return PLUGIN_CONTINUE
static szCvar[16], iValue
for(new i; i<TOTAL_CVARS; i++)
{
copy(szCvar, 15, g_szCvars[i])
if(!equal(cvar, szCvar))
continue
iValue = g_iCvarsValues[i]
if(str_to_num(value) >= iValue)
return PLUGIN_HANDLED
if(parm[0] == 1)
{
if(++g_iRecidive[id] >= MAX_RECIDIVE)
{
server_cmd("kick #%i ^"%s^"", get_user_userid(id), g_szKickMsg)
return PLUGIN_HANDLED
}
client_print(id, print_chat, "** [Good Rates] Server failed to set your %s to %i", szCvar, iValue)
client_print(id, print_chat, "** [Good Rates] You will be kicked at %i attempts (current %i)", MAX_RECIDIVE, g_iRecidive[id])
}
else
{
client_print(id, print_chat, "** [Good Rates] Server tried to set your %s to %i", szCvar, iValue)
client_print(id, print_chat, "** [Good Rates] Server will check again in 5 sec.")
}
client_cmd(id, "%s %i", szCvar, iValue)
if(task_exists(id+TASKID1+i))
remove_task(id+TASKID1+i)
new Recheck[MAX_CVAR_LEN+1]
Recheck[0] = 100*i
new n = copy(Recheck[1], MAX_CVAR_LEN-1, szCvar)
set_task(5.0, "Task_Recheck", id+TASKID1+(100*i), Recheck, n+3)
return PLUGIN_HANDLED
}
return PLUGIN_CONTINUE
}
public Task_Recheck(Recheck[], id)
{
id -= (TASKID1+Recheck[0])
if(!is_user_connected(id))
return
static parm[2]
parm[0] = 1
query_client_cvar(id , Recheck[1], "cvar_result", 2, parm)
}
__________________
|
|