Raised This Month: $51 Target: $400
 12% 

Solved Detect CVar value change ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Furchee
Member
Join Date: Aug 2010
Old 02-15-2017 , 20:18   Detect CVar value change ?
Reply With Quote #1

[SOLVED. SEE LAST POST OF MINE FOR ANSWER AND CODE.]

So I am currently struggling to understand why my code isn't detecting when someone changes "voice_inputfromfile" to anything besides 0.

Could I get some assistance ?
PHP Code:
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0"
#define message "You were kicked for attempting to micspam. Please set voice_inputfromfile to 0."

public Plugin:myinfo 
{
    
name "Slam Protection",
    
author "Furchee",
    
description "Kicks clients that have voice_inputfromfile set to 1.",
    
version PLUGIN_VERSION,
    
url "http://furchee.com"
};

public 
OnPluginStart()
{
    
//AddCommandListener(CheckMeBaby, "voice_inputfromfile");
    
RegConsoleCmd("voice_inputfromfile"CheckMeBaby)
}

/*public Action:Stalker(client, const String:commands[], argd)
{
    decl String:commands[192];
    
    if(!StrEqual(commands, "0"))
    {
        StringToInt(commands
        return Plugin_Continue;
    }
    else if(!StrEqual(commands, "0"))
    {
        LogAction(client, -1, "%L triggered mic spam protection, kicking", client);
        KickClient(client, "%s", message);
        return Plugin_Continue;
    }
    return Plugin_Handled;
}*/

public OnClientPutInServer(client)
{
    
CreateTimer(2.0StartVarCheckerclient);
}

public 
Action:CheckMeBaby(clientargs)
{
    if(
client && args)
    {
        new 
String:strCommand[5];
        
GetCmdArg(1strCommandsizeof(strCommand));
        
        if(
StringToInt(strCommand) == 0)
        {
            return 
Plugin_Handled;
        }
        
        else if (
StringToInt(strCommand) != 0)
        {
            
LogAction(client, -1"%L triggered mic spam protection, kicking"client);
            
KickClient(client"%s"message);
        }
    }
    return 
Plugin_Continue;
}

public 
Action:StartVarChecker(Handle:timerany:client)
{    
    
/*if (!IsClientInGame(client))
        return Plugin_Stop;
    */
    
    
QueryClientConVar(client"voice_inputfromfile"ConVarQueryFinished:ClientConVarclient);
    return 
Plugin_Continue;
}

public 
ClientConVar(QueryCookie:cookieclientConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
    if(!
StrEqual(cvarValue"0"))
    {
        
LogAction(client, -1"%L triggered mic spam protection, kicking"client);
        
KickClient(client"%s"message);
    }


Last edited by Furchee; 02-16-2017 at 22:28.
Furchee is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 02-15-2017 , 20:28   Re: Detect CVar value change ?
Reply With Quote #2

Something like this:

PHP Code:
public void OnPluginStart()
{
    
HookConVarChange(FindConVar("voice_inputfromfile"), Convar_Callback);
}

public 
void Convar_Callback(ConVar convarchar[] oldValuechar[] newValue)
{
    
//Do something...




Nevermind, i just read your code... use QueryClientConVar: https://sm.alliedmods.net/new-api/co...ryClientConVar
to detect client convar value.

PHP Code:
public void OnPluginStart()
{
    for (
int i 1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i) || !IsFakeClient(i))
            continue;
        
QueryClientConVar(i"voice_inputfromfile"Convar_Callback);
    }
}

public 
Convar_Callback(QueryCookie cookieint clientConVarQueryResult result, const char[] cvarName, const char[] cvarValue)
{
    
//Do something

__________________

Last edited by Chaosxk; 02-15-2017 at 20:40.
Chaosxk is offline
Furchee
Member
Join Date: Aug 2010
Old 02-15-2017 , 21:42   Re: Detect CVar value change ?
Reply With Quote #3

Quote:
Originally Posted by Chaosxk View Post
Nevermind, i just read your code... use QueryClientConVar: https://sm.alliedmods.net/new-api/co...ryClientConVar
to detect client convar value.
I should have been more descriptive, sorry.

The plugin does in fact function but ONLY when a client connects to the server (with the value being != 0) does it kick them. What I want is the other part of the code to work that will detect when they change the CVar while in-game and kick them when it detects it.

As you can see I tried making a hook onto that CVar but it doesn't seem to react at all while using the CommandListener or the RegCmd.

Last edited by Furchee; 02-15-2017 at 21:42.
Furchee is offline
Hunter6272
Senior Member
Join Date: Jun 2015
Location: Don't know
Old 02-16-2017 , 01:00   Re: Detect CVar value change ?
Reply With Quote #4

WoW! If Slam protection really works, can someone post here a fully working code?
__________________
Patience is the key to success.
Hunter6272 is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 02-16-2017 , 02:42   Re: Detect CVar value change ?
Reply With Quote #5

Quote:
Originally Posted by Furchee View Post
I should have been more descriptive, sorry.

The plugin does in fact function but ONLY when a client connects to the server (with the value being != 0) does it kick them. What I want is the other part of the code to work that will detect when they change the CVar while in-game and kick them when it detects it.

As you can see I tried making a hook onto that CVar but it doesn't seem to react at all while using the CommandListener or the RegCmd.

I see, CommandListener/RegCmd only works on commands that client sends to server. Not convars, so they won't do anything with convars.

AFAIK i don't think there is a forward/hook to detect when a client changes their convars. The only alternative that i could think of is to use a repeating timer to query the the client convar (but obviously that is inefficient, maybe someone else can knows a better way)

Try this, it uses the repeating timer alternative:
PHP Code:
#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.0"
#define message "You were kicked for attempting to micspam. Please set voice_inputfromfile to 0."

public Plugin:myinfo 
{
    
name "Slam Protection",
    
author "Furchee",
    
description "Kicks clients that have voice_inputfromfile set to 1.",
    
version PLUGIN_VERSION,
    
url "http://furchee.com"
};

public 
OnPluginStart()
{
    
//3.0 seconds seems reasonable?
    
CreateTimer(3.0StartVarChecker_TIMER_REPEAT);
}

public 
Action:StartVarChecker(Handle:timer)
{    
    for (new 
1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i) || !IsFakeClient(i))
            continue;
        
QueryClientConVar(i"voice_inputfromfile"ConVarQueryFinished:ClientConVari);
    }
}

public 
ClientConVar(QueryCookie:cookieclientConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
    if(!
StrEqual(cvarValue"0"))
    {
        
LogAction(client, -1"%L triggered mic spam protection, kicking"client);
        
KickClient(client"%s"message);
    }

__________________
Chaosxk is offline
Furchee
Member
Join Date: Aug 2010
Old 02-16-2017 , 07:59   Re: Detect CVar value change ?
Reply With Quote #6

Quote:
Originally Posted by Chaosxk View Post
I see, CommandListener/RegCmd only works on commands that client sends to server. Not convars, so they won't do anything with convars.

AFAIK i don't think there is a forward/hook to detect when a client changes their convars. The only alternative that i could think of is to use a repeating timer to query the the client convar (but obviously that is inefficient, maybe someone else can knows a better way)

Try this, it uses the repeating timer alternative:
<code>
Thank you so much for your detailed response.
That would make sense as to why it never worked. Wasn't aware convars aren't checked as regular commands.
Appreciate it! (I'll test this once I'm back from work and if everything goes well I will change the thread title to solved.)
Furchee is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 02-16-2017 , 09:45   Re: Detect CVar value change ?
Reply With Quote #7

Check if server have this feature already. Type this without value you should get cvar result back in console.

sm_cvar sv_allow_voice_from_file

...and if it give output value, change cvar
sm_cvar sv_allow_voice_from_file 0

*edit
Players can still play music through microfone input though
__________________
Do not Private Message @me

Last edited by Bacardi; 02-16-2017 at 09:47.
Bacardi is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 02-16-2017 , 09:50   Re: Detect CVar value change ?
Reply With Quote #8

Quote:
Originally Posted by Bacardi View Post
Players can still play music through microfone input though
Yeah, just about anybody can setup a thirdparty app that takes over your mic's output where a player can play music with the same quality etc. I had a similar setup for h1z1.
Mitchell is offline
Furchee
Member
Join Date: Aug 2010
Old 02-16-2017 , 19:39   Re: Detect CVar value change ?
Reply With Quote #9

Quote:
Originally Posted by Bacardi View Post
Check if server have this feature already. Type this without value you should get cvar result back in console.

sm_cvar sv_allow_voice_from_file

...and if it give output value, change cvar
sm_cvar sv_allow_voice_from_file 0

*edit
Players can still play music through microfone input though
Afraid there is no Cvar like that at all. I did "find allow" as well as "find voice" through the client console and found nothing of the sort.
I am aware you can still use virtual audio cable and what not but a lot of people use SLAM and this would weed out the majority of children that prefer using it.

With that said, the previously linked code doesn't work at all.

MASSIVE UPDATE and EDIT HERE:
Got it working! I assumed it wasn't working because it wasn't checking / binding to the clients correctly so I went looking around for a voice callback and found this thread.
The code I used (I'm sure many would like to have it) is as follows (with of course both Dhooks and VoiceAnnounceEX installed):
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <basecomm>
#include <voiceannounce_ex>

#define PLUGIN_VERSION "1.0"
#define message "You were kicked for attempting to micspam. Please set voice_inputfromfile to 0."

public Plugin:myinfo 
{
    
name "Slam Protection",
    
author "Furchee",
    
description "Kicks clients that have voice_inputfromfile set to 1.",
    
version PLUGIN_VERSION,
    
url "http://furchee.com"
};

public 
OnClientPutInServer(client)
{
    
CreateTimer(2.0StartVarCheckerclient);
}

public 
void OnClientSpeakingEx(client)
{
    
QueryClientConVar(client"voice_inputfromfile"ConVarQueryFinished:ClientConVarclient);
}

public 
Action:StartVarChecker(Handle:timerany:client)
{    
    
/*if (!IsClientInGame(client))
        return Plugin_Stop;
    */
    
    
QueryClientConVar(client"voice_inputfromfile"ConVarQueryFinished:ClientConVarclient);
    return 
Plugin_Continue;
}

public 
ClientConVar(QueryCookie:cookieclientConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
    if(!
StrEqual(cvarValue"0"))
    {
        
LogAction(client, -1"%L triggered mic spam protection, kicking"client);
        
KickClient(client"%s"message);
    }


Last edited by Furchee; 02-16-2017 at 22:30.
Furchee is offline
luckykevin
Member
Join Date: Feb 2017
Old 03-21-2017 , 23:00   Re: Detect CVar value change ?
Reply With Quote #10

Works like a charm dude. Thank you! The part I love is that even when they have voice_inputfromfile set to 1, it only kicks them when they actually use +voicerecord.

So to test it, I had voice_inputfromfile 1 but it didn't kick me. Then, when I pressed my voice bind, it kicked me instantly. Sick!
luckykevin 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 17:54.


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