diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-09-16 11:10:06 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-09-16 11:10:06 +0000 |
commit | 88e3d219588052a8ab222ab4f6f2b27c9c29c1b2 (patch) | |
tree | 6b15bf0fe700d61b3aa451d0810a07a175b06774 /src/account-server/main-account.cpp | |
parent | be461a5ca51e10dad40c87385440f6ddae14fca0 (diff) | |
download | manaserv-88e3d219588052a8ab222ab4f6f2b27c9c29c1b2.tar.gz manaserv-88e3d219588052a8ab222ab4f6f2b27c9c29c1b2.tar.bz2 manaserv-88e3d219588052a8ab222ab4f6f2b27c9c29c1b2.tar.xz manaserv-88e3d219588052a8ab222ab4f6f2b27c9c29c1b2.zip |
Added global accounting of beings.
Diffstat (limited to 'src/account-server/main-account.cpp')
-rw-r--r-- | src/account-server/main-account.cpp | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/src/account-server/main-account.cpp b/src/account-server/main-account.cpp index 1aacf2fb..68cb134b 100644 --- a/src/account-server/main-account.cpp +++ b/src/account-server/main-account.cpp @@ -24,6 +24,7 @@ #include <getopt.h> #include <signal.h> #include <iostream> +#include <fstream> #include <physfs.h> #include <enet/enet.h> @@ -44,13 +45,15 @@ #include "utils/logger.h" #include "utils/processorutils.hpp" #include "utils/stringfilter.h" +#include "utils/timer.h" // Default options that automake should be able to override. #define DEFAULT_LOG_FILE "tmwserv-account.log" +#define DEFAULT_STATS_FILE "tmwserv.stats" #define DEFAULT_CONFIG_FILE "tmwserv.xml" #define DEFAULT_ITEMSDB_FILE "items.xml" -bool running = true; /**< Determines if server keeps running */ +static bool running = true; /**< Determines if server keeps running */ Configuration config; /**< XML config reader */ @@ -75,7 +78,7 @@ ChatChannelManager *chatChannelManager; GuildManager *guildManager; /** Callback used when SIGQUIT signal is received. */ -void closeGracefully(int) +static void closeGracefully(int) { running = false; } @@ -83,7 +86,7 @@ void closeGracefully(int) /** * Initializes the server. */ -void initialize() +static void initialize() { // Reset to default segmentation fault handling for debugging purposes @@ -185,7 +188,7 @@ void initialize() /** * Deinitializes the server. */ -void deinitialize() +static void deinitialize() { delete stringFilter; // Write configuration file @@ -211,11 +214,35 @@ void deinitialize() PHYSFS_deinit(); } +/** + * Dumps statistics. + */ +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"; + serverHandler->dumpStatistics(os); + os << "</statistics>\n"; +} /** * Show command line arguments */ -void printHelp() +static void printHelp() { std::cout << "tmwserv" << std::endl << std::endl << "Options: " << std::endl @@ -228,7 +255,7 @@ void printHelp() /** * Parse the command line arguments */ -void parseOptions(int argc, char *argv[]) +static void parseOptions(int argc, char *argv[]) { const char *optstring = "h"; @@ -293,10 +320,14 @@ int main(int argc, char *argv[]) return 3; } + // Dump statistics every 10 seconds. + utils::Timer statTimer(10000); + while (running) { accountHandler->process(50); chatHandler->process(50); serverHandler->process(50); + if (statTimer.poll()) dumpStatistics(); } LOG_INFO("Received: Quit signal, closing down..."); |