AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Config.cpp File Reference
#include "Config.h"
#include "Log.h"
#include "StringConvert.h"
#include "StringFormat.h"
#include "Tokenize.h"
#include "Util.h"
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <locale>
#include <mutex>
#include <unordered_map>
#include <unordered_set>

Go to the source code of this file.

Macros

#define TEMPLATE_CONFIG_OPTION(__typename)    template __typename ConfigMgr::GetOption<__typename>(std::string const& name, __typename const& def, bool showLogs /*= true*/) const;
 

Functions

Optional< std::string > GetEnvFromCache (std::string const &configName, std::string const &envVarName)
 
template<>
std::string ConfigMgr::GetValueDefault< std::string > (std::string const &name, std::string const &def, bool showLogs) const
 

Macro Definition Documentation

◆ TEMPLATE_CONFIG_OPTION

#define TEMPLATE_CONFIG_OPTION (   __typename)     template __typename ConfigMgr::GetOption<__typename>(std::string const& name, __typename const& def, bool showLogs /*= true*/) const;

Function Documentation

◆ ConfigMgr::GetValueDefault< std::string >()

template<>
std::string ConfigMgr::GetValueDefault< std::string > ( std::string const &  name,
std::string const &  def,
bool  showLogs 
) const
602{
603 auto const& itr = _configOptions.find(name);
604 bool notFound = itr == _configOptions.end();
605 auto envVarName = GetEnvVarName(name);
606 Optional<std::string> envVar = GetEnvFromCache(name, envVarName);
607 if (envVar)
608 {
609 // If showLogs and this key/value pair wasn't found in the currently saved config
610 if (showLogs && (notFound || itr->second != envVar->c_str()))
611 {
612 LOG_INFO("server.loading", "> Config: Found config value '{}' from environment variable '{}'.", name, envVarName);
613 AddKey(name, *envVar, "ENVIRONMENT", false, false);
614 }
615
616 return *envVar;
617 }
618 else if (notFound)
619 {
620 if (showLogs)
621 {
622 bool isCritical = _criticalConfigOptions.find(name) != _criticalConfigOptions.end();
623 ConfigSeverity severity = isCritical ? _policy.criticalOptionSeverity : _policy.missingOptionSeverity;
624
625 if (isCritical)
626 {
627 LogWithSeverity(severity, _filename,
628 "> Config:\n\nFATAL ERROR: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.\n\nYour server cannot start without this option!",
629 name, _filename, name, def, envVarName);
630 }
631 else
632 {
633 std::string configs = _filename;
634 if (!_moduleConfigFiles.empty())
635 configs += " or module config";
636
637 LogWithSeverity(severity, _filename,
638 "> Config: Missing property {} in config file {}, add \"{} = {}\" to this file or define '{}' as an environment variable.",
639 name, configs, name, def, envVarName);
640 }
641 }
642
643 return def;
644 }
645
646 return itr->second;
647}
#define LOG_INFO(filterType__,...)
Definition Log.h:166
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
Optional< std::string > GetEnvFromCache(std::string const &configName, std::string const &envVarName)
Definition Config.cpp:489
ConfigSeverity
Definition Config.h:27

References ConfigPolicy::criticalOptionSeverity, GetEnvFromCache(), LOG_INFO, and ConfigPolicy::missingOptionSeverity.

◆ GetEnvFromCache()

Optional< std::string > GetEnvFromCache ( std::string const &  configName,
std::string const &  envVarName 
)
490{
491 auto foundInCache = _envVarCache.find(envVarName);
492 Optional<std::string> foundInEnv;
493 // If it's not in the cache
494 if (foundInCache == _envVarCache.end())
495 {
496 // Check the env itself
497 foundInEnv = EnvVarForIniKey(configName);
498 if (foundInEnv)
499 {
500 // If it's found in the env, put it in the cache
501 _envVarCache.emplace(envVarName, *foundInEnv);
502 }
503 // Return the result of checking env
504 return foundInEnv;
505 }
506
507 return foundInCache->second;
508}

Referenced by ConfigMgr::GetValueDefault< std::string >(), and ConfigMgr::GetValueDefault().