plugins/basecomm/gag.sp
author Nicholas Hastings <skamonkey@gmail.com>
Mon May 31 16:31:10 2010 -0400 (2010-05-31)
changeset 3028 5ff200ebefc5
parent 2640 fdc0583f4615
child 3340 7eb2b72e42d8
permissions -rw-r--r--
Fixed tf2.inc incorrectly attempting to load tf2 ext on all games (bug 4197, r=fyren)
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod Basecomm
     5  * Part of Basecomm plugin, menu and other functionality.
     6  *
     7  * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     8  * =============================================================================
     9  *
    10  * This program is free software; you can redistribute it and/or modify it under
    11  * the terms of the GNU General Public License, version 3.0, as published by the
    12  * Free Software Foundation.
    13  * 
    14  * This program is distributed in the hope that it will be useful, but WITHOUT
    15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    16  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    17  * details.
    18  *
    19  * You should have received a copy of the GNU General Public License along with
    20  * this program.  If not, see <http://www.gnu.org/licenses/>.
    21  *
    22  * As a special exception, AlliedModders LLC gives you permission to link the
    23  * code of this program (as well as its derivative works) to "Half-Life 2," the
    24  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    25  * by the Valve Corporation.  You must obey the GNU General Public License in
    26  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    27  * this exception to all derivative works.  AlliedModders LLC defines further
    28  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    29  * or <http://www.sourcemod.net/license.php>.
    30  *
    31  * Version: $Id$
    32  */
    33 
    34 enum CommType
    35 {
    36 	CommType_Mute,
    37 	CommType_UnMute,
    38 	CommType_Gag,
    39 	CommType_UnGag,
    40 	CommType_Silence,
    41 	CommType_UnSilence
    42 };
    43 
    44 DisplayGagTypesMenu(client)
    45 {
    46 	new Handle:menu = CreateMenu(MenuHandler_GagTypes);
    47 	
    48 	decl String:title[100];
    49 	Format(title, sizeof(title), "%T: %N", "Choose Type", client, g_GagTarget[client]);
    50 	SetMenuTitle(menu, title);
    51 	SetMenuExitBackButton(menu, true);
    52 	
    53 	new target = g_GagTarget[client];
    54 	
    55 	if (!g_Muted[target])
    56 	{
    57 		AddMenuItem(menu, "0", "Mute Player");
    58 	}
    59 	else
    60 	{
    61 		AddMenuItem(menu, "1", "UnMute Player");
    62 	}
    63 	
    64 	if (!g_Gagged[target])
    65 	{
    66 		AddMenuItem(menu, "2", "Gag Player");
    67 	}
    68 	else
    69 	{
    70 		AddMenuItem(menu, "3", "UnGag Player");
    71 	}
    72 	
    73 	if (!g_Muted[target] || !g_Gagged[target])
    74 	{
    75 		AddMenuItem(menu, "4", "Silence Player");
    76 	}
    77 	else
    78 	{
    79 		AddMenuItem(menu, "5", "UnSilence Player");
    80 	}
    81 		
    82 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    83 }
    84 
    85 DisplayGagPlayerMenu(client)
    86 {
    87 	new Handle:menu = CreateMenu(MenuHandler_GagPlayer);
    88 	
    89 	decl String:title[100];
    90 	Format(title, sizeof(title), "%T:", "Gag/Mute player", client);
    91 	SetMenuTitle(menu, title);
    92 	SetMenuExitBackButton(menu, true);
    93 	
    94 	AddTargetsToMenu(menu, client, true, false);
    95 	
    96 	DisplayMenu(menu, client, MENU_TIME_FOREVER);
    97 }
    98 
    99 public AdminMenu_Gag(Handle:topmenu, 
   100 					  TopMenuAction:action,
   101 					  TopMenuObject:object_id,
   102 					  param,
   103 					  String:buffer[],
   104 					  maxlength)
   105 {
   106 	if (action == TopMenuAction_DisplayOption)
   107 	{
   108 		Format(buffer, maxlength, "%T", "Gag/Mute player", param);
   109 	}
   110 	else if (action == TopMenuAction_SelectOption)
   111 	{
   112 		DisplayGagPlayerMenu(param);
   113 	}
   114 }
   115 
   116 public MenuHandler_GagPlayer(Handle:menu, MenuAction:action, param1, param2)
   117 {
   118 	if (action == MenuAction_End)
   119 	{
   120 		CloseHandle(menu);
   121 	}
   122 	else if (action == MenuAction_Cancel)
   123 	{
   124 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   125 		{
   126 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   127 		}
   128 	}
   129 	else if (action == MenuAction_Select)
   130 	{
   131 		decl String:info[32];
   132 		new userid, target;
   133 		
   134 		GetMenuItem(menu, param2, info, sizeof(info));
   135 		userid = StringToInt(info);
   136 
   137 		if ((target = GetClientOfUserId(userid)) == 0)
   138 		{
   139 			PrintToChat(param1, "[SM] %t", "Player no longer available");
   140 		}
   141 		else if (!CanUserTarget(param1, target))
   142 		{
   143 			PrintToChat(param1, "[SM] %t", "Unable to target");
   144 		}
   145 		else
   146 		{
   147 			g_GagTarget[param1] = GetClientOfUserId(userid);
   148 			DisplayGagTypesMenu(param1);
   149 		}
   150 	}
   151 }
   152 
   153 public MenuHandler_GagTypes(Handle:menu, MenuAction:action, param1, param2)
   154 {
   155 	if (action == MenuAction_End)
   156 	{
   157 		CloseHandle(menu);
   158 	}
   159 	else if (action == MenuAction_Cancel)
   160 	{
   161 		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   162 		{
   163 			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   164 		}
   165 	}
   166 	else if (action == MenuAction_Select)
   167 	{
   168 		decl String:info[32];
   169 		new CommType:type;
   170 		
   171 		GetMenuItem(menu, param2, info, sizeof(info));
   172 		type = CommType:StringToInt(info);
   173 		
   174 		decl String:name[MAX_NAME_LENGTH];
   175 		GetClientName(g_GagTarget[param1], name, sizeof(name));
   176 
   177 		switch (type)
   178 		{
   179 			case CommType_Mute:
   180 			{
   181 				PerformMute(param1, g_GagTarget[param1]);
   182 				ShowActivity2(param1, "[SM] ", "%t", "Muted target", "_s", name);
   183 			}
   184 			case CommType_UnMute:
   185 			{
   186 				PerformUnMute(param1, g_GagTarget[param1]);
   187 				ShowActivity2(param1, "[SM] ", "%t", "Unmuted target", "_s", name);
   188 			}
   189 			case CommType_Gag:
   190 			{
   191 				PerformGag(param1, g_GagTarget[param1]);
   192 				ShowActivity2(param1, "[SM] ", "%t", "Gagged target", "_s", name);
   193 			}
   194 			case CommType_UnGag:
   195 			{
   196 				PerformUnGag(param1, g_GagTarget[param1]);
   197 				ShowActivity2(param1, "[SM] ", "%t", "Ungagged target", "_s", name);
   198 			}
   199 			case CommType_Silence:
   200 			{
   201 				PerformSilence(param1, g_GagTarget[param1]);
   202 				ShowActivity2(param1, "[SM] ", "%t", "Silenced target", "_s", name);
   203 			}
   204 			case CommType_UnSilence:
   205 			{
   206 				PerformUnSilence(param1, g_GagTarget[param1]);
   207 				ShowActivity2(param1, "[SM] ", "%t", "Unsilenced target", "_s", name);
   208 			}
   209 		}
   210 	}
   211 }
   212 
   213 PerformMute(client, target)
   214 {
   215 	g_Muted[target] = true;
   216 	SetClientListeningFlags(target, VOICE_MUTED);	
   217 	LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
   218 }
   219 
   220 PerformUnMute(client, target)
   221 {
   222 	g_Muted[target] = false;
   223 	if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   224 	{
   225 		SetClientListeningFlags(target, VOICE_LISTENALL);
   226 	}
   227 	else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   228 	{
   229 		SetClientListeningFlags(target, VOICE_TEAM);
   230 	}
   231 	else
   232 	{
   233 		SetClientListeningFlags(target, VOICE_NORMAL);
   234 	}
   235 	
   236 	LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
   237 }
   238 
   239 PerformGag(client, target)
   240 {
   241 	g_Gagged[target] = true;
   242 	LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
   243 }
   244 
   245 PerformUnGag(client, target)
   246 {
   247 	g_Gagged[target] = false;
   248 	LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
   249 }
   250 
   251 PerformSilence(client, target)
   252 {
   253 	if (!g_Gagged[target])
   254 	{
   255 		g_Gagged[target] = true;
   256 	}
   257 	
   258 	if (!g_Muted[target])
   259 	{
   260 		g_Muted[target] = true;
   261 		SetClientListeningFlags(target, VOICE_MUTED);
   262 	}
   263 	
   264 	LogAction(client, target, "\"%L\" silenced \"%L\"", client, target);
   265 }
   266 
   267 PerformUnSilence(client, target)
   268 {
   269 	if (g_Gagged[target])
   270 	{
   271 		g_Gagged[target] = false;
   272 	}
   273 	
   274 	if (g_Muted[target])
   275 	{
   276 		g_Muted[target] = false;
   277 		
   278 		if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   279 		{
   280 			SetClientListeningFlags(target, VOICE_LISTENALL);
   281 		}
   282 		else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   283 		{
   284 			SetClientListeningFlags(target, VOICE_TEAM);
   285 		}
   286 		else
   287 		{
   288 			SetClientListeningFlags(target, VOICE_NORMAL);
   289 		}	
   290 	}
   291 	
   292 	LogAction(client, target, "\"%L\" unsilenced \"%L\"", client, target);
   293 }
   294 
   295 public Action:Command_Mute(client, args)
   296 {	
   297 	if (args < 1)
   298 	{
   299 		ReplyToCommand(client, "[SM] Usage: sm_mute <player>");
   300 		return Plugin_Handled;
   301 	}
   302 	
   303 	decl String:arg[64];
   304 	GetCmdArg(1, arg, sizeof(arg));
   305 	
   306 	decl String:target_name[MAX_TARGET_LENGTH];
   307 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   308 	
   309 	if ((target_count = ProcessTargetString(
   310 			arg,
   311 			client, 
   312 			target_list, 
   313 			MAXPLAYERS, 
   314 			0,
   315 			target_name,
   316 			sizeof(target_name),
   317 			tn_is_ml)) <= 0)
   318 	{
   319 		ReplyToTargetError(client, target_count);
   320 		return Plugin_Handled;
   321 	}
   322 
   323 	for (new i = 0; i < target_count; i++)
   324 	{
   325 		new target = target_list[i];
   326 		
   327 		PerformMute(client, target);
   328 	}
   329 	
   330 	if (tn_is_ml)
   331 	{
   332 		ShowActivity2(client, "[SM] ", "%t", "Muted target", target_name);
   333 	}
   334 	else
   335 	{
   336 		ShowActivity2(client, "[SM] ", "%t", "Muted target", "_s", target_name);
   337 	}
   338 	
   339 	return Plugin_Handled;	
   340 }
   341 
   342 public Action:Command_Gag(client, args)
   343 {	
   344 	if (args < 1)
   345 	{
   346 		ReplyToCommand(client, "[SM] Usage: sm_gag <player>");
   347 		return Plugin_Handled;
   348 	}
   349 	
   350 	decl String:arg[64];
   351 	GetCmdArg(1, arg, sizeof(arg));
   352 	
   353 	decl String:target_name[MAX_TARGET_LENGTH];
   354 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   355 	
   356 	if ((target_count = ProcessTargetString(
   357 			arg,
   358 			client, 
   359 			target_list, 
   360 			MAXPLAYERS, 
   361 			0,
   362 			target_name,
   363 			sizeof(target_name),
   364 			tn_is_ml)) <= 0)
   365 	{
   366 		ReplyToTargetError(client, target_count);
   367 		return Plugin_Handled;
   368 	}
   369 
   370 	for (new i = 0; i < target_count; i++)
   371 	{
   372 		new target = target_list[i];
   373 		
   374 		PerformGag(client, target);
   375 	}
   376 	
   377 	if (tn_is_ml)
   378 	{
   379 		ShowActivity2(client, "[SM] ", "%t", "Gagged target", target_name);
   380 	}
   381 	else
   382 	{
   383 		ShowActivity2(client, "[SM] ", "%t", "Gagged target", "_s", target_name);
   384 	}
   385 	
   386 	return Plugin_Handled;	
   387 }
   388 
   389 public Action:Command_Silence(client, args)
   390 {	
   391 	if (args < 1)
   392 	{
   393 		ReplyToCommand(client, "[SM] Usage: sm_silence <player>");
   394 		return Plugin_Handled;
   395 	}
   396 	
   397 	decl String:arg[64];
   398 	GetCmdArg(1, arg, sizeof(arg));
   399 	
   400 	decl String:target_name[MAX_TARGET_LENGTH];
   401 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   402 	
   403 	if ((target_count = ProcessTargetString(
   404 			arg,
   405 			client, 
   406 			target_list, 
   407 			MAXPLAYERS, 
   408 			0,
   409 			target_name,
   410 			sizeof(target_name),
   411 			tn_is_ml)) <= 0)
   412 	{
   413 		ReplyToTargetError(client, target_count);
   414 		return Plugin_Handled;
   415 	}
   416 
   417 	for (new i = 0; i < target_count; i++)
   418 	{
   419 		new target = target_list[i];
   420 		
   421 		PerformSilence(client, target);
   422 	}
   423 	
   424 	if (tn_is_ml)
   425 	{
   426 		ShowActivity2(client, "[SM] ", "%t", "Silenced target", target_name);
   427 	}
   428 	else
   429 	{
   430 		ShowActivity2(client, "[SM] ", "%t", "Silenced target", "_s", target_name);
   431 	}
   432 	
   433 	return Plugin_Handled;	
   434 }
   435 
   436 public Action:Command_Unmute(client, args)
   437 {	
   438 	if (args < 1)
   439 	{
   440 		ReplyToCommand(client, "[SM] Usage: sm_unmute <player>");
   441 		return Plugin_Handled;
   442 	}
   443 	
   444 	decl String:arg[64];
   445 	GetCmdArg(1, arg, sizeof(arg));
   446 	
   447 	decl String:target_name[MAX_TARGET_LENGTH];
   448 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   449 	
   450 	if ((target_count = ProcessTargetString(
   451 			arg,
   452 			client, 
   453 			target_list, 
   454 			MAXPLAYERS, 
   455 			0,
   456 			target_name,
   457 			sizeof(target_name),
   458 			tn_is_ml)) <= 0)
   459 	{
   460 		ReplyToTargetError(client, target_count);
   461 		return Plugin_Handled;
   462 	}
   463 
   464 	for (new i = 0; i < target_count; i++)
   465 	{
   466 		new target = target_list[i];
   467 		
   468 		if (!g_Muted[target])
   469 		{
   470 			continue;
   471 		}
   472 		
   473 		PerformUnMute(client, target);
   474 	}
   475 	
   476 	if (tn_is_ml)
   477 	{
   478 		ShowActivity2(client, "[SM] ", "%t", "Unmuted target", target_name);
   479 	}
   480 	else
   481 	{
   482 		ShowActivity2(client, "[SM] ", "%t", "Unmuted target", "_s", target_name);
   483 	}
   484 	
   485 	return Plugin_Handled;	
   486 }
   487 
   488 public Action:Command_Ungag(client, args)
   489 {	
   490 	if (args < 1)
   491 	{
   492 		ReplyToCommand(client, "[SM] Usage: sm_ungag <player>");
   493 		return Plugin_Handled;
   494 	}
   495 	
   496 	decl String:arg[64];
   497 	GetCmdArg(1, arg, sizeof(arg));
   498 	
   499 	decl String:target_name[MAX_TARGET_LENGTH];
   500 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   501 	
   502 	if ((target_count = ProcessTargetString(
   503 			arg,
   504 			client, 
   505 			target_list, 
   506 			MAXPLAYERS, 
   507 			0,
   508 			target_name,
   509 			sizeof(target_name),
   510 			tn_is_ml)) <= 0)
   511 	{
   512 		ReplyToTargetError(client, target_count);
   513 		return Plugin_Handled;
   514 	}
   515 
   516 	for (new i = 0; i < target_count; i++)
   517 	{
   518 		new target = target_list[i];
   519 		
   520 		PerformUnGag(client, target);
   521 	}
   522 	
   523 	if (tn_is_ml)
   524 	{
   525 		ShowActivity2(client, "[SM] ", "%t", "Ungagged target", target_name);
   526 	}
   527 	else
   528 	{
   529 		ShowActivity2(client, "[SM] ", "%t", "Ungagged target", "_s", target_name);
   530 	}
   531 	
   532 	return Plugin_Handled;	
   533 }
   534 
   535 public Action:Command_Unsilence(client, args)
   536 {	
   537 	if (args < 1)
   538 	{
   539 		ReplyToCommand(client, "[SM] Usage: sm_unsilence <player>");
   540 		return Plugin_Handled;
   541 	}
   542 	
   543 	decl String:arg[64];
   544 	GetCmdArg(1, arg, sizeof(arg));
   545 	
   546 	decl String:target_name[MAX_TARGET_LENGTH];
   547 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   548 	
   549 	if ((target_count = ProcessTargetString(
   550 			arg,
   551 			client, 
   552 			target_list, 
   553 			MAXPLAYERS, 
   554 			0,
   555 			target_name,
   556 			sizeof(target_name),
   557 			tn_is_ml)) <= 0)
   558 	{
   559 		ReplyToTargetError(client, target_count);
   560 		return Plugin_Handled;
   561 	}
   562 
   563 	for (new i = 0; i < target_count; i++)
   564 	{
   565 		new target = target_list[i];
   566 		
   567 		PerformUnSilence(client, target);
   568 	}
   569 	
   570 	if (tn_is_ml)
   571 	{
   572 		ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", target_name);
   573 	}
   574 	else
   575 	{
   576 		ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", "_s", target_name);
   577 	}
   578 	
   579 	return Plugin_Handled;	
   580 }