summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-11-01 13:44:38 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-11-01 17:13:46 +0100
commit5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed (patch)
tree19d2d94b8c90ccb9a24529102431e6a68c0b7a4b /src
parentfba5a19e5885e3f4ddca2c249a96fbbe24c846b8 (diff)
downloadmanaserv-5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed.tar.gz
manaserv-5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed.tar.bz2
manaserv-5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed.tar.xz
manaserv-5922e27d2bc4d2b5ab906afbe2bc029ac90cb2ed.zip
Have one place where the Configuration is initialized
Also, removed the fallback to the standard config file path when a config file path is specified on the command line. Surely that's not what you would want to happen. Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src')
-rw-r--r--src/account-server/main-account.cpp56
-rw-r--r--src/common/configuration.cpp15
-rw-r--r--src/common/configuration.h6
-rw-r--r--src/game-server/main-game.cpp56
4 files changed, 39 insertions, 94 deletions
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index 0adf1285..19ffb23f 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -56,7 +56,6 @@ using utils::Logger;
// Default options that automake should be able to override.
#define DEFAULT_LOG_FILE "manaserv-account.log"
#define DEFAULT_STATS_FILE "manaserv.stats"
-#define DEFAULT_CONFIG_FILE "manaserv.xml"
#define DEFAULT_ATTRIBUTEDB_FILE "attributes.xml"
static bool running = true; /**< Determines if server keeps running */
@@ -82,47 +81,6 @@ static void closeGracefully(int)
running = false;
}
-static void initializeConfiguration(std::string configPath = std::string())
-{
- if (configPath.empty())
- configPath = DEFAULT_CONFIG_FILE;
-
- bool configFound = true;
- if (!Configuration::initialize(configPath))
- {
- configFound = false;
-
- // If the config file isn't the default and fail to load,
- // we try the default one with a warning.
- if (configPath.compare(DEFAULT_CONFIG_FILE))
- {
- LOG_WARN("Invalid config path: " << configPath
- << ". Trying default value: " << DEFAULT_CONFIG_FILE ".");
- configPath = DEFAULT_CONFIG_FILE;
- configFound = true;
-
- if (!Configuration::initialize(configPath))
- configFound = false;
- }
-
- if (!configFound)
- {
- LOG_FATAL("Refusing to run without configuration!" << std::endl
- << "Invalid config path: " << configPath << ".");
- exit(EXIT_CONFIG_NOT_FOUND);
- }
- }
-
- LOG_INFO("Using config file: " << configPath);
-
- // Check inter-server password.
- if (Configuration::getValue("net_password", std::string()).empty())
- {
- LOG_FATAL("SECURITY WARNING: 'net_password' not set!");
- exit(EXIT_BAD_CONFIG_PARAMETER);
- }
-}
-
/**
* Initializes the server.
*/
@@ -263,7 +221,6 @@ static void printHelp()
struct CommandLineOptions
{
CommandLineOptions():
- configPath(DEFAULT_CONFIG_FILE),
verbosity(Logger::Warn),
verbosityChanged(false),
port(DEFAULT_SERVER_PORT),
@@ -336,7 +293,18 @@ int main(int argc, char *argv[])
CommandLineOptions options;
parseOptions(argc, argv, options);
- initializeConfiguration(options.configPath);
+ if (!Configuration::initialize(options.configPath))
+ {
+ LOG_FATAL("Refusing to run without configuration!");
+ exit(EXIT_CONFIG_NOT_FOUND);
+ }
+
+ // Check inter-server password.
+ if (Configuration::getValue("net_password", std::string()).empty())
+ {
+ LOG_FATAL("SECURITY WARNING: 'net_password' not set!");
+ exit(EXIT_BAD_CONFIG_PARAMETER);
+ }
// General initialization
initialize();
diff --git a/src/common/configuration.cpp b/src/common/configuration.cpp
index 89b77e32..15ce6763 100644
--- a/src/common/configuration.cpp
+++ b/src/common/configuration.cpp
@@ -29,20 +29,25 @@
#include "utils/xml.h"
#include "utils/string.h"
+#define DEFAULT_CONFIG_FILE "manaserv.xml"
+
/**< Persistent configuration. */
static std::map< std::string, std::string > options;
/**< Location of config file. */
static std::string configPath;
-bool Configuration::initialize(const std::string &filename)
+bool Configuration::initialize(const std::string &fileName)
{
- configPath = filename;
+ if (fileName.empty())
+ configPath = DEFAULT_CONFIG_FILE;
+ else
+ configPath = fileName;
- XML::Document doc(filename, false);
+ XML::Document doc(configPath, false);
xmlNodePtr node = doc.rootNode();
if (!node || !xmlStrEqual(node->name, BAD_CAST "configuration")) {
- LOG_WARN("No configuration file '" << filename.c_str() << "'.");
+ LOG_WARN("No configuration file '" << configPath.c_str() << "'.");
return false;
}
@@ -60,6 +65,8 @@ bool Configuration::initialize(const std::string &filename)
options[key] = value;
}
+ LOG_INFO("Using config file: " << configPath);
+
return true;
}
diff --git a/src/common/configuration.h b/src/common/configuration.h
index dbb0a7d4..e7fe8edd 100644
--- a/src/common/configuration.h
+++ b/src/common/configuration.h
@@ -28,10 +28,12 @@ namespace Configuration
{
/**
* Loads the configuration options into memory.
- * @param filename path to the configuration file .
+ *
+ * @param filename path to the configuration file. When empty, the default
+ * config file 'manaserv.xml' is used.
* @return whether the configuration file could be read
*/
- bool initialize(const std::string &filename);
+ bool initialize(const std::string &fileName = std::string());
void deinitialize();
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index a9a6652a..e7a06c84 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -63,7 +63,6 @@ using utils::Logger;
// Default options that automake should be able to override.
#define DEFAULT_LOG_FILE "manaserv-game.log"
-#define DEFAULT_CONFIG_FILE "manaserv.xml"
#define DEFAULT_ITEMSDB_FILE "items.xml"
#define DEFAULT_EQUIPDB_FILE "equip.xml"
#define DEFAULT_SKILLSDB_FILE "skills.xml"
@@ -108,47 +107,6 @@ static void closeGracefully(int)
running = false;
}
-static void initializeConfiguration(std::string configPath = std::string())
-{
- if (configPath.empty())
- configPath = DEFAULT_CONFIG_FILE;
-
- bool configFound = true;
- if (!Configuration::initialize(configPath))
- {
- configFound = false;
-
- // If the config file isn't the default and fail to load,
- // we try the default one with a warning.
- if (configPath.compare(DEFAULT_CONFIG_FILE))
- {
- LOG_WARN("Invalid config path: " << configPath
- << ". Trying default value: " << DEFAULT_CONFIG_FILE ".");
- configPath = DEFAULT_CONFIG_FILE;
- configFound = true;
-
- if (!Configuration::initialize(configPath))
- configFound = false;
- }
-
- if (!configFound)
- {
- LOG_FATAL("Refusing to run without configuration!" << std::endl
- << "Invalid config path: " << configPath << ".");
- exit(EXIT_CONFIG_NOT_FOUND);
- }
- }
-
- LOG_INFO("Using config file: " << configPath);
-
- // Check inter-server password.
- if (Configuration::getValue("net_password", std::string()).empty())
- {
- LOG_FATAL("SECURITY WARNING: 'net_password' not set!");
- exit(EXIT_BAD_CONFIG_PARAMETER);
- }
-}
-
static void initializeServer()
{
// Used to close via process signals
@@ -266,7 +224,6 @@ static void printHelp()
struct CommandLineOptions
{
CommandLineOptions():
- configPath(DEFAULT_CONFIG_FILE),
verbosity(Logger::Warn),
verbosityChanged(false),
port(DEFAULT_SERVER_PORT + 3),
@@ -339,7 +296,18 @@ int main(int argc, char *argv[])
CommandLineOptions options;
parseOptions(argc, argv, options);
- initializeConfiguration(options.configPath);
+ if (!Configuration::initialize(options.configPath))
+ {
+ LOG_FATAL("Refusing to run without configuration!");
+ exit(EXIT_CONFIG_NOT_FOUND);
+ }
+
+ // Check inter-server password.
+ if (Configuration::getValue("net_password", std::string()).empty())
+ {
+ LOG_FATAL("SECURITY WARNING: 'net_password' not set!");
+ exit(EXIT_BAD_CONFIG_PARAMETER);
+ }
if (!options.verbosityChanged)
options.verbosity = static_cast<Logger::Level>(