plugins/adminmenu.sp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/adminmenu.sp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,250 +0,0 @@
     1.4 -/**
     1.5 - * vim: set ts=4 :
     1.6 - * =============================================================================
     1.7 - * SourceMod Admin Menu Plugin
     1.8 - * Creates the base admin menu, for plugins to add items to.
     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 -new g_maxPlayers;
    1.52 -
    1.53 -/* Forwards */
    1.54 -new Handle:hOnAdminMenuReady = INVALID_HANDLE;
    1.55 -new Handle:hOnAdminMenuCreated = INVALID_HANDLE;
    1.56 -
    1.57 -/* Menus */
    1.58 -new Handle:hAdminMenu = INVALID_HANDLE;
    1.59 -
    1.60 -/* Top menu objects */
    1.61 -new TopMenuObject:obj_playercmds = INVALID_TOPMENUOBJECT;
    1.62 -new TopMenuObject:obj_servercmds = INVALID_TOPMENUOBJECT;
    1.63 -new TopMenuObject:obj_votingcmds = INVALID_TOPMENUOBJECT;
    1.64 -
    1.65 -#include "adminmenu/dynamicmenu.sp"
    1.66 -
    1.67 -public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
    1.68 -{
    1.69 -	CreateNative("GetAdminTopMenu", __GetAdminTopMenu);
    1.70 -	CreateNative("AddTargetsToMenu", __AddTargetsToMenu);
    1.71 -	RegPluginLibrary("adminmenu");
    1.72 -	return true;
    1.73 -}
    1.74 -
    1.75 -public OnPluginStart()
    1.76 -{
    1.77 -	LoadTranslations("common.phrases");
    1.78 -	LoadTranslations("adminmenu.phrases");
    1.79 -	
    1.80 -	hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
    1.81 -	hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
    1.82 -
    1.83 -	RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "Displays the admin menu");
    1.84 -}
    1.85 -
    1.86 -public OnConfigsExecuted()
    1.87 -{
    1.88 -	decl String:path[PLATFORM_MAX_PATH];
    1.89 -	decl String:error[256];
    1.90 -	
    1.91 -	BuildPath(Path_SM, path, sizeof(path), "configs/adminmenu_sorting.txt");
    1.92 -	
    1.93 -	if (!LoadTopMenuConfig(hAdminMenu, path, error, sizeof(error)))
    1.94 -	{
    1.95 -		LogError("Could not load admin menu config (file \"%s\": %s)", path, error);
    1.96 -		return;
    1.97 -	}
    1.98 -}
    1.99 -
   1.100 -public OnMapStart()
   1.101 -{
   1.102 -	g_maxPlayers = GetMaxClients();
   1.103 -	
   1.104 -	ParseConfigs();
   1.105 -}
   1.106 -
   1.107 -public OnAllPluginsLoaded()
   1.108 -{
   1.109 -	hAdminMenu = CreateTopMenu(DefaultCategoryHandler);
   1.110 -	
   1.111 -	obj_playercmds = AddToTopMenu(hAdminMenu, 
   1.112 -		"PlayerCommands",
   1.113 -		TopMenuObject_Category,
   1.114 -		DefaultCategoryHandler,
   1.115 -		INVALID_TOPMENUOBJECT);
   1.116 -
   1.117 -	obj_servercmds = AddToTopMenu(hAdminMenu,
   1.118 -		"ServerCommands",
   1.119 -		TopMenuObject_Category,
   1.120 -		DefaultCategoryHandler,
   1.121 -		INVALID_TOPMENUOBJECT);
   1.122 -
   1.123 -	obj_votingcmds = AddToTopMenu(hAdminMenu,
   1.124 -		"VotingCommands",
   1.125 -		TopMenuObject_Category,
   1.126 -		DefaultCategoryHandler,
   1.127 -		INVALID_TOPMENUOBJECT);
   1.128 -		
   1.129 -	BuildDynamicMenu();
   1.130 -	
   1.131 -	Call_StartForward(hOnAdminMenuCreated);
   1.132 -	Call_PushCell(hAdminMenu);
   1.133 -	Call_Finish();
   1.134 -	
   1.135 -	Call_StartForward(hOnAdminMenuReady);
   1.136 -	Call_PushCell(hAdminMenu);
   1.137 -	Call_Finish();
   1.138 -}
   1.139 -
   1.140 -public DefaultCategoryHandler(Handle:topmenu, 
   1.141 -						TopMenuAction:action,
   1.142 -						TopMenuObject:object_id,
   1.143 -						param,
   1.144 -						String:buffer[],
   1.145 -						maxlength)
   1.146 -{
   1.147 -	if (action == TopMenuAction_DisplayTitle)
   1.148 -	{
   1.149 -		if (object_id == INVALID_TOPMENUOBJECT)
   1.150 -		{
   1.151 -			Format(buffer, maxlength, "%T:", "Admin Menu", param);
   1.152 -		}
   1.153 -		else if (object_id == obj_playercmds)
   1.154 -		{
   1.155 -			Format(buffer, maxlength, "%T:", "Player Commands", param);
   1.156 -		}
   1.157 -		else if (object_id == obj_servercmds)
   1.158 -		{
   1.159 -			Format(buffer, maxlength, "%T:", "Server Commands", param);
   1.160 -		}
   1.161 -		else if (object_id == obj_votingcmds)
   1.162 -		{
   1.163 -			Format(buffer, maxlength, "%T:", "Voting Commands", param);
   1.164 -		}
   1.165 -	}
   1.166 -	else if (action == TopMenuAction_DisplayOption)
   1.167 -	{
   1.168 -		if (object_id == obj_playercmds)
   1.169 -		{
   1.170 -			Format(buffer, maxlength, "%T", "Player Commands", param);
   1.171 -		}
   1.172 -		else if (object_id == obj_servercmds)
   1.173 -		{
   1.174 -			Format(buffer, maxlength, "%T", "Server Commands", param);
   1.175 -		}
   1.176 -		else if (object_id == obj_votingcmds)
   1.177 -		{
   1.178 -			Format(buffer, maxlength, "%T", "Voting Commands", param);
   1.179 -		}
   1.180 -	}
   1.181 -}
   1.182 -
   1.183 -public __GetAdminTopMenu(Handle:plugin, numParams)
   1.184 -{
   1.185 -	return _:hAdminMenu;
   1.186 -}
   1.187 -
   1.188 -public __AddTargetsToMenu(Handle:plugin, numParams)
   1.189 -{
   1.190 -	new bool:alive_only = false;
   1.191 -	
   1.192 -	if (numParams >= 4)
   1.193 -	{
   1.194 -		alive_only = GetNativeCell(4);
   1.195 -	}
   1.196 -	
   1.197 -	return UTIL_AddTargetsToMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3), alive_only);
   1.198 -}
   1.199 -
   1.200 -public Action:Command_DisplayMenu(client, args)
   1.201 -{
   1.202 -	if (client == 0)
   1.203 -	{
   1.204 -		ReplyToCommand(client, "[SM] %t", "Command is in-game only");
   1.205 -		return Plugin_Handled;
   1.206 -	}
   1.207 -	
   1.208 -	DisplayTopMenu(hAdminMenu, client, TopMenuPosition_Start);
   1.209 -	
   1.210 -	return Plugin_Handled;
   1.211 -}
   1.212 -
   1.213 -stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only, bool:alive_only)
   1.214 -{
   1.215 -	new max_clients = GetMaxClients();
   1.216 -	decl String:user_id[12];
   1.217 -	decl String:name[MAX_NAME_LENGTH];
   1.218 -	decl String:display[MAX_NAME_LENGTH+12];
   1.219 -	
   1.220 -	new num_clients;
   1.221 -	
   1.222 -	for (new i = 1; i <= max_clients; i++)
   1.223 -	{
   1.224 -		if (!IsClientConnected(i) || IsClientInKickQueue(i))
   1.225 -		{
   1.226 -			continue;
   1.227 -		}
   1.228 -		
   1.229 -		if (in_game_only && !IsClientInGame(i))
   1.230 -		{
   1.231 -			continue;
   1.232 -		}
   1.233 -		
   1.234 -		if (alive_only && !IsPlayerAlive(i))
   1.235 -		{
   1.236 -			continue;
   1.237 -		}
   1.238 -		
   1.239 -		if (source_client && !CanUserTarget(source_client, i))
   1.240 -		{
   1.241 -			continue;
   1.242 -		}
   1.243 -		
   1.244 -		IntToString(GetClientUserId(i), user_id, sizeof(user_id));
   1.245 -		GetClientName(i, name, sizeof(name));
   1.246 -		Format(display, sizeof(display), "%s (%s)", name, user_id);
   1.247 -		AddMenuItem(menu, user_id, display);
   1.248 -		num_clients++;
   1.249 -	}
   1.250 -	
   1.251 -	return num_clients;
   1.252 -}
   1.253 -