plugins/basecomm.sp
author FlaminSarge <flaminsarge@gmail.com>
Mon Aug 12 01:18:01 2013 +0100 (2013-08-12)
changeset 4001 608bc5be1ef0
parent 3974 9b3779f472d4
child 4120 4b581bb374c8
permissions -rw-r--r--
Add support for more CalcIsAttackCritical helpers. (bug 5576, r=asherkin)
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Communication Plugin
     5  * Provides fucntionality for controlling communication on the server
     6  *
     7  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    10  * This program is free software; you can redistribute it and/or modify it under
    11  * the terms of the GNU General Public License, version 3.0, as published by the
    12  * Free Software Foundation.
    13  * 1
    14  * This program is distributed in the hope that it will be useful, but WITHOUT
    15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    17  * details.
    18  *
    19  * You should have received a copy of the GNU General Public License along with
    20  * this program.  If not, see <http://www.gnu.org/licenses/>.
    21  *
    22  * As a special exception, AlliedModders LLC gives you permission to link the
    23  * code of this program (as well as its derivative works) to "Half-Life 2," the
    24  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    25  * by the Valve Corporation.  You must obey the GNU General Public License in
    26  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    27  * this exception to all derivative works.  AlliedModders LLC defines further
    28  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    29  * or <http://www.sourcemod.net/license.php>.
    30  *
    31  * Version: $Id$
    32  */
    33 
    34 #include <sourcemod>
    35 #include <sdktools>
    36 #undef REQUIRE_PLUGIN
    37 #include <adminmenu>
    38 
    39 #pragma semicolon 1
    40 
    41 public Plugin:myinfo =
    42 {
    43 	name = "Basic Comm Control",
    44 	author = "AlliedModders LLC",
    45 	description = "Provides methods of controlling communication.",
    46 	version = SOURCEMOD_VERSION,
    47 	url = "http://www.sourcemod.net/"
    48 };
    49 
    50 new bool:g_Muted[MAXPLAYERS+1];		// Is the player muted?
    51 new bool:g_Gagged[MAXPLAYERS+1];	// Is the player gagged?
    52 
    53 new Handle:g_Cvar_Deadtalk = INVALID_HANDLE;	// Holds the handle for sm_deadtalk
    54 new Handle:g_Cvar_Alltalk = INVALID_HANDLE;	// Holds the handle for sv_alltalk
    55 new bool:g_Hooked = false;			// Tracks if we've hooked events for deadtalk
    56 
    57 new Handle:hTopMenu = INVALID_HANDLE;
    58 
    59 new g_GagTarget[MAXPLAYERS+1];
    60 
    61 #include "basecomm/gag.sp"
    62 #include "basecomm/natives.sp"
    63 #include "basecomm/forwards.sp"
    64 
    65 public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
    66 {
    67 	CreateNative("BaseComm_IsClientGagged", Native_IsClientGagged);
    68 	CreateNative("BaseComm_IsClientMuted",  Native_IsClientMuted);
    69 	CreateNative("BaseComm_SetClientGag",   Native_SetClientGag);
    70 	CreateNative("BaseComm_SetClientMute",  Native_SetClientMute);
    71 	RegPluginLibrary("basecomm");
    72 	
    73 	return APLRes_Success;
    74 }
    75 
    76 public OnPluginStart()
    77 {
    78 	LoadTranslations("common.phrases");
    79 	LoadTranslations("basecomm.phrases");
    80 	
    81 	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);
    82 	g_Cvar_Alltalk = FindConVar("sv_alltalk");
    83 	
    84 	RegAdminCmd("sm_mute", Command_Mute, ADMFLAG_CHAT, "sm_mute <player> - Removes a player's ability to use voice.");
    85 	RegAdminCmd("sm_gag", Command_Gag, ADMFLAG_CHAT, "sm_gag <player> - Removes a player's ability to use chat.");
    86 	RegAdminCmd("sm_silence", Command_Silence, ADMFLAG_CHAT, "sm_silence <player> - Removes a player's ability to use voice or chat.");
    87 	
    88 	RegAdminCmd("sm_unmute", Command_Unmute, ADMFLAG_CHAT, "sm_unmute <player> - Restores a player's ability to use voice.");
    89 	RegAdminCmd("sm_ungag", Command_Ungag, ADMFLAG_CHAT, "sm_ungag <player> - Restores a player's ability to use chat.");
    90 	RegAdminCmd("sm_unsilence", Command_Unsilence, ADMFLAG_CHAT, "sm_unsilence <player> - Restores a player's ability to use voice and chat.");	
    91 	
    92 	HookConVarChange(g_Cvar_Deadtalk, ConVarChange_Deadtalk);
    93 	HookConVarChange(g_Cvar_Alltalk, ConVarChange_Alltalk);
    94 	
    95 	/* Account for late loading */
    96 	new Handle:topmenu;
    97 	if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
    98 	{
    99 		OnAdminMenuReady(topmenu);
   100 	}
   101 }
   102 
   103 public OnAdminMenuReady(Handle:topmenu)
   104 {
   105 	/* Block us from being called twice */
   106 	if (topmenu == hTopMenu)
   107 	{
   108 		return;
   109 	}
   110 	
   111 	/* Save the Handle */
   112 	hTopMenu = topmenu;
   113 	
   114 	/* Build the "Player Commands" category */
   115 	new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
   116 	
   117 	if (player_commands != INVALID_TOPMENUOBJECT)
   118 	{
   119 		AddToTopMenu(hTopMenu, 
   120 			"sm_gag",
   121 			TopMenuObject_Item,
   122 			AdminMenu_Gag,
   123 			player_commands,
   124 			"sm_gag",
   125 			ADMFLAG_CHAT);
   126 	}
   127 }
   128 
   129 public ConVarChange_Deadtalk(Handle:convar, const String:oldValue[], const String:newValue[])
   130 {
   131 	if (GetConVarInt(g_Cvar_Deadtalk))
   132 	{
   133 		HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
   134 		HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
   135 		g_Hooked = true;
   136 	}
   137 	else if (g_Hooked)
   138 	{
   139 		UnhookEvent("player_spawn", Event_PlayerSpawn);
   140 		UnhookEvent("player_death", Event_PlayerDeath);		
   141 		g_Hooked = false;
   142 	}
   143 }
   144 
   145 
   146 public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
   147 {
   148 	g_Gagged[client] = false;
   149 	g_Muted[client] = false;
   150 	
   151 	return true;
   152 }
   153 
   154 public Action:OnClientSayCommand(client, const String:command[], const String:sArgs[])
   155 {
   156 	if (client)
   157 	{
   158 		if (g_Gagged[client])
   159 		{
   160 			return Plugin_Stop;		
   161 		}
   162 	}
   163 	
   164 	return Plugin_Continue;
   165 }
   166 
   167 public ConVarChange_Alltalk(Handle:convar, const String:oldValue[], const String:newValue[])
   168 {
   169 	new mode = GetConVarInt(g_Cvar_Deadtalk);
   170 	
   171 	for (new i = 1; i <= MaxClients; i++)
   172 	{
   173 		if (!IsClientInGame(i))
   174 		{
   175 			continue;
   176 		}
   177 		
   178 		if (g_Muted[i])
   179 		{
   180 			SetClientListeningFlags(i, VOICE_MUTED);
   181 		}
   182 		else if (GetConVarBool(g_Cvar_Alltalk))
   183 		{
   184 			SetClientListeningFlags(i, VOICE_NORMAL);
   185 		}
   186 		else if (!IsPlayerAlive(i))
   187 		{
   188 			if (mode == 1)
   189 			{
   190 				SetClientListeningFlags(i, VOICE_LISTENALL);
   191 			}
   192 			else if (mode == 2)
   193 			{
   194 				SetClientListeningFlags(i, VOICE_TEAM);
   195 			}
   196 		}
   197 	}
   198 }
   199 
   200 public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
   201 {
   202 	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   203 	
   204 	if (!client)
   205 	{
   206 		return;	
   207 	}
   208 	
   209 	if (g_Muted[client])
   210 	{
   211 		SetClientListeningFlags(client, VOICE_MUTED);
   212 	}
   213 	else
   214 	{
   215 		SetClientListeningFlags(client, VOICE_NORMAL);
   216 	}
   217 }
   218 
   219 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
   220 {
   221 	new client = GetClientOfUserId(GetEventInt(event, "userid"));
   222 	
   223 	if (!client)
   224 	{
   225 		return;	
   226 	}
   227 	
   228 	if (g_Muted[client])
   229 	{
   230 		SetClientListeningFlags(client, VOICE_MUTED);
   231 		return;
   232 	}
   233 	
   234 	if (GetConVarBool(g_Cvar_Alltalk))
   235 	{
   236 		SetClientListeningFlags(client, VOICE_NORMAL);
   237 		return;
   238 	}
   239 	
   240 	new mode = GetConVarInt(g_Cvar_Deadtalk);
   241 	if (mode == 1)
   242 	{
   243 		SetClientListeningFlags(client, VOICE_LISTENALL);
   244 	}
   245 	else if (mode == 2)
   246 	{
   247 		SetClientListeningFlags(client, VOICE_TEAM);
   248 	}
   249 }