1.1 --- a/extensions/sdktools/voice.cpp Fri Mar 28 06:21:34 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,167 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod SDKTools Extension
1.8 - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
1.9 - * =============================================================================
1.10 - *
1.11 - * This program is free software; you can redistribute it and/or modify it under
1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
1.13 - * Free Software Foundation.
1.14 - *
1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 - * details.
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License along with
1.21 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 - *
1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 - * by the Valve Corporation. You must obey the GNU General Public License in
1.27 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 - * this exception to all derivative works. AlliedModders LLC defines further
1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 - * or <http://www.sourcemod.net/license.php>.
1.31 - *
1.32 - * Version: $Id$
1.33 - */
1.34 -
1.35 -#include <extension.h>
1.36 -
1.37 -#define SPEAK_NORMAL 0
1.38 -#define SPEAK_MUTED 1
1.39 -#define SPEAK_ALL 2
1.40 -#define SPEAK_LISTENALL 4
1.41 -#define SPEAK_TEAM 8
1.42 -#define SPEAK_LISTENTEAM 16
1.43 -
1.44 -size_t g_VoiceFlags[65];
1.45 -size_t g_VoiceFlagsCount = 0;
1.46 -
1.47 -SH_DECL_HOOK3(IVoiceServer, SetClientListening, SH_NOATTRIB, 0, bool, int, int, bool);
1.48 -
1.49 -bool SDKTools::OnSetClientListening(int iReceiver, int iSender, bool bListen)
1.50 -{
1.51 - if (g_VoiceFlags[iSender] & SPEAK_MUTED)
1.52 - {
1.53 - RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, false));
1.54 - }
1.55 -
1.56 - if ((g_VoiceFlags[iSender] & SPEAK_ALL) || (g_VoiceFlags[iReceiver] & SPEAK_LISTENALL))
1.57 - {
1.58 - RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, true));
1.59 - }
1.60 -
1.61 - if ((g_VoiceFlags[iSender] & SPEAK_TEAM) || (g_VoiceFlags[iReceiver] & SPEAK_LISTENTEAM))
1.62 - {
1.63 - IGamePlayer *pReceiver = playerhelpers->GetGamePlayer(iReceiver);
1.64 - IGamePlayer *pSender = playerhelpers->GetGamePlayer(iSender);
1.65 -
1.66 - if (pReceiver && pSender && pReceiver->IsInGame() && pSender->IsInGame())
1.67 - {
1.68 - IPlayerInfo *pRInfo = pReceiver->GetPlayerInfo();
1.69 - IPlayerInfo *pSInfo = pSender->GetPlayerInfo();
1.70 -
1.71 - if (pRInfo && pSInfo && pRInfo->GetTeamIndex() == pSInfo->GetTeamIndex())
1.72 - {
1.73 - RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, true));
1.74 - }
1.75 - }
1.76 - }
1.77 -
1.78 - RETURN_META_VALUE(MRES_IGNORED, bListen);
1.79 -}
1.80 -
1.81 -void SDKTools::OnClientDisconnecting(int client)
1.82 -{
1.83 - if (g_VoiceFlags[client])
1.84 - {
1.85 - g_VoiceFlags[client] = 0;
1.86 - if (!--g_VoiceFlagsCount)
1.87 - {
1.88 - SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
1.89 - }
1.90 - }
1.91 -}
1.92 -
1.93 -static cell_t SetClientListeningFlags(IPluginContext *pContext, const cell_t *params)
1.94 -{
1.95 - IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
1.96 - if (player == NULL)
1.97 - {
1.98 - return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
1.99 - } else if (!player->IsConnected()) {
1.100 - return pContext->ThrowNativeError("Client %d is not connected", params[1]);
1.101 - }
1.102 -
1.103 - if (!params[2] && g_VoiceFlags[params[1]])
1.104 - {
1.105 - if (!--g_VoiceFlagsCount)
1.106 - {
1.107 - SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
1.108 - }
1.109 - } else if (!g_VoiceFlags[params[1]] && params[2]) {
1.110 -
1.111 - if (!g_VoiceFlagsCount++)
1.112 - {
1.113 - SH_ADD_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
1.114 - }
1.115 - }
1.116 -
1.117 - g_VoiceFlags[params[1]] = params[2];
1.118 -
1.119 - return 1;
1.120 -}
1.121 -
1.122 -static cell_t GetClientListeningFlags(IPluginContext *pContext, const cell_t *params)
1.123 -{
1.124 - IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
1.125 - if (player == NULL)
1.126 - {
1.127 - return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
1.128 - } else if (!player->IsConnected()) {
1.129 - return pContext->ThrowNativeError("Client %d is not connected", params[1]);
1.130 - }
1.131 -
1.132 - return g_VoiceFlags[params[1]];
1.133 -}
1.134 -
1.135 -static cell_t SetClientListening(IPluginContext *pContext, const cell_t *params)
1.136 -{
1.137 - IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
1.138 - if (player == NULL)
1.139 - {
1.140 - return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
1.141 - } else if (!player->IsConnected()) {
1.142 - return pContext->ThrowNativeError("Client %d is not connected", params[1]);
1.143 - }
1.144 -
1.145 - bool bListen = !params[3] ? false : true;
1.146 -
1.147 - return voiceserver->SetClientListening(params[1], params[2], bListen) ? 1 : 0;
1.148 -}
1.149 -
1.150 -static cell_t GetClientListening(IPluginContext *pContext, const cell_t *params)
1.151 -{
1.152 - IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
1.153 - if (player == NULL)
1.154 - {
1.155 - return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
1.156 - } else if (!player->IsConnected()) {
1.157 - return pContext->ThrowNativeError("Client %d is not connected", params[1]);
1.158 - }
1.159 -
1.160 - return voiceserver->GetClientListening(params[1], params[2]) ? 1 : 0;
1.161 -}
1.162 -
1.163 -sp_nativeinfo_t g_VoiceNatives[] =
1.164 -{
1.165 - {"SetClientListeningFlags", SetClientListeningFlags},
1.166 - {"GetClientListeningFlags", GetClientListeningFlags},
1.167 - {"SetClientListening", SetClientListening},
1.168 - {"GetClientListening", GetClientListening},
1.169 - {NULL, NULL},
1.170 -};