summaryrefslogtreecommitdiff
path: root/src/account-server/main-account.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-24 18:18:51 +0200
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-05-24 18:18:51 +0200
commit509d0a5cd64e37c5f6397ce20b4aef877b604e18 (patch)
tree0c98b29338211001afdb4b49e41c19fcc4234688 /src/account-server/main-account.cpp
parent5a401a833d9807a257331f49a8a8ba9768a12655 (diff)
downloadmanaserv-509d0a5cd64e37c5f6397ce20b4aef877b604e18.tar.gz
manaserv-509d0a5cd64e37c5f6397ce20b4aef877b604e18.tar.bz2
manaserv-509d0a5cd64e37c5f6397ce20b4aef877b604e18.tar.xz
manaserv-509d0a5cd64e37c5f6397ce20b4aef877b604e18.zip
Stopped tmwserv from writing to its configuration file
This was confusing, since changes made to the config file while the server is running are lost once the server exists. Also, XML comments were being stripped by the server. The command line option to set the port now only applies to a single run, and isn't saved in the configuration. There shouldn't be a need for the server to write to its configuration file, it might not even have the rights to do so.
Diffstat (limited to 'src/account-server/main-account.cpp')
-rw-r--r--src/account-server/main-account.cpp67
1 files changed, 41 insertions, 26 deletions
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp
index b207ae0e..4aa171bb 100644
--- a/src/account-server/main-account.cpp
+++ b/src/account-server/main-account.cpp
@@ -46,6 +46,8 @@
#include "utils/stringfilter.h"
#include "utils/timer.h"
+using utils::Logger;
+
// Default options that automake should be able to override.
#define DEFAULT_LOG_FILE "tmwserv-account.log"
#define DEFAULT_STATS_FILE "tmwserv.stats"
@@ -84,7 +86,6 @@ static void closeGracefully(int)
*/
static void initialize()
{
-
// Reset to default segmentation fault handling for debugging purposes
signal(SIGSEGV, SIG_DFL);
@@ -253,26 +254,39 @@ static void printHelp()
exit(0);
}
+struct CommandLineOptions
+{
+ CommandLineOptions():
+ verbosity(Logger::INFO),
+ port(Configuration::getValue("net_accountServerPort",
+ DEFAULT_SERVER_PORT))
+ {}
+
+ Logger::Level verbosity;
+ int port;
+};
+
/**
* Parse the command line arguments
*/
-static void parseOptions(int argc, char *argv[])
+static void parseOptions(int argc, char *argv[], CommandLineOptions &options)
{
const char *optstring = "h";
- const struct option long_options[] = {
+ const struct option long_options[] =
+ {
{ "help", no_argument, 0, 'h' },
{ "verbosity", required_argument, 0, 'v' },
{ "port", required_argument, 0, 'p' },
{ 0, 0, 0, 0 }
};
- while (optind < argc) {
+ while (optind < argc)
+ {
int result = getopt_long(argc, argv, optstring, long_options, NULL);
- if (result == -1) {
+ if (result == -1)
break;
- }
switch (result) {
default: // Unknown option
@@ -281,18 +295,11 @@ static void parseOptions(int argc, char *argv[])
printHelp();
break;
case 'v':
- // Set Verbosity to level
- unsigned short verbosityLevel;
- verbosityLevel = atoi(optarg);
- utils::Logger::setVerbosity(utils::Logger::Level(verbosityLevel));
- LOG_INFO("Setting Log Verbosity Level to " << verbosityLevel);
+ options.verbosity = static_cast<Logger::Level>(atoi(optarg));
+ LOG_INFO("Using log verbosity level " << options.verbosity);
break;
case 'p':
- // Change the port to listen on.
- unsigned short portToListenOn;
- portToListenOn = atoi(optarg);
- Configuration::setValue("ListenOnPort", portToListenOn);
- LOG_INFO("Setting Default Port to " << portToListenOn);
+ options.port = atoi(optarg);
break;
}
}
@@ -308,17 +315,18 @@ int main(int argc, char *argv[])
LOG_INFO("The Mana World Account+Chat Server v" << PACKAGE_VERSION);
#endif
- // Parse Command Line Options
- parseOptions(argc, argv);
+ // Parse command line options
+ CommandLineOptions options;
+ parseOptions(argc, argv, options);
+ Logger::setVerbosity(options.verbosity);
- // General Initialization
+ // General initialization
initialize();
- int port = Configuration::getValue("net_accountServerPort", DEFAULT_SERVER_PORT);
std::string host = Configuration::getValue("net_listenHost", std::string());
- if (!AccountClientHandler::initialize(port, host) ||
- !GameServerHandler::initialize(port + 1, host) ||
- !chatHandler->startListen(port + 2, host))
+ if (!AccountClientHandler::initialize(options.port, host) ||
+ !GameServerHandler::initialize(options.port + 1, host) ||
+ !chatHandler->startListen(options.port + 2, host))
{
LOG_FATAL("Unable to create an ENet server host.");
return 3;
@@ -341,15 +349,22 @@ int main(int argc, char *argv[])
storage->setWorldStateVar("accountserver_version", revision);
// -------------------------------------------------------------------------
- while (running) {
+ while (running)
+ {
AccountClientHandler::process();
GameServerHandler::process();
chatHandler->process(50);
- if (statTimer.poll()) dumpStatistics();
- if (banTimer.poll()) storage->checkBannedAccounts();
+
+ if (statTimer.poll())
+ dumpStatistics();
+
+ if (banTimer.poll())
+ storage->checkBannedAccounts();
}
LOG_INFO("Received: Quit signal, closing down...");
chatHandler->stopListen();
deinitialize();
+
+ return 0;
}