plugins/basecomm/gag.sp
author Asher Baker <asherkin@limetech.org>
Sat Apr 14 01:12:24 2012 +0100 (2012-04-14)
changeset 3477 8762e8fcbc50
parent 3340 7eb2b72e42d8
child 3645 80c9ae186971
permissions -rw-r--r--
Backed out changeset: 387b27fb575b (bug 5227)
     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, bool:silent=false)
   214 {
   215 	g_Muted[target] = true;
   216 	SetClientListeningFlags(target, VOICE_MUTED);	
   217 	
   218 	if (!silent)
   219 	{
   220 		LogAction(client, target, "\"%L\" muted \"%L\"", client, target);
   221 	}
   222 }
   223 
   224 PerformUnMute(client, target, bool:silent=false)
   225 {
   226 	g_Muted[target] = false;
   227 	if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   228 	{
   229 		SetClientListeningFlags(target, VOICE_LISTENALL);
   230 	}
   231 	else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   232 	{
   233 		SetClientListeningFlags(target, VOICE_TEAM);
   234 	}
   235 	else
   236 	{
   237 		SetClientListeningFlags(target, VOICE_NORMAL);
   238 	}
   239 	
   240 	if (!silent)
   241 	{
   242 		LogAction(client, target, "\"%L\" unmuted \"%L\"", client, target);
   243 	}
   244 }
   245 
   246 PerformGag(client, target, bool:silent=false)
   247 {
   248 	g_Gagged[target] = true;
   249 	
   250 	if (!silent)
   251 	{
   252 		LogAction(client, target, "\"%L\" gagged \"%L\"", client, target);
   253 	}
   254 }
   255 
   256 PerformUnGag(client, target, bool:silent=false)
   257 {
   258 	g_Gagged[target] = false;
   259 	
   260 	if (!silent)
   261 	{
   262 		LogAction(client, target, "\"%L\" ungagged \"%L\"", client, target);
   263 	}
   264 }
   265 
   266 PerformSilence(client, target)
   267 {
   268 	if (!g_Gagged[target])
   269 	{
   270 		g_Gagged[target] = true;
   271 	}
   272 	
   273 	if (!g_Muted[target])
   274 	{
   275 		g_Muted[target] = true;
   276 		SetClientListeningFlags(target, VOICE_MUTED);
   277 	}
   278 	
   279 	LogAction(client, target, "\"%L\" silenced \"%L\"", client, target);
   280 }
   281 
   282 PerformUnSilence(client, target)
   283 {
   284 	if (g_Gagged[target])
   285 	{
   286 		g_Gagged[target] = false;
   287 	}
   288 	
   289 	if (g_Muted[target])
   290 	{
   291 		g_Muted[target] = false;
   292 		
   293 		if (GetConVarInt(g_Cvar_Deadtalk) == 1 && !IsPlayerAlive(target))
   294 		{
   295 			SetClientListeningFlags(target, VOICE_LISTENALL);
   296 		}
   297 		else if (GetConVarInt(g_Cvar_Deadtalk) == 2 && !IsPlayerAlive(target))
   298 		{
   299 			SetClientListeningFlags(target, VOICE_TEAM);
   300 		}
   301 		else
   302 		{
   303 			SetClientListeningFlags(target, VOICE_NORMAL);
   304 		}	
   305 	}
   306 	
   307 	LogAction(client, target, "\"%L\" unsilenced \"%L\"", client, target);
   308 }
   309 
   310 public Action:Command_Mute(client, args)
   311 {	
   312 	if (args < 1)
   313 	{
   314 		ReplyToCommand(client, "[SM] Usage: sm_mute <player>");
   315 		return Plugin_Handled;
   316 	}
   317 	
   318 	decl String:arg[64];
   319 	GetCmdArg(1, arg, sizeof(arg));
   320 	
   321 	decl String:target_name[MAX_TARGET_LENGTH];
   322 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   323 	
   324 	if ((target_count = ProcessTargetString(
   325 			arg,
   326 			client, 
   327 			target_list, 
   328 			MAXPLAYERS, 
   329 			0,
   330 			target_name,
   331 			sizeof(target_name),
   332 			tn_is_ml)) <= 0)
   333 	{
   334 		ReplyToTargetError(client, target_count);
   335 		return Plugin_Handled;
   336 	}
   337 
   338 	for (new i = 0; i < target_count; i++)
   339 	{
   340 		new target = target_list[i];
   341 		
   342 		PerformMute(client, target);
   343 	}
   344 	
   345 	if (tn_is_ml)
   346 	{
   347 		ShowActivity2(client, "[SM] ", "%t", "Muted target", target_name);
   348 	}
   349 	else
   350 	{
   351 		ShowActivity2(client, "[SM] ", "%t", "Muted target", "_s", target_name);
   352 	}
   353 	
   354 	return Plugin_Handled;	
   355 }
   356 
   357 public Action:Command_Gag(client, args)
   358 {	
   359 	if (args < 1)
   360 	{
   361 		ReplyToCommand(client, "[SM] Usage: sm_gag <player>");
   362 		return Plugin_Handled;
   363 	}
   364 	
   365 	decl String:arg[64];
   366 	GetCmdArg(1, arg, sizeof(arg));
   367 	
   368 	decl String:target_name[MAX_TARGET_LENGTH];
   369 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   370 	
   371 	if ((target_count = ProcessTargetString(
   372 			arg,
   373 			client, 
   374 			target_list, 
   375 			MAXPLAYERS, 
   376 			0,
   377 			target_name,
   378 			sizeof(target_name),
   379 			tn_is_ml)) <= 0)
   380 	{
   381 		ReplyToTargetError(client, target_count);
   382 		return Plugin_Handled;
   383 	}
   384 
   385 	for (new i = 0; i < target_count; i++)
   386 	{
   387 		new target = target_list[i];
   388 		
   389 		PerformGag(client, target);
   390 	}
   391 	
   392 	if (tn_is_ml)
   393 	{
   394 		ShowActivity2(client, "[SM] ", "%t", "Gagged target", target_name);
   395 	}
   396 	else
   397 	{
   398 		ShowActivity2(client, "[SM] ", "%t", "Gagged target", "_s", target_name);
   399 	}
   400 	
   401 	return Plugin_Handled;	
   402 }
   403 
   404 public Action:Command_Silence(client, args)
   405 {	
   406 	if (args < 1)
   407 	{
   408 		ReplyToCommand(client, "[SM] Usage: sm_silence <player>");
   409 		return Plugin_Handled;
   410 	}
   411 	
   412 	decl String:arg[64];
   413 	GetCmdArg(1, arg, sizeof(arg));
   414 	
   415 	decl String:target_name[MAX_TARGET_LENGTH];
   416 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   417 	
   418 	if ((target_count = ProcessTargetString(
   419 			arg,
   420 			client, 
   421 			target_list, 
   422 			MAXPLAYERS, 
   423 			0,
   424 			target_name,
   425 			sizeof(target_name),
   426 			tn_is_ml)) <= 0)
   427 	{
   428 		ReplyToTargetError(client, target_count);
   429 		return Plugin_Handled;
   430 	}
   431 
   432 	for (new i = 0; i < target_count; i++)
   433 	{
   434 		new target = target_list[i];
   435 		
   436 		PerformSilence(client, target);
   437 	}
   438 	
   439 	if (tn_is_ml)
   440 	{
   441 		ShowActivity2(client, "[SM] ", "%t", "Silenced target", target_name);
   442 	}
   443 	else
   444 	{
   445 		ShowActivity2(client, "[SM] ", "%t", "Silenced target", "_s", target_name);
   446 	}
   447 	
   448 	return Plugin_Handled;	
   449 }
   450 
   451 public Action:Command_Unmute(client, args)
   452 {	
   453 	if (args < 1)
   454 	{
   455 		ReplyToCommand(client, "[SM] Usage: sm_unmute <player>");
   456 		return Plugin_Handled;
   457 	}
   458 	
   459 	decl String:arg[64];
   460 	GetCmdArg(1, arg, sizeof(arg));
   461 	
   462 	decl String:target_name[MAX_TARGET_LENGTH];
   463 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   464 	
   465 	if ((target_count = ProcessTargetString(
   466 			arg,
   467 			client, 
   468 			target_list, 
   469 			MAXPLAYERS, 
   470 			0,
   471 			target_name,
   472 			sizeof(target_name),
   473 			tn_is_ml)) <= 0)
   474 	{
   475 		ReplyToTargetError(client, target_count);
   476 		return Plugin_Handled;
   477 	}
   478 
   479 	for (new i = 0; i < target_count; i++)
   480 	{
   481 		new target = target_list[i];
   482 		
   483 		if (!g_Muted[target])
   484 		{
   485 			continue;
   486 		}
   487 		
   488 		PerformUnMute(client, target);
   489 	}
   490 	
   491 	if (tn_is_ml)
   492 	{
   493 		ShowActivity2(client, "[SM] ", "%t", "Unmuted target", target_name);
   494 	}
   495 	else
   496 	{
   497 		ShowActivity2(client, "[SM] ", "%t", "Unmuted target", "_s", target_name);
   498 	}
   499 	
   500 	return Plugin_Handled;	
   501 }
   502 
   503 public Action:Command_Ungag(client, args)
   504 {	
   505 	if (args < 1)
   506 	{
   507 		ReplyToCommand(client, "[SM] Usage: sm_ungag <player>");
   508 		return Plugin_Handled;
   509 	}
   510 	
   511 	decl String:arg[64];
   512 	GetCmdArg(1, arg, sizeof(arg));
   513 	
   514 	decl String:target_name[MAX_TARGET_LENGTH];
   515 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   516 	
   517 	if ((target_count = ProcessTargetString(
   518 			arg,
   519 			client, 
   520 			target_list, 
   521 			MAXPLAYERS, 
   522 			0,
   523 			target_name,
   524 			sizeof(target_name),
   525 			tn_is_ml)) <= 0)
   526 	{
   527 		ReplyToTargetError(client, target_count);
   528 		return Plugin_Handled;
   529 	}
   530 
   531 	for (new i = 0; i < target_count; i++)
   532 	{
   533 		new target = target_list[i];
   534 		
   535 		PerformUnGag(client, target);
   536 	}
   537 	
   538 	if (tn_is_ml)
   539 	{
   540 		ShowActivity2(client, "[SM] ", "%t", "Ungagged target", target_name);
   541 	}
   542 	else
   543 	{
   544 		ShowActivity2(client, "[SM] ", "%t", "Ungagged target", "_s", target_name);
   545 	}
   546 	
   547 	return Plugin_Handled;	
   548 }
   549 
   550 public Action:Command_Unsilence(client, args)
   551 {	
   552 	if (args < 1)
   553 	{
   554 		ReplyToCommand(client, "[SM] Usage: sm_unsilence <player>");
   555 		return Plugin_Handled;
   556 	}
   557 	
   558 	decl String:arg[64];
   559 	GetCmdArg(1, arg, sizeof(arg));
   560 	
   561 	decl String:target_name[MAX_TARGET_LENGTH];
   562 	decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
   563 	
   564 	if ((target_count = ProcessTargetString(
   565 			arg,
   566 			client, 
   567 			target_list, 
   568 			MAXPLAYERS, 
   569 			0,
   570 			target_name,
   571 			sizeof(target_name),
   572 			tn_is_ml)) <= 0)
   573 	{
   574 		ReplyToTargetError(client, target_count);
   575 		return Plugin_Handled;
   576 	}
   577 
   578 	for (new i = 0; i < target_count; i++)
   579 	{
   580 		new target = target_list[i];
   581 		
   582 		PerformUnSilence(client, target);
   583 	}
   584 	
   585 	if (tn_is_ml)
   586 	{
   587 		ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", target_name);
   588 	}
   589 	else
   590 	{
   591 		ShowActivity2(client, "[SM] ", "%t", "Unsilenced target", "_s", target_name);
   592 	}
   593 	
   594 	return Plugin_Handled;	
   595 }