diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp index f5d99d4..1e75672 100644 --- a/src/db/Db2DbiXX.cpp +++ b/src/db/Db2DbiXX.cpp @@ -123,13 +123,14 @@ void Db2DbiXX::startGame(int gametype, const string &mapname, const string &base sql->reconnect(); Rollback(); //in case there was some garbage that could be comitted (like warmup or an unfinished game) SetOk(true); + timestamp = oss.getDateTime(); if(oss.restOfLine.find("\\isWarmup\\1") != string::npos) { SetOk(false); cout << "Warmup: " << servername << ", " << oss.getTimeStamp() << endl; return; } - if(IsDuplicate(servername,oss.getDateTime())) + if(IsDuplicate(servername,timestamp)) { SetOk(false); cout << "Duplicate:" << servername << ", " << oss.getTimeStamp() << endl; @@ -137,7 +138,7 @@ void Db2DbiXX::startGame(int gametype, const string &mapname, const string &base } if(last_value) { - *sql << "INSERT INTO oastat_games(gametype, mapname, basegame,servername,time) VALUES (?,LOWER(?),?,?,?)",gametype,mapname,basegame,servername,oss.getDateTime(),exec(); + *sql << "INSERT INTO oastat_games(gametype, mapname, basegame,servername,time) VALUES (?,LOWER(?),?,?,?)",gametype,mapname,basegame,servername,timestamp,exec(); gamenumber = getLastGameNumber(); if(gamenumber < 1) { @@ -149,7 +150,7 @@ void Db2DbiXX::startGame(int gametype, const string &mapname, const string &base { gamenumber = getNextGameNumber(); *sql << "INSERT INTO oastat_games(gamenumber,gametype, mapname, basegame,servername,time) VALUES (?,?,LOWER(?),?,?,?)", - gamenumber,gametype,mapname,basegame,servername,oss.getDateTime(),exec(); + gamenumber,gametype,mapname,basegame,servername,timestamp,exec(); } DebugMessage("startGame"); } @@ -181,7 +182,7 @@ int Db2DbiXX::getGameNumber() return gamenumber; } -void Db2DbiXX::setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill, const OaStatStruct &oss) +void Db2DbiXX::setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill) { if(!isok) return; @@ -190,7 +191,7 @@ void Db2DbiXX::setPlayerInfo(const std::string &guid, const std::string &nicknam try { *sql << "SAVEPOINT SETPLAYER",exec(); - *sql << "INSERT INTO oastat_players(guid,nickname,lastseen,isBot, model, headmodel) VALUES (?,?,?,?,?,?)",guid,nickname,oss.getDateTime(),(isBot? "y":"n"),model,headmodel,exec(); + *sql << "INSERT INTO oastat_players(guid,nickname,lastseen,isBot, model, headmodel) VALUES (?,?,?,?,?,?)",guid,nickname,timestamp,(isBot? "y":"n"),model,headmodel,exec(); *sql << "RELEASE SAVEPOINT SETPLAYER",exec(); //Needed by postgresql } catch (dbixx_error &e) @@ -198,7 +199,7 @@ void Db2DbiXX::setPlayerInfo(const std::string &guid, const std::string &nicknam DebugMessage("Already inserted? "+(string)e.what()); *sql << "ROLLBACK TO SAVEPOINT SETPLAYER",exec(); } - *sql << "UPDATE oastat_players SET nickname = ?,lastseen = ?,isBot = ?, model = ?, headmodel = ? WHERE guid = ? AND lastseen < ?",nickname,oss.getDateTime(),(isBot? "y":"n"),model,headmodel,guid,oss.getDateTime(),exec(); + *sql << "UPDATE oastat_players SET nickname = ?,lastseen = ?,isBot = ?, model = ?, headmodel = ? WHERE guid = ? AND lastseen < ?",nickname,timestamp,(isBot? "y":"n"),model,headmodel,guid,timestamp,exec(); } try { diff --git a/src/db/Db2DbiXX.hpp b/src/db/Db2DbiXX.hpp index e5483ef..0bb5f4a 100644 --- a/src/db/Db2DbiXX.hpp +++ b/src/db/Db2DbiXX.hpp @@ -46,7 +46,7 @@ public: void addGameCvar(const std::string &cvar, const std::string &value); void endGame(int second); int getGameNumber(); - void setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill, const OaStatStruct &oss); + void setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill); void addKill(int second, const std::string &attackerID, const std::string &targetID, int type); //void addCapture(int second, string player, int team); void addAward(int second, const std::string &player, int award); @@ -64,7 +64,8 @@ private: transaction *commitlock; bool isok; bool debug; - int gamenumber; + int gamenumber; /** Gamenumber we are currently working on */ + tm timestamp; /** Start time of the game we are currently working on */ int getNextGameNumber(); int getLastGameNumber(); void Commit(); diff --git a/src/db/Db2Xml.cpp b/src/db/Db2Xml.cpp index 6134268..2d0fd48 100644 --- a/src/db/Db2Xml.cpp +++ b/src/db/Db2Xml.cpp @@ -124,7 +124,7 @@ int Db2Xml::getGameNumber() { return 1; } -void Db2Xml::setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill, const OaStatStruct &oss) +void Db2Xml::setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill) { if(!isOk) return; diff --git a/src/db/Db2Xml.hpp b/src/db/Db2Xml.hpp index e564b07..2fbb1db 100644 --- a/src/db/Db2Xml.hpp +++ b/src/db/Db2Xml.hpp @@ -49,7 +49,7 @@ public: void endGame(int second); int getGameNumber(); void setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, - int second, int team, const std::string &model, const std::string &headmodel, int skill, const OaStatStruct &oss); + int second, int team, const std::string &model, const std::string &headmodel, int skill); void addKill(int second, const std::string &attackerID, const std::string &targetID, int type); //void addCapture(int second, string player, int team); void addAward(int second, const std::string &player, int award); diff --git a/src/db/database.hpp b/src/db/database.hpp index 4156f09..9390823 100644 --- a/src/db/database.hpp +++ b/src/db/database.hpp @@ -88,7 +88,7 @@ public: * @param headmodel - headmodel used * @param skill - bot skill, bots only */ - virtual void setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill, const OaStatStruct &oss) = 0; + virtual void setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill) = 0; /** * Represents a kill diff --git a/src/oastatstruct.cpp b/src/oastatstruct.cpp index 57b87fc..fe9ab8a 100644 --- a/src/oastatstruct.cpp +++ b/src/oastatstruct.cpp @@ -31,8 +31,6 @@ using namespace std; using namespace std; -tm OaStatStruct::_datetime; - namespace { void makeLower(string &x) diff --git a/src/oastatstruct.h b/src/oastatstruct.h index 211aa5d..719b45f 100644 --- a/src/oastatstruct.h +++ b/src/oastatstruct.h @@ -72,12 +72,7 @@ public: */ void setTimeStamp(const std::string ×tring); private: - /** - * This is static because it must be shared between all oastatstructs to ensure that they all know the same time... - * As a side effect we cannot process more than one game at once - * TODO: find a better way to do this! - */ - static tm _datetime; + tm _datetime; }; #endif /* _OASTATSTRUCT_H */ diff --git a/src/oss2db/Disconnect2Db.cpp b/src/oss2db/Disconnect2Db.cpp index 92e61b1..2f078dd 100644 --- a/src/oss2db/Disconnect2Db.cpp +++ b/src/oss2db/Disconnect2Db.cpp @@ -43,5 +43,5 @@ void Disconnect2Db::process(const OaStatStruct &oss) string player = clientIdMap.at(oss.parameters.at(0)); - dp->setPlayerInfo(player,"",false,oss.second,-1,"","",-1,oss); + dp->setPlayerInfo(player,"",false,oss.second,-1,"","",-1); } diff --git a/src/oss2db/init2db.cpp b/src/oss2db/init2db.cpp index 0153027..8f6241d 100644 --- a/src/oss2db/init2db.cpp +++ b/src/oss2db/init2db.cpp @@ -49,7 +49,7 @@ void Init2Db::process(const OaStatStruct &oss) string servername = arguments["sv_hostname"]; oss_copy.setTimeStamp(arguments["g_timestamp"]); - dp->startGame(gametype,mapname,basegame,servername,&oss_copy); + dp->startGame(gametype,mapname,basegame,servername,oss_copy); map::iterator it; for(it = arguments.begin(); it != arguments.end(); it++) { diff --git a/src/oss2db/userinfo2db.cpp b/src/oss2db/userinfo2db.cpp index cc0bfed..41601ac 100644 --- a/src/oss2db/userinfo2db.cpp +++ b/src/oss2db/userinfo2db.cpp @@ -64,5 +64,5 @@ void Userinfo2Db::process(const OaStatStruct &oss) } string player = clientIdMap[oss.parameters.at(0)]; - dp->setPlayerInfo(player,arguments["n"],isBot,oss.second,atoi(arguments["t"].c_str()), arguments["model"],arguments["hmodel"],-1,oss); + dp->setPlayerInfo(player,arguments["n"],isBot,oss.second,atoi(arguments["t"].c_str()), arguments["model"],arguments["hmodel"],-1); }