ds@661: /** ds@661: * vim: set ts=4 : ds@1330: * ============================================================================= dvander@1231: * SourceMod ds@1947: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1330: * ============================================================================= ds@661: * ds@1330: * This program is free software; you can redistribute it and/or modify it under ds@1330: * the terms of the GNU General Public License, version 3.0, as published by the ds@1330: * Free Software Foundation. dvander@1231: * ds@1330: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1330: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1330: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1330: * details. dvander@1231: * ds@1330: * You should have received a copy of the GNU General Public License along with ds@1330: * this program. If not, see . dvander@1231: * ds@1330: * As a special exception, AlliedModders LLC gives you permission to link the ds@1330: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1330: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1330: * by the Valve Corporation. You must obey the GNU General Public License in ds@1330: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1330: * this exception to all derivative works. AlliedModders LLC defines further ds@1330: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1330: * or . ds@661: * ds@661: * Version: $Id$ ds@661: */ ds@661: dvander@1406: #include ds@661: #include "CoreConfig.h" ds@661: #include "sourcemod.h" ds@661: #include "sourcemm_api.h" ds@661: #include "sm_srvcmds.h" dvander@978: #include "sm_version.h" dvander@978: #include "sm_stringutil.h" ds@661: #include "LibrarySys.h" ds@661: #include "Logger.h" dvander@978: #include "PluginSys.h" dvander@978: #include "ForwardSys.h" dvander@2235: #include "frame_hooks.h" ds@661: ds@661: #ifdef PLATFORM_WINDOWS ds@661: ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file"); dvander@663: #elif defined PLATFORM_LINUX ds@661: ConVar sm_corecfgfile("sm_corecfgfile", "addons/sourcemod/configs/core.cfg", 0, "SourceMod core configuration file"); ds@661: #endif ds@661: dvander@978: IForward *g_pOnServerCfg = NULL; dvander@978: IForward *g_pOnConfigsExecuted = NULL; dvander@2065: IForward *g_pOnAutoConfigsBuffered = NULL; ds@661: CoreConfig g_CoreConfig; dvander@978: bool g_bConfigsExecd = false; dvander@2166: bool g_bServerExecd = false; dvander@2166: bool g_bGotServerStart = false; dvander@2166: bool g_bGotTrigger = false; dvander@2166: ConCommand *g_pExecPtr = NULL; dvander@2166: ConVar *g_ServerCfgFile = NULL; dvander@2166: dvander@2166: void CheckAndFinalizeConfigs(); dvander@2166: ds@2400: #if SOURCE_ENGINE >= SE_ORANGEBOX dvander@2166: SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); dvander@2166: void Hook_ExecDispatchPre(const CCommand &cmd) dvander@2166: #else dvander@2166: extern bool __SourceHook_FHAddConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0); dvander@2166: extern bool __SourceHook_FHRemoveConCommandDispatch(void *,bool,class fastdelegate::FastDelegate0); dvander@2166: void Hook_ExecDispatchPre() dvander@2166: #endif dvander@2166: { ds@2400: #if SOURCE_ENGINE == SE_EPISODEONE dvander@2166: CCommand cmd; dvander@2166: #endif dvander@2166: dvander@2166: const char *arg = cmd.Arg(1); dvander@2166: dvander@2166: if (!g_bServerExecd dvander@2166: && arg != NULL dvander@2166: && strcmp(arg, g_ServerCfgFile->GetString()) == 0) dvander@2166: { dvander@2166: g_bGotTrigger = true; dvander@2166: } dvander@2166: } dvander@2166: ds@2400: #if SOURCE_ENGINE >= SE_ORANGEBOX dvander@2166: void Hook_ExecDispatchPost(const CCommand &cmd) dvander@2166: #else dvander@2166: void Hook_ExecDispatchPost() dvander@2166: #endif dvander@2166: { dvander@2166: if (g_bGotTrigger) dvander@2166: { dvander@2166: g_bGotTrigger = false; dvander@2166: g_bServerExecd = true; dvander@2166: CheckAndFinalizeConfigs(); dvander@2166: } dvander@2166: } dvander@2166: dvander@2166: void CheckAndFinalizeConfigs() dvander@2166: { dvander@2166: if ((g_bServerExecd || g_ServerCfgFile == NULL) dvander@2166: && g_bGotServerStart) dvander@2166: { ds@2400: #if SOURCE_ENGINE >= SE_ORANGEBOX dvander@2235: g_PendingInternalPush = true; dvander@2236: #else dvander@2236: SM_InternalCmdTrigger(); dvander@2236: #endif dvander@2166: } dvander@2166: } ds@661: ds@661: void CoreConfig::OnSourceModAllInitialized() ds@661: { ds@661: g_RootMenu.AddRootConsoleCommand("config", "Set core configuration options", this); dvander@978: g_pOnServerCfg = g_Forwards.CreateForward("OnServerCfg", ET_Ignore, 0, NULL); dvander@978: g_pOnConfigsExecuted = g_Forwards.CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL); dvander@2065: g_pOnAutoConfigsBuffered = g_Forwards.CreateForward("OnAutoConfigsBuffered", ET_Ignore, 0, NULL); ds@661: } ds@661: ds@661: void CoreConfig::OnSourceModShutdown() ds@661: { ds@661: g_RootMenu.RemoveRootConsoleCommand("config", this); dvander@978: g_Forwards.ReleaseForward(g_pOnServerCfg); dvander@978: g_Forwards.ReleaseForward(g_pOnConfigsExecuted); dvander@2065: g_Forwards.ReleaseForward(g_pOnAutoConfigsBuffered); dvander@2166: dvander@2166: if (g_pExecPtr != NULL) dvander@2166: { dvander@2166: SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false); dvander@2166: SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true); dvander@2166: g_pExecPtr = NULL; dvander@2166: } dvander@978: } dvander@978: dvander@978: void CoreConfig::OnSourceModLevelChange(const char *mapName) dvander@978: { dvander@2166: static bool already_checked = false; dvander@2166: dvander@2166: if (!already_checked) dvander@2166: { dvander@2335: if (engine->IsDedicatedServer()) dvander@2335: { dvander@2335: g_ServerCfgFile = icvar->FindVar("servercfgfile"); dvander@2335: } dvander@2335: else dvander@2335: { dvander@2335: g_ServerCfgFile = icvar->FindVar("lservercfgfile"); dvander@2335: } dvander@2335: dvander@2166: if (g_ServerCfgFile != NULL) dvander@2166: { ds@2400: g_pExecPtr = FindCommand("exec"); dvander@2166: if (g_pExecPtr != NULL) dvander@2166: { dvander@2166: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPre, false); dvander@2166: SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, g_pExecPtr, Hook_ExecDispatchPost, true); dvander@2166: } dvander@2166: else dvander@2166: { dvander@2166: g_ServerCfgFile = NULL; dvander@2166: } dvander@2166: } dvander@2166: already_checked = true; dvander@2166: } dvander@2166: dvander@978: g_bConfigsExecd = false; dvander@2166: g_bServerExecd = false; dvander@2166: g_bGotServerStart = false; dvander@2166: g_bGotTrigger = false; ds@661: } ds@661: faluco@1541: void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &command) ds@661: { faluco@1541: int argcount = command.ArgC(); ds@661: if (argcount >= 4) ds@661: { faluco@1541: const char *option = command.Arg(2); faluco@1541: const char *value = command.Arg(3); ds@661: dvander@663: char error[255]; ds@661: ds@669: ConfigResult res = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error)); dvander@663: ds@669: if (res == ConfigResult_Reject) ds@661: { ds@669: g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\" (%s)", option, value, error); ds@669: } else if (res == ConfigResult_Ignore) { ds@669: g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option); dvander@665: } else { dvander@665: g_RootMenu.ConsolePrint("Config option \"%s\" successfully set to \"%s.\"", option, value); ds@661: } ds@661: ds@661: return; ds@661: } ds@661: ds@661: g_RootMenu.ConsolePrint("[SM] Usage: sm config