diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp index fa9752f..c1b56ea 100644 --- a/src/db/Db2DbiXX.cpp +++ b/src/db/Db2DbiXX.cpp @@ -23,8 +23,6 @@ http://code.google.com/p/oastat/ #include "Db2DbiXX.hpp" -static const string booltext[2] = {"n","y"}; - void Db2DbiXX::InitStrings(string backend) { last_value = false; @@ -58,7 +56,7 @@ void Db2DbiXX::ReadConfigFromDb() } } -bool Db2DbiXX::IsDuplicate(string servername, tm thetime) +bool Db2DbiXX::IsDuplicate(const string &servername,const tm &thetime) { result res; *sql << "SELECT 'X' FROM oastat_games WHERE servername = ? AND time = ?",servername,thetime,res; @@ -100,7 +98,7 @@ Db2DbiXX::Db2DbiXX(string dbargs) sql->connect(); ReadConfigFromDb(); commitlock = new transaction(*sql); - debug = true; + debug = false; //sql(dbargs); } @@ -183,7 +181,7 @@ int Db2DbiXX::getGameNumber() return gamenumber; } -void Db2DbiXX::setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, const OaStatStruct *oss) +void Db2DbiXX::setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, const OaStatStruct &oss) { if(!isok) return; @@ -192,7 +190,7 @@ void Db2DbiXX::setPlayerInfo(string guid, string nickname, bool isBot, int secon try { *sql << "SAVEPOINT SETPLAYER",exec(); - *sql << "INSERT INTO oastat_players(guid,nickname,lastseen,isBot, model, headmodel) VALUES (?,?,?,?,?,?)",guid,nickname,oss->getDateTime(),booltext[isBot],model,headmodel,exec(); + *sql << "INSERT INTO oastat_players(guid,nickname,lastseen,isBot, model, headmodel) VALUES (?,?,?,?,?,?)",guid,nickname,oss.getDateTime(),(isBot? "y":"n"),model,headmodel,exec(); *sql << "RELEASE SAVEPOINT SETPLAYER",exec(); //Needed by postgresql } catch (dbixx_error &e) @@ -200,7 +198,7 @@ void Db2DbiXX::setPlayerInfo(string guid, string nickname, bool isBot, int secon 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(),booltext[isBot],model,headmodel,guid,oss->getDateTime(),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(); } try { diff --git a/src/db/Db2DbiXX.hpp b/src/db/Db2DbiXX.hpp index 678a8f9..0dcf35b 100644 --- a/src/db/Db2DbiXX.hpp +++ b/src/db/Db2DbiXX.hpp @@ -46,7 +46,7 @@ public: void addGameCvar(string cvar, string value); void endGame(int second); int getGameNumber(); - void setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, const OaStatStruct *oss); + void setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, const OaStatStruct &oss); void addKill(int second, string attackerID, string targetID, int type); //void addCapture(int second, string player, int team); void addAward(int second, string player, int award); @@ -74,7 +74,7 @@ private: void DebugMessage(const string &msg); void InitStrings(string backend); void ReadConfigFromDb(); - bool IsDuplicate(string servername, tm thetime); + bool IsDuplicate(const string &servername, const tm &thetime); int getPlayerId(const string &guid); std::map playerids; string sql_backend; diff --git a/src/db/Db2Xml.cpp b/src/db/Db2Xml.cpp index 98874d8..4f397ef 100644 --- a/src/db/Db2Xml.cpp +++ b/src/db/Db2Xml.cpp @@ -124,7 +124,7 @@ int Db2Xml::getGameNumber() { return 1; } -void Db2Xml::setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, const OaStatStruct *oss) +void Db2Xml::setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, const OaStatStruct &oss) { if(!isOk) return; diff --git a/src/db/Db2Xml.hpp b/src/db/Db2Xml.hpp index f88ba26..c91b7c0 100644 --- a/src/db/Db2Xml.hpp +++ b/src/db/Db2Xml.hpp @@ -48,7 +48,7 @@ public: void addGameCvar(string cvar, string value); void endGame(int second); int getGameNumber(); - void setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, const OaStatStruct *oss); + void setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, const OaStatStruct &oss); void addKill(int second, string attackerID, string targetID, int type); //void addCapture(int second, string player, int team); void addAward(int second, string player, int award); diff --git a/src/db/database.hpp b/src/db/database.hpp index 9713006..a10ca6a 100644 --- a/src/db/database.hpp +++ b/src/db/database.hpp @@ -86,7 +86,7 @@ public: * @param headmodel - headmodel used * @param skill - bot skill, bots only */ - virtual void setPlayerInfo(std::string guid, std::string nickname, bool isBot, int second, int team, std::string model, std::string headmodel, int skill, const OaStatStruct *oss) = 0; + virtual void setPlayerInfo(std::string guid, std::string nickname, bool isBot, int second, int team, std::string model, std::string headmodel, int skill, const OaStatStruct &oss) = 0; /** * Represents a kill diff --git a/src/oastat.cpp b/src/oastat.cpp index d7f814c..ff3b9ab 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp @@ -30,9 +30,11 @@ http://code.google.com/p/oastat/ #include #include #include +#include using namespace std; +using namespace boost; #include "db/database.hpp" #ifdef USEDBIXX @@ -66,7 +68,7 @@ static int processStdIn(istream* in_p); Database *db; -vector commands; +vector > commands; /** @@ -76,21 +78,21 @@ vector commands; void addCommands() { //Add new commands here - commands.push_back(new Kill2Db()); - commands.push_back(new Init2Db()); - commands.push_back(new Shutdown2Db()); - commands.push_back(new Userinfo2Db()); - commands.push_back(new Disconnect2Db()); - commands.push_back(new Award2Db()); - commands.push_back(new Ctf2Db()); - commands.push_back(new Point2Db()); - commands.push_back(new Ctf1f2Db()); - commands.push_back(new Elimination2Db()); - commands.push_back(new CtfElimination2Db()); - commands.push_back(new Harvester2Db()); - commands.push_back(new Challenge2Db()); - commands.push_back(new Warmup2Db()); - commands.push_back(new Accuracy2Db()); + commands.push_back(shared_ptr(new Kill2Db() ) ); + commands.push_back(shared_ptr(new Init2Db() ) ); + commands.push_back(shared_ptr(new Shutdown2Db() ) ); + commands.push_back(shared_ptr(new Userinfo2Db()) ); + commands.push_back(shared_ptr(new Disconnect2Db()) ); + commands.push_back(shared_ptr(new Award2Db()) ); + commands.push_back(shared_ptr(new Ctf2Db()) ); + commands.push_back(shared_ptr(new Point2Db()) ); + commands.push_back(shared_ptr(new Ctf1f2Db()) ); + commands.push_back(shared_ptr(new Elimination2Db()) ); + commands.push_back(shared_ptr(new CtfElimination2Db()) ); + commands.push_back(shared_ptr(new Harvester2Db()) ); + commands.push_back(shared_ptr(new Challenge2Db()) ); + commands.push_back(shared_ptr(new Warmup2Db()) ); + commands.push_back(shared_ptr(new Accuracy2Db()) ); //Add more commands just above here for(unsigned int i=0; isetPlayerInfo(player,"",false,oss.second,-1,"","",-1,&oss); + dp->setPlayerInfo(player,"",false,oss.second,-1,"","",-1,oss); } diff --git a/src/oss2db/userinfo2db.cpp b/src/oss2db/userinfo2db.cpp index 8fedcb6..cc0bfed 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,oss); }