Fix freeing non-heap object warning from GCC (r=ann).
3 * =============================================================================
4 * SourceMod Communication Plugin
5 * Provides fucntionality for controlling communication on the server
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
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.
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
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/>.
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>.
41 public Plugin:myinfo =
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/"
50 new bool:g_Muted[MAXPLAYERS+1]; // Is the player muted?
51 new bool:g_Gagged[MAXPLAYERS+1]; // Is the player gagged?
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
57 new Handle:hTopMenu = INVALID_HANDLE;
59 new g_GagTarget[MAXPLAYERS+1];
61 #include "basecomm/gag.sp"
62 #include "basecomm/natives.sp"
63 #include "basecomm/forwards.sp"
65 public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
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");
73 return APLRes_Success;
76 public OnPluginStart()
78 LoadTranslations("common.phrases");
79 LoadTranslations("basecomm.phrases");
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");
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.");
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.");
92 HookConVarChange(g_Cvar_Deadtalk, ConVarChange_Deadtalk);
93 HookConVarChange(g_Cvar_Alltalk, ConVarChange_Alltalk);
95 /* Account for late loading */
97 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
99 OnAdminMenuReady(topmenu);
102 // Normally, OnClientSayCommand would be aqequate and more appropirate here, but it does
103 // not catch attempted chat triggers, which we also want to be blocked if a player is gagged.
104 AddCommandListener(Command_Say, "say");
105 AddCommandListener(Command_Say, "say_team");
107 new String:gameDir[64];
108 GetGameFolderName(gameDir, sizeof(gameDir));
109 if (StrEqual(gameDir, "insurgency", false))
111 AddCommandListener(Command_Say, "say2");
113 else if (StrEqual(gameDir, "nucleardawn", false))
115 AddCommandListener(Command_Say, "say_squad");
119 public OnAdminMenuReady(Handle:topmenu)
121 /* Block us from being called twice */
122 if (topmenu == hTopMenu)
127 /* Save the Handle */
130 /* Build the "Player Commands" category */
131 new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
133 if (player_commands != INVALID_TOPMENUOBJECT)
135 AddToTopMenu(hTopMenu,
145 public ConVarChange_Deadtalk(Handle:convar, const String:oldValue[], const String:newValue[])
147 if (GetConVarInt(g_Cvar_Deadtalk))
149 HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
150 HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
155 UnhookEvent("player_spawn", Event_PlayerSpawn);
156 UnhookEvent("player_death", Event_PlayerDeath);
162 public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
164 g_Gagged[client] = false;
165 g_Muted[client] = false;
170 public Action:Command_Say(client, const String:command[], argc)
174 if (g_Gagged[client])
180 return Plugin_Continue;
183 public ConVarChange_Alltalk(Handle:convar, const String:oldValue[], const String:newValue[])
185 new mode = GetConVarInt(g_Cvar_Deadtalk);
187 for (new i = 1; i <= MaxClients; i++)
189 if (!IsClientInGame(i))
196 SetClientListeningFlags(i, VOICE_MUTED);
198 else if (GetConVarBool(g_Cvar_Alltalk))
200 SetClientListeningFlags(i, VOICE_NORMAL);
202 else if (!IsPlayerAlive(i))
206 SetClientListeningFlags(i, VOICE_LISTENALL);
210 SetClientListeningFlags(i, VOICE_TEAM);
216 public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
218 new client = GetClientOfUserId(GetEventInt(event, "userid"));
227 SetClientListeningFlags(client, VOICE_MUTED);
231 SetClientListeningFlags(client, VOICE_NORMAL);
235 public Event_PlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
237 new client = GetClientOfUserId(GetEventInt(event, "userid"));
246 SetClientListeningFlags(client, VOICE_MUTED);
250 if (GetConVarBool(g_Cvar_Alltalk))
252 SetClientListeningFlags(client, VOICE_NORMAL);
256 new mode = GetConVarInt(g_Cvar_Deadtalk);
259 SetClientListeningFlags(client, VOICE_LISTENALL);
263 SetClientListeningFlags(client, VOICE_TEAM);