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
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
33 #include <extension.h>
35 #define SPEAK_NORMAL 0
38 #define SPEAK_LISTENALL 4
40 size_t g_VoiceFlags[65];
41 size_t g_VoiceFlagsCount = 0;
43 SH_DECL_HOOK3(IVoiceServer, SetClientListening, SH_NOATTRIB, 0, bool, int, int, bool);
45 bool SDKTools::OnSetClientListening(int iReceiver, int iSender, bool bListen)
47 if (g_VoiceFlags[iSender] & SPEAK_MUTED)
49 RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, false));
52 if (g_VoiceFlags[iSender] & SPEAK_ALL)
54 RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, true));
57 if (g_VoiceFlags[iReceiver] & SPEAK_LISTENALL)
59 RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, true));
62 RETURN_META_VALUE(MRES_IGNORED, bListen);
65 void SDKTools::OnClientDisconnecting(int client)
67 if (g_VoiceFlags[client])
69 g_VoiceFlags[client] = 0;
70 if (!--g_VoiceFlagsCount)
72 SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
77 static cell_t SetClientListeningFlags(IPluginContext *pContext, const cell_t *params)
79 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
82 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
83 } else if (!player->IsConnected()) {
84 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
87 if (!params[2] && g_VoiceFlags[params[1]])
89 if (!--g_VoiceFlagsCount)
91 SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
93 } else if (!g_VoiceFlags[params[1]] && params[2]) {
95 if (!g_VoiceFlagsCount++)
97 SH_ADD_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
101 g_VoiceFlags[params[1]] = params[2];
106 static cell_t GetClientListeningFlags(IPluginContext *pContext, const cell_t *params)
108 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
111 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
112 } else if (!player->IsConnected()) {
113 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
116 return g_VoiceFlags[params[1]];
119 static cell_t SetClientListening(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 bool bListen = !params[3] ? false : true;
131 return voiceserver->SetClientListening(params[1], params[2], bListen) ? 1 : 0;
134 static cell_t GetClientListening(IPluginContext *pContext, const cell_t *params)
136 IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
139 return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
140 } else if (!player->IsConnected()) {
141 return pContext->ThrowNativeError("Client %d is not connected", params[1]);
144 return voiceserver->GetClientListening(params[1], params[2]) ? 1 : 0;
147 sp_nativeinfo_t g_VoiceNatives[] =
149 {"SetClientListeningFlags", SetClientListeningFlags},
150 {"GetClientListeningFlags", GetClientListeningFlags},
151 {"SetClientListening", SetClientListening},
152 {"GetClientListening", GetClientListening},