diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-08-21 23:37:47 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2010-08-22 00:26:47 +0200 |
commit | 296577b5a88732b8a97a3ebce7cda8f92ab7511f (patch) | |
tree | f15596785e8e842f056b6e390d7c5227091898c9 | |
parent | 40579ae75e0ae9db204a864ac0738234098f707c (diff) | |
download | manaserv-296577b5a88732b8a97a3ebce7cda8f92ab7511f.tar.gz manaserv-296577b5a88732b8a97a3ebce7cda8f92ab7511f.tar.bz2 manaserv-296577b5a88732b8a97a3ebce7cda8f92ab7511f.tar.xz manaserv-296577b5a88732b8a97a3ebce7cda8f92ab7511f.zip |
Changed the location of configuration, logs and stats
Instead of searching for the configuration file in ~/.manaserv.xml, the
file is now expected to be in the working directory of the server. The
logs and statistics will also be written there.
This should make it easier to run differently configured servers on the
same machine, and should also be a bit more straight-forward to setup.
Reviewed-by: Yohann Ferreira
-rw-r--r-- | README | 9 | ||||
-rw-r--r-- | docs/manaserv.xml.example (renamed from docs/manaserv.xml) | 2 | ||||
-rw-r--r-- | src/account-server/main-account.cpp | 58 | ||||
-rw-r--r-- | src/common/configuration.cpp | 12 | ||||
-rw-r--r-- | src/common/configuration.hpp | 11 | ||||
-rw-r--r-- | src/game-server/main-game.cpp | 67 |
6 files changed, 55 insertions, 104 deletions
@@ -39,8 +39,9 @@ Currently, manaserv expects these to be merged into a single 'data' directory. CONFIGURATION -The configuration is currently loaded from ~/.manaserv.xml. An example file is -located at docs/manaserv.xml. +The server loads its configuration from manaserv.xml, which it tries to find in +the directory where you're running the server from. An example file is located +at docs/manaserv.xml.example. Default option values: @@ -49,6 +50,10 @@ Default option values: gameServerAddress localhost gameServerPort 9604 + serverPath . + serverDataPath example/serverdata + clientDataPath example/clientdata + RUNNING diff --git a/docs/manaserv.xml b/docs/manaserv.xml.example index 909400a8..d41b2984 100644 --- a/docs/manaserv.xml +++ b/docs/manaserv.xml.example @@ -1,6 +1,6 @@ <?xml version="1.0"?> <!-- - An example configuration file for ~/.manaserv.xml + An example configuration file. Documentation: http://doc.manasource.org/manaserv.xml diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index e43f1a65..335a872a 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -1,6 +1,7 @@ /* * The Mana Server * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2010 The Mana Developers * * This file is part of The Mana Server. * @@ -75,34 +76,23 @@ static void closeGracefully(int) running = false; } -static void initConfig() +static void initializeConfiguration() { - /* - * If the path values aren't defined, we set the default - * depending on the platform. - */ - // The config path #if defined CONFIG_FILE std::string configPath = CONFIG_FILE; #else - -#if (defined __USE_UNIX98 || defined __FreeBSD__) - std::string configPath = getenv("HOME"); - configPath += "/."; - configPath += DEFAULT_CONFIG_FILE; -#else // Win32, ... std::string configPath = DEFAULT_CONFIG_FILE; -#endif - #endif // defined CONFIG_FILE - Configuration::initialize(configPath); + + if (!Configuration::initialize(configPath)) { + LOG_FATAL("Refusing to run without configuration!"); + exit(1); + } + LOG_INFO("Using config file: " << configPath); // check inter-server password if (Configuration::getValue("net_password", "") == "") - { - LOG_WARN("SECURITY WARNING: No 'net_password' set in " << configPath << - " - set one ASAP or this server WILL get h4x0rd!!"); - } + LOG_WARN("SECURITY WARNING: 'net_password' not set!"); } /** @@ -123,30 +113,16 @@ static void initialize() // Set enet to quit on exit. atexit(enet_deinitialize); - /* - * If the path values aren't defined, we set the default - * depending on the platform. - */ - // The log path #if defined LOG_FILE std::string logPath = LOG_FILE; #else - -#if (defined __USE_UNIX98 || defined __FreeBSD__) - std::string logPath = getenv("HOME"); - logPath += "/."; - logPath += DEFAULT_LOG_FILE; -#else // Win32, ... std::string logPath = DEFAULT_LOG_FILE; -#endif - #endif // defined LOG_FILE // Initialize PhysicsFS PHYSFS_init(""); // Initialize the logger. - using namespace utils; Logger::setLogFile(logPath); // write the messages to both the screen and the log file. @@ -166,7 +142,7 @@ static void initialize() } // --- Initialize the managers - stringFilter = new StringFilter; // The slang's and double quotes filter. + stringFilter = new utils::StringFilter; // The slang's and double quotes filter. chatChannelManager = new ChatChannelManager; guildManager = new GuildManager; postalManager = new PostManager; @@ -194,7 +170,7 @@ static void initialize() /** * Deinitializes the server. */ -static void deinitialize() +static void deinitializeServer() { // Write configuration file Configuration::deinitialize(); @@ -229,17 +205,9 @@ static void dumpStatistics() #if defined STATS_FILE std::string path = STATS_FILE; #else - -#if (defined __USE_UNIX98 || defined __FreeBSD__) - std::string path = getenv("HOME"); - path += "/."; - path += DEFAULT_STATS_FILE; -#else // Win32, ... std::string path = DEFAULT_STATS_FILE; #endif -#endif - std::ofstream os(path.c_str()); os << "<statistics>\n"; GameServerHandler::dumpStatistics(os); @@ -323,7 +291,7 @@ int main(int argc, char *argv[]) #ifdef PACKAGE_VERSION LOG_INFO("The Mana Account+Chat Server v" << PACKAGE_VERSION); #endif - initConfig(); + initializeConfiguration(); // Parse command line options CommandLineOptions options; @@ -379,7 +347,7 @@ int main(int argc, char *argv[]) LOG_INFO("Received: Quit signal, closing down..."); chatHandler->stopListen(); - deinitialize(); + deinitializeServer(); return 0; } diff --git a/src/common/configuration.cpp b/src/common/configuration.cpp index 80364b0b..0f0a5844 100644 --- a/src/common/configuration.cpp +++ b/src/common/configuration.cpp @@ -1,6 +1,7 @@ /* * The Mana Server * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2010 The Mana Developers * * This file is part of The Mana Server. * @@ -32,19 +33,23 @@ static std::map< std::string, std::string > options; /**< Location of config file. */ static std::string configPath; -void Configuration::initialize(const std::string &filename) +bool Configuration::initialize(const std::string &filename) { configPath = filename; xmlDocPtr doc = xmlReadFile(filename.c_str(), NULL, 0); - if (!doc) return; + if (!doc) { + LOG_WARN("Could not read configuration file '" << filename.c_str() << "'."); + return false; + } xmlNodePtr node = xmlDocGetRootElement(doc); if (!node || !xmlStrEqual(node->name, BAD_CAST "configuration")) { LOG_WARN("No configuration file '" << filename.c_str() << "'."); - return; + xmlFreeDoc(doc); + return false; } for (node = node->xmlChildrenNode; node != NULL; node = node->next) @@ -62,6 +67,7 @@ void Configuration::initialize(const std::string &filename) } xmlFreeDoc(doc); + return true; } void Configuration::deinitialize() diff --git a/src/common/configuration.hpp b/src/common/configuration.hpp index 5e930a99..0627c290 100644 --- a/src/common/configuration.hpp +++ b/src/common/configuration.hpp @@ -1,6 +1,7 @@ /* * The Mana Server * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2010 The Mana Developers * * This file is part of The Mana Server. * @@ -18,8 +19,8 @@ * along with The Mana Server. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef __INIREAD_H -#define __INIREAD_H +#ifndef CONFIGURATION_H +#define CONFIGURATION_H #include <string> @@ -28,8 +29,9 @@ namespace Configuration /** * Loads the configuration options into memory. * @param filename path to the configuration file . + * @return whether the configuration file could be read */ - void initialize(const std::string &filename); + bool initialize(const std::string &filename); void deinitialize(); @@ -51,4 +53,5 @@ namespace Configuration #ifndef DEFAULT_SERVER_PORT #define DEFAULT_SERVER_PORT 9601 #endif -#endif + +#endif // CONFIGURATION_H diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp index 0901ce16..2ae84a06 100644 --- a/src/game-server/main-game.cpp +++ b/src/game-server/main-game.cpp @@ -1,6 +1,7 @@ /* * The Mana Server * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2010 The Mana Developers * * This file is part of The Mana Server. * @@ -92,43 +93,28 @@ PostMan *postMan; BandwidthMonitor *gBandwidth; /** Callback used when SIGQUIT signal is received. */ -void closeGracefully(int) +static void closeGracefully(int) { running = false; } -/** - * Initialize the configuration - */ -void initConfig() +static void initializeConfiguration() { - /* - * If the path values aren't defined, we set the default - * depending on the platform. - */ - // The config path -#if defined CONFIG_FILE +#ifdef CONFIG_FILE std::string configPath = CONFIG_FILE; #else - -#if (defined __USE_UNIX98 || defined __FreeBSD__) - std::string configPath = getenv("HOME"); - configPath += "/."; - configPath += DEFAULT_CONFIG_FILE; -#else // Win32, ... std::string configPath = DEFAULT_CONFIG_FILE; #endif -#endif // defined CONFIG_FILE - Configuration::initialize(configPath); - LOG_INFO("Using config file: " << configPath); + if (!Configuration::initialize(configPath)) { + LOG_FATAL("Refusing to run without configuration!"); + exit(1); + } + LOG_INFO("Using config file: " << configPath); } -/** - * Initializes the server. - */ -void initialize() +static void initializeServer() { // Reset to default segmentation fault handling for debugging purposes signal(SIGSEGV, SIG_DFL); @@ -140,30 +126,16 @@ void initialize() signal(SIGINT, closeGracefully); signal(SIGTERM, closeGracefully); - /* - * If the path values aren't defined, we set the default - * depending on the platform. - */ - // The log path #if defined LOG_FILE std::string logPath = LOG_FILE; #else - -#if (defined __USE_UNIX98 || defined __FreeBSD__) - std::string logPath = getenv("HOME"); - logPath += "/."; - logPath += DEFAULT_LOG_FILE; -#else // Win32, ... std::string logPath = DEFAULT_LOG_FILE; -#endif - #endif // defined LOG_FILE // Initialize PhysicsFS PHYSFS_init(""); // Initialize the logger. - using namespace utils; Logger::setLogFile(logPath); // Write the messages to both the screen and the log file. @@ -172,7 +144,7 @@ void initialize() // --- Initialize the managers // Initialize the slang's and double quotes filter. - stringFilter = new StringFilter; + stringFilter = new utils::StringFilter; ResourceManager::initialize(); if (MapManager::initialize(DEFAULT_MAPSDB_FILE) < 1) @@ -218,10 +190,7 @@ void initialize() } -/** - * Deinitializes the server. - */ -void deinitialize() +static void deinitializeServer() { // Write configuration file Configuration::deinitialize(); @@ -247,9 +216,9 @@ void deinitialize() /** - * Show command line arguments + * Show command line arguments. */ -void printHelp() +static void printHelp() { std::cout << "manaserv" << std::endl << std::endl << "Options: " << std::endl @@ -279,7 +248,7 @@ struct CommandLineOptions /** * Parse the command line arguments */ -void parseOptions(int argc, char *argv[], CommandLineOptions &options) +static void parseOptions(int argc, char *argv[], CommandLineOptions &options) { const char *optstring = "h"; @@ -326,7 +295,7 @@ int main(int argc, char *argv[]) LOG_INFO("The Mana Game Server v" << PACKAGE_VERSION); #endif - initConfig(); + initializeConfiguration(); // Parse command line options CommandLineOptions options; @@ -339,7 +308,7 @@ int main(int argc, char *argv[]) Logger::setVerbosity(options.verbosity); // General initialization - initialize(); + initializeServer(); // Make an initial attempt to connect to the account server // Try again after longer and longer intervals when connection fails. @@ -438,5 +407,5 @@ int main(int argc, char *argv[]) LOG_INFO("Received: Quit signal, closing down..."); gameHandler->stopListen(); accountHandler->stop(); - deinitialize(); + deinitializeServer(); } |