extensions/sdktools/voice.cpp
changeset 1235 88bb46f9731e
child 1245 bb0611ab4bed
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/sdktools/voice.cpp	Wed Aug 01 04:17:36 2007 +0000
     1.3 @@ -0,0 +1,122 @@
     1.4 +#include <extension.h>
     1.5 +
     1.6 +#define SPEAK_NORMAL		0
     1.7 +#define SPEAK_MUTED			1
     1.8 +#define SPEAK_ALL			2
     1.9 +#define SPEAK_LISTENALL		4
    1.10 +
    1.11 +size_t g_VoiceFlags[65];
    1.12 +size_t g_VoiceFlagsCount = 0;
    1.13 +
    1.14 +SH_DECL_HOOK3(IVoiceServer, SetClientListening, SH_NOATTRIB, 0, bool, int, int, bool);
    1.15 +
    1.16 +bool SDKTools::OnSetClientListening(int iReceiver, int iSender, bool bListen)
    1.17 +{
    1.18 +	if (g_VoiceFlags[iSender] & SPEAK_MUTED) 
    1.19 +	{
    1.20 +		RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, false));
    1.21 +	}
    1.22 +
    1.23 +	if (g_VoiceFlags[iSender] & SPEAK_ALL)
    1.24 +	{
    1.25 +		RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, true));
    1.26 +	}
    1.27 +
    1.28 +	if (g_VoiceFlags[iReceiver] & SPEAK_LISTENALL)
    1.29 +	{
    1.30 +		RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, bListen, &IVoiceServer::SetClientListening, (iReceiver, iSender, true));
    1.31 +	}
    1.32 +
    1.33 +	RETURN_META_VALUE(MRES_IGNORED, bListen);
    1.34 +}
    1.35 +
    1.36 +void SDKTools::OnClientDisconnecting(int client)
    1.37 +{
    1.38 +	if (g_VoiceFlags[client])
    1.39 +	{	
    1.40 +		g_VoiceFlags[client] = 0;
    1.41 +		if (!--g_VoiceFlagsCount)
    1.42 +		{
    1.43 +			SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
    1.44 +		}
    1.45 +	}
    1.46 +}
    1.47 +
    1.48 +static cell_t SetClientListeningFlags(IPluginContext *pContext, const cell_t *params)
    1.49 +{
    1.50 +	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
    1.51 +	if (player == NULL)
    1.52 +	{
    1.53 +		return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
    1.54 +	} else if (!player->IsConnected()) {
    1.55 +		return pContext->ThrowNativeError("Client %d is not connected", params[1]);
    1.56 +	}
    1.57 +
    1.58 +	if (!params[2] && g_VoiceFlags[params[1]])
    1.59 +	{
    1.60 +		if (!--g_VoiceFlagsCount)
    1.61 +		{
    1.62 +			SH_REMOVE_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
    1.63 +		}
    1.64 +	} else if (!g_VoiceFlags[params[1]] && params[2]) {
    1.65 +
    1.66 +		if (!g_VoiceFlagsCount++)
    1.67 +		{
    1.68 +			SH_ADD_HOOK_MEMFUNC(IVoiceServer, SetClientListening, voiceserver, &g_SdkTools, &SDKTools::OnSetClientListening, false);
    1.69 +		}
    1.70 +	}
    1.71 +
    1.72 +	g_VoiceFlags[params[1]] = params[2];
    1.73 +
    1.74 +	return 1;
    1.75 +}
    1.76 +
    1.77 +static cell_t GetClientListeningFlags(IPluginContext *pContext, const cell_t *params)
    1.78 +{
    1.79 +	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
    1.80 +	if (player == NULL)
    1.81 +	{
    1.82 +		return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
    1.83 +	} else if (!player->IsConnected()) {
    1.84 +		return pContext->ThrowNativeError("Client %d is not connected", params[1]);
    1.85 +	}
    1.86 +
    1.87 +	return g_VoiceFlags[params[1]];
    1.88 +}
    1.89 +
    1.90 +static cell_t SetClientListening(IPluginContext *pContext, const cell_t *params)
    1.91 +{
    1.92 +	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
    1.93 +	if (player == NULL)
    1.94 +	{
    1.95 +		return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
    1.96 +	} else if (!player->IsConnected()) {
    1.97 +		return pContext->ThrowNativeError("Client %d is not connected", params[1]);
    1.98 +	}
    1.99 +
   1.100 +	bool bListen = !params[3] ? false : true;
   1.101 +
   1.102 +	return voiceserver->SetClientListening(params[1], params[2], bListen) ? 1 : 0;
   1.103 +}
   1.104 +
   1.105 +static cell_t GetClientListening(IPluginContext *pContext, const cell_t *params)
   1.106 +{
   1.107 +	IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
   1.108 +	if (player == NULL)
   1.109 +	{
   1.110 +		return pContext->ThrowNativeError("Client index %d is invalid", params[1]);
   1.111 +	} else if (!player->IsConnected()) {
   1.112 +		return pContext->ThrowNativeError("Client %d is not connected", params[1]);
   1.113 +	}
   1.114 +
   1.115 +	return voiceserver->GetClientListening(params[1], params[2]) ? 1 : 0;
   1.116 +}
   1.117 +
   1.118 +sp_nativeinfo_t g_VoiceNatives[] = 
   1.119 +{
   1.120 +	{"SetClientListeningFlags",		SetClientListeningFlags},
   1.121 +	{"GetClientListeningFlags",		GetClientListeningFlags},
   1.122 +	{"SetClientListening",			SetClientListening},
   1.123 +	{"GetClientListening",			GetClientListening},
   1.124 +	{NULL,							NULL},
   1.125 +};