1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/basecommands/execcfg.sp Sun Jul 06 04:49:55 2008 +0000
1.3 @@ -0,0 +1,158 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod Basecommands Plugin
1.8 + * Provides exec cfg functionality
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 +new Handle:g_ConfigMenu = INVALID_HANDLE;
1.38 +
1.39 +PerformExec(client, String:path[])
1.40 +{
1.41 + if (!FileExists(path))
1.42 + {
1.43 + ReplyToCommand(client, "[SM] %t", "Config not found", path[4]);
1.44 + return;
1.45 + }
1.46 +
1.47 + ShowActivity2(client, "[SM] ", "%t", "Executed config", path[4]);
1.48 +
1.49 + LogAction(client, -1, "\"%L\" executed config (file \"%s\")", client, path[4]);
1.50 +
1.51 + ServerCommand("exec \"%s\"", path[4]);
1.52 +}
1.53 +
1.54 +public AdminMenu_ExecCFG(Handle:topmenu,
1.55 + TopMenuAction:action,
1.56 + TopMenuObject:object_id,
1.57 + param,
1.58 + String:buffer[],
1.59 + maxlength)
1.60 +{
1.61 + if (action == TopMenuAction_DisplayOption)
1.62 + {
1.63 + Format(buffer, maxlength, "%T", "Exec CFG", param);
1.64 + }
1.65 + else if (action == TopMenuAction_SelectOption)
1.66 + {
1.67 + DisplayMenu(g_ConfigMenu, param, MENU_TIME_FOREVER);
1.68 + }
1.69 +}
1.70 +
1.71 +public MenuHandler_ExecCFG(Handle:menu, MenuAction:action, param1, param2)
1.72 +{
1.73 + if (action == MenuAction_Cancel)
1.74 + {
1.75 + if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.76 + {
1.77 + DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.78 + }
1.79 + }
1.80 + else if (action == MenuAction_Select)
1.81 + {
1.82 + decl String:path[256];
1.83 +
1.84 + GetMenuItem(menu, param2, path, sizeof(path));
1.85 +
1.86 + PerformExec(param1, path);
1.87 + }
1.88 +}
1.89 +
1.90 +public Action:Command_ExecCfg(client, args)
1.91 +{
1.92 + if (args < 1)
1.93 + {
1.94 + ReplyToCommand(client, "[SM] Usage: sm_execcfg <filename>");
1.95 + return Plugin_Handled;
1.96 + }
1.97 +
1.98 + new String:path[64] = "cfg/";
1.99 + GetCmdArg(1, path[4], sizeof(path)-4);
1.100 +
1.101 + PerformExec(client, path);
1.102 +
1.103 + return Plugin_Handled;
1.104 +}
1.105 +
1.106 +new Handle:config_parser = INVALID_HANDLE;
1.107 +ParseConfigs()
1.108 +{
1.109 + if (config_parser == INVALID_HANDLE)
1.110 + {
1.111 + config_parser = SMC_CreateParser();
1.112 + }
1.113 +
1.114 + SMC_SetReaders(config_parser, NewSection, KeyValue, EndSection);
1.115 +
1.116 + if (g_ConfigMenu != INVALID_HANDLE)
1.117 + {
1.118 + CloseHandle(g_ConfigMenu);
1.119 + }
1.120 +
1.121 + g_ConfigMenu = CreateMenu(MenuHandler_ExecCFG);
1.122 + SetMenuTitle(g_ConfigMenu, "Choose Config");
1.123 + SetMenuExitBackButton(g_ConfigMenu, true);
1.124 +
1.125 + decl String:configPath[256];
1.126 + BuildPath(Path_SM, configPath, sizeof(configPath), "configs/adminmenu_cfgs.txt");
1.127 +
1.128 + if (!FileExists(configPath))
1.129 + {
1.130 + LogError("Unable to locate exec config file, no maps loaded.");
1.131 +
1.132 + return;
1.133 + }
1.134 +
1.135 + new line;
1.136 + new SMCError:err = SMC_ParseFile(config_parser, configPath, line);
1.137 + if (err != SMCError_Okay)
1.138 + {
1.139 + decl String:error[256];
1.140 + SMC_GetErrorString(err, error, sizeof(error));
1.141 + LogError("Could not parse file (line %d, file \"%s\"):", line, configPath);
1.142 + LogError("Parser encountered error: %s", error);
1.143 + }
1.144 +
1.145 + return;
1.146 +}
1.147 +
1.148 +public SMCResult:NewSection(Handle:smc, const String:name[], bool:opt_quotes)
1.149 +{
1.150 +
1.151 +}
1.152 +
1.153 +public SMCResult:KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
1.154 +{
1.155 + AddMenuItem(g_ConfigMenu, key, value);
1.156 +}
1.157 +
1.158 +public SMCResult:EndSection(Handle:smc)
1.159 +{
1.160 +
1.161 +}