2007-04-05 05:02:00 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* ===============================================================
|
|
|
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
|
|
|
* ===============================================================
|
|
|
|
*
|
|
|
|
* This file is not open source and may not be copied without explicit
|
|
|
|
* written permission of AlliedModders LLC. This file may not be redistributed
|
|
|
|
* in whole or significant part.
|
|
|
|
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "CoreConfig.h"
|
|
|
|
#include "sourcemod.h"
|
|
|
|
#include "sourcemm_api.h"
|
|
|
|
#include "sm_srvcmds.h"
|
|
|
|
#include "LibrarySys.h"
|
|
|
|
#include "TextParsers.h"
|
|
|
|
#include "Logger.h"
|
|
|
|
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file");
|
2007-04-05 07:25:11 +02:00
|
|
|
#elif defined PLATFORM_LINUX
|
2007-04-05 05:02:00 +02:00
|
|
|
ConVar sm_corecfgfile("sm_corecfgfile", "addons/sourcemod/configs/core.cfg", 0, "SourceMod core configuration file");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
CoreConfig g_CoreConfig;
|
|
|
|
|
|
|
|
void CoreConfig::OnSourceModAllInitialized()
|
|
|
|
{
|
|
|
|
g_RootMenu.AddRootConsoleCommand("config", "Set core configuration options", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoreConfig::OnSourceModShutdown()
|
|
|
|
{
|
|
|
|
g_RootMenu.RemoveRootConsoleCommand("config", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoreConfig::OnRootConsoleCommand(const char *command, unsigned int argcount)
|
|
|
|
{
|
|
|
|
if (argcount >= 4)
|
|
|
|
{
|
|
|
|
const char *option = engine->Cmd_Argv(2);
|
|
|
|
const char *value = engine->Cmd_Argv(3);
|
|
|
|
|
2007-04-05 07:25:11 +02:00
|
|
|
char error[255];
|
2007-04-05 05:02:00 +02:00
|
|
|
|
2007-04-05 12:55:40 +02:00
|
|
|
ConfigResult res = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error));
|
2007-04-05 07:25:11 +02:00
|
|
|
|
2007-04-05 12:55:40 +02:00
|
|
|
if (res == ConfigResult_Reject)
|
2007-04-05 05:02:00 +02:00
|
|
|
{
|
2007-04-05 12:55:40 +02:00
|
|
|
g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\" (%s)", option, value, error);
|
|
|
|
} else if (res == ConfigResult_Ignore) {
|
|
|
|
g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option);
|
2007-04-05 07:45:35 +02:00
|
|
|
} else {
|
|
|
|
g_RootMenu.ConsolePrint("Config option \"%s\" successfully set to \"%s.\"", option, value);
|
2007-04-05 05:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_RootMenu.ConsolePrint("[SM] Usage: sm config <option> <value>");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CoreConfig::Initialize()
|
|
|
|
{
|
|
|
|
SMCParseError err;
|
|
|
|
char filePath[PLATFORM_MAX_PATH];
|
|
|
|
|
|
|
|
/* Try to get command line value of core config convar */
|
|
|
|
const char *corecfg = icvar->GetCommandLineValue("sm_corecfgfile");
|
|
|
|
|
|
|
|
/* If sm_corecfgfile not specified on command line, use default value */
|
|
|
|
if (!corecfg)
|
|
|
|
{
|
|
|
|
corecfg = sm_corecfgfile.GetDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format path to config file */
|
2007-05-03 05:45:53 +02:00
|
|
|
g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg);
|
2007-04-05 05:02:00 +02:00
|
|
|
|
|
|
|
/* Parse config file */
|
2007-04-05 12:55:40 +02:00
|
|
|
if ((err=g_TextParser.ParseFile_SMC(filePath, this, NULL, NULL)) != SMCParse_Okay)
|
2007-04-05 05:02:00 +02:00
|
|
|
{
|
2007-04-05 07:45:35 +02:00
|
|
|
/* :TODO: This won't actually log or print anything :( - So fix that somehow */
|
2007-04-05 07:25:11 +02:00
|
|
|
const char *error = g_TextParser.GetSMCErrorString(err);
|
|
|
|
g_Logger.LogFatal("[SM] Error encountered parsing core config file: %s", error ? error : "");
|
2007-04-05 05:02:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SMCParseResult CoreConfig::ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes)
|
|
|
|
{
|
2007-04-05 07:25:11 +02:00
|
|
|
char error[255];
|
|
|
|
ConfigResult err = SetConfigOption(key, value, ConfigSource_File, error, sizeof(error));
|
2007-04-05 05:02:00 +02:00
|
|
|
|
2007-04-05 07:25:11 +02:00
|
|
|
if (err == ConfigResult_Reject)
|
2007-04-05 05:02:00 +02:00
|
|
|
{
|
2007-04-05 07:25:11 +02:00
|
|
|
/* This is a fatal error */
|
2007-04-05 07:45:35 +02:00
|
|
|
g_Logger.LogFatal("Config error (key: %s) (value: %s) %s", key, value, error);
|
2007-04-05 05:02:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2007-04-05 07:25:11 +02:00
|
|
|
ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value, ConfigSource source, char *error, size_t maxlength)
|
2007-04-05 05:02:00 +02:00
|
|
|
{
|
2007-04-05 07:25:11 +02:00
|
|
|
ConfigResult result;
|
2007-04-05 05:02:00 +02:00
|
|
|
|
|
|
|
/* Notify! */
|
|
|
|
SMGlobalClass *pBase = SMGlobalClass::head;
|
|
|
|
while (pBase)
|
|
|
|
{
|
2007-04-05 07:25:11 +02:00
|
|
|
if ((result = pBase->OnSourceModConfigChanged(option, value, source, error, maxlength)) != ConfigResult_Ignore)
|
2007-04-05 05:02:00 +02:00
|
|
|
{
|
2007-04-05 07:25:11 +02:00
|
|
|
return result;
|
2007-04-05 05:02:00 +02:00
|
|
|
}
|
|
|
|
pBase = pBase->m_pGlobalClassNext;
|
|
|
|
}
|
|
|
|
|
2007-04-05 07:25:11 +02:00
|
|
|
return ConfigResult_Ignore;
|
2007-04-05 05:02:00 +02:00
|
|
|
}
|