00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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
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> ¤tPlayers, std::list<std::string> &result);
00107
00108 };
00109
00110 #endif
00111