plugins/adminmenu.sp
changeset 1510 de71b8774afc
child 1518 5c2bbd2506fc
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/adminmenu.sp	Mon Oct 01 18:50:07 2007 +0000
     1.3 @@ -0,0 +1,176 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod Anti-Flood Plugin
     1.8 + * Protects against chat flooding.
     1.9 + *
    1.10 + * SourceMod (C)2004-2007 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 +#pragma semicolon 1
    1.38 +
    1.39 +#include <sourcemod>
    1.40 +#include <topmenus>
    1.41 +
    1.42 +public Plugin:myinfo = 
    1.43 +{
    1.44 +	name = "Admin Menu",
    1.45 +	author = "AlliedModders LLC",
    1.46 +	description = "Administration Menu",
    1.47 +	version = SOURCEMOD_VERSION,
    1.48 +	url = "http://www.sourcemod.net/"
    1.49 +};
    1.50 +
    1.51 +/* Forwards */
    1.52 +new Handle:hOnAdminMenuReady = INVALID_HANDLE;
    1.53 +new Handle:hOnAdminMenuCreated = INVALID_HANDLE;
    1.54 +
    1.55 +/* Menus */
    1.56 +new Handle:hAdminMenu = INVALID_HANDLE;
    1.57 +
    1.58 +/* Top menu objects */
    1.59 +new TopMenuObject:obj_playercmds = INVALID_TOPMENUOBJECT;
    1.60 +
    1.61 +public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
    1.62 +{
    1.63 +	CreateNative("GetAdminTopMenu", __GetAdminTopMenu);
    1.64 +	CreateNative("AddTargetsToMenu", __AddTargetsToMenu);
    1.65 +	RegPluginLibrary("adminmenu");
    1.66 +	return true;
    1.67 +}
    1.68 +
    1.69 +public OnPluginStart()
    1.70 +{
    1.71 +	LoadTranslations("common.phrases");
    1.72 +	
    1.73 +	hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
    1.74 +	hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
    1.75 +
    1.76 +	RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "sm_admin");
    1.77 +}
    1.78 +
    1.79 +public OnAllPluginsLoaded()
    1.80 +{
    1.81 +	hAdminMenu = CreateTopMenu(CategoryHandler);
    1.82 +	
    1.83 +	obj_playercmds = AddToTopMenu(hAdminMenu, 
    1.84 +		"PlayerCommands",
    1.85 +		TopMenuObject_Category,
    1.86 +		CategoryHandler,
    1.87 +		INVALID_TOPMENUOBJECT);
    1.88 +	
    1.89 +	Call_StartForward(hOnAdminMenuCreated);
    1.90 +	Call_PushCell(hAdminMenu);
    1.91 +	Call_Finish();
    1.92 +	
    1.93 +	Call_StartForward(hOnAdminMenuReady);
    1.94 +	Call_PushCell(hAdminMenu);
    1.95 +	Call_Finish();
    1.96 +}
    1.97 +
    1.98 +public CategoryHandler(Handle:topmenu, 
    1.99 +						TopMenuAction:action,
   1.100 +						TopMenuObject:object_id,
   1.101 +						param,
   1.102 +						String:buffer[],
   1.103 +						maxlength)
   1.104 +{
   1.105 +	if (action == TopMenuAction_DrawTitle)
   1.106 +	{
   1.107 +		if (object_id == INVALID_TOPMENUOBJECT)
   1.108 +		{
   1.109 +			Format(buffer, maxlength, "%T:", "Admin Menu", param);
   1.110 +		}
   1.111 +		else if (object_id == obj_playercmds)
   1.112 +		{
   1.113 +			Format(buffer, maxlength, "%T:", "Player Commands", param);
   1.114 +		}
   1.115 +	}
   1.116 +	else if (action == TopMenuAction_DrawOption)
   1.117 +	{
   1.118 +		if (object_id == obj_playercmds)
   1.119 +		{
   1.120 +			Format(buffer, maxlength, "%T", "Player Commands", param);
   1.121 +		}
   1.122 +		return ITEMDRAW_DEFAULT;
   1.123 +	}
   1.124 +	
   1.125 +	return 0;
   1.126 +}
   1.127 +
   1.128 +public __GetAdminTopMenu(Handle:plugin, numParams)
   1.129 +{
   1.130 +	return _:hAdminMenu;
   1.131 +}
   1.132 +
   1.133 +public __AddTargetsToMenu(Handle:plugin, numParams)
   1.134 +{
   1.135 +	return UTIL_AddTargetsToMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3));
   1.136 +}
   1.137 +
   1.138 +public Action:Command_DisplayMenu(client, args)
   1.139 +{
   1.140 +	DisplayTopMenu(hAdminMenu, client, TopMenuPosition_Start);
   1.141 +	
   1.142 +	return Plugin_Handled;
   1.143 +}
   1.144 +
   1.145 +stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only)
   1.146 +{
   1.147 +	new max_clients = GetMaxClients();
   1.148 +	decl String:user_id[12];
   1.149 +	decl String:name[MAX_NAME_LENGTH];
   1.150 +	decl String:display[MAX_NAME_LENGTH+12];
   1.151 +	
   1.152 +	new num_clients;
   1.153 +	
   1.154 +	for (new i = 1; i <= max_clients; i++)
   1.155 +	{
   1.156 +		if (!IsClientConnected(i) || IsClientInKickQueue(i))
   1.157 +		{
   1.158 +			continue;
   1.159 +		}
   1.160 +		
   1.161 +		if (in_game_only && !IsClientInGame(i))
   1.162 +		{
   1.163 +			continue;
   1.164 +		}
   1.165 +		
   1.166 +		if (source_client && !CanUserTarget(source_client, i))
   1.167 +		{
   1.168 +			continue;
   1.169 +		}
   1.170 +		
   1.171 +		IntToString(GetClientUserId(i), user_id, sizeof(user_id));
   1.172 +		GetClientName(i, name, sizeof(name));
   1.173 +		Format(display, sizeof(display), "%s (%s)", name, user_id);
   1.174 +		AddMenuItem(menu, user_id, display);
   1.175 +		num_clients++;
   1.176 +	}
   1.177 +	
   1.178 +	return num_clients;
   1.179 +}