From bb7f7eff516ad653e6902c2d160f8df1c0862f18 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Wed, 6 Jul 2011 22:34:21 -0400 Subject: [PATCH] Added native interface for Basecomm plugin (bug 2594, r=fyren). --- plugins/basecomm.sp | 11 +++ plugins/basecomm/gag.sp | 31 ++++++-- plugins/basecomm/natives.sp | 138 +++++++++++++++++++++++++++++++++++ plugins/include/basecomm.inc | 93 +++++++++++++++++++++++ 4 files changed, 265 insertions(+), 8 deletions(-) create mode 100644 plugins/basecomm/natives.sp create mode 100644 plugins/include/basecomm.inc diff --git a/plugins/basecomm.sp b/plugins/basecomm.sp index e7f30499..74f9f1cd 100644 --- a/plugins/basecomm.sp +++ b/plugins/basecomm.sp @@ -59,6 +59,17 @@ new Handle:hTopMenu = INVALID_HANDLE; new g_GagTarget[MAXPLAYERS+1]; #include "basecomm/gag.sp" +#include "basecomm/natives.sp" + +public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) +{ + CreateNative("BaseComm_IsClientGagged", Native_IsClientGagged); + CreateNative("BaseComm_IsClientMuted", Native_IsClientMuted); + CreateNative("BaseComm_SetClientGag", Native_SetClientGag); + CreateNative("BaseComm_SetClientMute", Native_SetClientMute); + + return APLRes_Success; +} public OnPluginStart() { diff --git a/plugins/basecomm/gag.sp b/plugins/basecomm/gag.sp index 062e7185..5f36ba51 100644 --- a/plugins/basecomm/gag.sp +++ b/plugins/basecomm/gag.sp @@ -210,14 +210,18 @@ public MenuHandler_GagTypes(Handle:menu, MenuAction:action, param1, param2) } } -PerformMute(client, target) +PerformMute(client, target, bool:silent=false) { g_Muted[target] = true; SetClientListeningFlags(target, VOICE_MUTED); - LogAction(client, target, "\"%L\" muted \"%L\"", client, target); + + if (!silent) + { + LogAction(client, target, "\"%L\" muted \"%L\"", client, target); + } } -PerformUnMute(client, target) +PerformUnMute(client, target, bool:silent=false) { g_Muted[target] = false; if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target)) @@ -233,19 +237,30 @@ PerformUnMute(client, target) SetClientListeningFlags(target, VOICE_NORMAL); } - LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target); + if (!silent) + { + LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target); + } } -PerformGag(client, target) +PerformGag(client, target, bool:silent=false) { g_Gagged[target] = true; - LogAction(client, target, "\"%L\" gagged \"%L\"", client, target); + + if (!silent) + { + LogAction(client, target, "\"%L\" gagged \"%L\"", client, target); + } } -PerformUnGag(client, target) +PerformUnGag(client, target, bool:silent=false) { g_Gagged[target] = false; - LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target); + + if (!silent) + { + LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target); + } } PerformSilence(client, target) diff --git a/plugins/basecomm/natives.sp b/plugins/basecomm/natives.sp new file mode 100644 index 00000000..5957d96d --- /dev/null +++ b/plugins/basecomm/natives.sp @@ -0,0 +1,138 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod Basecomm + * Part of Basecomm plugin, menu and other functionality. + * + * SourceMod (C)2004-2011 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + + public Native_IsClientGagged(Handle:hPlugin, numParams) +{ + new client = GetNativeCell(1); + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index %d", client); + } + + if (!IsClientInGame(client)) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not in game", client); + } + + return g_Gagged[client]; +} + +public Native_IsClientMuted(Handle:hPlugin, numParams) +{ + new client = GetNativeCell(1); + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index %d", client); + } + + if (!IsClientInGame(client)) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not in game", client); + } + + return g_Muted[client]; +} + +public Native_SetClientGag(Handle:hPlugin, numParams) +{ + new client = GetNativeCell(1); + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index %d", client); + } + + if (!IsClientInGame(client)) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not in game", client); + } + + new bool:gagState = GetNativeCell(2); + + if (gagState) + { + if (g_Gagged[client]) + { + return false; + } + + PerformGag(-1, client, true); + } + else + { + if (!g_Gagged[client]) + { + return false; + } + + PerformUnGag(-1, client, true); + } + + return true; +} + +public Native_SetClientMute(Handle:hPlugin, numParams) +{ + new client = GetNativeCell(1); + if (client < 1 || client > MaxClients) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Invalid client index %d", client); + } + + if (!IsClientInGame(client)) + { + return ThrowNativeError(SP_ERROR_NATIVE, "Client %d is not in game", client); + } + + new bool:muteState = GetNativeCell(2); + + if (muteState) + { + if (g_Muted[client]) + { + return false; + } + + PerformMute(-1, client, true); + } + else + { + if (!g_Muted[client]) + { + return false; + } + + PerformUnMute(-1, client, true); + } + + return true; +} diff --git a/plugins/include/basecomm.inc b/plugins/include/basecomm.inc new file mode 100644 index 00000000..785a13e9 --- /dev/null +++ b/plugins/include/basecomm.inc @@ -0,0 +1,93 @@ +/** + * vim: set ts=4 : + * ============================================================================= + * SourceMod (C)2004-2011 AlliedModders LLC. All rights reserved. + * ============================================================================= + * + * This file is part of the SourceMod/SourcePawn SDK. + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License, version 3.0, as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + * + * As a special exception, AlliedModders LLC gives you permission to link the + * code of this program (as well as its derivative works) to "Half-Life 2," the + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software + * by the Valve Corporation. You must obey the GNU General Public License in + * all respects for all other code used. Additionally, AlliedModders LLC grants + * this exception to all derivative works. AlliedModders LLC defines further + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), + * or . + * + * Version: $Id$ + */ + +#if defined _basecomm_included + #endinput +#endif +#define _basecomm_included + +/** + * Returns whether or not a client is gagged + * + * @param client Client index. + * @return True if client is gagged, false otherwise. + */ +native bool:BaseComm_IsClientGagged(client); + +/** + * Returns whether or not a client is muted + * + * @param client Client index. + * @return True if client is muted, false otherwise. + */ +native bool:BaseComm_IsClientMuted(client); + +/** + * Sets a client's gag state + * + * @param client Client index. + * @param gagState True to gag client, false to ungag. + * @return True if this caused a change in gag state, false otherwise. + */ +native bool:BaseComm_SetClientGag(client, bool:gagState); + +/** + * Sets a client's mute state + * + * @param client Client index. + * @param muteState True to mute client, false to unmute. + * @return True if this caused a change in mute state, false otherwise. + */ +native bool:BaseComm_SetClientMute(client, bool:muteState); + +/* DO NOT EDIT BELOW THIS LINE */ + +public SharedPlugin:__pl_basecomm = +{ + name = "basecomm", + file = "basecomm.smx", +#if defined REQUIRE_PLUGIN + required = 1, +#else + required = 0, +#endif +}; + +#if !defined REQUIRE_PLUGIN +public __pl_basecomm_SetNTVOptional() +{ + MarkNativeAsOptional("BaseComm_IsClientGagged"); + MarkNativeAsOptional("BaseComm_IsClientMuted"); + MarkNativeAsOptional("BaseComm_SetClientGag"); + MarkNativeAsOptional("BaseComm_SetClientMute"); +} +#endif