2008-03-30 09:00:22 +02:00
/ * *
* vim : set ts = 4 :
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* SourceMod Communication Plugin
* Provides fucntionality for controlling communication on the server
*
* SourceMod ( C ) 2004 - 2008 AlliedModders LLC . All rights reserved .
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*
* This program is free software ; you can redistribute it and / or modify it under
* the terms of the GNU General Public License , version 3.0 , as published by the
* Free Software Foundation .
* 1
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE . See the GNU General Public License for more
* details .
*
* You should have received a copy of the GNU General Public License along with
* this program . If not , see < http : //www.gnu.org/licenses/>.
*
* As a special exception , AlliedModders LLC gives you permission to link the
* code of this program ( as well as its derivative works ) to " Half-Life 2, " the
* " Source Engine, " the " SourcePawn JIT, " and any Game MODs that run on software
* by the Valve Corporation . You must obey the GNU General Public License in
* all respects for all other code used . Additionally , AlliedModders LLC grants
* this exception to all derivative works . AlliedModders LLC defines further
* exceptions , found in LICENSE . txt ( as of this writing , version JULY - 31 - 2007 ) ,
* or < http : //www.sourcemod.net/license.php>.
*
* Version : $ Id $
* /
# include <sourcemod>
# include <sdktools>
# undef REQUIRE_PLUGIN
# include <adminmenu>
# pragma semicolon 1
2016-05-11 16:44:58 +02:00
# pragma newdecls required
2008-03-30 09:00:22 +02:00
2016-05-11 16:44:58 +02:00
public Plugin myinfo =
2008-03-30 09:00:22 +02:00
{
name = " Basic Comm Control " ,
author = " AlliedModders LLC " ,
2009-12-15 05:27:26 +01:00
description = " Provides methods of controlling communication. " ,
2008-03-30 09:00:22 +02:00
version = SOURCEMOD_VERSION ,
url = " http://www.sourcemod.net/ "
} ;
2018-12-15 22:51:03 +01:00
enum struct PlayerState {
bool isMuted ; // Is the player muted?
bool isGagged ; // Is the player gagged?
int gagTarget ;
}
PlayerState playerstate [ MAXPLAYERS + 1 ] ;
2008-03-30 09:00:22 +02:00
2014-11-10 01:35:52 +01:00
ConVar g_Cvar_Deadtalk ; // Holds the handle for sm_deadtalk
ConVar g_Cvar_Alltalk ; // Holds the handle for sv_alltalk
2016-05-11 16:44:58 +02:00
bool g_Hooked = false ; // Tracks if we've hooked events for deadtalk
2008-03-30 09:00:22 +02:00
2014-10-29 03:03:38 +01:00
TopMenu hTopMenu ;
2008-03-30 09:00:22 +02:00
# include "basecomm/gag.sp"
2011-07-07 04:34:21 +02:00
# include "basecomm/natives.sp"
2012-09-03 21:45:11 +02:00
# include "basecomm/forwards.sp"
2011-07-07 04:34:21 +02:00
2016-05-11 16:44:58 +02:00
public APLRes AskPluginLoad2 ( Handle myself , bool late , char [ ] error , int err_max )
2011-07-07 04:34:21 +02:00
{
CreateNative ( " BaseComm_IsClientGagged " , Native_IsClientGagged ) ;
CreateNative ( " BaseComm_IsClientMuted " , Native_IsClientMuted ) ;
CreateNative ( " BaseComm_SetClientGag " , Native_SetClientGag ) ;
CreateNative ( " BaseComm_SetClientMute " , Native_SetClientMute ) ;
2011-11-03 14:06:22 +01:00
RegPluginLibrary ( " basecomm " ) ;
2011-07-07 04:34:21 +02:00
return APLRes_Success ;
}
2008-03-30 09:00:22 +02:00
2016-05-11 16:44:58 +02:00
public void OnPluginStart ( )
2008-03-30 09:00:22 +02:00
{
LoadTranslations ( " common.phrases " ) ;
LoadTranslations ( " basecomm.phrases " ) ;
g_Cvar_Deadtalk = CreateConVar ( " sm_deadtalk " , " 0 " , " Controls how dead communicate. 0 - Off. 1 - Dead players ignore teams. 2 - Dead players talk to living teammates. " , 0 , true , 0.0 , true , 2.0 ) ;
g_Cvar_Alltalk = FindConVar ( " sv_alltalk " ) ;
RegAdminCmd ( " sm_mute " , Command_Mute , ADMFLAG_CHAT , " sm_mute <player> - Removes a player's ability to use voice. " ) ;
RegAdminCmd ( " sm_gag " , Command_Gag , ADMFLAG_CHAT , " sm_gag <player> - Removes a player's ability to use chat. " ) ;
RegAdminCmd ( " sm_silence " , Command_Silence , ADMFLAG_CHAT , " sm_silence <player> - Removes a player's ability to use voice or chat. " ) ;
RegAdminCmd ( " sm_unmute " , Command_Unmute , ADMFLAG_CHAT , " sm_unmute <player> - Restores a player's ability to use voice. " ) ;
RegAdminCmd ( " sm_ungag " , Command_Ungag , ADMFLAG_CHAT , " sm_ungag <player> - Restores a player's ability to use chat. " ) ;
RegAdminCmd ( " sm_unsilence " , Command_Unsilence , ADMFLAG_CHAT , " sm_unsilence <player> - Restores a player's ability to use voice and chat. " ) ;
2014-11-10 01:35:52 +01:00
g_Cvar_Deadtalk . AddChangeHook ( ConVarChange_Deadtalk ) ;
g_Cvar_Alltalk . AddChangeHook ( ConVarChange_Alltalk ) ;
2008-03-30 09:00:22 +02:00
/* Account for late loading */
2014-10-29 03:03:38 +01:00
TopMenu topmenu ;
if ( LibraryExists ( " adminmenu " ) & & ( ( topmenu = GetAdminTopMenu ( ) ) ! = null ) )
2008-03-30 09:00:22 +02:00
{
OnAdminMenuReady ( topmenu ) ;
}
}
2016-05-11 16:44:58 +02:00
public void OnAdminMenuReady ( Handle aTopMenu )
2008-03-30 09:00:22 +02:00
{
2014-12-12 08:34:00 +01:00
TopMenu topmenu = TopMenu . FromHandle ( aTopMenu ) ;
2008-03-30 09:00:22 +02:00
/* Block us from being called twice */
if ( topmenu = = hTopMenu )
{
return ;
}
/* Save the Handle */
hTopMenu = topmenu ;
/* Build the "Player Commands" category */
2014-10-29 03:03:38 +01:00
TopMenuObject player_commands = hTopMenu . FindCategory ( ADMINMENU_PLAYERCOMMANDS ) ;
2008-03-30 09:00:22 +02:00
if ( player_commands ! = INVALID_TOPMENUOBJECT )
{
2014-10-29 03:03:38 +01:00
hTopMenu . AddItem ( " sm_gag " , AdminMenu_Gag , player_commands , " sm_gag " , ADMFLAG_CHAT ) ;
2008-03-30 09:00:22 +02:00
}
}
2016-05-11 16:44:58 +02:00
public void ConVarChange_Deadtalk ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
2008-03-30 09:00:22 +02:00
{
2014-11-10 01:35:52 +01:00
if ( g_Cvar_Deadtalk . IntValue )
2008-03-30 09:00:22 +02:00
{
HookEvent ( " player_spawn " , Event_PlayerSpawn , EventHookMode_Post ) ;
HookEvent ( " player_death " , Event_PlayerDeath , EventHookMode_Post ) ;
g_Hooked = true ;
}
else if ( g_Hooked )
{
UnhookEvent ( " player_spawn " , Event_PlayerSpawn ) ;
UnhookEvent ( " player_death " , Event_PlayerDeath ) ;
g_Hooked = false ;
}
}
2016-05-11 16:44:58 +02:00
public bool OnClientConnect ( int client , char [ ] rejectmsg , int maxlen )
2008-03-30 09:00:22 +02:00
{
2018-12-15 22:51:03 +01:00
playerstate [ client ] . isGagged = false ;
playerstate [ client ] . isMuted = false ;
2008-03-30 09:00:22 +02:00
return true ;
}
2016-05-11 16:44:58 +02:00
public Action OnClientSayCommand ( int client , const char [ ] command , const char [ ] sArgs )
2008-03-30 09:00:22 +02:00
{
2018-12-15 22:51:03 +01:00
if ( client & & playerstate [ client ] . isGagged )
2008-03-30 09:00:22 +02:00
{
2014-02-28 16:38:36 +01:00
return Plugin_Stop ;
2008-03-30 09:00:22 +02:00
}
return Plugin_Continue ;
}
2014-11-10 01:35:52 +01:00
public void ConVarChange_Alltalk ( ConVar convar , const char [ ] oldValue , const char [ ] newValue )
2008-03-30 09:00:22 +02:00
{
2014-11-10 01:35:52 +01:00
int mode = g_Cvar_Deadtalk . IntValue ;
2008-03-30 09:00:22 +02:00
2014-11-10 01:35:52 +01:00
for ( int i = 1 ; i < = MaxClients ; i + + )
2008-03-30 09:00:22 +02:00
{
if ( ! IsClientInGame ( i ) )
{
continue ;
}
2018-12-15 22:51:03 +01:00
if ( playerstate [ i ] . isMuted )
2008-03-30 09:00:22 +02:00
{
SetClientListeningFlags ( i , VOICE_MUTED ) ;
}
2014-11-10 01:35:52 +01:00
else if ( g_Cvar_Alltalk . BoolValue )
2008-03-30 09:00:22 +02:00
{
SetClientListeningFlags ( i , VOICE_NORMAL ) ;
}
2010-07-26 14:23:49 +02:00
else if ( ! IsPlayerAlive ( i ) )
2008-03-30 09:00:22 +02:00
{
if ( mode = = 1 )
{
SetClientListeningFlags ( i , VOICE_LISTENALL ) ;
}
else if ( mode = = 2 )
{
SetClientListeningFlags ( i , VOICE_TEAM ) ;
}
}
}
}
2016-05-11 16:44:58 +02:00
public void Event_PlayerSpawn ( Event event , const char [ ] name , bool dontBroadcast )
2008-03-30 09:00:22 +02:00
{
2016-05-11 16:44:58 +02:00
int client = GetClientOfUserId ( event . GetInt ( " userid " ) ) ;
2008-03-30 09:00:22 +02:00
2008-10-09 09:18:16 +02:00
if ( ! client )
{
return ;
}
2018-12-15 22:51:03 +01:00
if ( playerstate [ client ] . isMuted )
2008-03-30 09:00:22 +02:00
{
SetClientListeningFlags ( client , VOICE_MUTED ) ;
}
else
{
SetClientListeningFlags ( client , VOICE_NORMAL ) ;
}
}
2016-05-11 16:44:58 +02:00
public void Event_PlayerDeath ( Event event , const char [ ] name , bool dontBroadcast )
2008-03-30 09:00:22 +02:00
{
2014-11-09 23:39:09 +01:00
int client = GetClientOfUserId ( event . GetInt ( " userid " ) ) ;
2008-03-30 09:00:22 +02:00
2008-10-09 09:18:16 +02:00
if ( ! client )
{
return ;
}
2018-12-15 22:51:03 +01:00
if ( playerstate [ client ] . isMuted )
2008-03-30 09:00:22 +02:00
{
SetClientListeningFlags ( client , VOICE_MUTED ) ;
return ;
}
2014-11-10 01:35:52 +01:00
if ( g_Cvar_Alltalk . BoolValue )
2008-03-30 09:00:22 +02:00
{
SetClientListeningFlags ( client , VOICE_NORMAL ) ;
return ;
}
2014-11-10 01:35:52 +01:00
int mode = g_Cvar_Deadtalk . IntValue ;
2008-03-30 09:00:22 +02:00
if ( mode = = 1 )
{
SetClientListeningFlags ( client , VOICE_LISTENALL ) ;
}
else if ( mode = = 2 )
{
SetClientListeningFlags ( client , VOICE_TEAM ) ;
}
}