commit bebac2ed
Warmup games are now ignored
git-svn-id: http://oastat.googlecode.com/svn/trunk@27 a36be8df-c75f-1e49-46ad-4f0ee64bdc62
Changed files
diff --git a/src/Makefile b/src/Makefile
index c417080..3076cc8 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -6,7 +6,7 @@ USESTDOUT=0
BASE_LIBS=-lgcrypt
BASE_CFLAGS=-c -g -O0
-O_FILES=build/oastat.o build/oastatstruct.o build/kill2db.o build/init2db.o build/shutdown2db.o build/userinfo2db.o build/disconnect2db.o build/award2db.o build/ctf2db.o build/point2db.o build/ctf1f2db.o build/elimination2db.o build/ctfelim2db.o build/harvester2db.o
+O_FILES=build/oastat.o build/oastatstruct.o build/kill2db.o build/init2db.o build/shutdown2db.o build/userinfo2db.o build/disconnect2db.o build/award2db.o build/ctf2db.o build/point2db.o build/ctf1f2db.o build/elimination2db.o build/ctfelim2db.o build/harvester2db.o build/challenge2db.o build/warmup2db.o
ifeq ($(USESTDOUT),1)
O_FILES+= build/db2stdout.o
@@ -89,3 +89,10 @@ build/point2db.o: oss2db/Point2Db.cpp oss2db/Point2Db.hpp
build/harvester2db.o: oss2db/Harvester2Db.cpp oss2db/Harvester2Db.hpp
g++ $(BASE_CFLAGS) oss2db/Harvester2Db.cpp -o build/harvester2db.o
+
+build/challenge2db.o: oss2db/Challenge2Db.cpp oss2db/Challenge2Db.hpp
+ g++ $(BASE_CFLAGS) oss2db/Challenge2Db.cpp -o build/challenge2db.o
+
+build/warmup2db.o: oss2db/Warmup2Db.cpp oss2db/Warmup2Db.hpp
+ g++ $(BASE_CFLAGS) oss2db/Warmup2Db.cpp -o build/warmup2db.o
+
diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp
index 34b15a0..1e5093f 100644
--- a/src/db/Db2DbiXX.cpp
+++ b/src/db/Db2DbiXX.cpp
@@ -19,6 +19,7 @@
#define PLAYERSINSERT "INSERT INTO oastat_players(guid,nickname,lastseen,isBot, model, headmodel) VALUES (?,?,?,?,?,?)"
#define PLAYERSUPDATE "UPDATE oastat_players SET nickname = ?,lastseen = ?,isBot = ?, model = ?, headmodel = ? WHERE guid = ? AND lastseen < ?"
#define USERINFOINSERT "INSERT INTO oastat_userinfo(gamenumber,second,player,team,model,skill) VALUES (?,?,(SELECT playerid FROM oastat_players WHERE guid = ?),?,?,?)"
+#define USERINFOUPDATE "UPDATE oastat_userinfo SET team = ?, model = ?, skill = ? WHERE gamenumber = ? AND second = ? AND player IN (SELECT playerid FROM oastat_players WHERE GUID = ?)"
#define ENDGAME "UPDATE oastat_games SET second=? WHERE gamenumber = ?"
#define KILL "INSERT INTO oastat_kills(gamenumber,second,attacker,target,modtype) VALUES(?,?,?,(SELECT playerid FROM oastat_players WHERE guid = ?),?)"
#define AWARD "INSERT INTO oastat_awards(gamenumber,second,player,award) VALUES (?,?,(SELECT playerid FROM oastat_players WHERE guid = ?),?)"
@@ -28,6 +29,7 @@
#define ELIMINATION "INSERT INTO oastat_team_events(gamenumber,second,team,eventtype,generic1,gametype) VALUES (?,?,?,?,?,'elimination')"
#define CTF_ELIM "INSERT INTO oastat_team_events(gamenumber,second,team,player,eventtype,generic1,gametype) VALUES (?,?,?,(SELECT playerid FROM oastat_players WHERE guid = ?),?,?,'ctfelim')"
#define HARVESTER "INSERT INTO oastat_team_events(gamenumber,second,team,player,player2,eventtype,amount,gametype) VALUES (?,?,?,(SELECT playerid FROM oastat_players WHERE guid = ?),(SELECT playerid FROM oastat_players WHERE guid = ?),?,?,'harvester')"
+#define CHALLENGES "INSERT INTO oastat_challenges(gamenumber,player,challenge,amount) VALUES (?,(SELECT playerid FROM oastat_players WHERE guid = ?),?,?)"
static string S_GETLASTGAMENUMBER = GETLASTGAMENUMBER;
static string S_STARTGAME = STARTGAME;
@@ -36,6 +38,7 @@ static string S_STARTGAME_LASTVALUE = STARTGAME_LASTVALUE;
static string S_PLAYERSINSERT = PLAYERSINSERT;
static string S_PLAYERSUPDATE = PLAYERSUPDATE;
static string S_USERINFOINSERT = USERINFOINSERT;
+static string S_USERINFOUPDATE = USERINFOUPDATE;
static string S_ENDGAME = ENDGAME;
static string S_KILL = KILL;
static string S_AWARD = AWARD;
@@ -45,6 +48,7 @@ static string S_CTF1F = CTF1F;
static string S_ELIMINATION = ELIMINATION;
static string S_CTF_ELIM = CTF_ELIM;
static string S_HARVESTER = HARVESTER;
+static string S_CHALLENGES = CHALLENGES;
static string booltext[2] = {"n","y"};
@@ -153,7 +157,14 @@ void Db2DbiXX::setPlayerInfo(string guid, string nickname, bool isBot, int secon
}
*sql << S_PLAYERSUPDATE,nickname,oss->getDateTime(),booltext[isBot],model,headmodel,guid,oss->getDateTime(),exec();
}
- *sql << S_USERINFOINSERT,gamenumber,second,guid,team,model,skill,exec();
+ try{
+ *sql << "SAVEPOINT SETUSERINFO",exec();
+ *sql << S_USERINFOINSERT,gamenumber,second,guid,team,model,skill,exec();
+ *sql << "RELEASE SAVEPOINT SETUSERINFO",exec(); //Needed by postgresql
+ }catch (dbixx_error &e) {
+ *sql << "ROLLBACK TO SAVEPOINT SETUSERINFO",exec();
+ *sql << S_USERINFOUPDATE,team,model,skill,gamenumber,second,guid,exec();
+ }
DebugMessage("setPlayerInfo for "+nickname+" with GUID: "+guid);
}
@@ -202,6 +213,11 @@ void Db2DbiXX::addHarvester(int second, string player1, string player2, int team
DebugMessage("addHarvester");
}
+void Db2DbiXX::addChallenge(int second, string player, int challenge, int amount) {
+ *sql << S_CHALLENGES,gamenumber,player,challenge,amount,exec();
+ DebugMessage("addChallenge");
+}
+
int Db2DbiXX::getNextGameNumber() {
int result = -1;
row r;
@@ -236,6 +252,11 @@ int Db2DbiXX::getLastGameNumber() {
This is a helper function so we never forget to start a new transaction after a commit.
*/
void Db2DbiXX::Commit() {
+ if(!isok)
+ {
+ Rollback();
+ return;
+ }
commitlock->commit();
delete commitlock;
commitlock = new transaction(*sql);
@@ -257,6 +278,10 @@ void Db2DbiXX::SetOk(bool ok) {
isok = ok;
}
+void Db2DbiXX::doNotCommit() {
+ SetOk(false);
+}
+
void Db2DbiXX::DebugMessage(string msg) {
if(debug) {
cout << "oastat: " << msg << endl;
diff --git a/src/db/Db2DbiXX.hpp b/src/db/Db2DbiXX.hpp
index f618a15..7fb1cd8 100644
--- a/src/db/Db2DbiXX.hpp
+++ b/src/db/Db2DbiXX.hpp
@@ -38,6 +38,8 @@ public:
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 doNotCommit();
private:
session *sql;
transaction *commitlock;
diff --git a/src/db/database.hpp b/src/db/database.hpp
index af4749e..35d1485 100644
--- a/src/db/database.hpp
+++ b/src/db/database.hpp
@@ -67,6 +67,11 @@ class Database {
virtual int getGameNumber() = 0;
/**
+ * If this is called the game will be not be written to the database. This is good for warmup or games ended prematurely.
+ */
+ virtual void doNotCommit() = 0;
+
+ /**
* Document setPlayerInfo(string,string,bool,int,int,string,string,int) here...
*
* @param guid - the hashed GUID of the player
@@ -175,6 +180,16 @@ class Database {
* @param score number of skulls brought in in one capture
*/
virtual void addHarvester(int second, string player1, string player2, int team, int event, int score) = 0;
+
+ /**
+ * Add information about a scored challenge
+ *
+ * @param second time from gamestart
+ * @param player player getting the challenge
+ * @param challenge the challenge gotten (see challenges.h)
+ * @param amount normally 1
+ */
+ virtual void addChallenge(int second, string player, int challenge, int amount) = 0;
};
#endif //_DATABASE_H
diff --git a/src/oastat.cpp b/src/oastat.cpp
index 4ab6209..7f67845 100644
--- a/src/oastat.cpp
+++ b/src/oastat.cpp
@@ -56,6 +56,8 @@ using namespace std;
#include "oss2db/Elimination2Db.hpp"
#include "oss2db/CtfElimination2Db.hpp"
#include "oss2db/Harvester2Db.hpp"
+#include "oss2db/Challenge2Db.hpp"
+#include "oss2db/Warmup2Db.hpp"
string clientIdMap[MAX_ID];
@@ -84,6 +86,8 @@ void addCommands()
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());
//Add more commands just above here
for(int i=0;i<commands.size();i++) {
diff --git a/src/oss2db/Challenge2Db.cpp b/src/oss2db/Challenge2Db.cpp
new file mode 100644
index 0000000..eb5631b
--- /dev/null
+++ b/src/oss2db/Challenge2Db.cpp
@@ -0,0 +1,28 @@
+/*
+ * File: Challenge2Db.cpp
+ * Author: poul
+ *
+ * Created on 19. august 2011, 22:44
+ */
+
+#include "Challenge2Db.hpp"
+
+string Challenge2Db::getCommand() {
+ return "Challenge";
+}
+
+
+bool Challenge2Db::canProcess(OaStatStruct oss) {
+ if(oss.command != getCommand() || oss.parameters.size()<3)
+ return false;
+ return true;
+}
+
+void Challenge2Db::process(OaStatStruct oss) {
+ if(!canProcess(oss))
+ return; //Invalid oss
+
+ string player = clientIdMap[oss.parameters.at(0)];
+
+ dp->addChallenge(oss.second,player,oss.parameters.at(1),oss.parameters.at(2));
+}
\ No newline at end of file
diff --git a/src/oss2db/Challenge2Db.hpp b/src/oss2db/Challenge2Db.hpp
new file mode 100644
index 0000000..e6c8c1a
--- /dev/null
+++ b/src/oss2db/Challenge2Db.hpp
@@ -0,0 +1,25 @@
+/*
+ * File: Challenge2Db.hpp
+ * Author: poul
+ *
+ * Created on 19. august 2011, 22:45
+ */
+
+#ifndef CHALLENGE2DB_HPP
+#define CHALLENGE2DB_HPP
+
+#include "struct2db.h"
+#include "../local.h"
+
+class Challenge2Db : public Struct2Db {
+public:
+ string getCommand();
+ bool canProcess(OaStatStruct oss);
+
+ void process(OaStatStruct oss);
+private:
+
+};
+
+#endif /* CHALLENGE2DB_HPP */
+
diff --git a/src/oss2db/Warmup2Db.cpp b/src/oss2db/Warmup2Db.cpp
new file mode 100644
index 0000000..c79b6ab
--- /dev/null
+++ b/src/oss2db/Warmup2Db.cpp
@@ -0,0 +1,25 @@
+/*
+ * File: Warmup2Db.cpp
+ * Author: poul
+ *
+ * Created on 26. august 2011, 20:28
+ */
+
+#include "Warmup2Db.hpp"
+
+string Warmup2Db::getCommand() {
+ return "Warmup";
+}
+
+bool Warmup2Db::canProcess(OaStatStruct oss) {
+ if(oss.command != getCommand())
+ return false;
+ return true;
+}
+
+void Warmup2Db::process(OaStatStruct oss) {
+ if(!canProcess(oss))
+ return; //Invalid oss
+
+ dp->doNotCommit();
+}
\ No newline at end of file
diff --git a/src/oss2db/Warmup2Db.hpp b/src/oss2db/Warmup2Db.hpp
new file mode 100644
index 0000000..83ce1dd
--- /dev/null
+++ b/src/oss2db/Warmup2Db.hpp
@@ -0,0 +1,25 @@
+/*
+ * File: Warmup2Db.hpp
+ * Author: poul
+ *
+ * Created on 26. august 2011, 20:28
+ */
+
+#ifndef WARMUP2DB_HPP
+#define WARMUP2DB_HPP
+
+#include "struct2db.h"
+#include "../local.h"
+
+class Warmup2Db : public Struct2Db {
+public:
+ string getCommand();
+ bool canProcess(OaStatStruct oss);
+
+ void process(OaStatStruct oss);
+private:
+
+};
+
+#endif /* WARMUP2DB_HPP */
+