2008-03-30 09:00:22 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Basecommands Plugin
|
|
|
|
* Provides sm_who functionality
|
|
|
|
*
|
|
|
|
* SourceMod (C)2004-2008 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* 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 <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
2008-04-11 19:16:36 +02:00
|
|
|
* Version: $Id$
|
2008-03-30 09:00:22 +02:00
|
|
|
*/
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
void PerformWho(int client, int target, ReplySource reply, bool is_admin)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
char name[MAX_NAME_LENGTH];
|
2008-03-30 09:00:22 +02:00
|
|
|
GetClientName(target, name, sizeof(name));
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
bool show_name = false;
|
|
|
|
char admin_name[MAX_NAME_LENGTH];
|
|
|
|
AdminId id = GetUserAdmin(target);
|
|
|
|
if (id != INVALID_ADMIN_ID && id.GetUsername(admin_name, sizeof(admin_name)))
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
show_name = true;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
ReplySource old_reply = SetCmdReplySource(reply);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
if (id == INVALID_ADMIN_ID)
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] %t", "Player is not an admin", name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!is_admin)
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] %t", "Player is an admin", name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
int flags = GetUserFlagBits(target);
|
|
|
|
char flagstring[255];
|
2008-03-30 09:00:22 +02:00
|
|
|
if (flags == 0)
|
|
|
|
{
|
|
|
|
strcopy(flagstring, sizeof(flagstring), "none");
|
|
|
|
}
|
|
|
|
else if (flags & ADMFLAG_ROOT)
|
|
|
|
{
|
|
|
|
strcopy(flagstring, sizeof(flagstring), "root");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlagsToString(flagstring, sizeof(flagstring), flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (show_name)
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] %t", "Admin logged in as", name, admin_name, flagstring);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] %t", "Admin logged in anon", name, flagstring);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCmdReplySource(old_reply);
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
void DisplayWhoMenu(int client)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
Menu menu = new Menu(MenuHandler_Who);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
char title[100];
|
2008-03-30 09:00:22 +02:00
|
|
|
Format(title, sizeof(title), "%T:", "Identify player", client);
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.SetTitle(title);
|
|
|
|
menu.ExitBackButton = true;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2009-10-21 00:48:56 +02:00
|
|
|
AddTargetsToMenu2(menu, 0, COMMAND_FILTER_CONNECTED);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.Display(client, MENU_TIME_FOREVER);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public void AdminMenu_Who(TopMenu topmenu,
|
|
|
|
TopMenuAction action,
|
|
|
|
TopMenuObject object_id,
|
|
|
|
int param,
|
|
|
|
char[] buffer,
|
|
|
|
int maxlength)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (action == TopMenuAction_DisplayOption)
|
|
|
|
{
|
|
|
|
Format(buffer, maxlength, "%T", "Identify player", param);
|
|
|
|
}
|
|
|
|
else if (action == TopMenuAction_SelectOption)
|
|
|
|
{
|
|
|
|
DisplayWhoMenu(param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public int MenuHandler_Who(Menu menu, MenuAction action, int param1, int param2)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (action == MenuAction_End)
|
|
|
|
{
|
2014-11-16 01:30:45 +01:00
|
|
|
delete menu;
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
else if (action == MenuAction_Cancel)
|
|
|
|
{
|
2014-10-29 03:03:38 +01:00
|
|
|
if (param2 == MenuCancel_ExitBack && hTopMenu)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-10-29 03:03:38 +01:00
|
|
|
hTopMenu.Display(param1, TopMenuPosition_LastCategory);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (action == MenuAction_Select)
|
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
char info[32];
|
|
|
|
int userid, target;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.GetItem(param2, info, sizeof(info));
|
2008-03-30 09:00:22 +02:00
|
|
|
userid = StringToInt(info);
|
|
|
|
|
|
|
|
if ((target = GetClientOfUserId(userid)) == 0)
|
|
|
|
{
|
|
|
|
PrintToChat(param1, "[SM] %t", "Player no longer available");
|
|
|
|
}
|
|
|
|
else if (!CanUserTarget(param1, target))
|
|
|
|
{
|
|
|
|
PrintToChat(param1, "[SM] %t", "Unable to target");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PerformWho(param1, target, SM_REPLY_TO_CHAT, (GetUserFlagBits(param1) != 0 ? true : false));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Re-draw the menu if they're still valid */
|
|
|
|
|
|
|
|
/* - Close the menu? redisplay? jump back up to the category?
|
|
|
|
if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
|
|
|
|
{
|
|
|
|
DisplayWhoMenu(param1);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
2016-05-11 16:44:58 +02:00
|
|
|
public Action Command_Who(int client, int args)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
bool is_admin = false;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2008-05-15 00:40:36 +02:00
|
|
|
if (!client || (client && GetUserFlagBits(client) != 0))
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
is_admin = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args < 1)
|
|
|
|
{
|
|
|
|
/* Display header */
|
2016-05-11 16:44:58 +02:00
|
|
|
char t_access[16], t_name[16], t_username[16];
|
2013-08-25 16:15:35 +02:00
|
|
|
Format(t_access, sizeof(t_access), "%T", "Admin access", client);
|
|
|
|
Format(t_name, sizeof(t_name), "%T", "Name", client);
|
|
|
|
Format(t_username, sizeof(t_username), "%T", "Username", client);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
if (is_admin)
|
|
|
|
{
|
|
|
|
PrintToConsole(client, " %-24.23s %-18.17s %s", t_name, t_username, t_access);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintToConsole(client, " %-24.23s %s", t_name, t_access);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* List all players */
|
2016-05-11 16:44:58 +02:00
|
|
|
char flagstring[255];
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
for (int i=1; i<=MaxClients; i++)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (!IsClientInGame(i))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2016-05-11 16:44:58 +02:00
|
|
|
int flags = GetUserFlagBits(i);
|
|
|
|
AdminId id = GetUserAdmin(i);
|
2008-03-30 09:00:22 +02:00
|
|
|
if (flags == 0)
|
|
|
|
{
|
|
|
|
strcopy(flagstring, sizeof(flagstring), "none");
|
|
|
|
}
|
|
|
|
else if (flags & ADMFLAG_ROOT)
|
|
|
|
{
|
|
|
|
strcopy(flagstring, sizeof(flagstring), "root");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FlagsToString(flagstring, sizeof(flagstring), flags);
|
|
|
|
}
|
2016-05-11 16:44:58 +02:00
|
|
|
char name[MAX_NAME_LENGTH];
|
|
|
|
char username[MAX_NAME_LENGTH];
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
GetClientName(i, name, sizeof(name));
|
|
|
|
|
|
|
|
if (id != INVALID_ADMIN_ID)
|
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
id.GetUsername(username, sizeof(username));
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_admin)
|
|
|
|
{
|
|
|
|
PrintToConsole(client, "%2d. %-24.23s %-18.17s %s", i, name, username, flagstring);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (flags == 0)
|
|
|
|
{
|
|
|
|
PrintToConsole(client, "%2d. %-24.23s %t", i, name, "No");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PrintToConsole(client, "%2d. %-24.23s %t", i, name, "Yes");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] %t", "See console for output");
|
|
|
|
}
|
|
|
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
char arg[65];
|
2008-03-30 09:00:22 +02:00
|
|
|
GetCmdArg(1, arg, sizeof(arg));
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
int target = FindTarget(client, arg, false, false);
|
2008-03-30 09:00:22 +02:00
|
|
|
if (target == -1)
|
|
|
|
{
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
|
|
|
PerformWho(client, target, GetCmdReplySource(), is_admin);
|
|
|
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|