git repos / oastat

commit ebf90121

sago007 · 2012-10-14 18:15
ebf901210570dd52b6eeae311f8325b7fedac8d1 patch · browse files
parent f93c4aff755fe48afdd9ad6663f5ef04fbe894bc

The earlier commit that added const in some places also removed a static variable from oastatstruct. That had unforseen consequences. Temporarely made it static again until I find the correct solution

Changed files

M src/db/Db2DbiXX.cpp before
M src/db/Db2DbiXX.hpp before
M src/db/Db2Xml.cpp before
M src/db/Db2Xml.hpp before
M src/db/database.hpp before
M src/oastat.cpp before
M src/oastatstruct.cpp before
M src/oastatstruct.h before
M src/oss2db/Disconnect2Db.cpp before
M src/oss2db/userinfo2db.cpp before
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<std::string,int> 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 <gcrypt.h>
#include <stdio.h>
#include <list>
+#include <boost/shared_ptr.hpp>
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<Struct2Db*> commands;
+vector<shared_ptr<Struct2Db> > commands;
/**
@@ -76,21 +78,21 @@ vector<Struct2Db*> 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<Struct2Db>(new Kill2Db() ) );
+ commands.push_back(shared_ptr<Struct2Db>(new Init2Db() ) );
+ commands.push_back(shared_ptr<Struct2Db>(new Shutdown2Db() ) );
+ commands.push_back(shared_ptr<Struct2Db>(new Userinfo2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Disconnect2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Award2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Ctf2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Point2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Ctf1f2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Elimination2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new CtfElimination2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Harvester2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Challenge2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Warmup2Db()) );
+ commands.push_back(shared_ptr<Struct2Db>(new Accuracy2Db()) );
//Add more commands just above here
for(unsigned int i=0; i<commands.size(); i++)
@@ -153,7 +155,7 @@ static int processStdIn(istream* in_p)
}
}
}
- catch (exception &e2)
+ catch (std::exception &e2)
{
/*
If there is an error write it in the log and try again continue
diff --git a/src/oastatstruct.cpp b/src/oastatstruct.cpp index fe9ab8a..57b87fc 100644 --- a/src/oastatstruct.cpp +++ b/src/oastatstruct.cpp
@@ -31,6 +31,8 @@ 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 59c81ca..211aa5d 100644 --- a/src/oastatstruct.h +++ b/src/oastatstruct.h
@@ -72,7 +72,12 @@ public:
*/
void setTimeStamp(const std::string &timestring);
private:
- tm _datetime;
+ /**
+ * 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;
};
#endif /* _OASTATSTRUCT_H */
diff --git a/src/oss2db/Disconnect2Db.cpp b/src/oss2db/Disconnect2Db.cpp index 3985392..92e61b1 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,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);
}