00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <common/StatsLoggerMySQL.h>
00022 #include <common/StatsLoggerPGSQL.h>
00023 #include <common/StatsLoggerFile.h>
00024 #include <common/OptionsScorched.h>
00025 #include <common/Logger.h>
00026 #include <server/ScorchedServer.h>
00027 #include <stdlib.h>
00028
00029 StatsLogger *StatsLogger::instance_ = 0;
00030
00031 StatsLogger *StatsLogger::instance()
00032 {
00033 #ifndef S3D_SERVER
00034 if (!instance_) instance_ = new StatsLoggerNone;
00035 #endif
00036
00037 if (!instance_)
00038 {
00039 const char *statsLogger =
00040 ScorchedServer::instance()->getOptionsGame().getStatsLogger();
00041 if (strcmp(statsLogger, "mysql") == 0)
00042 {
00043 #ifdef HAVE_MYSQL
00044 instance_ = new StatsLoggerMySQL();
00045 Logger::log( "Created mysql stats logger.");
00046 #else
00047 S3D::dialogExit("StatsLogger",
00048 "Atempted to create mysql stats logger\n"
00049 "but mysql support has not been compiled into this\n"
00050 "scorched3d binary.");
00051 #endif
00052 if (strcmp(ScorchedServer::instance()->getOptionsGame().getPublishAddress(),
00053 "AutoDetect") == 0)
00054 {
00055 S3D::dialogExit("StatsLogger",
00056 "Stats logging enabled but AutoDetect used for server address");
00057 }
00058 }
00059 else if (strcmp(statsLogger, "pgsql") == 0)
00060 {
00061 #ifdef HAVE_PGSQL
00062 instance_ = new StatsLoggerPGSQL;
00063 Logger::log( "Created pgsql stats logger.");
00064 #else
00065 S3D::dialogExit("StatsLogger",
00066 "Atempted to create pgsql stats logger\n"
00067 "but pgsql support has not been compiled into this\n"
00068 "scorched3d binary.");
00069 #endif
00070 if (strcmp(ScorchedServer::instance()->getOptionsGame().getPublishAddress(),
00071 "AutoDetect") == 0)
00072 {
00073 S3D::dialogExit("StatsLogger",
00074 "Stats logging enabled but AutoDetect used for server address");
00075 }
00076 }
00077 else if (strcmp(statsLogger, "file") == 0)
00078 {
00079 Logger::log( "Created file stats logger.");
00080 instance_ = new StatsLoggerFile;
00081
00082 if (strcmp(ScorchedServer::instance()->getOptionsGame().getPublishAddress(),
00083 "AutoDetect") == 0)
00084 {
00085 S3D::dialogExit("StatsLogger",
00086 "Stats logging enabled but AutoDetect used for server address");
00087 }
00088 }
00089 else
00090 {
00091 Logger::log( "Created null stats logger.");
00092 instance_ = new StatsLoggerNone;
00093 }
00094 }
00095 return instance_;
00096 }
00097
00098 StatsLogger::StatsLogger()
00099 {
00100
00101 }
00102
00103 StatsLogger::~StatsLogger()
00104 {
00105 }
00106