git repos / oastat

commit ddbec969

sago007 · 2011-01-11 21:45
ddbec96917d2db04d8346fb7e5f9d290f441dd92 patch · browse files
parent c07ea3da46c2d8078d95925246491c1672660e9e

CTF and CTF1F


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

Changed files

M src/Makefile before
M src/db/Db2DbiXX.cpp before
M src/db/Db2DbiXX.hpp before
M src/db/database.hpp before
M src/oastat.cpp before
M src/oastatstruct.cpp before
M src/oastatstruct.h before
A src/oss2db/Ctf1f2Db.cpp
A src/oss2db/Ctf1f2Db.hpp
A src/oss2db/Point2Db.cpp
A src/oss2db/Point2Db.hpp
M src/oss2db/init2db.cpp before
diff --git a/src/Makefile b/src/Makefile index 0c76171..02bd6e0 100644 --- a/src/Makefile +++ b/src/Makefile
@@ -6,7 +6,7 @@ USESTDOUT=0
BASE_LIBS=-lgcrypt
BASE_CFLAGS=-c -g
-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
+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
ifeq ($(USESTDOUT),1)
O_FILES+= build/db2stdout.o
@@ -70,3 +70,9 @@ build/award2db.o: oss2db/Award2Db.cpp oss2db/Award2Db.h
build/ctf2db.o: oss2db/Ctf2Db.cpp
g++ $(BASE_CFLAGS) oss2db/Ctf2Db.cpp -o build/ctf2db.o
+build/ctf1f2db.o: oss2db/Ctf1f2Db.cpp
+ g++ $(BASE_CFLAGS) oss2db/Ctf1f2Db.cpp -o build/ctf1f2db.o
+
+build/point2db.o: oss2db/Point2Db.cpp oss2db/Point2Db.hpp
+ g++ $(BASE_CFLAGS) oss2db/Point2Db.cpp -o build/point2db.o
+
diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp index b7b0766..5f29c7c 100644 --- a/src/db/Db2DbiXX.cpp +++ b/src/db/Db2DbiXX.cpp
@@ -9,21 +9,21 @@
#define GETNEXTGAMENUMBER "SELECT nextval('oastat_games_gamenumber_seq')"
-#define STARTGAME "INSERT INTO oastat_games(gamenumber,gametype, mapname, basegame) VALUES (?,?,?,?)"
+#define STARTGAME "INSERT INTO oastat_games(gamenumber,gametype, mapname, basegame,servername,time) VALUES (?,?,LOWER(?),?,?,?)"
#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 = ?"
+#define PLAYERSUPDATE "UPDATE oastat_players SET nickname = ?,lastseen = ?,isBot = ?, model = ?, headmodel = ? WHERE guid = ? AND lastseen < ?"
#define USERINFOINSERT "INSERT INTO oastat_userinfo(gamenumber,second,guid,team,model,skill) VALUES (?,?,?,?,?,?)"
-#define ENDGAME "UPDATE oastat_games SET second=?,time = now() where gamenumber = ?"
+#define ENDGAME "UPDATE oastat_games SET second=? WHERE gamenumber = ?"
#define KILL "INSERT INTO oastat_kills(gamenumber,second,attacker,target,modtype) VALUES(?,?,?,?,?)"
-#define CAPTURE "INSERT INTO oastat_captures(gamenumber,second,player,team) VALUES (?,?,?,?)"
#define AWARD "INSERT INTO oastat_awards(gamenumber,second,player,award) VALUES (?,?,?,?)"
+#define POINT "INSERT INTO oastat_points(gamenumber,second,player,score) VALUES (?,?,?,?)"
#define CTF "INSERT INTO oastat_team_events(gamenumber,second,team,player,gametype,eventtype) VALUES (?,?,?,?,'ctf',?)"
+#define CTF1F "INSERT INTO oastat_team_events(gamenumber,second,team,player,gametype,eventtype) VALUES (?,?,?,?,'1fctf',?)"
+#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 (?,?,?,?,?,?,'ctfelim')"
-static char* booltext[2] = {"false","true"};
-static long long int MakeTimestamp(tm timestamp) {
- return mktime(&timestamp);
-}
+static char* booltext[2] = {"false","true"};
Db2DbiXX::Db2DbiXX() {
sql = new session("pgsql");
@@ -67,12 +67,12 @@ void Db2DbiXX::createTables() {
}
-void Db2DbiXX::startGame(int gametype, string mapname, string basegame) {
+void Db2DbiXX::startGame(int gametype, string mapname, string basegame, string servername, OaStatStruct *oss) {
sql->reconnect();
Rollback(); //in case there was some garbage that could be comitted (like warmup or an unfinished game)
SetOk(true);
gamenumber = getNextGameNumber();
- *sql << STARTGAME,gamenumber,gametype,mapname,basegame,exec();
+ *sql << STARTGAME,gamenumber,gametype,mapname,basegame,servername,oss->getDateTime(),exec();
DebugMessage("startGame");
}
@@ -100,7 +100,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 << PLAYERSUPDATE,nickname,oss->getDateTime(),booltext[isBot],model,headmodel,guid,exec();
+ *sql << PLAYERSUPDATE,nickname,oss->getDateTime(),booltext[isBot],model,headmodel,guid,oss->getDateTime(),exec();
}
*sql << USERINFOINSERT,gamenumber,second,guid,team,model,skill,exec();
DebugMessage("setPlayerInfo for "+nickname+" with GUID: "+guid);
@@ -111,21 +111,31 @@ void Db2DbiXX::addKill(int second, string attackerID, string targetID, int type)
DebugMessage("addKill");
}
-void Db2DbiXX::addCapture(int second, string player, int team) {
+/*void Db2DbiXX::addCapture(int second, string player, int team) {
*sql<< CAPTURE,gamenumber,second,player,team,exec();
DebugMessage("addCapture");
-}
+}*/
void Db2DbiXX::addAward(int second, string player, int award) {
*sql << AWARD,gamenumber,second,player,award,exec();
DebugMessage("addAward");
}
+void Db2DbiXX::addScoreInfo(int second, string player, int score) {
+ *sql << POINT,gamenumber,second,player,score,exec();
+ DebugMessage("addScoreInfo");
+}
+
void Db2DbiXX::addCtf(int second, string player, int team, int event) {
*sql << CTF,gamenumber,second,team,player,event,exec();
DebugMessage("addCtf");
}
+void Db2DbiXX::addCtf1f(int second, string player, int team, int event) {
+ *sql << CTF1F,gamenumber,second,team,player,event,exec();
+ DebugMessage("addCtf1f");
+}
+
int Db2DbiXX::getNextGameNumber() {
int result = -1;
row r;
diff --git a/src/db/Db2DbiXX.hpp b/src/db/Db2DbiXX.hpp index 66ed8fc..e6e4f8e 100644 --- a/src/db/Db2DbiXX.hpp +++ b/src/db/Db2DbiXX.hpp
@@ -24,14 +24,16 @@ public:
Db2DbiXX(const Db2DbiXX& orig);
virtual ~Db2DbiXX();
void createTables();
- void startGame(int gametype, string mapname, string basegame);
+ void startGame(int gametype, string mapname, string basegame, string servername, OaStatStruct *oss);
void endGame(int second);
int getGameNumber();
void setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill, OaStatStruct *oss);
void addKill(int second, string attackerID, string targetID, int type);
- void addCapture(int second, string player, int team);
+ //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);
private:
session *sql;
transaction *commitlock;
diff --git a/src/db/database.hpp b/src/db/database.hpp index 9afe2da..dbf71dc 100644 --- a/src/db/database.hpp +++ b/src/db/database.hpp
@@ -42,7 +42,7 @@ class Database {
* @param mapname - the mapname used for this game
* @param basegame - the mod... normally baseoa
*/
- virtual void startGame(int gametype, string mapname, string basegame) = 0;
+ virtual void startGame(int gametype, string mapname, string basegame, string servername, OaStatStruct *oss) = 0;
/**
* Called then a game ends.
@@ -89,7 +89,7 @@ class Database {
* @param player guid of the player if any, empty if none
* @param team
*/
- virtual void addCapture(int second, string player, int team) = 0;
+ //virtual void addCapture(int second, string player, int team) = 0;
/**
* Add an award: Like Defence, Excelent, Gauntlet and so on
@@ -101,6 +101,17 @@ class Database {
virtual void addAward(int second, string player, int award) = 0;
/**
+ * Adds information about a players score that is changing.
+ * Notice that the score is the total amount of points the
+ * player has for the entire match
+ *
+ * @param second time of the event
+ * @param player hashed guid of the player
+ * @param score the Total
+ */
+ virtual void addScoreInfo(int second, string player, int score) = 0;
+
+ /**
* Adds an event from a CTF-game.
*
* Note that event:
@@ -115,6 +126,22 @@ class Database {
* @param event
*/
virtual void addCtf(int second, string player, int team, int event) = 0;
+
+ /**
+ * Adds an event from a 1FCTF-game.
+ *
+ * Note that event:
+ * 0 | Flag is taken
+ * 1 | Flag is captured
+ * 2 | Flag is returned (like timeout)
+ * 3 | Flagcarrier got killed
+ *
+ * @param second
+ * @param player
+ * @param team
+ * @param event
+ */
+ virtual void addCtf1f(int second, string player, int team, int event) = 0;
};
#endif //_DATABASE_H
diff --git a/src/oastat.cpp b/src/oastat.cpp index 20f1917..d2daee7 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp
@@ -50,6 +50,8 @@ using namespace std;
#include "oss2db/Disconnect2Db.h"
#include "oss2db/Award2Db.h"
#include "oss2db/Ctf2Db.hpp"
+#include "oss2db/Ctf1f2Db.hpp"
+#include "oss2db/Point2Db.hpp"
string clientIdMap[MAX_ID];
@@ -73,6 +75,8 @@ void addCommands()
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());
//Add more commands just above here
for(int i=0;i<commands.size();i++) {
@@ -122,29 +126,6 @@ int main (int argc, const char* argv[])
}
return 0;
- //Rest of file is for testing
-
- /*string line = " 3:33 Kill: 2 5 6: aaargh!!!!!!!!!!!!!! killed RALV by MOD_ROCKET";
-
- OaStatStruct oss;
- oss.parseLine(line);
-
- cout << "Time: '" << oss.second << "' command: '" << oss.command << "' restOfLine: '" << oss.restOfLine << "'" << endl;
-
- for (int i=0; i<oss.parameters.size(); i++) {
- cout << i << ": " << oss.parameters.at(i) << endl;
- }
-
- Kill2Db k2db;
- Struct2Db *s2dp = &k2db;
-
- s2dp->setDb(db);
-
- s2dp->process(oss);
-
- db->addKill(10, "DSAGOJSAOGFJWA55555555AGA", "AHFDSHDFBSDTRHSJYFDSGFA", 3);
-
- return 0;*/
}
static int processStdIn() {
diff --git a/src/oastatstruct.cpp b/src/oastatstruct.cpp index f12909c..52ee5c1 100644 --- a/src/oastatstruct.cpp +++ b/src/oastatstruct.cpp
@@ -27,6 +27,8 @@ using namespace std;
#include <iostream>
#include <iomanip>
+tm OaStatStruct::_datetime;
+
OaStatStruct::OaStatStruct() {
second = 0;
command = "";
@@ -59,8 +61,8 @@ void OaStatStruct::parseLine(string line) {
string tempTimeString = line.substr(0,7);
int posColon = tempTimeString.find(":");
int minute = atoi(tempTimeString.substr(0,posColon).c_str());
- time_t thetime = time(NULL);
- gmtime_r(&thetime,&_datetime);
+ /*time_t thetime = time(NULL);
+ gmtime_r(&thetime,&_datetime);*/
second = atoi(tempTimeString.substr(posColon+1,7).c_str());
second+=minute*60;
line = line.substr(7,line.length()); //Cut the first part of the string.
@@ -142,10 +144,25 @@ string ZeroPadNumber(int num, int size = 2)
string OaStatStruct::getTimeStamp() {
string s;
- s = "TIMESTAMP \'" + ZeroPadNumber(_datetime.tm_year+1900,4) + "-" + ZeroPadNumber(_datetime.tm_mon) + "-"
+ s = "TIMESTAMP \'" + ZeroPadNumber(_datetime.tm_year+1900,4) + "-" + ZeroPadNumber(_datetime.tm_mon+1) + "-"
+ ZeroPadNumber(_datetime.tm_mday) + " " + ZeroPadNumber(_datetime.tm_hour) + ":"
+ ZeroPadNumber(_datetime.tm_min) + ":" + ZeroPadNumber(_datetime.tm_sec) + "\'";
return s;
}
-
+void OaStatStruct::setTimeStamp(string timestring) {
+ std::stringstream ss(timestring);
+ string tmp;
+ getline(ss,tmp,'-');
+ _datetime.tm_year = atoi(tmp.c_str())-1900;
+ getline(ss,tmp,'-');
+ _datetime.tm_mon = atoi(tmp.c_str())-1;
+ getline(ss,tmp,' ');
+ _datetime.tm_mday = atoi(tmp.c_str());
+ getline(ss,tmp,':');
+ _datetime.tm_hour = atoi(tmp.c_str());
+ getline(ss,tmp,':');
+ _datetime.tm_min = atoi(tmp.c_str());
+ getline(ss,tmp);
+ _datetime.tm_sec = atoi(tmp.c_str());
+}
diff --git a/src/oastatstruct.h b/src/oastatstruct.h index b77e005..de8363a 100644 --- a/src/oastatstruct.h +++ b/src/oastatstruct.h
@@ -64,8 +64,13 @@ public:
* TIMESTAMP 'YYYY-MM-
*/
string getTimeStamp();
+
+ /*
+ Sets _datetime. Requires input in the format: "YYYY-MM-DD HH:MM:SS"
+ */
+ void setTimeStamp(string timestring);
private:
- tm _datetime;
+ static tm _datetime;
};
#endif /* _OASTATSTRUCT_H */
diff --git a/src/oss2db/Ctf1f2Db.cpp b/src/oss2db/Ctf1f2Db.cpp new file mode 100644 index 0000000..d640993 --- /dev/null +++ b/src/oss2db/Ctf1f2Db.cpp
@@ -0,0 +1,32 @@
+/*
+ * File: Ctf1f2Db.cpp
+ * Author: poul
+ *
+ * Created on 11. januar 2011, 20:48
+ */
+
+#include "Ctf1f2Db.hpp"
+
+Ctf1f2Db::Ctf1f2Db() {
+}
+
+Ctf1f2Db::Ctf1f2Db(const Ctf1f2Db& orig) {
+}
+
+Ctf1f2Db::~Ctf1f2Db() {
+}
+
+string Ctf1f2Db::getCommand() {
+ return "1FCTF";
+}
+
+void Ctf1f2Db::process(OaStatStruct oss) {
+ if(oss.command != getCommand() || oss.parameters.size()<3 || oss.parameters.at(0)<0)
+ return; //Invalid oss
+
+ string player = "";
+ if(oss.parameters.at(0)!=-1)
+ player= clientIdMap[oss.parameters.at(0)];
+
+ dp->addCtf1f(oss.second,player,oss.parameters.at(1) /*team*/, oss.parameters.at(2) /*event*/);
+}
diff --git a/src/oss2db/Ctf1f2Db.hpp b/src/oss2db/Ctf1f2Db.hpp new file mode 100644 index 0000000..670775c --- /dev/null +++ b/src/oss2db/Ctf1f2Db.hpp
@@ -0,0 +1,28 @@
+/*
+ * File: Ctf1f2Db.hpp
+ * Author: poul
+ *
+ * Created on 11. januar 2011, 20:48
+ */
+
+#ifndef _CTF1F2DB_HPP
+#define _CTF1F2DB_HPP
+
+#include "struct2db.h"
+#include "../local.h"
+
+class Ctf1f2Db : public Struct2Db {
+public:
+ Ctf1f2Db();
+ Ctf1f2Db(const Ctf1f2Db& orig);
+ virtual ~Ctf1f2Db();
+
+ string getCommand();
+
+ void process(OaStatStruct oss);
+private:
+
+};
+
+#endif /* _CTF1F2DB_HPP */
+
diff --git a/src/oss2db/Point2Db.cpp b/src/oss2db/Point2Db.cpp new file mode 100644 index 0000000..3eebb14 --- /dev/null +++ b/src/oss2db/Point2Db.cpp
@@ -0,0 +1,30 @@
+/*
+ * File: Point2Db.cpp
+ * Author: poul
+ *
+ * Created on 10. januar 2011, 21:32
+ */
+
+#include "Point2Db.hpp"
+
+Point2Db::Point2Db() {
+}
+
+Point2Db::Point2Db(const Point2Db& orig) {
+}
+
+Point2Db::~Point2Db() {
+}
+
+string Point2Db::getCommand() {
+ return "PlayerScore";
+}
+
+void Point2Db::process(OaStatStruct oss) {
+ if(oss.command != getCommand() || oss.parameters.size()<2 || oss.parameters.at(0)<0)
+ return; //Invalid oss
+
+ string player = clientIdMap[oss.parameters.at(0)];
+
+ dp->addScoreInfo(oss.second,player,oss.parameters.at(1));
+}
\ No newline at end of file
diff --git a/src/oss2db/Point2Db.hpp b/src/oss2db/Point2Db.hpp new file mode 100644 index 0000000..ef1a7c0 --- /dev/null +++ b/src/oss2db/Point2Db.hpp
@@ -0,0 +1,28 @@
+/*
+ * File: Point2Db.hpp
+ * Author: poul
+ *
+ * Created on 10. januar 2011, 21:32
+ */
+
+#ifndef _POINT2DB_HPP
+#define _POINT2DB_HPP
+
+#include "struct2db.h"
+#include "../local.h"
+
+class Point2Db : public Struct2Db {
+public:
+ Point2Db();
+ Point2Db(const Point2Db& orig);
+ virtual ~Point2Db();
+
+ string getCommand();
+
+ void process(OaStatStruct oss);
+private:
+
+};
+
+#endif /* _POINT2DB_HPP */
+
diff --git a/src/oss2db/init2db.cpp b/src/oss2db/init2db.cpp index 465bb2d..15a08de 100644 --- a/src/oss2db/init2db.cpp +++ b/src/oss2db/init2db.cpp
@@ -42,6 +42,8 @@ void Init2Db::process(OaStatStruct oss) {
int gametype = atoi(arguments["g_gametype"].c_str());
string basegame = arguments["gamename"];
string mapname = arguments["mapname"];
+ string servername = arguments["sv_hostname"];
+ oss.setTimeStamp(arguments["g_timestamp"]);
- dp->startGame(gametype,mapname,basegame);
+ dp->startGame(gametype,mapname,basegame,servername,&oss);
}