New stock to get m_fFlags, and #defines for its bits.
3 * =============================================================================
4 * SourceMod Basecommands Plugin
5 * Provides exec cfg functionality
7 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
31 * Version: $Id: admin-flatfile.sp 1438 2007-09-16 03:45:06Z dvander $
34 new Handle:g_ConfigMenu = INVALID_HANDLE;
36 PerformExec(client, String:path[])
38 if (!FileExists(path))
40 ReplyToCommand(client, "[SM] %t", "Config not found", path[4]);
44 ShowActivity2(client, "[SM] ", "%t", "Executed config", path[4]);
46 LogAction(client, -1, "\"%L\" executed config (file \"%s\")", client, path[4]);
48 ServerCommand("exec \"%s\"", path[4]);
51 public AdminMenu_ExecCFG(Handle:topmenu,
53 TopMenuObject:object_id,
58 if (action == TopMenuAction_DisplayOption)
60 Format(buffer, maxlength, "%T", "Exec CFG", param);
62 else if (action == TopMenuAction_SelectOption)
64 DisplayMenu(g_ConfigMenu, param, MENU_TIME_FOREVER);
68 public MenuHandler_ExecCFG(Handle:menu, MenuAction:action, param1, param2)
70 if (action == MenuAction_Cancel)
72 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
74 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
77 else if (action == MenuAction_Select)
79 decl String:path[256];
81 GetMenuItem(menu, param2, path, sizeof(path));
83 PerformExec(param1, path);
87 public Action:Command_ExecCfg(client, args)
91 ReplyToCommand(client, "[SM] Usage: sm_execcfg <filename>");
92 return Plugin_Handled;
95 new String:path[64] = "cfg/";
96 GetCmdArg(1, path[4], sizeof(path)-4);
98 PerformExec(client, path);
100 return Plugin_Handled;
103 new Handle:config_parser = INVALID_HANDLE;
106 if (config_parser == INVALID_HANDLE)
108 config_parser = SMC_CreateParser();
111 SMC_SetReaders(config_parser, NewSection, KeyValue, EndSection);
113 if (g_ConfigMenu != INVALID_HANDLE)
115 CloseHandle(g_ConfigMenu);
118 g_ConfigMenu = CreateMenu(MenuHandler_ExecCFG);
119 SetMenuTitle(g_ConfigMenu, "Choose Config");
120 SetMenuExitBackButton(g_ConfigMenu, true);
122 decl String:configPath[256];
123 BuildPath(Path_SM, configPath, sizeof(configPath), "configs/adminmenu_cfgs.txt");
125 if (!FileExists(configPath))
127 LogError("Unable to locate exec config file, no maps loaded.");
133 new SMCError:err = SMC_ParseFile(config_parser, configPath, line);
134 if (err != SMCError_Okay)
136 decl String:error[256];
137 SMC_GetErrorString(err, error, sizeof(error));
138 LogError("Could not parse file (line %d, file \"%s\"):", line, configPath);
139 LogError("Parser encountered error: %s", error);
145 public SMCResult:NewSection(Handle:smc, const String:name[], bool:opt_quotes)
150 public SMCResult:KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
152 AddMenuItem(g_ConfigMenu, key, value);
155 public SMCResult:EndSection(Handle:smc)