diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp index c1b56ea..f5d99d4 100644 --- a/src/db/Db2DbiXX.cpp +++ b/src/db/Db2DbiXX.cpp @@ -23,7 +23,7 @@ http://code.google.com/p/oastat/ #include "Db2DbiXX.hpp" -void Db2DbiXX::InitStrings(string backend) +void Db2DbiXX::InitStrings(const string &backend) { last_value = false; if(backend == "pgsql") @@ -77,7 +77,7 @@ Db2DbiXX::Db2DbiXX() debug = false; } -Db2DbiXX::Db2DbiXX(string dbargs) +Db2DbiXX::Db2DbiXX(const string &dbargs) { stringstream stream(stringstream::in | stringstream::out); stream << dbargs; @@ -118,26 +118,26 @@ void Db2DbiXX::createTables() } -void Db2DbiXX::startGame(int gametype, string mapname, string basegame, string servername, const OaStatStruct *oss) +void Db2DbiXX::startGame(int gametype, const string &mapname, const string &basegame, const string &servername, const OaStatStruct &oss) { sql->reconnect(); Rollback(); //in case there was some garbage that could be comitted (like warmup or an unfinished game) SetOk(true); - if(oss->restOfLine.find("\\isWarmup\\1") != string::npos) + if(oss.restOfLine.find("\\isWarmup\\1") != string::npos) { SetOk(false); - cout << "Warmup: " << servername << ", " << oss->getTimeStamp() << endl; + cout << "Warmup: " << servername << ", " << oss.getTimeStamp() << endl; return; } - if(IsDuplicate(servername,oss->getDateTime())) + if(IsDuplicate(servername,oss.getDateTime())) { SetOk(false); - cout << "Duplicate:" << servername << ", " << oss->getTimeStamp() << endl; + cout << "Duplicate:" << servername << ", " << oss.getTimeStamp() << endl; return; } 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,oss.getDateTime(),exec(); gamenumber = getLastGameNumber(); if(gamenumber < 1) { @@ -149,12 +149,12 @@ void Db2DbiXX::startGame(int gametype, string mapname, string basegame, string s { 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,oss.getDateTime(),exec(); } DebugMessage("startGame"); } -void Db2DbiXX::addGameCvar(string cvar, string value) +void Db2DbiXX::addGameCvar(const std::string &cvar, const std::string &value) { if(!isok) return; @@ -181,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(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) { if(!isok) return; @@ -214,7 +214,7 @@ void Db2DbiXX::setPlayerInfo(string guid, string nickname, bool isBot, int secon DebugMessage("setPlayerInfo for "+nickname+" with GUID: "+guid); } -void Db2DbiXX::addKill(int second, string attackerID, string targetID, int type) +void Db2DbiXX::addKill(int second, const std::string &attackerID, const std::string &targetID, int type) { if(!isok) return; @@ -222,7 +222,7 @@ void Db2DbiXX::addKill(int second, string attackerID, string targetID, int type) DebugMessage("addKill"); } -void Db2DbiXX::addAward(int second, string player, int award) +void Db2DbiXX::addAward(int second, const std::string &player, int award) { if(!isok) return; @@ -230,7 +230,7 @@ void Db2DbiXX::addAward(int second, string player, int award) DebugMessage("addAward"); } -void Db2DbiXX::addScoreInfo(int second, string player, int score) +void Db2DbiXX::addScoreInfo(int second, const std::string &player, int score) { if(!isok) return; @@ -238,7 +238,7 @@ void Db2DbiXX::addScoreInfo(int second, string player, int score) DebugMessage("addScoreInfo"); } -void Db2DbiXX::addCtf(int second, string player, int team, int event) +void Db2DbiXX::addCtf(int second, const std::string &player, int team, int event) { if(!isok) return; @@ -246,7 +246,7 @@ void Db2DbiXX::addCtf(int second, string player, int team, int event) DebugMessage("addCtf"); } -void Db2DbiXX::addCtf1f(int second, string player, int team, int event) +void Db2DbiXX::addCtf1f(int second, const std::string &player, int team, int event) { if(!isok) return; @@ -263,7 +263,7 @@ void Db2DbiXX::addElimination(int second, int roundnumber, int team, int event) DebugMessage("addElimination"); } -void Db2DbiXX::addCtfElimination(int second, int roundnumber, string player, int team, int event) +void Db2DbiXX::addCtfElimination(int second, int roundnumber, const std::string &player, int team, int event) { if(!isok) return; @@ -271,7 +271,7 @@ void Db2DbiXX::addCtfElimination(int second, int roundnumber, string player, int DebugMessage("addCtfElimination"); } -void Db2DbiXX::addHarvester(int second, string player1, string player2, int team, int event, int score) +void Db2DbiXX::addHarvester(int second, const std::string &player1, const std::string &player2, int team, int event, int score) { if(!isok) return; @@ -280,7 +280,7 @@ void Db2DbiXX::addHarvester(int second, string player1, string player2, int team DebugMessage("addHarvester"); } -void Db2DbiXX::addChallenge(int second, string player, int challenge, int amount) +void Db2DbiXX::addChallenge(int second, const std::string &player, int challenge, int amount) { if(!isok) return; @@ -288,7 +288,7 @@ void Db2DbiXX::addChallenge(int second, string player, int challenge, int amount DebugMessage("addChallenge"); } -void Db2DbiXX::addAccuracy(int second, string player, int type, int shotsFired, int shotsHit) +void Db2DbiXX::addAccuracy(int second, const std::string &player, int type, int shotsFired, int shotsHit) { if(!isok) return; diff --git a/src/db/Db2DbiXX.hpp b/src/db/Db2DbiXX.hpp index 0dcf35b..e5483ef 100644 --- a/src/db/Db2DbiXX.hpp +++ b/src/db/Db2DbiXX.hpp @@ -38,26 +38,26 @@ class Db2DbiXX : public Database { public: Db2DbiXX(); - Db2DbiXX(string dbargs); + Db2DbiXX(const string &dbargs); Db2DbiXX(const Db2DbiXX& orig); virtual ~Db2DbiXX(); void createTables(); - void startGame(int gametype, string mapname, string basegame, string servername, const OaStatStruct *oss); - void addGameCvar(string cvar, string value); + void startGame(int gametype, const string &mapname, const string &basegame, const string &servername, const OaStatStruct &oss); + void addGameCvar(const std::string &cvar, const std::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 addKill(int second, string attackerID, string targetID, int type); + 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 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, string player, int award); - void addScoreInfo(int second, string player, int score); - void addCtf(int second, string player, int team, int event); - void addCtf1f(int second, string player, int team, int event); + void addAward(int second, const std::string &player, int award); + void addScoreInfo(int second, const std::string &player, int score); + void addCtf(int second, const std::string &player, int team, int event); + void addCtf1f(int second, const std::string &player, int team, int event); void addElimination(int second, int roundnumber, int team, int event); - void addCtfElimination(int second, int roundnumber, string player, int team, int event); - void addHarvester(int second, string player1, string player2, int team, int event, int score); - void addChallenge(int second, string player, int challenge, int amount); - void addAccuracy(int secind, string player, int type, int shotsFired, int shotsHit); + void addCtfElimination(int second, int roundnumber, const std::string &player, int team, int event); + void addHarvester(int second, const std::string &player1, const std::string &player2, int team, int event, int score); + void addChallenge(int second, const std::string &player, int challenge, int amount); + void addAccuracy(int second, const std::string &player, int type, int shotsFired, int shotsHit); void doNotCommit(); private: session *sql; @@ -72,7 +72,7 @@ private: bool Ok(); void SetOk(bool ok); void DebugMessage(const string &msg); - void InitStrings(string backend); + void InitStrings(const string &backend); void ReadConfigFromDb(); bool IsDuplicate(const string &servername, const tm &thetime); int getPlayerId(const string &guid); diff --git a/src/db/Db2Xml.cpp b/src/db/Db2Xml.cpp index 4f397ef..6134268 100644 --- a/src/db/Db2Xml.cpp +++ b/src/db/Db2Xml.cpp @@ -78,11 +78,11 @@ Db2Xml::~Db2Xml() { } -void Db2Xml::startGame(int gametype, string mapname, string basegame, string servername, const OaStatStruct *oss) +void Db2Xml::startGame(int gametype, const string &mapname, const string &basegame, const string &servername, const OaStatStruct &oss) { isOk = true; p_xmlcontent = ""; - p_gametime = oss->getDateTime(); + p_gametime = oss.getDateTime(); p_servername = servername; p_xmlcontent += "\n"; p_xmlcontent += (boost::format(" %1%\n") % getXmlEscaped(p_servername) ).str(); @@ -93,7 +93,7 @@ void Db2Xml::startGame(int gametype, string mapname, string basegame, string ser % (p_gametime.tm_year+1900) % (p_gametime.tm_mon+1) % (p_gametime.tm_mday) % (p_gametime.tm_hour) % (p_gametime.tm_min) % (p_gametime.tm_sec) ).str(); } -void Db2Xml::addGameCvar(string cvar, string value) +void Db2Xml::addGameCvar(const std::string &cvar, const std::string &value) { if(!isOk) return; @@ -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(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) { if(!isOk) return; @@ -140,7 +140,7 @@ void Db2Xml::setPlayerInfo(string guid, string nickname, bool isBot, int second, p_xmlcontent += (boost::format(" %1%\n") % skill).str(); p_xmlcontent += " \n"; } -void Db2Xml::addKill(int second, string attackerID, string targetID, int type) +void Db2Xml::addKill(int second, const std::string &attackerID, const std::string &targetID, int type) { if(!isOk) return; @@ -152,17 +152,17 @@ void Db2Xml::addKill(int second, string attackerID, string targetID, int type) p_xmlcontent += " \n"; } //void addCapture(int second, string player, int team); -void Db2Xml::addAward(int second, string player, int award) +void Db2Xml::addAward(int second, const std::string &player, int award) { if(!isOk) return; p_xmlcontent += " \n"; p_xmlcontent += (boost::format(" %1%\n") % second).str(); p_xmlcontent += (boost::format(" %1%\n") % player).str(); - p_xmlcontent += (boost::format(" %1%\n") % second).str(); + p_xmlcontent += (boost::format(" %1%\n") % award).str(); p_xmlcontent += " \n"; } -void Db2Xml::addScoreInfo(int second, string player, int score) +void Db2Xml::addScoreInfo(int second, const std::string &player, int score) { if(!isOk) return; @@ -172,7 +172,7 @@ void Db2Xml::addScoreInfo(int second, string player, int score) p_xmlcontent += (boost::format(" %1%\n") % score).str(); p_xmlcontent += " \n"; } -void Db2Xml::addCtf(int second, string player, int team, int event) +void Db2Xml::addCtf(int second, const std::string &player, int team, int event) { if(!isOk) return; @@ -183,7 +183,7 @@ void Db2Xml::addCtf(int second, string player, int team, int event) p_xmlcontent += (boost::format(" %1%\n") % event).str(); p_xmlcontent += " \n"; } -void Db2Xml::addCtf1f(int second, string player, int team, int event) +void Db2Xml::addCtf1f(int second, const std::string &player, int team, int event) { if(!isOk) return; @@ -205,7 +205,7 @@ void Db2Xml::addElimination(int second, int roundnumber, int team, int event) p_xmlcontent += (boost::format(" %1%\n") % event).str(); p_xmlcontent += " \n"; } -void Db2Xml::addCtfElimination(int second, int roundnumber, string player, int team, int event) +void Db2Xml::addCtfElimination(int second, int roundnumber, const std::string &player, int team, int event) { if(!isOk) return; @@ -217,7 +217,7 @@ void Db2Xml::addCtfElimination(int second, int roundnumber, string player, int t p_xmlcontent += (boost::format(" %1%\n") % event).str(); p_xmlcontent += " \n"; } -void Db2Xml::addHarvester(int second, string player1, string player2, int team, int event, int score) +void Db2Xml::addHarvester(int second, const std::string &player1, const std::string &player2, int team, int event, int score) { if(!isOk) return; @@ -230,7 +230,7 @@ void Db2Xml::addHarvester(int second, string player1, string player2, int team, p_xmlcontent += (boost::format(" %1%\n") % score).str(); p_xmlcontent += " \n"; } -void Db2Xml::addChallenge(int second, string player, int challenge, int amount) +void Db2Xml::addChallenge(int second, const std::string &player, int challenge, int amount) { if(!isOk) return; @@ -242,7 +242,7 @@ void Db2Xml::addChallenge(int second, string player, int challenge, int amount) p_xmlcontent += " \n"; } -void Db2Xml::addAccuracy(int second, string player, int type, int shotsFired, int shotsHit) +void Db2Xml::addAccuracy(int second, const std::string &player, int type, int shotsFired, int shotsHit) { if(!isOk) return; @@ -260,7 +260,7 @@ void Db2Xml::doNotCommit() isOk = false; } -int Db2Xml::getPsoudoId(string guid) +int Db2Xml::getPsoudoId(const string &guid) { int ret = psoudo_playerids[guid]; if(ret > 0) @@ -272,7 +272,7 @@ int Db2Xml::getPsoudoId(string guid) return ret; } -string Db2Xml::getXmlEscaped(string org) +string Db2Xml::getXmlEscaped(const string &org) { string result = org; boost::algorithm::replace_all(result,(string)"&",(string)"&"); diff --git a/src/db/Db2Xml.hpp b/src/db/Db2Xml.hpp index c91b7c0..e564b07 100644 --- a/src/db/Db2Xml.hpp +++ b/src/db/Db2Xml.hpp @@ -44,22 +44,23 @@ public: Db2Xml(const Db2Xml& orig); virtual ~Db2Xml(); void createTables(); - void startGame(int gametype, string mapname, string basegame, string servername, const OaStatStruct *oss); - void addGameCvar(string cvar, string value); + void startGame(int gametype, const string &mapname, const string &basegame, const string &servername, const OaStatStruct &oss); + void addGameCvar(const std::string &cvar, const std::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 addKill(int second, string attackerID, string targetID, int type); + 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 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, string player, int award); - void addScoreInfo(int second, string player, int score); - void addCtf(int second, string player, int team, int event); - void addCtf1f(int second, string player, int team, int event); + void addAward(int second, const std::string &player, int award); + void addScoreInfo(int second, const std::string &player, int score); + void addCtf(int second, const std::string &player, int team, int event); + void addCtf1f(int second, const std::string &player, int team, int event); void addElimination(int second, int roundnumber, int team, int event); - void addCtfElimination(int second, int roundnumber, string player, int team, int event); - void addHarvester(int second, string player1, string player2, int team, int event, int score); - void addChallenge(int second, string player, int challenge, int amount); - void addAccuracy(int secind, string player, int type, int shotsFired, int shotsHit); + void addCtfElimination(int second, int roundnumber, const std::string &player, int team, int event); + void addHarvester(int second, const std::string &player1, const std::string &player2, int team, int event, int score); + void addChallenge(int second, const std::string &player, int challenge, int amount); + void addAccuracy(int second, const std::string &player, int type, int shotsFired, int shotsHit); void doNotCommit(); private: string p_output_dir; @@ -76,8 +77,8 @@ private: map psoudo_playerids; int nextId; - int getPsoudoId(string guid); - string getXmlEscaped(string org); + int getPsoudoId(const string &guid); + string getXmlEscaped(const string &org); }; #endif /* DB2XML_HPP */ diff --git a/src/db/database.hpp b/src/db/database.hpp index a10ca6a..4156f09 100644 --- a/src/db/database.hpp +++ b/src/db/database.hpp @@ -44,8 +44,10 @@ public: * @param gametype - integer of the gametype DM=0,CTF=4, Elim=8 and so on * @param mapname - the mapname used for this game * @param basegame - the mod... normally baseoa + * @param servername - name of the server + * @param oss - the original OaStatStruct. Used to retrieve time */ - virtual void startGame(int gametype, std::string mapname, std::string basegame, std::string servername, const OaStatStruct *oss) = 0; + virtual void startGame(int gametype, const std::string &mapname, const std::string &basegame, const std::string &servername, const OaStatStruct &oss) = 0; /** * Adds information about a cvar to the last started game @@ -53,7 +55,7 @@ public: * @param cvar - The name of the cvar (limited to 100 chars) * @param value - The value of the cvar as a string */ - virtual void addGameCvar(std::string cvar, std::string value) = 0; + virtual void addGameCvar(const std::string &cvar, const std::string &value) = 0; /** * Called then a game ends. @@ -86,7 +88,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(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; /** * Represents a kill @@ -96,7 +98,7 @@ public: * @param targetID hashed guid of the victim * @param type weapon number */ - virtual void addKill(int second, std::string attackerID, std::string targetID, int type) = 0; + virtual void addKill(int second, const std::string &attackerID, const std::string &targetID, int type) = 0; /** * A flag/skull capture or obelisk destruction @@ -114,7 +116,7 @@ public: * @param player hashed guid of the player * @param award the award, numbers must be found in code */ - virtual void addAward(int second, std::string player, int award) = 0; + virtual void addAward(int second, const std::string &player, int award) = 0; /** * Adds information about a players score that is changing. @@ -125,7 +127,7 @@ public: * @param player hashed guid of the player * @param score the Total */ - virtual void addScoreInfo(int second, std::string player, int score) = 0; + virtual void addScoreInfo(int second, const std::string &player, int score) = 0; /** * Adds an event from a CTF-game. @@ -141,7 +143,7 @@ public: * @param team * @param event */ - virtual void addCtf(int second, std::string player, int team, int event) = 0; + virtual void addCtf(int second, const std::string &player, int team, int event) = 0; /** * Adds an event from a 1FCTF-game. @@ -157,8 +159,16 @@ public: * @param team * @param event */ - virtual void addCtf1f(int second, std::string player, int team, int event) = 0; + virtual void addCtf1f(int second, const std::string &player, int team, int event) = 0; + /** + * Adds an event from an Elimination game. + * + * @param second + * @param roundnumber + * @param team + * @param event + */ virtual void addElimination(int second, int roundnumber, int team, int event) = 0; /** @@ -170,7 +180,7 @@ public: * @param team the team the event is about * @param event the event type */ - virtual void addCtfElimination(int second, int roundnumber, std::string player, int team, int event) = 0; + virtual void addCtfElimination(int second, int roundnumber, const std::string &player, int team, int event) = 0; /** * Document addHarvester(int,string,string,int,int,int) here... @@ -182,7 +192,7 @@ public: * @param event the event number * @param score number of skulls brought in in one capture */ - virtual void addHarvester(int second, std::string player1, std::string player2, int team, int event, int score) = 0; + virtual void addHarvester(int second, const std::string &player1, const std::string &player2, int team, int event, int score) = 0; /** * Add information about a scored challenge @@ -192,17 +202,17 @@ public: * @param challenge the challenge gotten (see challenges.h) * @param amount normally 1 */ - virtual void addChallenge(int second, std::string player, int challenge, int amount) = 0; + virtual void addChallenge(int second, const std::string &player, int challenge, int amount) = 0; /** * adds accuracy information. - * @param secind Time the information was given. Usually not logged as the information is for the whole match + * @param second Time the information was given. Usually not logged as the information is for the whole match * @param player Player that the information is recorded for * @param type The weapon type * @param shotsFired Number of shots fired in the match * @param shotsHit Number of hits */ - virtual void addAccuracy(int secind, std::string player, int type, int shotsFired, int shotsHit) = 0; + virtual void addAccuracy(int second, const std::string &player, int type, int shotsFired, int shotsHit) = 0; }; #endif //_DATABASE_H diff --git a/src/oastat.cpp b/src/oastat.cpp index ff3b9ab..bfbd9a4 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp @@ -66,9 +66,9 @@ vector clientIdMap; static int processStdIn(istream* in_p); -Database *db; +static Database *db; -vector > commands; +static vector > commands; /** @@ -103,7 +103,7 @@ void addCommands() -static int processStdIn(istream* in_p) +int processStdIn(istream* in_p) { bool done = true; OaStatStruct *startstruct;