2008-03-30 09:00:22 +02:00
|
|
|
/**
|
2014-10-30 04:41:36 +01:00
|
|
|
* vim: set ts=4 sw=4 tw=99 noet :
|
2008-03-30 09:00:22 +02:00
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Basecommands Plugin
|
|
|
|
* Provides exec cfg functionality
|
|
|
|
*
|
|
|
|
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
2008-04-11 19:16:36 +02:00
|
|
|
* Version: $Id$
|
2008-03-30 09:00:22 +02:00
|
|
|
*/
|
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
Menu g_ConfigMenu = null;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
void PerformExec(int client, char[] path)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (!FileExists(path))
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] %t", "Config not found", path[4]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowActivity2(client, "[SM] ", "%t", "Executed config", path[4]);
|
|
|
|
|
|
|
|
LogAction(client, -1, "\"%L\" executed config (file \"%s\")", client, path[4]);
|
|
|
|
|
|
|
|
ServerCommand("exec \"%s\"", path[4]);
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public void AdminMenu_ExecCFG(TopMenu topmenu,
|
|
|
|
TopMenuAction action,
|
|
|
|
TopMenuObject object_id,
|
|
|
|
int param,
|
|
|
|
char[] buffer,
|
|
|
|
int maxlength)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (action == TopMenuAction_DisplayOption)
|
|
|
|
{
|
|
|
|
Format(buffer, maxlength, "%T", "Exec CFG", param);
|
|
|
|
}
|
|
|
|
else if (action == TopMenuAction_SelectOption)
|
|
|
|
{
|
2014-11-16 01:30:45 +01:00
|
|
|
g_ConfigMenu.Display(param, MENU_TIME_FOREVER);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public int MenuHandler_ExecCFG(Menu menu, MenuAction action, int param1, int param2)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (action == MenuAction_Cancel)
|
|
|
|
{
|
2014-10-29 03:03:38 +01:00
|
|
|
if (param2 == MenuCancel_ExitBack && hTopMenu)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-10-29 03:03:38 +01:00
|
|
|
hTopMenu.Display(param1, TopMenuPosition_LastCategory);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (action == MenuAction_Select)
|
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
char path[256];
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
menu.GetItem(param2, path, sizeof(path));
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
PerformExec(param1, path);
|
|
|
|
}
|
2013-04-08 14:00:13 +02:00
|
|
|
else if (action == MenuAction_Display)
|
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
char title[128];
|
2013-04-08 14:00:13 +02:00
|
|
|
Format(title, sizeof(title), "%T", "Choose Config", param1);
|
2016-05-11 16:44:58 +02:00
|
|
|
|
|
|
|
Panel panel = view_as<Panel>(param2);
|
|
|
|
panel.SetTitle(title);
|
2013-04-08 14:00:13 +02:00
|
|
|
}
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
public Action Command_ExecCfg(int client, int args)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (args < 1)
|
|
|
|
{
|
|
|
|
ReplyToCommand(client, "[SM] Usage: sm_execcfg <filename>");
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
char path[64] = "cfg/";
|
2008-03-30 09:00:22 +02:00
|
|
|
GetCmdArg(1, path[4], sizeof(path)-4);
|
|
|
|
|
|
|
|
PerformExec(client, path);
|
|
|
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
SMCParser config_parser;
|
2016-05-11 16:44:58 +02:00
|
|
|
void ParseConfigs()
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-10-30 04:41:36 +01:00
|
|
|
if (!config_parser)
|
2014-12-01 03:57:38 +01:00
|
|
|
config_parser = new SMCParser();
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
config_parser.OnEnterSection = NewSection;
|
|
|
|
config_parser.OnLeaveSection = EndSection;
|
|
|
|
config_parser.OnKeyValue = KeyValue;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-11-16 01:30:45 +01:00
|
|
|
if (g_ConfigMenu != null)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-11-16 01:30:45 +01:00
|
|
|
delete g_ConfigMenu;
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
g_ConfigMenu = new Menu(MenuHandler_ExecCFG, MenuAction_Display);
|
2014-11-16 01:30:45 +01:00
|
|
|
g_ConfigMenu.SetTitle("%T", "Choose Config", LANG_SERVER);
|
|
|
|
g_ConfigMenu.ExitBackButton = true;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2016-05-11 16:44:58 +02:00
|
|
|
char configPath[256];
|
2008-03-30 09:00:22 +02:00
|
|
|
BuildPath(Path_SM, configPath, sizeof(configPath), "configs/adminmenu_cfgs.txt");
|
|
|
|
|
|
|
|
if (!FileExists(configPath))
|
|
|
|
{
|
|
|
|
LogError("Unable to locate exec config file, no maps loaded.");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
int line;
|
|
|
|
SMCError err = config_parser.ParseFile(configPath, line);
|
2008-03-30 09:00:22 +02:00
|
|
|
if (err != SMCError_Okay)
|
|
|
|
{
|
2016-05-11 16:44:58 +02:00
|
|
|
char error[256];
|
2008-03-30 09:00:22 +02:00
|
|
|
SMC_GetErrorString(err, error, sizeof(error));
|
|
|
|
LogError("Could not parse file (line %d, file \"%s\"):", line, configPath);
|
|
|
|
LogError("Parser encountered error: %s", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult NewSection(SMCParser smc, const char[] name, bool opt_quotes)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult KeyValue(SMCParser smc, const char[] key, const char[] value, bool key_quotes, bool value_quotes)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-11-16 01:30:45 +01:00
|
|
|
g_ConfigMenu.AddItem(key, value);
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult EndSection(SMCParser smc)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|