3 * =============================================================================
4 * SourceMod Basecommands Plugin
5 * Provides sm_who functionality
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
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.
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
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/>.
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>.
34 PerformWho(client, target, ReplySource:reply, bool:is_admin)
36 decl String:name[MAX_NAME_LENGTH];
37 GetClientName(target, name, sizeof(name));
39 new bool:show_name = false;
40 new String:admin_name[MAX_NAME_LENGTH];
41 new AdminId:id = GetUserAdmin(target);
42 if (id != INVALID_ADMIN_ID && GetAdminUsername(id, admin_name, sizeof(admin_name)))
47 new ReplySource:old_reply = SetCmdReplySource(reply);
49 if (id == INVALID_ADMIN_ID)
51 ReplyToCommand(client, "[SM] %t", "Player is not an admin", name);
57 ReplyToCommand(client, "[SM] %t", "Player is an admin", name);
61 new flags = GetUserFlagBits(target);
62 decl String:flagstring[255];
65 strcopy(flagstring, sizeof(flagstring), "none");
67 else if (flags & ADMFLAG_ROOT)
69 strcopy(flagstring, sizeof(flagstring), "root");
73 FlagsToString(flagstring, sizeof(flagstring), flags);
78 ReplyToCommand(client, "[SM] %t", "Admin logged in as", name, admin_name, flagstring);
82 ReplyToCommand(client, "[SM] %t", "Admin logged in anon", name, flagstring);
87 SetCmdReplySource(old_reply);
90 DisplayWhoMenu(client)
92 new Handle:menu = CreateMenu(MenuHandler_Who);
94 decl String:title[100];
95 Format(title, sizeof(title), "%T:", "Identify player", client);
96 SetMenuTitle(menu, title);
97 SetMenuExitBackButton(menu, true);
99 AddTargetsToMenu(menu, client, false, false);
101 DisplayMenu(menu, client, MENU_TIME_FOREVER);
104 public AdminMenu_Who(Handle:topmenu,
105 TopMenuAction:action,
106 TopMenuObject:object_id,
111 if (action == TopMenuAction_DisplayOption)
113 Format(buffer, maxlength, "%T", "Identify player", param);
115 else if (action == TopMenuAction_SelectOption)
117 DisplayWhoMenu(param);
121 public MenuHandler_Who(Handle:menu, MenuAction:action, param1, param2)
123 if (action == MenuAction_End)
127 else if (action == MenuAction_Cancel)
129 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
131 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
134 else if (action == MenuAction_Select)
136 decl String:info[32];
139 GetMenuItem(menu, param2, info, sizeof(info));
140 userid = StringToInt(info);
142 if ((target = GetClientOfUserId(userid)) == 0)
144 PrintToChat(param1, "[SM] %t", "Player no longer available");
146 else if (!CanUserTarget(param1, target))
148 PrintToChat(param1, "[SM] %t", "Unable to target");
152 PerformWho(param1, target, SM_REPLY_TO_CHAT, (GetUserFlagBits(param1) != 0 ? true : false));
155 /* Re-draw the menu if they're still valid */
157 /* - Close the menu? redisplay? jump back up to the category?
158 if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
160 DisplayWhoMenu(param1);
165 public Action:Command_Who(client, args)
167 new bool:is_admin = false;
169 if (!client || (client && GetUserFlagBits(client) != 0))
177 decl String:t_access[16], String:t_name[16], String:t_username[16];
178 Format(t_access, sizeof(t_access), "%t", "Admin access", client);
179 Format(t_name, sizeof(t_name), "%t", "Name", client);
180 Format(t_username, sizeof(t_username), "%t", "Username", client);
184 PrintToConsole(client, " %-24.23s %-18.17s %s", t_name, t_username, t_access);
188 PrintToConsole(client, " %-24.23s %s", t_name, t_access);
191 /* List all players */
192 new maxClients = GetMaxClients();
193 decl String:flagstring[255];
195 for (new i=1; i<=maxClients; i++)
197 if (!IsClientInGame(i))
201 new flags = GetUserFlagBits(i);
202 new AdminId:id = GetUserAdmin(i);
205 strcopy(flagstring, sizeof(flagstring), "none");
207 else if (flags & ADMFLAG_ROOT)
209 strcopy(flagstring, sizeof(flagstring), "root");
213 FlagsToString(flagstring, sizeof(flagstring), flags);
215 decl String:name[MAX_NAME_LENGTH];
216 new String:username[MAX_NAME_LENGTH];
218 GetClientName(i, name, sizeof(name));
220 if (id != INVALID_ADMIN_ID)
222 GetAdminUsername(id, username, sizeof(username));
227 PrintToConsole(client, "%2d. %-24.23s %-18.17s %s", i, name, username, flagstring);
233 PrintToConsole(client, "%2d. %-24.23s %t", i, name, "No");
237 PrintToConsole(client, "%2d. %-24.23s %t", i, name, "Yes");
242 if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
244 ReplyToCommand(client, "[SM] %t", "See console for output");
247 return Plugin_Handled;
251 GetCmdArg(1, arg, sizeof(arg));
253 new target = FindTarget(client, arg, false, false);
256 return Plugin_Handled;
259 PerformWho(client, target, GetCmdReplySource(), is_admin);
261 return Plugin_Handled;