git repos / oastat

commit 766323e5

sago007 · 2010-06-07 17:30
766323e5eae104a7aec2b133bd3546c4c718f362 patch · browse files
parent f12203f086fee6a861658c17c3e86cf6f94478b9

Now without lock, but still with a possible race condition.


git-svn-id: http://oastat.googlecode.com/svn/trunk@5 a36be8df-c75f-1e49-46ad-4f0ee64bdc62

Changed files

M src/db/Db2PostgreSQL.cpp before
M src/db/database.hpp before
diff --git a/src/db/Db2PostgreSQL.cpp b/src/db/Db2PostgreSQL.cpp index 1be0855..1835dd7 100644 --- a/src/db/Db2PostgreSQL.cpp +++ b/src/db/Db2PostgreSQL.cpp
@@ -129,7 +129,7 @@ void Db2PostgreSQL::createTables()
void Db2PostgreSQL::startGame(int gametype, string mapname, string basegame)
{
simpleQuery("BEGIN");
- simpleQuery("LOCK TABLE OASTAT_GAMES IN SHARE ROW EXCLUSIVE"); //Hold a lock until we have selected the just inserted line
+ //simpleQuery("LOCK TABLE OASTAT_GAMES IN SHARE ROW EXCLUSIVE"); //Hold a lock until we have selected the just inserted line
gamenumber = -1; //Prevent any following sql commands from completing until this is set!
sprintf(query_string,STARTGAME,gametype,mapname.c_str(),basegame.c_str());
res = PQexec(conn, query_string);
@@ -140,7 +140,8 @@ void Db2PostgreSQL::startGame(int gametype, string mapname, string basegame)
return;
}
PQclear(res);
- res = PQexec(conn, "SELECT MAX(gamenumber) FROM OASTAT_GAMES");
+ //res = PQexec(conn, "SELECT MAX(gamenumber) FROM OASTAT_GAMES");
+ res = PQexec(conn, "SELECT currval('oastat_games_gamenumber_seq')");
if (PQresultStatus(res) != PGRES_TUPLES_OK ) {
PQclear(res);
simpleQuery("ROLLBACK");
@@ -149,8 +150,8 @@ void Db2PostgreSQL::startGame(int gametype, string mapname, string basegame)
gamenumber = atoi(PQgetvalue(res,0,0));
cout << "GAME: " << PQgetvalue(res,0,0) << ":" << gamenumber << endl;
PQclear(res);
- simpleQuery("COMMIT"); //release lock
- simpleQuery("BEGIN"); //This is just for performace...
+ //simpleQuery("COMMIT"); //release lock
+ //simpleQuery("BEGIN"); //This is just for performace...
}
int Db2PostgreSQL::getGameNumber()
diff --git a/src/db/database.hpp b/src/db/database.hpp index a7e1620..d0c02f5 100644 --- a/src/db/database.hpp +++ b/src/db/database.hpp
@@ -71,10 +71,32 @@ class Database {
*/
virtual void setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill = -1) = 0;
+ /**
+ * Represents a kill
+ *
+ * @param second time of the kill
+ * @param attackerID hashed guid of the attacker
+ * @param targetID hashed guid of the victim
+ * @param type weapon number
+ */
virtual void addKill(int second, string attackerID, string targetID, int type) = 0;
+ /**
+ * A flag/skull capture or obelisk destruction
+ *
+ * @param second time of the event
+ * @param player guid of the player if any, empty if none
+ * @param team
+ */
virtual void addCapture(int second, string player, int team) = 0;
+ /**
+ * Add an award: Like Defence, Excelent, Gauntlet and so on
+ *
+ * @param second time of the
+ * @param player hashed guid of the player
+ * @param award the award, numbers must be found in code
+ */
virtual void addAward(int second, string player, int award) = 0;
};