Added VOICE_TEAM and VOICE_LISTENTEAM flags to the SDKTools voice functionality.
3 * =============================================================================
4 * SourceMod SDKTools Extension
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include <extension.h>
34 #define SPEAK_NORMAL 0
37 #define SPEAK_LISTENALL 4
39 #define SPEAK_LISTENTEAM 16
41 size_t g_VoiceFlags[65];
42 size_t g_VoiceFlagsCount = 0;
44 SH_DECL_HOOK3(IVoiceServer, SetClientListening, SH_NOATTRIB, 0, bool, int, int, bool);
46 bool SDKTools::OnSetClientListening(int iReceiver, int iSender, bool bListen)
48 if (g_VoiceFlags[iSender] & SPEAK_MUTED)
50 RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, false));
53 if ((g_VoiceFlags[iSender] & SPEAK_ALL) || (g_VoiceFlags[iReceiver] & SPEAK_LISTENALL))
55 RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, true));
58 if ((g_VoiceFlags[iSender] & SPEAK_TEAM) || (g_VoiceFlags[iReceiver] & SPEAK_LISTENTEAM))
60 IGamePlayer *pReceiver = playerhelpers->GetGamePlayer(iReceiver);
61 IGamePlayer *pSender = playerhelpers->GetGamePlayer(iSender);
63 if (pReceiver && pSender && pReceiver->IsInGame() && pSender->IsInGame())
65 IPlayerInfo *pRInfo = pReceiver->GetPlayerInfo();
66 IPlayerInfo *pSInfo = pSender->GetPlayerInfo();
68 if (pRInfo && pSInfo && pRInfo->GetTeamIndex() == pSInfo->GetTeamIndex())
70 RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, true));
75 RETURN_META_VALUE(MRES_IGNORED, bListen);
78 void SDKTools::OnClientDisconnecting(int client)
80 if (g_VoiceFlags[client])
82 g_VoiceFlags[client] = 0;
83 if (!--g_VoiceFlagsCount)
85 SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
90 static cell_t SetClientListeningFlags(IPluginContext *pContext, const cell_t *params)
92 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
95 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
96 } else if (!player->IsConnected()) {
97 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
100 if (!params[2] && g_VoiceFlags[params[1]])
102 if (!--g_VoiceFlagsCount)
104 SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
106 } else if (!g_VoiceFlags[params[1]] && params[2]) {
108 if (!g_VoiceFlagsCount++)
110 SH_ADD_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
114 g_VoiceFlags[params[1]] = params[2];
119 static cell_t GetClientListeningFlags(IPluginContext *pContext, const cell_t *params)
121 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
124 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
125 } else if (!player->IsConnected()) {
126 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
129 return g_VoiceFlags[params[1]];
132 static cell_t SetClientListening(IPluginContext *pContext, const cell_t *params)
134 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
137 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
138 } else if (!player->IsConnected()) {
139 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
142 bool bListen = !params[3] ? false : true;
144 return voiceserver->SetClientListening(params[1], params[2], bListen) ? 1 : 0;
147 static cell_t GetClientListening(IPluginContext *pContext, const cell_t *params)
149 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
152 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
153 } else if (!player->IsConnected()) {
154 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
157 return voiceserver->GetClientListening(params[1], params[2]) ? 1 : 0;
160 sp_nativeinfo_t g_VoiceNatives[] =
162 {"SetClientListeningFlags", SetClientListeningFlags},
163 {"GetClientListeningFlags", GetClientListeningFlags},
164 {"SetClientListening", SetClientListening},
165 {"GetClientListening", GetClientListening},