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