core/CoreConfig.cpp
changeset 663 b526b82e256e
parent 661 5c0988b9bf0c
child 665 74fa35a4c27c
     1.1 --- a/core/CoreConfig.cpp	Thu Apr 05 03:16:03 2007 +0000
     1.2 +++ b/core/CoreConfig.cpp	Thu Apr 05 05:25:11 2007 +0000
     1.3 @@ -22,7 +22,7 @@
     1.4  
     1.5  #ifdef PLATFORM_WINDOWS
     1.6  ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file");
     1.7 -#else
     1.8 +#elif defined PLATFORM_LINUX
     1.9  ConVar sm_corecfgfile("sm_corecfgfile", "addons/sourcemod/configs/core.cfg", 0, "SourceMod core configuration file");
    1.10  #endif
    1.11  
    1.12 @@ -45,21 +45,13 @@
    1.13  		const char *option = engine->Cmd_Argv(2);
    1.14  		const char *value = engine->Cmd_Argv(3);
    1.15  
    1.16 -		CoreConfigErr err = SetConfigOption(option, value);
    1.17 +		char error[255];
    1.18  
    1.19 -		switch (err)
    1.20 +		ConfigResult err = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error));
    1.21 +
    1.22 +		if (err == ConfigResult_Reject)
    1.23  		{
    1.24 -		case CoreConfig_NoRuntime:
    1.25 -			g_RootMenu.ConsolePrint("[SM] Cannot set \"%s\" while SourceMod is running.", option);
    1.26 -			break;
    1.27 -		case CoreConfig_InvalidValue:
    1.28 -			g_RootMenu.ConsolePrint("[SM] Invalid value \"%s\" specified for configuration option \"%s\"", value, option);
    1.29 -			break;
    1.30 -		case CoreConfig_InvalidOption:
    1.31 -			g_RootMenu.ConsolePrint("[SM] Invalid configuration option specified: %s", option);
    1.32 -			break;
    1.33 -		default:
    1.34 -			break;
    1.35 +			g_Logger.LogError("Could not set config option \"%s\" to \"%s\" (error: %s)", option, value, error);
    1.36  		}
    1.37  
    1.38  		return;
    1.39 @@ -90,44 +82,39 @@
    1.40  		!= SMCParse_Okay)
    1.41  	{
    1.42  		/* :TODO: This won't actually log or print anything :( - So fix that somehow */
    1.43 -		g_Logger.LogError("[SM] Error encountered parsing core config file: %s", g_TextParser.GetSMCErrorString(err));
    1.44 +		const char *error = g_TextParser.GetSMCErrorString(err);
    1.45 +		g_Logger.LogFatal("[SM] Error encountered parsing core config file: %s", error ? error : "");
    1.46  	}
    1.47  }
    1.48  
    1.49  SMCParseResult CoreConfig::ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes)
    1.50  {
    1.51 -	CoreConfigErr err = SetConfigOption(key, value);
    1.52 +	char error[255];
    1.53 +	ConfigResult err = SetConfigOption(key, value, ConfigSource_File, error, sizeof(error));
    1.54  
    1.55 -	if (err == CoreConfig_InvalidOption)
    1.56 +	if (err == ConfigResult_Reject)
    1.57  	{
    1.58 -		g_Logger.LogError("[SM] Warning: Ignoring invalid option \"%s\" in configuration file.", key);
    1.59 -	} else if (err == CoreConfig_InvalidValue) {
    1.60 -		g_Logger.LogError("[SM] Warning encountered parsing core configuration file.");
    1.61 -		g_Logger.LogError("[SM] Invalid value \"%s\" specified for option \"%s\"", value, key);
    1.62 +		/* This is a fatal error */
    1.63 +		g_Logger.LogFatal("%s", error);
    1.64  	}
    1.65  
    1.66  	return SMCParse_Continue;
    1.67  }
    1.68  
    1.69 -CoreConfigErr CoreConfig::SetConfigOption(const char *option, const char *value)
    1.70 +ConfigResult CoreConfig::SetConfigOption(const char *option, const char *value, ConfigSource source, char *error, size_t maxlength)
    1.71  {
    1.72 -	CoreConfigErr err = CoreConfig_TOTAL;
    1.73 -	CoreConfigErr currentErr;
    1.74 +	ConfigResult result;
    1.75  
    1.76  	/* Notify! */
    1.77  	SMGlobalClass *pBase = SMGlobalClass::head;
    1.78  	while (pBase)
    1.79  	{
    1.80 -		currentErr = pBase->OnSourceModConfigChanged(option, value);
    1.81 -
    1.82 -		/* Lowest error code has priority */
    1.83 -		if (currentErr < err)
    1.84 +		if ((result = pBase->OnSourceModConfigChanged(option, value, source, error, maxlength)) != ConfigResult_Ignore)
    1.85  		{
    1.86 -			err = currentErr;
    1.87 +			return result;
    1.88  		}
    1.89 -
    1.90  		pBase = pBase->m_pGlobalClassNext;
    1.91  	}
    1.92  
    1.93 -	return err;
    1.94 +	return ConfigResult_Ignore;
    1.95  }