AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [ANY] Block / Limit Chat (1.0.2) (https://forums.alliedmods.net/showthread.php?t=202812)

Sheepdude 12-10-2012 19:40

[ANY] Block / Limit Chat (1.0.2)
 
1 Attachment(s)
Block / Limit Chat

Version 1.0.2


Table of Contents
----------------------------------------------------
Description
Commands and Cvars
Installation
Credits
Changelog
To Do
Notes
Download


Description
----------------------------------------------------
This plugin blocks players from freely using chat:
  • Players may only type specific phrases that are listed
    in a text file.
  • Admins can be given the ability to chat freely, and may grant or
    deny unrestricted chat privileges for players.
  • Players can !requestchat, which will create an admin vote
    to determine if a player should be given unrestricted chat permission.


How is this different from !gag
----------------------------------------------------
Unlike !gag, players can still talk, but only using pre-determined phrases.
Also, this plugin assumes you generally do not want to allow chat on your server.
Players are automatically disallowed from using non-phrase chat, unless they are admin.


Commands and Cvars
----------------------------------------------------
Commands
sm_requestchat <reason> Request permission to use chat freely. This calls an admin vote for approval. Can only be used once per map.
sm_limitchat_give <@all/@ct/@t/partial name> - (ADMFLAG_GENERIC) Grants unrestricted chat privileges to a player or group of players.
sm_limitchat_take <@all/@ct/@t/partial name> - (ADMFLAG_GENERIC) Denies unrestricted chat privileges for a player or group of players.

Cvars
sm_limitchat_version - Plugin version.
sm_limitchat_enable - (Default 1) Enable or disable plugin (1 - enable, 0 - disable).
sm_limitchat_admins - (Default 1) Admins are automatically allowed to use chat freely (1 - allow admins to chat, 0 - disallow)
sm_limitchat_request - (Default 1) Allow players to request unrestricted chat permission (1 - allow, 0 - disallow)
sm_limitchat_needed - (Default 0.55) Percentage of admin votes needed to grant unrestricted chat permission (must be 50% or above to work).


Installation
----------------------------------------------------
Unzip limitchat_1.0.2.zip into your server game directory.
Change allowed phrases in /addons/sourcemod/configs/allowedchatphrases.txt.


Credits
----------------------------------------------------
  • Thanks to VJScope for suggesting ideas and requesting the plugin.

Changelog
----------------------------------------------------
  • 1.0.0 (10 December 2012)
    -Initial version.

  • 1.0.1 (11 December 2012)
    -Bug fix: Convar sm_limitchat_admins now works as intended.

  • 1.0.2 (12 December 2012)
    -Convar sm_limitchat_admins now takes effect immediately (no longer requires a map change).

To Do
----------------------------------------------------
  • None.

Notes
----------------------------------------------------
  • SourceMod commands that aren't listed in allowedchatphrases.txt (such as !rtv) still function normally; they just won't appear in chat.
  • Use /addons/sourcemod/configs/adminoverrides.cfg to change admin permissions.
Example admin_overrides.cfg:
Code:

Overrides
{
        "sm_limitchat_give"        "z"
        "sm_limitchat_take"        "c"
        "limitchat"                "jh"
}

In this example, only admins with the "z" flag can give players full chat permission. Admins with the "c" flag can remove player chat permissions, and admins who have both "j" and "h" flags are automatically allowed to use chat freely when they connect.

Download
----------------------------------------------------

VJScope 12-11-2012 10:26

Re: [ANY] Block / Limit Chat
 
First of all thank you very much for this plugin!

Small problem:
sm_limitchat_admins 0 doesn't work for some reason.

Errorlog (I think I fixed that respawn.phrases.txt, don't mind it):
Code:

L 12/11/2012 - 17:34:35: Info (map "cs_office") (file "errors_20121211.log")
L 12/11/2012 - 17:34:35: [SM] Fatal error encountered parsing translation file "respawn.phrases.txt"
L 12/11/2012 - 17:34:35: [SM] Error (line 0, column 0): Stream failed to open
L 12/11/2012 - 17:34:35: [SM] Native "IsClientInGame" reported: Client index 0 is invalid
L 12/11/2012 - 17:34:35: [SM] Displaying call stack trace for plugin "limitchat.smx":
L 12/11/2012 - 17:34:35: [SM]  [0]  Line 81, limitchat.sp::OnSayCommand()


Sheepdude 12-11-2012 14:07

Re: [ANY] Block / Limit Chat (1.0.1)
 
sm_limitchat_admins 0 should work now. =)

VJScope 12-12-2012 07:56

Re: [ANY] Block / Limit Chat (1.0.1)
 
Yeah, works now! Thank you! (Still a minor bug that if I try to switch that sm_limitchat_admins back to 1, still "chat not allowed"). I guess it needs server restart after changing admin-rights or these configs We don't mind but just to let you know. GREAT WORK!!!

Sheepdude 12-12-2012 20:03

Re: [ANY] Block / Limit Chat (1.0.2)
 
I changed sm_limitchat_admins to take effect immediately instead of on a map change. I wouldn't say it was a bug, just a decision, but yeah immediate effect is probably better.

SGCatlantis 02-15-2013 17:09

Re: [ANY] Block / Limit Chat (1.0.2)
 
Hi,

no work for HL2 mod: Stargate :The last Stand :cry:

medic917 09-14-2014 14:08

Re: [ANY] Block / Limit Chat (1.0.2)
 
Can't find one for microphone do you have it?

Ejziponken 08-27-2019 06:38

Re: [ANY] Block / Limit Chat (1.0.2)
 
L 08/27/2019 - 12:23:59: [SM] Exception reported: Client index 0 is invalid
L 08/27/2019 - 12:23:59: [SM] Blaming: limitchat.smx
L 08/27/2019 - 12:23:59: [SM] Call stack trace:
L 08/27/2019 - 12:23:59: [SM] [0] IsClientInGame
L 08/27/2019 - 12:23:59: [SM] [1] Line 81, plugin.sp::OnSayCommand

Cruze 08-27-2019 12:16

Re: [ANY] Block / Limit Chat (1.0.2)
 
Quote:

Originally Posted by Ejziponken (Post 2664933)
L 08/27/2019 - 12:23:59: [SM] Exception reported: Client index 0 is invalid
L 08/27/2019 - 12:23:59: [SM] Blaming: limitchat.smx
L 08/27/2019 - 12:23:59: [SM] Call stack trace:
L 08/27/2019 - 12:23:59: [SM] [0] IsClientInGame
L 08/27/2019 - 12:23:59: [SM] [1] Line 81, plugin.sp::OnSayCommand

PHP Code:

#include <sourcemod>
#pragma semicolon 1

#define PLUGIN_VERSION "1.0.2"

public Plugin:myinfo 
{
    
name "Block / Limit Chat",
    
author "Sheepdude",
    
description "Limit chat to a specific list of phrases or only for admins and select players.",
    
version PLUGIN_VERSION,
    
url "http://www.clan-psycho.com"
};

new 
Handle:h_cvarEnable;
new 
Handle:h_cvarAdmins;
new 
Handle:h_cvarRequest;
new 
Handle:h_cvarNeeded;

new 
bool:g_cvarEnable;
new 
bool:g_cvarAdmins;
new 
bool:g_cvarRequest;
new 
Float:g_cvarNeeded;

new 
String:AllowedPhrases[128][64];
new 
bool:AllowedToChat[MAXPLAYERS+1];
new 
bool:RequestedChat[MAXPLAYERS+1];
new 
linecount;

public 
OnPluginStart()
{
    
CreateConVar("sm_limitchat_version"PLUGIN_VERSION"Block / Limit Chat plugin version"FCVAR_DONTRECORD|FCVAR_NOTIFY|FCVAR_PLUGIN|FCVAR_REPLICATED|FCVAR_SPONLY);
    
h_cvarEnable CreateConVar("sm_limitchat_enable""1""Enable plugin (1 - enable, 0 - disable)"0true0.0true1.0);
    
h_cvarAdmins CreateConVar("sm_limitchat_admins""1""Admins are automatically allowed to chat (1 - admins can chat, 0 - chat restricted)"0true0.0true1.0);
    
h_cvarRequest CreateConVar("sm_limitchat_request""1""Allow requests for chat permission (1 - allow, 0 - disallow)"0true0.0true1.0);
    
h_cvarNeeded CreateConVar("sm_limitchat_needed""0.55""Percentage of admin votes required to grant chat permission"0true0.0true2.0);
    
    
RegConsoleCmd("sm_requestchat"RequestChat);
    
RegAdminCmd("sm_limitchat_give"GiveChatADMFLAG_GENERIC"Grants players permission to chat.");
    
RegAdminCmd("sm_limitchat_take"TakeChatADMFLAG_GENERIC"Denies players permission to chat.");
    
    
HookConVarChange(h_cvarEnableConvarChanged);
    
HookConVarChange(h_cvarAdminsConvarChanged);
    
HookConVarChange(h_cvarRequestConvarChanged);
    
HookConVarChange(h_cvarNeededConvarChanged);
    
    
AddCommandListener(OnSayCommand"say");
    
AddCommandListener(OnSayCommand"say_team");
    
    
ReadTextFile();
}

/**********
 *Forwards*
***********/

public OnConfigsExecuted()
{
    
UpdateAllConvars();
    for(new 
1<= MaxClientsi++)
    {
        
RequestedChat[i] = false;
        
AllowedToChat[i] = false;
    }
    if(
g_cvarAdmins)
        
AllowAdminChat();
}

public 
OnClientPostAdminCheck(client)
{
    if(
IsClientInGame(client) && g_cvarAdmins && CheckCommandAccess(client"limitchat"ADMFLAG_GENERICtrue))
        
AllowedToChat[client] = true;
}

/**********
 *Commands*
***********/

public Action:OnSayCommand(client, const String:command[], args)
{
    if(!
client || !IsClientInGame(client) || AllowedToChat[client])
        return 
Plugin_Continue;
    
decl String:text[192];
    if (!
GetCmdArgString(textsizeof(text)))
        return 
Plugin_Stop;
    new 
startidx 0;
    if(
text[strlen(text)-1] == '"')
    {
        
text[strlen(text)-1] = '\0';
        
startidx 1;
    }
    if(!
IsValidPhrase(textstartidx))
    {
        
PrintToChat(client"Chat is not allowed.");
        return 
Plugin_Stop;
    }
    return 
Plugin_Continue;    
}

public 
Action:RequestChat(clientargs)
{
    if(!
g_cvarRequest)
        return 
Plugin_Handled;
    if(
args 1)
    {
        
ReplyToCommand(client"[SM] Usage: sm_requestchat <reason>");
        return 
Plugin_Handled;
    }
    if(
RequestedChat[client])
    {
        
ReplyToCommand(client"[SM] You may only request chat permission once per map.");
        return 
Plugin_Handled;
    }
    if(
IsVoteInProgress())
    {
        
ReplyToCommand(client"[SM] Vote is in progress, please wait to use this command.");
        return 
Plugin_Handled;
    }
    
decl String:argstring[64];
    
GetCmdArgString(argstringsizeof(argstring));
    
DoVoteMenu(clientargstring);
    return 
Plugin_Handled;
}

/****************
 *Admin Commands*
*****************/

public Action:GiveChat(clientargs)
{
    if(
args 0)
    {
        if(
CheckCommandAccess(client"sm_limitchat_give"ADMFLAG_GENERICtrue))
        {
            
decl String:target[64];
            new 
targetlist[MAXPLAYERS+1];
            
GetCmdArg(1targetsizeof(target));
            if(
FindMatchingPlayers(targettargetlist) == 0)
            {
                new 
targetindex FindTarget(clienttarget);
                if(
targetindex 0)
                {
                    
AllowedToChat[targetindex] = true;
                    
ShowActivity2(client"[SM] ""%N has granted %N permission to chat."clienttargetindex);
                }
            }
            else
                
ShowActivity2(client"[SM] ""%N has granted %s permission to chat."clienttarget);
        }
        else
            
ReplyToCommand(client"[SM] You do not have access to that command.");
    }
    else
        
ReplyToCommand(client"[SM] Usage: sm_givechat <@all/@ct/@t/partial name>");
    return 
Plugin_Handled;
}

public 
Action:TakeChat(clientargs)
{
    if(
args 0)
    {
        if(
CheckCommandAccess(client"sm_limitchat_take"ADMFLAG_GENERICtrue))
        {
            
decl String:target[64];
            new 
targetlist[MAXPLAYERS+1];
            
GetCmdArg(1targetsizeof(target));
            if(
FindMatchingPlayers(targettargetlist) == 0)
            {
                new 
targetindex FindTarget(clienttarget);
                if(
targetindex 0)
                {
                    
AllowedToChat[targetindex] = true;
                    
ShowActivity2(client"[SM] ""%N has denied %N permission to chat."clienttargetindex);
                }
            }
            else
                
ShowActivity2(client"[SM] ""%N has denied %s permission to chat."clienttarget);
        }
        else
            
ReplyToCommand(client"[SM] You do not have access to that command.");
    }
    else
        
ReplyToCommand(client"[SM] Usage: sm_takechat <@all/@ct/@t/partial name>");
    return 
Plugin_Handled;
}

/***********
 *Callbacks*
************/

public HandleVoteMenu(Handle:menuMenuAction:actionparam1param2
{
    if (
action == MenuAction_End
        
CloseHandle(menu);
    else if (
action == MenuAction_VoteEnd)
    {
        
decl String:buffer[8];
        
GetMenuItem(menu0buffersizeof(buffer));
        new 
client StringToInt(buffer);
        new 
admins[MAXPLAYERS+1];
        new 
count GetAdminList(admins);
        new 
votes;
        new 
totalVotes;
        
GetMenuVoteInfo(param2votestotalVotes);
        new 
Float:percent FloatDiv(float(votes), float(totalVotes));
        if(
param1 == 0)
        {
            if(
percent g_cvarNeeded)
            {
                
PrintToChat(client"[SM] You have been denied permission to chat freely.");
                for(new 
0counti++)
                    
PrintToChat(admins[i], "[SM] %N has been denied permission to chat. Received %d\%% of %d votes. (%d%% needed)"clientRoundToNearest(100.0 percent), totalVotesRoundToNearest(100.0 g_cvarNeeded));
            }
            else
            {
                
AllowedToChat[client] = true;
                
PrintToChat(client"[SM] You have been granted permission to chat freely.");
                for(new 
0counti++)
                    
PrintToChat(admins[i], "[SM] %N has been granted permission to chat. Received %d\%% of %d votes. (%d%% needed)"clientRoundToNearest(100.0 percent), totalVotesRoundToNearest(100.0 g_cvarNeeded));
            }
        }
        else
        {
            
PrintToChat(client"[SM] You have been denied permission to chat freely.");
            for(new 
0counti++)
                
PrintToChat(admins[i], "[SM] %N has been denied permission to chat. Received %d\%% of %d votes. (%d%% needed)"clientRoundToNearest(100.0 * (percent)), totalVotesRoundToNearest(100.0 g_cvarNeeded));
        }
    }
}

/*********
 *Helpers*
**********/

AllowAdminChat()
{
    new 
admins[MAXPLAYERS+1];
    new 
count GetAdminList(admins);
    for(new 
0counti++)
        
AllowedToChat[admins[i]] = true;
}

DoVoteMenu(client, const String:reason[])
{
    
decl String:buffer[8];
    
Format(buffersizeof(buffer), "%i"client);
    new 
Handle:menu CreateMenu(HandleVoteMenu);
    
SetMenuTitle(menu"%N has requested permission to use chat. Reason: %s"clientreason);
    
AddMenuItem(menubuffer"Allow");
    
AddMenuItem(menubuffer"Deny");
    new 
admins[MAXPLAYERS+1];
    new 
count GetAdminList(admins);
    
VoteMenu(menuadminscount15);
}

FindMatchingPlayers(const String:matchstr[], clients[])
{
    new 
0;
    if(
StrEqual(matchstr"@all"false))
    {
        for(new 
1<= MaxClientsx++)
        {
            if(
IsClientInGame(x))
            {
                
clients[k] = x;
                
k++;
            }
        }
    }
    else if(
StrEqual(matchstr"@t"false))
    {
        for(new 
1<= MaxClientsx++)
        {
            if(
IsClientInGame(x) && GetClientTeam(x) == 2)
            {
                
clients[k] = x;
                
k++;
            }
        }
    }
    else if(
StrEqual(matchstr"@ct"false))
    {
        for(new 
1<= MaxClientsx++)
        {
            if(
IsClientInGame(x) && GetClientTeam(x) == 3)
            {
                
clients[k] = x;
                
k++;
            }
        }
    }
    return 
k;
}

GetAdminList(admins[])
{
    new 
count 0;
    for(new 
1<= MaxClientsi++)
    {
        if(
IsClientInGame(i) && CheckCommandAccess(i"limitchat"ADMFLAG_GENERICtrue))
        {
            
admins[count] = i;
            
count++;
        }
    }
    return 
count;
}

bool:IsValidPhrase(const String:phrase[], startidx=0)
{
    for(new 
0linecounti++)
    {
        if(
strcmp(phrase[startidx], AllowedPhrases[i], false) == 0)
            return 
true;
    }
    return 
false;
}

ReadTextFile()
{
    new 
Handle:file OpenFile("addons/sourcemod/configs/allowedchatphrases.txt""r");
    
linecount 0;
    while(!
IsEndOfFile(file))
    {
        
ReadFileLine(fileAllowedPhrases[linecount], sizeof(AllowedPhrases[]));
        
TrimString(AllowedPhrases[linecount]);
        
linecount++;
        
PrintToServer("Linecount incremented to: %i"linecount);
    }
}

/*********
 *Convars*
**********/

public ConvarChanged(Handle:cvar, const String:oldVal[], const String:newVal[])
{
    if(
cvar == h_cvarEnable)
    {
        
g_cvarEnable GetConVarBool(h_cvarEnable);
        if(
g_cvarEnable)
        {
            
AddCommandListener(OnSayCommand"say");
            
AddCommandListener(OnSayCommand"say_team");
        }
        else
        {
            
RemoveCommandListener(OnSayCommand"say");
            
RemoveCommandListener(OnSayCommand"say_team");
        }
    }
    else if(
cvar == h_cvarAdmins)
    {
        
g_cvarAdmins GetConVarBool(h_cvarAdmins);
        
decl admins[MAXPLAYERS+1];
        new 
count GetAdminList(admins);
        for(new 
0counti++)
            
AllowedToChat[admins[i]] = (g_cvarAdminstrue false);
    }
    else if(
cvar == h_cvarRequest)
        
g_cvarRequest GetConVarBool(h_cvarRequest);
    else if(
cvar == h_cvarNeeded)
        
g_cvarNeeded GetConVarFloat(h_cvarNeeded);
}

UpdateAllConvars()
{
    
g_cvarEnable GetConVarBool(h_cvarEnable);
    
g_cvarAdmins GetConVarBool(h_cvarAdmins);
    
g_cvarRequest GetConVarBool(h_cvarRequest);
    
g_cvarNeeded GetConVarFloat(h_cvarNeeded);



Ejziponken 08-28-2019 10:53

Re: [ANY] Block / Limit Chat (1.0.2)
 
"sm_limitchat_give" "z"
"sm_limitchat_take" "z"
"limitchat" "a"

Players with a flag cant talk. :/


All times are GMT -4. The time now is 20:27.

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