1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/basecomm/gag.sp Sun Jul 06 04:49:55 2008 +0000
1.3 @@ -0,0 +1,580 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod Basecomm
1.8 + * Part of Basecomm plugin, menu and other functionality.
1.9 + *
1.10 + * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.11 + * =============================================================================
1.12 + *
1.13 + * This program is free software; you can redistribute it and/or modify it under
1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
1.15 + * Free Software Foundation.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.19 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.20 + * details.
1.21 + *
1.22 + * You should have received a copy of the GNU General Public License along with
1.23 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.24 + *
1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.28 + * by the Valve Corporation. You must obey the GNU General Public License in
1.29 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.30 + * this exception to all derivative works. AlliedModders LLC defines further
1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.32 + * or <http://www.sourcemod.net/license.php>.
1.33 + *
1.34 + * Version: $Id$
1.35 + */
1.36 +
1.37 +enum CommType
1.38 +{
1.39 + CommType_Mute,
1.40 + CommType_UnMute,
1.41 + CommType_Gag,
1.42 + CommType_UnGag,
1.43 + CommType_Silence,
1.44 + CommType_UnSilence
1.45 +};
1.46 +
1.47 +DisplayGagTypesMenu(client)
1.48 +{
1.49 + new Handle:menu = CreateMenu(MenuHandler_GagTypes);
1.50 +
1.51 + decl String:title[100];
1.52 + Format(title, sizeof(title), "%T:", "Choose Type", client);
1.53 + SetMenuTitle(menu, title);
1.54 + SetMenuExitBackButton(menu, true);
1.55 +
1.56 + new target = g_GagTarget[client];
1.57 +
1.58 + if (!g_Muted[target])
1.59 + {
1.60 + AddMenuItem(menu, "0", "Mute Player");
1.61 + }
1.62 + else
1.63 + {
1.64 + AddMenuItem(menu, "1", "UnMute Player");
1.65 + }
1.66 +
1.67 + if (!g_Gagged[target])
1.68 + {
1.69 + AddMenuItem(menu, "2", "Gag Player");
1.70 + }
1.71 + else
1.72 + {
1.73 + AddMenuItem(menu, "3", "UnGag Player");
1.74 + }
1.75 +
1.76 + if (!g_Muted[target] || !g_Gagged[target])
1.77 + {
1.78 + AddMenuItem(menu, "4", "Silence Player");
1.79 + }
1.80 + else
1.81 + {
1.82 + AddMenuItem(menu, "5", "UnSilence Player");
1.83 + }
1.84 +
1.85 + DisplayMenu(menu, client, MENU_TIME_FOREVER);
1.86 +}
1.87 +
1.88 +DisplayGagPlayerMenu(client)
1.89 +{
1.90 + new Handle:menu = CreateMenu(MenuHandler_GagPlayer);
1.91 +
1.92 + decl String:title[100];
1.93 + Format(title, sizeof(title), "%T:", "Gag/Mute player", client);
1.94 + SetMenuTitle(menu, title);
1.95 + SetMenuExitBackButton(menu, true);
1.96 +
1.97 + AddTargetsToMenu(menu, client, true, false);
1.98 +
1.99 + DisplayMenu(menu, client, MENU_TIME_FOREVER);
1.100 +}
1.101 +
1.102 +public AdminMenu_Gag(Handle:topmenu,
1.103 + TopMenuAction:action,
1.104 + TopMenuObject:object_id,
1.105 + param,
1.106 + String:buffer[],
1.107 + maxlength)
1.108 +{
1.109 + if (action == TopMenuAction_DisplayOption)
1.110 + {
1.111 + Format(buffer, maxlength, "%T", "Gag/Mute player", param);
1.112 + }
1.113 + else if (action == TopMenuAction_SelectOption)
1.114 + {
1.115 + DisplayGagPlayerMenu(param);
1.116 + }
1.117 +}
1.118 +
1.119 +public MenuHandler_GagPlayer(Handle:menu, MenuAction:action, param1, param2)
1.120 +{
1.121 + if (action == MenuAction_End)
1.122 + {
1.123 + CloseHandle(menu);
1.124 + }
1.125 + else if (action == MenuAction_Cancel)
1.126 + {
1.127 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.128 + {
1.129 + DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.130 + }
1.131 + }
1.132 + else if (action == MenuAction_Select)
1.133 + {
1.134 + decl String:info[32];
1.135 + new userid, target;
1.136 +
1.137 + GetMenuItem(menu, param2, info, sizeof(info));
1.138 + userid = StringToInt(info);
1.139 +
1.140 + if ((target = GetClientOfUserId(userid)) == 0)
1.141 + {
1.142 + PrintToChat(param1, "[SM] %t", "Player no longer available");
1.143 + }
1.144 + else if (!CanUserTarget(param1, target))
1.145 + {
1.146 + PrintToChat(param1, "[SM] %t", "Unable to target");
1.147 + }
1.148 + else
1.149 + {
1.150 + g_GagTarget[param1] = GetClientOfUserId(userid);
1.151 + DisplayGagTypesMenu(param1);
1.152 + }
1.153 + }
1.154 +}
1.155 +
1.156 +public MenuHandler_GagTypes(Handle:menu, MenuAction:action, param1, param2)
1.157 +{
1.158 + if (action == MenuAction_End)
1.159 + {
1.160 + CloseHandle(menu);
1.161 + }
1.162 + else if (action == MenuAction_Cancel)
1.163 + {
1.164 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.165 + {
1.166 + DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.167 + }
1.168 + }
1.169 + else if (action == MenuAction_Select)
1.170 + {
1.171 + decl String:info[32];
1.172 + new CommType:type;
1.173 +
1.174 + GetMenuItem(menu, param2, info, sizeof(info));
1.175 + type = CommType:StringToInt(info);
1.176 +
1.177 + decl String:name[MAX_NAME_LENGTH];
1.178 + GetClientName(g_GagTarget[param1], name, sizeof(name));
1.179 +
1.180 + switch (type)
1.181 + {
1.182 + case CommType_Mute:
1.183 + {
1.184 + PerformMute(param1, g_GagTarget[param1]);
1.185 + ShowActivity2(param1, "[SM] ", "%t", "Muted target", "_s", name);
1.186 + }
1.187 + case CommType_UnMute:
1.188 + {
1.189 + PerformUnMute(param1, g_GagTarget[param1]);
1.190 + ShowActivity2(param1, "[SM] ", "%t", "Unmuted target", "_s", name);
1.191 + }
1.192 + case CommType_Gag:
1.193 + {
1.194 + PerformGag(param1, g_GagTarget[param1]);
1.195 + ShowActivity2(param1, "[SM] ", "%t", "Gagged target", "_s", name);
1.196 + }
1.197 + case CommType_UnGag:
1.198 + {
1.199 + PerformUnGag(param1, g_GagTarget[param1]);
1.200 + ShowActivity2(param1, "[SM] ", "%t", "Ungagged target", "_s", name);
1.201 + }
1.202 + case CommType_Silence:
1.203 + {
1.204 + PerformSilence(param1, g_GagTarget[param1]);
1.205 + ShowActivity2(param1, "[SM] ", "%t", "Silenced target", "_s", name);
1.206 + }
1.207 + case CommType_UnSilence:
1.208 + {
1.209 + PerformUnSilence(param1, g_GagTarget[param1]);
1.210 + ShowActivity2(param1, "[SM] ", "%t", "Unsilenced target", "_s", name);
1.211 + }
1.212 + }
1.213 + }
1.214 +}
1.215 +
1.216 +PerformMute(client, target)
1.217 +{
1.218 + g_Muted[target] = true;
1.219 + SetClientListeningFlags(target, VOICE_MUTED);
1.220 + LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
1.221 +}
1.222 +
1.223 +PerformUnMute(client, target)
1.224 +{
1.225 + g_Muted[target] = false;
1.226 + if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
1.227 + {
1.228 + SetClientListeningFlags(target, VOICE_LISTENALL);
1.229 + }
1.230 + else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
1.231 + {
1.232 + SetClientListeningFlags(target, VOICE_TEAM);
1.233 + }
1.234 + else
1.235 + {
1.236 + SetClientListeningFlags(target, VOICE_NORMAL);
1.237 + }
1.238 +
1.239 + LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
1.240 +}
1.241 +
1.242 +PerformGag(client, target)
1.243 +{
1.244 + g_Gagged[target] = true;
1.245 + LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
1.246 +}
1.247 +
1.248 +PerformUnGag(client, target)
1.249 +{
1.250 + g_Gagged[target] = false;
1.251 + LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
1.252 +}
1.253 +
1.254 +PerformSilence(client, target)
1.255 +{
1.256 + if (!g_Gagged[target])
1.257 + {
1.258 + g_Gagged[target] = true;
1.259 + }
1.260 +
1.261 + if (!g_Muted[target])
1.262 + {
1.263 + g_Muted[target] = true;
1.264 + SetClientListeningFlags(target, VOICE_MUTED);
1.265 + }
1.266 +
1.267 + LogAction(client, target, "\"%L\" silenced \"%L\"", client, target);
1.268 +}
1.269 +
1.270 +PerformUnSilence(client, target)
1.271 +{
1.272 + if (g_Gagged[target])
1.273 + {
1.274 + g_Gagged[target] = false;
1.275 + }
1.276 +
1.277 + if (g_Muted[target])
1.278 + {
1.279 + g_Muted[target] = false;
1.280 +
1.281 + if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
1.282 + {
1.283 + SetClientListeningFlags(target, VOICE_LISTENALL);
1.284 + }
1.285 + else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
1.286 + {
1.287 + SetClientListeningFlags(target, VOICE_TEAM);
1.288 + }
1.289 + else
1.290 + {
1.291 + SetClientListeningFlags(target, VOICE_NORMAL);
1.292 + }
1.293 + }
1.294 +
1.295 + LogAction(client, target, "\"%L\" unsilenced \"%L\"", client, target);
1.296 +}
1.297 +
1.298 +public Action:Command_Mute(client, args)
1.299 +{
1.300 + if (args < 1)
1.301 + {
1.302 + ReplyToCommand(client, "[SM] Usage: sm_mute <player>");
1.303 + return Plugin_Handled;
1.304 + }
1.305 +
1.306 + decl String:arg[64];
1.307 + GetCmdArg(1, arg, sizeof(arg));
1.308 +
1.309 + decl String:target_name[MAX_TARGET_LENGTH];
1.310 + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
1.311 +
1.312 + if ((target_count = ProcessTargetString(
1.313 + arg,
1.314 + client,
1.315 + target_list,
1.316 + MAXPLAYERS,
1.317 + 0,
1.318 + target_name,
1.319 + sizeof(target_name),
1.320 + tn_is_ml)) <= 0)
1.321 + {
1.322 + ReplyToTargetError(client, target_count);
1.323 + return Plugin_Handled;
1.324 + }
1.325 +
1.326 + for (new i = 0; i < target_count; i++)
1.327 + {
1.328 + new target = target_list[i];
1.329 +
1.330 + PerformMute(client, target);
1.331 + }
1.332 +
1.333 + if (tn_is_ml)
1.334 + {
1.335 + ShowActivity2(client, "[SM] ", "%t", "Muted target", target_name);
1.336 + }
1.337 + else
1.338 + {
1.339 + ShowActivity2(client, "[SM] ", "%t", "Muted target", "_s", target_name);
1.340 + }
1.341 +
1.342 + return Plugin_Handled;
1.343 +}
1.344 +
1.345 +public Action:Command_Gag(client, args)
1.346 +{
1.347 + if (args < 1)
1.348 + {
1.349 + ReplyToCommand(client, "[SM] Usage: sm_gag <player>");
1.350 + return Plugin_Handled;
1.351 + }
1.352 +
1.353 + decl String:arg[64];
1.354 + GetCmdArg(1, arg, sizeof(arg));
1.355 +
1.356 + decl String:target_name[MAX_TARGET_LENGTH];
1.357 + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
1.358 +
1.359 + if ((target_count = ProcessTargetString(
1.360 + arg,
1.361 + client,
1.362 + target_list,
1.363 + MAXPLAYERS,
1.364 + 0,
1.365 + target_name,
1.366 + sizeof(target_name),
1.367 + tn_is_ml)) <= 0)
1.368 + {
1.369 + ReplyToTargetError(client, target_count);
1.370 + return Plugin_Handled;
1.371 + }
1.372 +
1.373 + for (new i = 0; i < target_count; i++)
1.374 + {
1.375 + new target = target_list[i];
1.376 +
1.377 + PerformGag(client, target);
1.378 + }
1.379 +
1.380 + if (tn_is_ml)
1.381 + {
1.382 + ShowActivity2(client, "[SM] ", "%t", "Gagged target", target_name);
1.383 + }
1.384 + else
1.385 + {
1.386 + ShowActivity2(client, "[SM] ", "%t", "Gagged target", "_s", target_name);
1.387 + }
1.388 +
1.389 + return Plugin_Handled;
1.390 +}
1.391 +
1.392 +public Action:Command_Silence(client, args)
1.393 +{
1.394 + if (args < 1)
1.395 + {
1.396 + ReplyToCommand(client, "[SM] Usage: sm_silence <player>");
1.397 + return Plugin_Handled;
1.398 + }
1.399 +
1.400 + decl String:arg[64];
1.401 + GetCmdArg(1, arg, sizeof(arg));
1.402 +
1.403 + decl String:target_name[MAX_TARGET_LENGTH];
1.404 + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
1.405 +
1.406 + if ((target_count = ProcessTargetString(
1.407 + arg,
1.408 + client,
1.409 + target_list,
1.410 + MAXPLAYERS,
1.411 + 0,
1.412 + target_name,
1.413 + sizeof(target_name),
1.414 + tn_is_ml)) <= 0)
1.415 + {
1.416 + ReplyToTargetError(client, target_count);
1.417 + return Plugin_Handled;
1.418 + }
1.419 +
1.420 + for (new i = 0; i < target_count; i++)
1.421 + {
1.422 + new target = target_list[i];
1.423 +
1.424 + PerformSilence(client, target);
1.425 + }
1.426 +
1.427 + if (tn_is_ml)
1.428 + {
1.429 + ShowActivity2(client, "[SM] ", "%t", "Silenced target", target_name);
1.430 + }
1.431 + else
1.432 + {
1.433 + ShowActivity2(client, "[SM] ", "%t", "Silenced target", "_s", target_name);
1.434 + }
1.435 +
1.436 + return Plugin_Handled;
1.437 +}
1.438 +
1.439 +public Action:Command_Unmute(client, args)
1.440 +{
1.441 + if (args < 1)
1.442 + {
1.443 + ReplyToCommand(client, "[SM] Usage: sm_unmute <player>");
1.444 + return Plugin_Handled;
1.445 + }
1.446 +
1.447 + decl String:arg[64];
1.448 + GetCmdArg(1, arg, sizeof(arg));
1.449 +
1.450 + decl String:target_name[MAX_TARGET_LENGTH];
1.451 + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
1.452 +
1.453 + if ((target_count = ProcessTargetString(
1.454 + arg,
1.455 + client,
1.456 + target_list,
1.457 + MAXPLAYERS,
1.458 + 0,
1.459 + target_name,
1.460 + sizeof(target_name),
1.461 + tn_is_ml)) <= 0)
1.462 + {
1.463 + ReplyToTargetError(client, target_count);
1.464 + return Plugin_Handled;
1.465 + }
1.466 +
1.467 + for (new i = 0; i < target_count; i++)
1.468 + {
1.469 + new target = target_list[i];
1.470 +
1.471 + if (!g_Muted[target])
1.472 + {
1.473 + continue;
1.474 + }
1.475 +
1.476 + PerformUnMute(client, target);
1.477 + }
1.478 +
1.479 + if (tn_is_ml)
1.480 + {
1.481 + ShowActivity2(client, "[SM] ", "%t", "Unmuted target", target_name);
1.482 + }
1.483 + else
1.484 + {
1.485 + ShowActivity2(client, "[SM] ", "%t", "Unmuted target", "_s", target_name);
1.486 + }
1.487 +
1.488 + return Plugin_Handled;
1.489 +}
1.490 +
1.491 +public Action:Command_Ungag(client, args)
1.492 +{
1.493 + if (args < 1)
1.494 + {
1.495 + ReplyToCommand(client, "[SM] Usage: sm_ungag <player>");
1.496 + return Plugin_Handled;
1.497 + }
1.498 +
1.499 + decl String:arg[64];
1.500 + GetCmdArg(1, arg, sizeof(arg));
1.501 +
1.502 + decl String:target_name[MAX_TARGET_LENGTH];
1.503 + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
1.504 +
1.505 + if ((target_count = ProcessTargetString(
1.506 + arg,
1.507 + client,
1.508 + target_list,
1.509 + MAXPLAYERS,
1.510 + 0,
1.511 + target_name,
1.512 + sizeof(target_name),
1.513 + tn_is_ml)) <= 0)
1.514 + {
1.515 + ReplyToTargetError(client, target_count);
1.516 + return Plugin_Handled;
1.517 + }
1.518 +
1.519 + for (new i = 0; i < target_count; i++)
1.520 + {
1.521 + new target = target_list[i];
1.522 +
1.523 + PerformUnGag(client, target);
1.524 + }
1.525 +
1.526 + if (tn_is_ml)
1.527 + {
1.528 + ShowActivity2(client, "[SM] ", "%t", "Ungagged target", target_name);
1.529 + }
1.530 + else
1.531 + {
1.532 + ShowActivity2(client, "[SM] ", "%t", "Ungagged target", "_s", target_name);
1.533 + }
1.534 +
1.535 + return Plugin_Handled;
1.536 +}
1.537 +
1.538 +public Action:Command_Unsilence(client, args)
1.539 +{
1.540 + if (args < 1)
1.541 + {
1.542 + ReplyToCommand(client, "[SM] Usage: sm_unsilence <player>");
1.543 + return Plugin_Handled;
1.544 + }
1.545 +
1.546 + decl String:arg[64];
1.547 + GetCmdArg(1, arg, sizeof(arg));
1.548 +
1.549 + decl String:target_name[MAX_TARGET_LENGTH];
1.550 + decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
1.551 +
1.552 + if ((target_count = ProcessTargetString(
1.553 + arg,
1.554 + client,
1.555 + target_list,
1.556 + MAXPLAYERS,
1.557 + 0,
1.558 + target_name,
1.559 + sizeof(target_name),
1.560 + tn_is_ml)) <= 0)
1.561 + {
1.562 + ReplyToTargetError(client, target_count);
1.563 + return Plugin_Handled;
1.564 + }
1.565 +
1.566 + for (new i = 0; i < target_count; i++)
1.567 + {
1.568 + new target = target_list[i];
1.569 +
1.570 + PerformUnSilence(client, target);
1.571 + }
1.572 +
1.573 + if (tn_is_ml)
1.574 + {
1.575 + ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", target_name);
1.576 + }
1.577 + else
1.578 + {
1.579 + ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", "_s", target_name);
1.580 + }
1.581 +
1.582 + return Plugin_Handled;
1.583 +}