ds@1952: /** ds@1952: * vim: set ts=4 : ds@1952: * ============================================================================= ds@1952: * SourceMod Admin Menu Plugin ds@1952: * Creates the base admin menu, for plugins to add items to. ds@1952: * ds@1952: * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved. ds@1952: * ============================================================================= ds@1952: * ds@1952: * This program is free software; you can redistribute it and/or modify it under ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the ds@1952: * Free Software Foundation. ds@1952: * ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1952: * details. ds@1952: * ds@1952: * You should have received a copy of the GNU General Public License along with ds@1952: * this program. If not, see . ds@1952: * ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1952: * this exception to all derivative works. AlliedModders LLC defines further ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1952: * or . ds@1952: * ds@1952: * Version: $Id$ ds@1952: */ ds@1952: ds@1952: #pragma semicolon 1 ds@1952: ds@1952: #include ds@1952: #include ds@1952: ds@1952: public Plugin:myinfo = ds@1952: { ds@1952: name = "Admin Menu", ds@1952: author = "AlliedModders LLC", ds@1952: description = "Administration Menu", ds@1952: version = SOURCEMOD_VERSION, ds@1952: url = "http://www.sourcemod.net/" ds@1952: }; ds@1952: ds@1952: new g_maxPlayers; ds@1952: ds@1952: /* Forwards */ ds@1952: new Handle:hOnAdminMenuReady = INVALID_HANDLE; ds@1952: new Handle:hOnAdminMenuCreated = INVALID_HANDLE; ds@1952: ds@1952: /* Menus */ ds@1952: new Handle:hAdminMenu = INVALID_HANDLE; ds@1952: ds@1952: /* Top menu objects */ ds@1952: new TopMenuObject:obj_playercmds = INVALID_TOPMENUOBJECT; ds@1952: new TopMenuObject:obj_servercmds = INVALID_TOPMENUOBJECT; ds@1952: new TopMenuObject:obj_votingcmds = INVALID_TOPMENUOBJECT; ds@1952: ds@1952: #include "adminmenu/dynamicmenu.sp" ds@1952: ds@1952: public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max) ds@1952: { ds@1952: CreateNative("GetAdminTopMenu", __GetAdminTopMenu); ds@1952: CreateNative("AddTargetsToMenu", __AddTargetsToMenu); ds@1952: CreateNative("AddTargetsToMenu2", __AddTargetsToMenu2); ds@1952: RegPluginLibrary("adminmenu"); ds@1952: return true; ds@1952: } ds@1952: ds@1952: public OnPluginStart() ds@1952: { ds@1952: LoadTranslations("common.phrases"); ds@1952: LoadTranslations("adminmenu.phrases"); ds@1952: ds@1952: hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell); ds@1952: hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell); ds@1952: ds@1952: RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "Displays the admin menu"); ds@1952: } ds@1952: ds@1952: public OnConfigsExecuted() ds@1952: { ds@1952: decl String:path[PLATFORM_MAX_PATH]; ds@1952: decl String:error[256]; ds@1952: ds@1952: BuildPath(Path_SM, path, sizeof(path), "configs/adminmenu_sorting.txt"); ds@1952: ds@1952: if (!LoadTopMenuConfig(hAdminMenu, path, error, sizeof(error))) ds@1952: { ds@1952: LogError("Could not load admin menu config (file \"%s\": %s)", path, error); ds@1952: return; ds@1952: } ds@1952: } ds@1952: ds@1952: public OnMapStart() ds@1952: { ds@1952: g_maxPlayers = GetMaxClients(); ds@1952: ds@1952: ParseConfigs(); ds@1952: } ds@1952: ds@1952: public OnAllPluginsLoaded() ds@1952: { ds@1952: hAdminMenu = CreateTopMenu(DefaultCategoryHandler); ds@1952: ds@1952: obj_playercmds = AddToTopMenu(hAdminMenu, ds@1952: "PlayerCommands", ds@1952: TopMenuObject_Category, ds@1952: DefaultCategoryHandler, ds@1952: INVALID_TOPMENUOBJECT); ds@1952: ds@1952: obj_servercmds = AddToTopMenu(hAdminMenu, ds@1952: "ServerCommands", ds@1952: TopMenuObject_Category, ds@1952: DefaultCategoryHandler, ds@1952: INVALID_TOPMENUOBJECT); ds@1952: ds@1952: obj_votingcmds = AddToTopMenu(hAdminMenu, ds@1952: "VotingCommands", ds@1952: TopMenuObject_Category, ds@1952: DefaultCategoryHandler, ds@1952: INVALID_TOPMENUOBJECT); ds@1952: ds@1952: BuildDynamicMenu(); ds@1952: ds@1952: Call_StartForward(hOnAdminMenuCreated); ds@1952: Call_PushCell(hAdminMenu); ds@1952: Call_Finish(); ds@1952: ds@1952: Call_StartForward(hOnAdminMenuReady); ds@1952: Call_PushCell(hAdminMenu); ds@1952: Call_Finish(); ds@1952: } ds@1952: ds@1952: public DefaultCategoryHandler(Handle:topmenu, ds@1952: TopMenuAction:action, ds@1952: TopMenuObject:object_id, ds@1952: param, ds@1952: String:buffer[], ds@1952: maxlength) ds@1952: { ds@1952: if (action == TopMenuAction_DisplayTitle) ds@1952: { ds@1952: if (object_id == INVALID_TOPMENUOBJECT) ds@1952: { ds@1952: Format(buffer, maxlength, "%T:", "Admin Menu", param); ds@1952: } ds@1952: else if (object_id == obj_playercmds) ds@1952: { ds@1952: Format(buffer, maxlength, "%T:", "Player Commands", param); ds@1952: } ds@1952: else if (object_id == obj_servercmds) ds@1952: { ds@1952: Format(buffer, maxlength, "%T:", "Server Commands", param); ds@1952: } ds@1952: else if (object_id == obj_votingcmds) ds@1952: { ds@1952: Format(buffer, maxlength, "%T:", "Voting Commands", param); ds@1952: } ds@1952: } ds@1952: else if (action == TopMenuAction_DisplayOption) ds@1952: { ds@1952: if (object_id == obj_playercmds) ds@1952: { ds@1952: Format(buffer, maxlength, "%T", "Player Commands", param); ds@1952: } ds@1952: else if (object_id == obj_servercmds) ds@1952: { ds@1952: Format(buffer, maxlength, "%T", "Server Commands", param); ds@1952: } ds@1952: else if (object_id == obj_votingcmds) ds@1952: { ds@1952: Format(buffer, maxlength, "%T", "Voting Commands", param); ds@1952: } ds@1952: } ds@1952: } ds@1952: ds@1952: public __GetAdminTopMenu(Handle:plugin, numParams) ds@1952: { ds@1952: return _:hAdminMenu; ds@1952: } ds@1952: ds@1952: public __AddTargetsToMenu(Handle:plugin, numParams) ds@1952: { ds@1952: new bool:alive_only = false; ds@1952: ds@1952: if (numParams >= 4) ds@1952: { ds@1952: alive_only = GetNativeCell(4); ds@1952: } ds@1952: ds@1952: return UTIL_AddTargetsToMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3), alive_only); ds@1952: } ds@1952: ds@1952: public __AddTargetsToMenu2(Handle:plugin, numParams) ds@1952: { ds@1952: return UTIL_AddTargetsToMenu2(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3)); ds@1952: } ds@1952: ds@1952: public Action:Command_DisplayMenu(client, args) ds@1952: { ds@1952: if (client == 0) ds@1952: { ds@1952: ReplyToCommand(client, "[SM] %t", "Command is in-game only"); ds@1952: return Plugin_Handled; ds@1952: } ds@1952: ds@1952: DisplayTopMenu(hAdminMenu, client, TopMenuPosition_Start); ds@1952: ds@1952: return Plugin_Handled; ds@1952: } ds@1952: ds@1952: stock UTIL_AddTargetsToMenu2(Handle:menu, source_client, flags) ds@1952: { ds@1952: new max_clients = GetMaxClients(); ds@1952: decl String:user_id[12]; ds@1952: decl String:name[MAX_NAME_LENGTH]; ds@1952: decl String:display[MAX_NAME_LENGTH+12]; ds@1952: ds@1952: new num_clients; ds@1952: ds@1952: for (new i = 1; i <= max_clients; i++) ds@1952: { ds@1952: if (!IsClientConnected(i) || IsClientInKickQueue(i)) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: ds@1952: PrintToServer("%d, %d, %d", i, flags, IsFakeClient(i)); ds@1952: ds@1952: if (((flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS) ds@1952: && IsFakeClient(i)) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: ds@1952: if (((flags & COMMAND_FILTER_CONNECTED) != COMMAND_FILTER_CONNECTED) ds@1952: && !IsClientInGame(i)) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: ds@1952: if (((flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE) ds@1952: && !IsPlayerAlive(i)) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: ds@1952: if (((flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD) ds@1952: && IsPlayerAlive(i)) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: ds@1952: if ((source_client && ((flags & COMMAND_FILTER_NO_IMMUNITY) != COMMAND_FILTER_NO_IMMUNITY)) ds@1952: && !CanUserTarget(source_client, i)) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: ds@1952: IntToString(GetClientUserId(i), user_id, sizeof(user_id)); ds@1952: GetClientName(i, name, sizeof(name)); ds@1952: Format(display, sizeof(display), "%s (%s)", name, user_id); ds@1952: AddMenuItem(menu, user_id, display); ds@1952: num_clients++; ds@1952: } ds@1952: ds@1952: return num_clients; ds@1952: } ds@1952: ds@1952: stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only, bool:alive_only) ds@1952: { ds@1952: new flags = 0; ds@1952: ds@1952: if (!in_game_only) ds@1952: { ds@1952: flags |= COMMAND_FILTER_CONNECTED; ds@1952: } ds@1952: ds@1952: if (alive_only) ds@1952: { ds@1952: flags |= COMMAND_FILTER_ALIVE; ds@1952: } ds@1952: ds@1952: return UTIL_AddTargetsToMenu2(menu, source_client, flags); ds@1952: } ds@1952: