plugins/basecommands/who.sp
branchrefac-jit
changeset 2168 c24a6fa957db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/basecommands/who.sp	Sun Jul 06 04:49:55 2008 +0000
     1.3 @@ -0,0 +1,262 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Basecommands Plugin
     1.8 + * Provides sm_who functionality
     1.9 + *
    1.10 + * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
    1.11 + * =============================================================================
    1.12 + *
    1.13 + * This program is free software; you can redistribute it and/or modify it under
    1.14 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.15 + * Free Software Foundation.
    1.16 + * 
    1.17 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.18 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.19 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.20 + * details.
    1.21 + *
    1.22 + * You should have received a copy of the GNU General Public License along with
    1.23 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.24 + *
    1.25 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.26 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.27 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.28 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.29 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.30 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.31 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.32 + * or <http://www.sourcemod.net/license.php>.
    1.33 + *
    1.34 + * Version: $Id$
    1.35 + */
    1.36 + 
    1.37 +PerformWho(client, target, ReplySource:reply, bool:is_admin)
    1.38 +{
    1.39 +	decl String:name[MAX_NAME_LENGTH];
    1.40 +	GetClientName(target, name, sizeof(name));
    1.41 +	
    1.42 +	new bool:show_name = false;
    1.43 +	new String:admin_name[MAX_NAME_LENGTH];
    1.44 +	new AdminId:id = GetUserAdmin(target);
    1.45 +	if (id != INVALID_ADMIN_ID && GetAdminUsername(id, admin_name, sizeof(admin_name)))
    1.46 +	{
    1.47 +		show_name = true;
    1.48 +	}
    1.49 +	
    1.50 +	new ReplySource:old_reply = SetCmdReplySource(reply);
    1.51 +	
    1.52 +	if (id == INVALID_ADMIN_ID)
    1.53 +	{
    1.54 +		ReplyToCommand(client, "[SM] %t", "Player is not an admin", name);
    1.55 +	}
    1.56 +	else
    1.57 +	{
    1.58 +		if (!is_admin)
    1.59 +		{
    1.60 +			ReplyToCommand(client, "[SM] %t", "Player is an admin", name);
    1.61 +		}
    1.62 +		else
    1.63 +		{
    1.64 +			new flags = GetUserFlagBits(target);
    1.65 +			decl String:flagstring[255];
    1.66 +			if (flags == 0)
    1.67 +			{
    1.68 +				strcopy(flagstring, sizeof(flagstring), "none");
    1.69 +			}
    1.70 +			else if (flags & ADMFLAG_ROOT)
    1.71 +			{
    1.72 +				strcopy(flagstring, sizeof(flagstring), "root");
    1.73 +			}
    1.74 +			else
    1.75 +			{
    1.76 +				FlagsToString(flagstring, sizeof(flagstring), flags);
    1.77 +			}
    1.78 +			
    1.79 +			if (show_name)
    1.80 +			{
    1.81 +				ReplyToCommand(client, "[SM] %t", "Admin logged in as", name, admin_name, flagstring);
    1.82 +			}
    1.83 +			else
    1.84 +			{
    1.85 +				ReplyToCommand(client, "[SM] %t", "Admin logged in anon", name, flagstring);
    1.86 +			}
    1.87 +		}
    1.88 +	}
    1.89 +	
    1.90 +	SetCmdReplySource(old_reply);
    1.91 +}
    1.92 +
    1.93 +DisplayWhoMenu(client)
    1.94 +{
    1.95 +	new Handle:menu = CreateMenu(MenuHandler_Who);
    1.96 +	
    1.97 +	decl String:title[100];
    1.98 +	Format(title, sizeof(title), "%T:", "Identify player", client);
    1.99 +	SetMenuTitle(menu, title);
   1.100 +	SetMenuExitBackButton(menu, true);
   1.101 +	
   1.102 +	AddTargetsToMenu(menu, client, false, false);
   1.103 +	
   1.104 +	DisplayMenu(menu, client, MENU_TIME_FOREVER);
   1.105 +}
   1.106 +
   1.107 +public AdminMenu_Who(Handle:topmenu, 
   1.108 +					  TopMenuAction:action,
   1.109 +					  TopMenuObject:object_id,
   1.110 +					  param,
   1.111 +					  String:buffer[],
   1.112 +					  maxlength)
   1.113 +{
   1.114 +	if (action == TopMenuAction_DisplayOption)
   1.115 +	{
   1.116 +		Format(buffer, maxlength, "%T", "Identify player", param);
   1.117 +	}
   1.118 +	else if (action == TopMenuAction_SelectOption)
   1.119 +	{
   1.120 +		DisplayWhoMenu(param);
   1.121 +	}
   1.122 +}
   1.123 +
   1.124 +public MenuHandler_Who(Handle:menu, MenuAction:action, param1, param2)
   1.125 +{
   1.126 +	if (action == MenuAction_End)
   1.127 +	{
   1.128 +		CloseHandle(menu);
   1.129 +	}
   1.130 +	else if (action == MenuAction_Cancel)
   1.131 +	{
   1.132 +		if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
   1.133 +		{
   1.134 +			DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
   1.135 +		}
   1.136 +	}
   1.137 +	else if (action == MenuAction_Select)
   1.138 +	{
   1.139 +		decl String:info[32];
   1.140 +		new userid, target;
   1.141 +		
   1.142 +		GetMenuItem(menu, param2, info, sizeof(info));
   1.143 +		userid = StringToInt(info);
   1.144 +
   1.145 +		if ((target = GetClientOfUserId(userid)) == 0)
   1.146 +		{
   1.147 +			PrintToChat(param1, "[SM] %t", "Player no longer available");
   1.148 +		}
   1.149 +		else if (!CanUserTarget(param1, target))
   1.150 +		{
   1.151 +			PrintToChat(param1, "[SM] %t", "Unable to target");
   1.152 +		}
   1.153 +		else
   1.154 +		{
   1.155 +			PerformWho(param1, target, SM_REPLY_TO_CHAT, (GetUserFlagBits(param1) != 0 ? true : false));
   1.156 +		}
   1.157 +		
   1.158 +		/* Re-draw the menu if they're still valid */
   1.159 +		
   1.160 +		/* - Close the menu? redisplay? jump back up to the category?
   1.161 +		if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
   1.162 +		{
   1.163 +			DisplayWhoMenu(param1);
   1.164 +		}
   1.165 +		*/
   1.166 +	}
   1.167 +}
   1.168 +public Action:Command_Who(client, args)
   1.169 +{
   1.170 +	new bool:is_admin = false;
   1.171 +	
   1.172 +	if (!client || (client && GetUserFlagBits(client) != 0))
   1.173 +	{
   1.174 +		is_admin = true;
   1.175 +	}
   1.176 +	
   1.177 +	if (args < 1)
   1.178 +	{
   1.179 +		/* Display header */
   1.180 +		decl String:t_access[16], String:t_name[16], String:t_username[16];
   1.181 +		Format(t_access, sizeof(t_access), "%t", "Admin access", client);
   1.182 +		Format(t_name, sizeof(t_name), "%t", "Name", client);
   1.183 +		Format(t_username, sizeof(t_username), "%t", "Username", client);
   1.184 +
   1.185 +		if (is_admin)
   1.186 +		{
   1.187 +			PrintToConsole(client, "    %-24.23s %-18.17s %s", t_name, t_username, t_access);
   1.188 +		}
   1.189 +		else
   1.190 +		{
   1.191 +			PrintToConsole(client, "    %-24.23s %s", t_name, t_access);
   1.192 +		}
   1.193 +
   1.194 +		/* List all players */
   1.195 +		new maxClients = GetMaxClients();
   1.196 +		decl String:flagstring[255];
   1.197 +
   1.198 +		for (new i=1; i<=maxClients; i++)
   1.199 +		{
   1.200 +			if (!IsClientInGame(i))
   1.201 +			{
   1.202 +				continue;
   1.203 +			}
   1.204 +			new flags = GetUserFlagBits(i);
   1.205 +			new AdminId:id = GetUserAdmin(i);
   1.206 +			if (flags == 0)
   1.207 +			{
   1.208 +				strcopy(flagstring, sizeof(flagstring), "none");
   1.209 +			}
   1.210 +			else if (flags & ADMFLAG_ROOT)
   1.211 +			{
   1.212 +				strcopy(flagstring, sizeof(flagstring), "root");
   1.213 +			}
   1.214 +			else
   1.215 +			{
   1.216 +				FlagsToString(flagstring, sizeof(flagstring), flags);
   1.217 +			}
   1.218 +			decl String:name[MAX_NAME_LENGTH];
   1.219 +			new String:username[MAX_NAME_LENGTH];
   1.220 +			
   1.221 +			GetClientName(i, name, sizeof(name));
   1.222 +			
   1.223 +			if (id != INVALID_ADMIN_ID)
   1.224 +			{
   1.225 +				GetAdminUsername(id, username, sizeof(username));
   1.226 +			}
   1.227 +			
   1.228 +			if (is_admin)
   1.229 +			{
   1.230 +				PrintToConsole(client, "%2d. %-24.23s %-18.17s %s", i, name, username, flagstring);
   1.231 +			}
   1.232 +			else
   1.233 +			{
   1.234 +				if (flags == 0)
   1.235 +				{
   1.236 +					PrintToConsole(client, "%2d. %-24.23s %t", i, name, "No");
   1.237 +				}
   1.238 +				else
   1.239 +				{
   1.240 +					PrintToConsole(client, "%2d. %-24.23s %t", i, name, "Yes");
   1.241 +				}
   1.242 +			}
   1.243 +		}
   1.244 +
   1.245 +		if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
   1.246 +		{
   1.247 +			ReplyToCommand(client, "[SM] %t", "See console for output");
   1.248 +		}
   1.249 +
   1.250 +		return Plugin_Handled;
   1.251 +	}
   1.252 +
   1.253 +	decl String:arg[65];
   1.254 +	GetCmdArg(1, arg, sizeof(arg));
   1.255 +
   1.256 +	new target = FindTarget(client, arg, false, false);
   1.257 +	if (target == -1)
   1.258 +	{
   1.259 +		return Plugin_Handled;
   1.260 +	}
   1.261 +	
   1.262 +	PerformWho(client, target, GetCmdReplySource(), is_admin);
   1.263 +
   1.264 +	return Plugin_Handled;
   1.265 +}