StatsLogger.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 

Generated on Mon Feb 16 15:14:49 2009 for Scorched3D by  doxygen 1.5.3