plugins/basecommands/who.sp
author David Anderson <dvander@alliedmods.net>
Tue Oct 16 18:37:24 2007 +0000 (2007-10-16)
changeset 1592 ff10cfeaf5d2
parent 1536 fe2146e4975d
child 1607 66b03a0e6ba7
permissions -rw-r--r--
overhaul of the phrases for consistency
renamed config files for adminmenu
cleaned up execcfg menu code
pred@1536
     1
pred@1536
     2
PerformWho(client, target, ReplySource:reply)
pred@1536
     3
{
pred@1536
     4
	new flags = GetUserFlagBits(target);
pred@1536
     5
	decl String:flagstring[255];
pred@1536
     6
	if (flags == 0)
pred@1536
     7
	{
pred@1536
     8
		strcopy(flagstring, sizeof(flagstring), "none");
pred@1536
     9
	} else if (flags & ADMFLAG_ROOT) {
pred@1536
    10
		strcopy(flagstring, sizeof(flagstring), "root");
pred@1536
    11
	} else {
pred@1536
    12
		FlagsToString(flagstring, sizeof(flagstring), flags);
pred@1536
    13
	}
pred@1536
    14
pred@1536
    15
	if (reply == SM_REPLY_TO_CHAT)
pred@1536
    16
		PrintToChat(client, "[SM] %t: %s", "Access", flagstring);
pred@1536
    17
	else
pred@1536
    18
		PrintToConsole(client, "[SM] %t: %s", "Access", flagstring);
pred@1536
    19
}
pred@1536
    20
pred@1536
    21
DisplayWhoMenu(client)
pred@1536
    22
{
pred@1536
    23
	new Handle:menu = CreateMenu(MenuHandler_Who);
pred@1536
    24
	
pred@1536
    25
	decl String:title[100];
dvander@1592
    26
	Format(title, sizeof(title), "%T:", "Identify player", client);
pred@1536
    27
	SetMenuTitle(menu, title);
pred@1536
    28
	SetMenuExitBackButton(menu, true);
pred@1536
    29
	
pred@1536
    30
	AddTargetsToMenu(menu, client, false);
pred@1536
    31
	
pred@1536
    32
	DisplayMenu(menu, client, MENU_TIME_FOREVER);
pred@1536
    33
}
pred@1536
    34
pred@1536
    35
public AdminMenu_Who(Handle:topmenu, 
pred@1536
    36
					  TopMenuAction:action,
pred@1536
    37
					  TopMenuObject:object_id,
pred@1536
    38
					  param,
pred@1536
    39
					  String:buffer[],
pred@1536
    40
					  maxlength)
pred@1536
    41
{
pred@1536
    42
	if (action == TopMenuAction_DisplayOption)
pred@1536
    43
	{
dvander@1592
    44
		Format(buffer, maxlength, "%T", "Identify player", param);
pred@1536
    45
	}
pred@1536
    46
	else if (action == TopMenuAction_SelectOption)
pred@1536
    47
	{
pred@1536
    48
		DisplayWhoMenu(param);
pred@1536
    49
	}
pred@1536
    50
}
pred@1536
    51
pred@1536
    52
public MenuHandler_Who(Handle:menu, MenuAction:action, param1, param2)
pred@1536
    53
{
pred@1536
    54
	if (action == MenuAction_End)
pred@1536
    55
	{
pred@1536
    56
		CloseHandle(menu);
pred@1536
    57
	}
pred@1536
    58
	else if (action == MenuAction_Cancel)
pred@1536
    59
	{
pred@1536
    60
		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
pred@1536
    61
		{
pred@1536
    62
			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
pred@1536
    63
		}
pred@1536
    64
	}
pred@1536
    65
	else if (action == MenuAction_Select)
pred@1536
    66
	{
pred@1536
    67
		decl String:info[32];
pred@1536
    68
		new userid, target;
pred@1536
    69
		
pred@1536
    70
		GetMenuItem(menu, param2, info, sizeof(info));
pred@1536
    71
		userid = StringToInt(info);
pred@1536
    72
pred@1536
    73
		if ((target = GetClientOfUserId(userid)) == 0)
pred@1536
    74
		{
pred@1536
    75
			PrintToChat(param1, "[SM] %t", "Player no longer available");
pred@1536
    76
		}
pred@1536
    77
		else if (!CanUserTarget(param1, target))
pred@1536
    78
		{
pred@1536
    79
			PrintToChat(param1, "[SM] %t", "Unable to target");
pred@1536
    80
		}
pred@1536
    81
		else
pred@1536
    82
		{
pred@1536
    83
			PerformWho(param1, target, SM_REPLY_TO_CHAT);
pred@1536
    84
		}
pred@1536
    85
		
pred@1536
    86
		/* Re-draw the menu if they're still valid */
pred@1536
    87
		
pred@1536
    88
		/* - Close the menu? redisplay? jump back up to the category?
pred@1536
    89
		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
pred@1536
    90
		{
pred@1536
    91
			DisplayWhoMenu(param1);
pred@1536
    92
		}
pred@1536
    93
		*/
pred@1536
    94
	}
pred@1536
    95
}
pred@1536
    96
public Action:Command_Who(client, args)
pred@1536
    97
{
pred@1536
    98
	if (args < 1)
pred@1536
    99
	{
pred@1536
   100
		/* Display header */
pred@1536
   101
		decl String:t_access[16], String:t_name[16];
pred@1536
   102
		Format(t_access, sizeof(t_access), "%t", "Access", client);
pred@1536
   103
		Format(t_name, sizeof(t_name), "%t", "Name", client);
pred@1536
   104
pred@1536
   105
		PrintToConsole(client, "%-24.23s %s", t_name, t_access);
pred@1536
   106
pred@1536
   107
		/* List all players */
pred@1536
   108
		new maxClients = GetMaxClients();
pred@1536
   109
		decl String:flagstring[255];
pred@1536
   110
pred@1536
   111
		for (new i=1; i<=maxClients; i++)
pred@1536
   112
		{
pred@1536
   113
			if (!IsClientInGame(i))
pred@1536
   114
			{
pred@1536
   115
				continue;
pred@1536
   116
			}
pred@1536
   117
			new flags = GetUserFlagBits(i);
pred@1536
   118
			if (flags == 0)
pred@1536
   119
			{
pred@1536
   120
				strcopy(flagstring, sizeof(flagstring), "none");
pred@1536
   121
			} else if (flags & ADMFLAG_ROOT) {
pred@1536
   122
				strcopy(flagstring, sizeof(flagstring), "root");
pred@1536
   123
			} else {
pred@1536
   124
				FlagsToString(flagstring, sizeof(flagstring), flags);
pred@1536
   125
			}
pred@1536
   126
			decl String:name[65];
pred@1536
   127
			GetClientName(i, name, sizeof(name));
pred@1536
   128
			PrintToConsole(client, "%d. %-24.23s %s", i, name, flagstring);
pred@1536
   129
		}
pred@1536
   130
pred@1536
   131
		if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
pred@1536
   132
		{
pred@1536
   133
			ReplyToCommand(client, "[SM] %t", "See console for output");
pred@1536
   134
		}
pred@1536
   135
pred@1536
   136
		return Plugin_Handled;
pred@1536
   137
	}
pred@1536
   138
pred@1536
   139
	decl String:arg[65];
pred@1536
   140
	GetCmdArg(1, arg, sizeof(arg));
pred@1536
   141
pred@1536
   142
	new clients[2];
pred@1536
   143
	new numClients = SearchForClients(arg, clients, 2);
pred@1536
   144
pred@1536
   145
	if (numClients == 0)
pred@1536
   146
	{
pred@1536
   147
		ReplyToCommand(client, "[SM] %t", "No matching client");
pred@1536
   148
		return Plugin_Handled;
pred@1536
   149
	} else if (numClients > 1) {
pred@1536
   150
		ReplyToCommand(client, "[SM] %t", "More than one client matches", arg);
pred@1536
   151
		return Plugin_Handled;
pred@1536
   152
	}
pred@1536
   153
	
pred@1536
   154
	PerformWho(client, clients[0], GetCmdReplySource());
pred@1536
   155
pred@1536
   156
	return Plugin_Handled;
pred@1536
   157
}