Raised This Month: $32 Target: $400
 8% 

Hooking a client's cvar change


Post New Thread Reply   
 
Thread Tools Display Modes
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-11-2008 , 05:25   Re: Hooking a client's cvar change
Reply With Quote #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 
formatex(g_szKickMsgMSG_LEN"Server failed to set your rates to acceptable values, ")
    
+= formatex(g_szKickMsg[n], MSG_LEN-n"min values for this server are : ")
    for(new 
jj<TOTAL_CVARSj++)
    {
        
+= 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=1id<=g_iMaxPlayersid++)
    {
        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"2parms)
    
query_client_cvar(id "cl_cmdrate" "cvar_result"2parms)
    
query_client_cvar(id "cl_updaterate" "cvar_result"2parms)
}

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 ii<TOTAL_CVARSi++)
    {
        
copy(szCvar15g_szCvars[i])
        if(!
equal(cvarszCvar))
            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(idprint_chat"** [Good Rates] Server failed to set your %s to %i"szCvariValue)
            
client_print(idprint_chat"** [Good Rates] You will be kicked at %i attempts (current %i)"MAX_RECIDIVEg_iRecidive[id])
        }
        else
        {
            
client_print(idprint_chat"** [Good Rates] Server tried to set your %s to %i"szCvariValue)
            
client_print(idprint_chat"** [Good Rates] Server will check again in 5 sec.")
        }
        
        
client_cmd(id"%s %i"szCvariValue)
        
        if(
task_exists(id+TASKID1+i))
            
remove_task(id+TASKID1+i)

        new 
Recheck[MAX_CVAR_LEN+1]
        
Recheck[0] = 100*i
        
new copy(Recheck[1], MAX_CVAR_LEN-1szCvar)
        
set_task(5.0"Task_Recheck"id+TASKID1+(100*i), Recheckn+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"2parm)

__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
alien
Senior Member
Join Date: Aug 2005
Location: London || Slovakia
Old 03-15-2008 , 00:13   Re: Hooking a client's cvar change
Reply With Quote #12

What about combining both functionalities?

1) Set default value on connect.
2) Set alias on afterwards.
3) Query cvar (hope it's working with blocking alias)
4) If cvar value differs from allowed one, kick player. Otherwise do nothing.

query_client_cvar seems to me a bit like expensive function to be run periodically.
__________________
alien is offline
Send a message via ICQ to alien
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-15-2008 , 03:03   Re: Hooking a client's cvar change
Reply With Quote #13

Quote:
Originally Posted by alien View Post
3) Query cvar (hope it's working with blocking alias)
Works, but blocking cvar with alias cmd should be exception (for cvar that allow some cheats/advantages for example).
Netcode variables shouldn't be blocked for example.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Lee
AlliedModders Donor
Join Date: Feb 2006
Old 03-15-2008 , 06:02   Re: Hooking a client's cvar change
Reply With Quote #14

Connorr, what is wrong with sv_minrate and sv_minupdaterate?
Lee is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode