git-svn-id: https://scorched3d.svn.sourceforge.net/svnroot/scorched3d/trunk/scorched...
[scorched3d/parasti.git] / src / common / common / StatsLoggerDatabase.h
blobadf28b62ded01a0266b9bc787eeb51e96ed9fb7b
1 ////////////////////////////////////////////////////////////////////////////////
2 // Scorched3D (c) 2000-2009
3 //
4 // This file is part of Scorched3D.
5 //
6 // Scorched3D is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // Scorched3D is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Scorched3D; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ////////////////////////////////////////////////////////////////////////////////
21 #if !defined(__INCLUDE_StatsLoggerDatabaseh_INCLUDE__)
22 #define __INCLUDE_StatsLoggerDatabaseh_INCLUDE__
24 #include <common/StatsLogger.h>
25 #include <time.h>
26 #include <string>
27 #include <map>
28 #include <set>
30 class Weapon;
31 class StatsLoggerDatabase : public StatsLogger
33 public:
34 StatsLoggerDatabase();
35 virtual ~StatsLoggerDatabase();
37 virtual int getKillCount(const char *uniqueId);
38 virtual void gameStart(std::list<Tank *> &tanks);
39 virtual void roundStart(std::list<Tank *> &tanks);
41 virtual std::list<std::string> getAliases(const char *unqiueId);
42 virtual std::list<std::string> getIpAliases(const char *unqiueId);
43 virtual TankRank tankRank(Tank *tank);
44 virtual void updateStats(Tank *tank);
45 virtual void periodicUpdate();
46 virtual std::string allocateId();
47 virtual unsigned int getStatsId(const char *uniqueId);
48 virtual std::string getTopRanks();
49 virtual std::string getPlayerInfo(const char *player);
50 virtual void combinePlayers(unsigned int player1, unsigned int player2);
52 virtual void tankConnected(Tank *tank);
53 virtual void tankDisconnected(Tank *tank);
54 virtual void tankJoined(Tank *tank);
56 virtual void tankFired(Tank *firedTank, Weapon *weapon);
57 virtual void tankResigned(Tank *resignedTank);
59 virtual void tankKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon);
60 virtual void tankTeamKilled(Tank *firedTank, Tank *deadTank, Weapon *weapon);
61 virtual void tankSelfKilled(Tank *firedTank, Weapon *weapon);
63 virtual void tankWon(Tank *tank);
64 virtual void tankOverallWinner(Tank *tank);
66 virtual void weaponFired(Weapon *weapon, bool deathAni);
67 virtual void weaponKilled(Weapon *weapon, bool deathAni);
69 protected:
70 struct RowResult
72 std::vector<std::string> columns;
73 std::map<std::string, unsigned int> names;
75 const char *getValue(const char *name);
78 // Overridden by new implementations
79 virtual bool runQuery(const char *, ...) = 0;
80 virtual std::list<RowResult> runSelectQuery(const char *, ...) = 0;
81 virtual bool connectDatabase(const char *host, const char *port,
82 const char *user, const char *passwd,
83 const char *db) = 0;
85 virtual int getLastInsertId() = 0;
86 virtual void escapeString(char *to, const char *from, unsigned long length) = 0;
88 // Default stuff
89 time_t updateTime_;
90 int serverid_;
91 int seriesid_;
92 int prefixid_;
93 bool success_;
94 bool displayStats_;
96 std::map<std::string, int> playerId_;
97 std::map<std::string, int> weaponId_;
99 void createLogger();
100 int getPlayerId(const char *uniqueId);
102 void addInfo(Tank *tank);
103 void addAliases(int playerId,
104 std::list<std::string> &results);
105 void addIpAliases(int playerId,
106 std::set<int> &currentPlayers, std::list<std::string> &result);
110 #endif