ds@1952: /**
ds@1952: * vim: set ts=4 :
ds@1952: * =============================================================================
ds@1952: * SourceMod Communication Plugin
ds@1952: * Provides fucntionality for controlling communication on the server
ds@1952: *
ds@1952: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
ds@1952: * =============================================================================
ds@1952: *
ds@1952: * This program is free software; you can redistribute it and/or modify it under
ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952: * Free Software Foundation.
ds@1952: * 1
ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
ds@1952: * details.
ds@1952: *
ds@1952: * You should have received a copy of the GNU General Public License along with
ds@1952: * this program. If not, see .
ds@1952: *
ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in
ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants
ds@1952: * this exception to all derivative works. AlliedModders LLC defines further
ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952: * or .
ds@1952: *
ds@1952: * Version: $Id$
ds@1952: */
ds@1952:
ds@1952: #include
ds@1952: #include
ds@1952: #undef REQUIRE_PLUGIN
ds@1952: #include
ds@1952:
ds@1952: #pragma semicolon 1
ds@1952:
ds@1952: public Plugin:myinfo =
ds@1952: {
ds@1952: name = "Basic Comm Control",
ds@1952: author = "AlliedModders LLC",
ds@1952: description = "Provides methods of controllingg communication.",
ds@1952: version = SOURCEMOD_VERSION,
ds@1952: url = "http://www.sourcemod.net/"
ds@1952: };
ds@1952:
ds@1952: new bool:g_Muted[MAXPLAYERS+1]; // Is the player muted?
ds@1952: new bool:g_Gagged[MAXPLAYERS+1]; // Is the player gagged?
ds@1952:
ds@1952: new Handle:g_Cvar_Deadtalk = INVALID_HANDLE; // Holds the handle for sm_deadtalk
ds@1952: new Handle:g_Cvar_Alltalk = INVALID_HANDLE; // Holds the handle for sv_alltalk
ds@1952: new bool:g_Hooked = false; // Tracks if we've hooked events for deadtalk
ds@1952:
ds@1952: new Handle:hTopMenu = INVALID_HANDLE;
ds@1952:
ds@1952: new g_GagTarget[MAXPLAYERS+1];
ds@1952:
ds@1952: #include "basecomm/gag.sp"
ds@1952:
ds@1952: public OnPluginStart()
ds@1952: {
ds@1952: LoadTranslations("common.phrases");
ds@1952: LoadTranslations("basecomm.phrases");
ds@1952:
ds@1952: 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: g_Cvar_Alltalk = FindConVar("sv_alltalk");
ds@1952:
ds@1952: RegConsoleCmd("say", Command_Say);
ds@1952: RegConsoleCmd("say_team", Command_Say);
ds@1952:
ds@1952: RegAdminCmd("sm_mute", Command_Mute, ADMFLAG_CHAT, "sm_mute - Removes a player's ability to use voice.");
ds@1952: RegAdminCmd("sm_gag", Command_Gag, ADMFLAG_CHAT, "sm_gag - Removes a player's ability to use chat.");
ds@1952: RegAdminCmd("sm_silence", Command_Silence, ADMFLAG_CHAT, "sm_silence - Removes a player's ability to use voice or chat.");
ds@1952:
ds@1952: RegAdminCmd("sm_unmute", Command_Unmute, ADMFLAG_CHAT, "sm_unmute - Restores a player's ability to use voice.");
ds@1952: RegAdminCmd("sm_ungag", Command_Ungag, ADMFLAG_CHAT, "sm_ungag - Restores a player's ability to use chat.");
ds@1952: RegAdminCmd("sm_unsilence", Command_Unsilence, ADMFLAG_CHAT, "sm_unsilence - Restores a player's ability to use voice and chat.");
ds@1952:
ds@1952: HookConVarChange(g_Cvar_Deadtalk, ConVarChange_Deadtalk);
ds@1952: HookConVarChange(g_Cvar_Alltalk, ConVarChange_Alltalk);
ds@1952:
ds@1952: /* Account for late loading */
ds@1952: new Handle:topmenu;
ds@1952: if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
ds@1952: {
ds@1952: OnAdminMenuReady(topmenu);
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: public OnAdminMenuReady(Handle:topmenu)
ds@1952: {
ds@1952: /* Block us from being called twice */
ds@1952: if (topmenu == hTopMenu)
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: /* Save the Handle */
ds@1952: hTopMenu = topmenu;
ds@1952:
ds@1952: /* Build the "Player Commands" category */
ds@1952: new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
ds@1952:
ds@1952: if (player_commands != INVALID_TOPMENUOBJECT)
ds@1952: {
ds@1952: AddToTopMenu(hTopMenu,
ds@1952: "sm_gag",
ds@1952: TopMenuObject_Item,
ds@1952: AdminMenu_Gag,
ds@1952: player_commands,
ds@1952: "sm_gag",
ds@1952: ADMFLAG_CHAT);
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: public ConVarChange_Deadtalk(Handle:convar, const String:oldValue[], const String:newValue[])
ds@1952: {
ds@1952: if (GetConVarInt(g_Cvar_Deadtalk))
ds@1952: {
ds@1952: HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
ds@1952: HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
ds@1952: g_Hooked = true;
ds@1952: }
ds@1952: else if (g_Hooked)
ds@1952: {
ds@1952: UnhookEvent("player_spawn", Event_PlayerSpawn);
ds@1952: UnhookEvent("player_death", Event_PlayerDeath);
ds@1952: g_Hooked = false;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952:
ds@1952: public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
ds@1952: {
ds@1952: g_Gagged[client] = false;
ds@1952: g_Muted[client] = false;
ds@1952:
ds@1952: return true;
ds@1952: }
ds@1952:
ds@1952: public Action:Command_Say(client, args)
ds@1952: {
ds@1952: if (client)
ds@1952: {
ds@1952: if (g_Gagged[client])
ds@1952: {
ds@1952: return Plugin_Handled;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: return Plugin_Continue;
ds@1952: }
ds@1952:
ds@1952: public ConVarChange_Alltalk(Handle:convar, const String:oldValue[], const String:newValue[])
ds@1952: {
ds@1952: new mode = GetConVarInt(g_Cvar_Deadtalk);
ds@1952: new maxClients = GetMaxClients();
ds@1952:
ds@1952: for (new i = 1; i <= maxClients; i++)
ds@1952: {
ds@1952: if (!IsClientInGame(i))
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952:
ds@1952: if (g_Muted[i])
ds@1952: {
ds@1952: SetClientListeningFlags(i, VOICE_MUTED);
ds@1952: }
ds@1952: else if (GetConVarBool(g_Cvar_Alltalk))
ds@1952: {
ds@1952: SetClientListeningFlags(i, VOICE_NORMAL);
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: if (mode == 1)
ds@1952: {
ds@1952: SetClientListeningFlags(i, VOICE_LISTENALL);
ds@1952: }
ds@1952: else if (mode == 2)
ds@1952: {
ds@1952: SetClientListeningFlags(i, VOICE_TEAM);
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952: {
ds@1952: new client = GetClientOfUserId(GetEventInt(event, "userid"));
ds@1952:
ds@1952: if (g_Muted[client])
ds@1952: {
ds@1952: SetClientListeningFlags(client, VOICE_MUTED);
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: SetClientListeningFlags(client, VOICE_NORMAL);
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
ds@1952: {
ds@1952: new client = GetClientOfUserId(GetEventInt(event, "userid"));
ds@1952:
ds@1952: if (g_Muted[client])
ds@1952: {
ds@1952: SetClientListeningFlags(client, VOICE_MUTED);
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: if (GetConVarBool(g_Cvar_Alltalk))
ds@1952: {
ds@1952: SetClientListeningFlags(client, VOICE_NORMAL);
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: new mode = GetConVarInt(g_Cvar_Deadtalk);
ds@1952: if (mode == 1)
ds@1952: {
ds@1952: SetClientListeningFlags(client, VOICE_LISTENALL);
ds@1952: }
ds@1952: else if (mode == 2)
ds@1952: {
ds@1952: SetClientListeningFlags(client, VOICE_TEAM);
ds@1952: }
ds@1952: }