StatsLoggerDatabase.h

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 #if !defined(__INCLUDE_StatsLoggerDatabaseh_INCLUDE__)
00022 #define __INCLUDE_StatsLoggerDatabaseh_INCLUDE__
00023 
00024 #include <common/StatsLogger.h>
00025 #include <time.h>
00026 #include <string>
00027 #include <map>
00028 #include <set>
00029 
00030 class Weapon;
00031 class StatsLoggerDatabase : public StatsLogger
00032 {
00033 public:
00034         StatsLoggerDatabase();
00035         virtual ~StatsLoggerDatabase();
00036 
00037         virtual int getKillCount(const char *uniqueId);
00038         virtual void gameStart(std::list<Tank *> &tanks);
00039         virtual void roundStart(std::list<Tank *> &tanks);
00040 
00041         virtual std::list<std::string> getAliases(const char *unqiueId);
00042         virtual std::list<std::string> getIpAliases(const char *unqiueId);
00043         virtual TankRank tankRank(Tank *tank);
00044         virtual void updateStats(Tank *tank);
00045         virtual void periodicUpdate();
00046         virtual std::string allocateId();
00047         virtual unsigned int getStatsId(const char *uniqueId);
00048         virtual std::string getTopRanks();
00049         virtual std::string getPlayerInfo(const char *player);
00050         virtual void combinePlayers(unsigned int player1, unsigned int player2);
00051 
00052         virtual void tankConnected(Tank *tank);
00053         virtual void tankDisconnected(Tank *tank);
00054         virtual void tankJoined(Tank *tank);
00055 
00056         virtual void tankFired(Tank *firedTank, Weapon *weapon);
00057         virtual void tankResigned(Tank *resignedTank);
00058 
00059         virtual void tankKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon);
00060         virtual void tankTeamKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon);
00061         virtual void tankSelfKilled(Tank *firedTank, Weapon *weapon);
00062 
00063         virtual void tankWon(Tank *tank);
00064         virtual void tankOverallWinner(Tank *tank);
00065 
00066         virtual void weaponFired(Weapon *weapon, bool deathAni);
00067         virtual void weaponKilled(Weapon *weapon, bool deathAni);
00068 
00069 protected:
00070         struct RowResult
00071         {
00072                 std::vector<std::string> columns;
00073                 std::map<std::string, unsigned int> names;
00074 
00075                 const char *getValue(const char *name);
00076         };
00077 
00078         // Overridden by new implementations
00079         virtual bool runQuery(const char *, ...) = 0;
00080         virtual std::list<RowResult> runSelectQuery(const char *, ...) = 0;
00081         virtual bool connectDatabase(const char *host, const char *port,
00082                 const char *user, const char *passwd, 
00083                 const char *db) = 0;
00084 
00085         virtual int getLastInsertId() = 0;
00086         virtual void escapeString(char *to, const char *from, unsigned long length) = 0;
00087 
00088         // Default stuff
00089         time_t updateTime_;
00090         int serverid_;
00091         int seriesid_;
00092         int prefixid_;
00093     bool success_;
00094         bool displayStats_;
00095 
00096         std::map<std::string, int> playerId_;
00097         std::map<std::string, int> weaponId_;
00098 
00099         void createLogger();
00100         int getPlayerId(const char *uniqueId);
00101 
00102         void addInfo(Tank *tank);
00103         void addAliases(int playerId, 
00104                 std::list<std::string> &results);
00105         void addIpAliases(int playerId, 
00106                 std::set<int> &currentPlayers, std::list<std::string> &result);
00107 
00108 };
00109 
00110 #endif 
00111 

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