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

Solved Temporarily saving a player's message (Anti-Spam plugin)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FAQU
Member
Join Date: Sep 2020
Location: Romania
Old 11-20-2020 , 04:56   Temporarily saving a player's message (Anti-Spam plugin)
Reply With Quote #1

I'm trying to make an anti-spam plugin. The basic ideea behind this is that if a player types the same message in chat 3 times in less than 10 seconds, he will be gagged.

The issue that I'm experiencing however is that if another player types anything in chat, the player who spammed won't get gagged anymore. For example if :

Player1: sourcemod
Player1: sourcemod
Player2: anything
Player1: sourcemod --> Player1 will not get gagged, although he spammed.

Basically what I need to make this work properly, is a way of temporarily storing the player's previous message.
Any help would be really appreciated.

Code here:
PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

char spamcount[MAXPLAYERS 1] =  { 0, ... };
char playermessage[200];
char samemessage[200];

public 
Plugin myinfo 
{
    
name "Anti-Spam",
    
author "FAQU",
    
description "Gags the player for sending the same message 3 times in less than 10 seconds."
};

public 
void OnPluginStart()
{
    
HookEvent("player_say"OnPlayerSay);
}

public 
void OnClientPutInServer(int client)
{
    
ResetSpamCount(client);
}

public 
void OnClientDisconnect(int client)
{
    
ResetSpamCount(client);
}

public 
Action OnPlayerSay(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
GetEventString(event"text"playermessagesizeof(playermessage));
    
    if (
spamcount[client] == 0)
    {
        
strcopy(samemessagesizeof(samemessage), playermessage);
        
spamcount[client]++;
        
CreateTimer(10.0Timer_ResetLimitclient);
        return 
Plugin_Handled;
    }
    
    if (
spamcount[client] == 1)
    {
        
GetEventString(event"text"playermessagesizeof(playermessage));
        if (
StrEqual(playermessagesamemessage))
        {
            
spamcount[client]++;
        }
        return 
Plugin_Handled;
    }
    
    if (
spamcount[client] == 2)
    {
        
GetEventString(event"text"playermessagesizeof(playermessage));
        if (
StrEqual(playermessagesamemessage))
        {
            
ServerCommand("sm_gag %N"client);
            
ResetSpamCount(client);
        }
        return 
Plugin_Handled;
    }
    else
    return 
Plugin_Handled;
}

public 
Action Timer_ResetLimit(Handle timerint client)
{
    
ResetSpamCount(client);
}

void ResetSpamCount(int client)
{
    
spamcount[client] = 0;


Last edited by FAQU; 11-20-2020 at 10:11.
FAQU is offline
FAQU
Member
Join Date: Sep 2020
Location: Romania
Old 11-20-2020 , 10:11   Re: Temporarily saving a player's message (Anti-Spam plugin)
Reply With Quote #2

The solution was to index both playermessage and samemessage per client.

Here is the fixed code:

PHP Code:
#include <sourcemod>
#include <sdktools>

#pragma semicolon 1
#pragma newdecls required

char spamcount[MAXPLAYERS 1] =  { 0, ... };
char playermessage[MAXPLAYERS 1][128];
char samemessage[MAXPLAYERS 1][128];

public 
Plugin myinfo 
{
    
name "Anti-Spam",
    
author "FAQU"
    
//description = "Gags the player for sending the same message 3 times in less than 10 seconds."
};

public 
void OnPluginStart()
{
    
HookEvent("player_say"OnPlayerSay);
}

public 
void OnClientPutInServer(int client)
{
    
ResetSpamCount(client);
}

public 
void OnClientDisconnect(int client)
{
    
ResetSpamCount(client);
}

public 
Action OnPlayerSay(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
GetEventString(event"text"playermessage[client], sizeof(playermessage));
    
    if (
spamcount[client] == 0)
    {
        
strcopy(samemessage[client], sizeof(samemessage), playermessage[client]);
        
spamcount[client]++;
        
CreateTimer(10.0Timer_ResetSpamcountclient);
        return 
Plugin_Handled;
    }
    
    if (
spamcount[client] == 1)
    {
        if (
StrEqual(playermessage[client], samemessage[client]))
        {
            
spamcount[client]++;
        }
        return 
Plugin_Handled;
    }
    
    if (
spamcount[client] == 2)
    {
        if (
StrEqual(playermessage[client], samemessage[client]))
        {
            
int userid GetClientUserId(client);
            
ServerCommand("sm_gag #%d"userid);
            
ResetSpamCount(client);
        }
        return 
Plugin_Handled;
    }
    else
    return 
Plugin_Handled;
}

public 
Action Timer_ResetSpamcount(Handle timerint client)
{
    
ResetSpamCount(client);
}

void ResetSpamCount(int client)
{
    
spamcount[client] = 0;


Last edited by FAQU; 11-22-2020 at 00:05. Reason: "The Almighty Goat; quit"
FAQU is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 11-21-2020 , 12:22   Re: Temporarily saving a player's message (Anti-Spam plugin)
Reply With Quote #3

1. Best would be to look at including <basecomm> and using the functions there to take are of muting/gagging people.

Go through include/basecomm.inc for more instructions.


2. If you absolutely insist on ServerCommand, - please do it more sanely, like:

PHP Code:
            ServerCommand("sm_gag %d"GetClientUserId(client)); 
3. With your current version, ... e.g.:

Quote:
Originally Posted by FAQU View Post
PHP Code:
            ServerCommand("sm_gag %N"client); 
I'm afraid you will hate when "The Almighty Goat; quit" is spamming on your server.

You know, no one really wants to mess with The Almighty Goat.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
FAQU
Member
Join Date: Sep 2020
Location: Romania
Old 11-21-2020 , 23:59   Re: Temporarily saving a player's message (Anti-Spam plugin)
Reply With Quote #4

The reason that I don't use basecomm is that I want the gag to go through extendedcomm. (a time-based gag/mute plugin)
The actual code that I'm using right now on my server looks more like this:
PHP Code:
int userid GetClientUserId(client);
ServerCommand("sm_gag #%d 4 anti-spam"userid); 
Already figured out that "The Almighty Goat; quit" might be lurking around, just forgot to update the code here.
Thanks for the heads-up.

Last edited by FAQU; 11-27-2020 at 04:10.
FAQU is offline
Reply


Thread Tools
Display Modes

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 20:28.


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