1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/adminmenu.sp Sun Mar 30 07:00:22 2008 +0000
1.3 @@ -0,0 +1,290 @@
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-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 +#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 + CreateNative("AddTargetsToMenu2", __AddTargetsToMenu2);
1.72 + RegPluginLibrary("adminmenu");
1.73 + return true;
1.74 +}
1.75 +
1.76 +public OnPluginStart()
1.77 +{
1.78 + LoadTranslations("common.phrases");
1.79 + LoadTranslations("adminmenu.phrases");
1.80 +
1.81 + hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
1.82 + hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
1.83 +
1.84 + RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "Displays the admin menu");
1.85 +}
1.86 +
1.87 +public OnConfigsExecuted()
1.88 +{
1.89 + decl String:path[PLATFORM_MAX_PATH];
1.90 + decl String:error[256];
1.91 +
1.92 + BuildPath(Path_SM, path, sizeof(path), "configs/adminmenu_sorting.txt");
1.93 +
1.94 + if (!LoadTopMenuConfig(hAdminMenu, path, error, sizeof(error)))
1.95 + {
1.96 + LogError("Could not load admin menu config (file \"%s\": %s)", path, error);
1.97 + return;
1.98 + }
1.99 +}
1.100 +
1.101 +public OnMapStart()
1.102 +{
1.103 + g_maxPlayers = GetMaxClients();
1.104 +
1.105 + ParseConfigs();
1.106 +}
1.107 +
1.108 +public OnAllPluginsLoaded()
1.109 +{
1.110 + hAdminMenu = CreateTopMenu(DefaultCategoryHandler);
1.111 +
1.112 + obj_playercmds = AddToTopMenu(hAdminMenu,
1.113 + "PlayerCommands",
1.114 + TopMenuObject_Category,
1.115 + DefaultCategoryHandler,
1.116 + INVALID_TOPMENUOBJECT);
1.117 +
1.118 + obj_servercmds = AddToTopMenu(hAdminMenu,
1.119 + "ServerCommands",
1.120 + TopMenuObject_Category,
1.121 + DefaultCategoryHandler,
1.122 + INVALID_TOPMENUOBJECT);
1.123 +
1.124 + obj_votingcmds = AddToTopMenu(hAdminMenu,
1.125 + "VotingCommands",
1.126 + TopMenuObject_Category,
1.127 + DefaultCategoryHandler,
1.128 + INVALID_TOPMENUOBJECT);
1.129 +
1.130 + BuildDynamicMenu();
1.131 +
1.132 + Call_StartForward(hOnAdminMenuCreated);
1.133 + Call_PushCell(hAdminMenu);
1.134 + Call_Finish();
1.135 +
1.136 + Call_StartForward(hOnAdminMenuReady);
1.137 + Call_PushCell(hAdminMenu);
1.138 + Call_Finish();
1.139 +}
1.140 +
1.141 +public DefaultCategoryHandler(Handle:topmenu,
1.142 + TopMenuAction:action,
1.143 + TopMenuObject:object_id,
1.144 + param,
1.145 + String:buffer[],
1.146 + maxlength)
1.147 +{
1.148 + if (action == TopMenuAction_DisplayTitle)
1.149 + {
1.150 + if (object_id == INVALID_TOPMENUOBJECT)
1.151 + {
1.152 + Format(buffer, maxlength, "%T:", "Admin Menu", param);
1.153 + }
1.154 + else if (object_id == obj_playercmds)
1.155 + {
1.156 + Format(buffer, maxlength, "%T:", "Player Commands", param);
1.157 + }
1.158 + else if (object_id == obj_servercmds)
1.159 + {
1.160 + Format(buffer, maxlength, "%T:", "Server Commands", param);
1.161 + }
1.162 + else if (object_id == obj_votingcmds)
1.163 + {
1.164 + Format(buffer, maxlength, "%T:", "Voting Commands", param);
1.165 + }
1.166 + }
1.167 + else if (action == TopMenuAction_DisplayOption)
1.168 + {
1.169 + if (object_id == obj_playercmds)
1.170 + {
1.171 + Format(buffer, maxlength, "%T", "Player Commands", param);
1.172 + }
1.173 + else if (object_id == obj_servercmds)
1.174 + {
1.175 + Format(buffer, maxlength, "%T", "Server Commands", param);
1.176 + }
1.177 + else if (object_id == obj_votingcmds)
1.178 + {
1.179 + Format(buffer, maxlength, "%T", "Voting Commands", param);
1.180 + }
1.181 + }
1.182 +}
1.183 +
1.184 +public __GetAdminTopMenu(Handle:plugin, numParams)
1.185 +{
1.186 + return _:hAdminMenu;
1.187 +}
1.188 +
1.189 +public __AddTargetsToMenu(Handle:plugin, numParams)
1.190 +{
1.191 + new bool:alive_only = false;
1.192 +
1.193 + if (numParams >= 4)
1.194 + {
1.195 + alive_only = GetNativeCell(4);
1.196 + }
1.197 +
1.198 + return UTIL_AddTargetsToMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3), alive_only);
1.199 +}
1.200 +
1.201 +public __AddTargetsToMenu2(Handle:plugin, numParams)
1.202 +{
1.203 + return UTIL_AddTargetsToMenu2(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3));
1.204 +}
1.205 +
1.206 +public Action:Command_DisplayMenu(client, args)
1.207 +{
1.208 + if (client == 0)
1.209 + {
1.210 + ReplyToCommand(client, "[SM] %t", "Command is in-game only");
1.211 + return Plugin_Handled;
1.212 + }
1.213 +
1.214 + DisplayTopMenu(hAdminMenu, client, TopMenuPosition_Start);
1.215 +
1.216 + return Plugin_Handled;
1.217 +}
1.218 +
1.219 +stock UTIL_AddTargetsToMenu2(Handle:menu, source_client, flags)
1.220 +{
1.221 + new max_clients = GetMaxClients();
1.222 + decl String:user_id[12];
1.223 + decl String:name[MAX_NAME_LENGTH];
1.224 + decl String:display[MAX_NAME_LENGTH+12];
1.225 +
1.226 + new num_clients;
1.227 +
1.228 + for (new i = 1; i <= max_clients; i++)
1.229 + {
1.230 + if (!IsClientConnected(i) || IsClientInKickQueue(i))
1.231 + {
1.232 + continue;
1.233 + }
1.234 +
1.235 + PrintToServer("%d, %d, %d", i, flags, IsFakeClient(i));
1.236 +
1.237 + if (((flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS)
1.238 + && IsFakeClient(i))
1.239 + {
1.240 + continue;
1.241 + }
1.242 +
1.243 + if (((flags & COMMAND_FILTER_CONNECTED) != COMMAND_FILTER_CONNECTED)
1.244 + && !IsClientInGame(i))
1.245 + {
1.246 + continue;
1.247 + }
1.248 +
1.249 + if (((flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE)
1.250 + && !IsPlayerAlive(i))
1.251 + {
1.252 + continue;
1.253 + }
1.254 +
1.255 + if (((flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD)
1.256 + && IsPlayerAlive(i))
1.257 + {
1.258 + continue;
1.259 + }
1.260 +
1.261 + if ((source_client && ((flags & COMMAND_FILTER_NO_IMMUNITY) != COMMAND_FILTER_NO_IMMUNITY))
1.262 + && !CanUserTarget(source_client, i))
1.263 + {
1.264 + continue;
1.265 + }
1.266 +
1.267 + IntToString(GetClientUserId(i), user_id, sizeof(user_id));
1.268 + GetClientName(i, name, sizeof(name));
1.269 + Format(display, sizeof(display), "%s (%s)", name, user_id);
1.270 + AddMenuItem(menu, user_id, display);
1.271 + num_clients++;
1.272 + }
1.273 +
1.274 + return num_clients;
1.275 +}
1.276 +
1.277 +stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only, bool:alive_only)
1.278 +{
1.279 + new flags = 0;
1.280 +
1.281 + if (!in_game_only)
1.282 + {
1.283 + flags |= COMMAND_FILTER_CONNECTED;
1.284 + }
1.285 +
1.286 + if (alive_only)
1.287 + {
1.288 + flags |= COMMAND_FILTER_ALIVE;
1.289 + }
1.290 +
1.291 + return UTIL_AddTargetsToMenu2(menu, source_client, flags);
1.292 +}
1.293 +