From ddfe6d84d63e32ee9a39c89d58a7772f5d9713f8 Mon Sep 17 00:00:00 2001 From: Scott Ehlert Date: Thu, 5 Apr 2007 03:02:00 +0000 Subject: [PATCH] Ugh, initial import of core config file stuff Warning: This is positively terrible code. It works, but needs A LOT of work still :\ --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40667 --- configs/core.cfg | 12 +++ core/CoreConfig.cpp | 133 +++++++++++++++++++++++++++++++++ core/CoreConfig.h | 50 +++++++++++++ core/Logger.cpp | 64 +++++++++++++--- core/Logger.h | 11 ++- core/Translator.cpp | 26 ++++++- core/Translator.h | 7 +- core/msvc8/sourcemod_mm.vcproj | 10 ++- core/sm_globals.h | 28 ++++++- core/sm_stringutil.cpp | 6 +- core/sourcemod.cpp | 35 ++++++++- core/sourcemod.h | 13 +++- 12 files changed, 368 insertions(+), 27 deletions(-) create mode 100644 configs/core.cfg create mode 100644 core/CoreConfig.cpp create mode 100644 core/CoreConfig.h diff --git a/configs/core.cfg b/configs/core.cfg new file mode 100644 index 00000000..d1a7c25c --- /dev/null +++ b/configs/core.cfg @@ -0,0 +1,12 @@ +"Core" +{ + "BasePath" "addons/sourcemod" + + "Logging" "on" + + "LogMode" "daily" + + "ServerLang" "en" + + "InvalidOpt" "hello" +} diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp new file mode 100644 index 00000000..0a5850dc --- /dev/null +++ b/core/CoreConfig.cpp @@ -0,0 +1,133 @@ +/** + * 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"); +#else +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); + + CoreConfigErr err = SetConfigOption(option, value); + + switch (err) + { + case CoreConfig_NoRuntime: + g_RootMenu.ConsolePrint("[SM] Cannot set \"%s\" while SourceMod is running.", option); + break; + case CoreConfig_InvalidValue: + g_RootMenu.ConsolePrint("[SM] Invalid value \"%s\" specified for configuration option \"%s\"", value, option); + break; + case CoreConfig_InvalidOption: + g_RootMenu.ConsolePrint("[SM] Invalid configuration option specified: %s", option); + break; + default: + break; + } + + return; + } + + g_RootMenu.ConsolePrint("[SM] Usage: sm config