From 1d0bb9b26b7ad58ab0bf979ac046f4511b3bf12b Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 5 May 2013 01:55:04 -0400 Subject: Rework the config file reader to be much more flexible and move many configuration directives to the actual modules they are used in. --- src/init.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/init.cpp') diff --git a/src/init.cpp b/src/init.cpp index b0812fedc..27f0a8689 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -120,8 +120,8 @@ void Anope::HandleSignal() try { - ServerConfig *new_config = new ServerConfig(); - delete Config; + Configuration::Conf *new_config = new Configuration::Conf(); + delete new_config; Config = new_config; } catch (const ConfigException &ex) @@ -197,14 +197,14 @@ static void InitSignals() static void remove_pidfile() { - remove(Config->PIDFilename.c_str()); + remove(Config->GetBlock("serverinfo")->Get("pid")); } /* Create our PID file and write the PID to it. */ static void write_pidfile() { - FILE *pidfile = fopen(Config->PIDFilename.c_str(), "w"); + FILE *pidfile = fopen(Config->GetBlock("serverinfo")->Get("pid"), "w"); if (pidfile) { #ifdef _WIN32 @@ -216,7 +216,7 @@ static void write_pidfile() atexit(remove_pidfile); } else - throw CoreException("Can not write to PID file " + Config->PIDFilename); + throw CoreException("Can not write to PID file " + Config->GetBlock("serverinfo")->Get("pid")); } void Anope::Init(int ac, char **av) @@ -303,7 +303,7 @@ void Anope::Init(int ac, char **av) { if (arg.empty()) throw CoreException("The --config option requires a file name"); - ServicesConf = ConfigurationFile(arg, false); + ServicesConf = Configuration::File(arg, false); } if (GetCommandLineArgument("confdir", 0, arg)) @@ -413,7 +413,7 @@ void Anope::Init(int ac, char **av) /* Read configuration file; exit if there are problems. */ try { - Config = new ServerConfig(); + Config = new Configuration::Conf(); } catch (const ConfigException &ex) { @@ -429,7 +429,8 @@ void Anope::Init(int ac, char **av) write_pidfile(); /* Create me */ - Me = new Server(NULL, Config->ServerName, 0, Config->ServerDesc, Config->Numeric); + Configuration::Block *block = Config->GetBlock("serverinfo"); + Me = new Server(NULL, block->Get("name"), 0, block->Get("description"), block->Get("id")); for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it) { it->second->server = Me; @@ -445,12 +446,13 @@ void Anope::Init(int ac, char **av) Language::InitLanguages(); /* Initialize random number generator */ - srand(Config->Seed); + block = Config->GetBlock("options"); + srand(block->Get("seed")); /* load modules */ Log() << "Loading modules..."; - for (std::list::iterator it = Config->ModulesAutoLoad.begin(), it_end = Config->ModulesAutoLoad.end(); it != it_end; ++it) - ModuleManager::LoadModule(*it, NULL); + for (int i = 0; i < Config->CountBlock("module"); ++i) + ModuleManager::LoadModule(Config->GetBlock("module", i)->Get("name"), NULL); Module *protocol = ModuleManager::FindFirstOf(PROTOCOL); if (protocol == NULL) -- cgit