diff --git a/sql/create_tables/oastat_create_tables_common.sql b/sql/create_tables/oastat_create_tables_common.sql index d0ff4a3..1c1ca73 100644 --- a/sql/create_tables/oastat_create_tables_common.sql +++ b/sql/create_tables/oastat_create_tables_common.sql @@ -23,6 +23,7 @@ CREATE TABLE oastat_team_events ( amount integer DEFAULT 1, gametype character varying(20) NOT NULL, player character varying(64), + player2 character varying(64), eventtype integer NOT NULL, generic1 integer ); diff --git a/src/Makefile b/src/Makefile index c22765e..c417080 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 +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 ifeq ($(USESTDOUT),1) O_FILES+= build/db2stdout.o @@ -87,3 +87,5 @@ build/ctfelim2db.o: oss2db/CtfElimination2Db.cpp build/point2db.o: oss2db/Point2Db.cpp oss2db/Point2Db.hpp g++ $(BASE_CFLAGS) oss2db/Point2Db.cpp -o build/point2db.o +build/harvester2db.o: oss2db/Harvester2Db.cpp oss2db/Harvester2Db.hpp + g++ $(BASE_CFLAGS) oss2db/Harvester2Db.cpp -o build/harvester2db.o diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp index e8cab62..3bb4e5b 100644 --- a/src/db/Db2DbiXX.cpp +++ b/src/db/Db2DbiXX.cpp @@ -27,6 +27,7 @@ #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')" +#define HARVESTER "INSERT INTO oastat_team_events(gamenumber,second,team,player,player2,eventtype,amount,gametype) VALUES (?,?,?,?,?,?,?,'harvester')" static string S_GETLASTGAMENUMBER = GETLASTGAMENUMBER; static string S_STARTGAME = STARTGAME; @@ -43,6 +44,7 @@ static string S_CTF = CTF; static string S_CTF1F = CTF1F; static string S_ELIMINATION = ELIMINATION; static string S_CTF_ELIM = CTF_ELIM; +static string S_HARVESTER = HARVESTER; static string booltext[2] = {"n","y"}; @@ -195,6 +197,11 @@ 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) { + *sql << S_HARVESTER,gamenumber,second,team,player1,player2,event,score,exec(); + DebugMessage("addHarvester"); +} + int Db2DbiXX::getNextGameNumber() { int result = -1; row r; diff --git a/src/db/Db2DbiXX.hpp b/src/db/Db2DbiXX.hpp index 73e1186..f618a15 100644 --- a/src/db/Db2DbiXX.hpp +++ b/src/db/Db2DbiXX.hpp @@ -37,6 +37,7 @@ public: void addCtf1f(int second, 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); private: session *sql; transaction *commitlock; diff --git a/src/db/database.hpp b/src/db/database.hpp index 6309689..af4749e 100644 --- a/src/db/database.hpp +++ b/src/db/database.hpp @@ -163,6 +163,18 @@ class Database { * @param event the event type */ virtual void addCtfElimination(int second, int roundnumber, string player, int team, int event) = 0; + + /** + * Document addHarvester(int,string,string,int,int,int) here... + * + * @param second time from gamestart + * @param player1 the player the event is about + * @param player2 the second player the event is about (player2 is fragcarrier) + * @param team the team from the logging event + * @param event the event number + * @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; }; #endif //_DATABASE_H diff --git a/src/oastat.cpp b/src/oastat.cpp index 17af8d1..2360688 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp @@ -55,6 +55,7 @@ using namespace std; #include "oss2db/Point2Db.hpp" #include "oss2db/Elimination2Db.hpp" #include "oss2db/CtfElimination2Db.hpp" +#include "oss2db/Harvester2Db.hpp" string clientIdMap[MAX_ID]; @@ -82,6 +83,7 @@ void addCommands() commands.push_back(new Ctf1f2Db()); commands.push_back(new Elimination2Db()); commands.push_back(new CtfElimination2Db()); + commands.push_back(new Harvester2Db()); //Add more commands just above here for(int i=0;igetCommand() << endl; + //cout << "checking " << commands.at(i)->getCommand() << endl; if(commands.at(i)->canProcess(oss)) { - cout << "Exectured by " << commands.at(i)->getCommand(); + //cout << "Exectured by " << commands.at(i)->getCommand(); commands.at(i)->process(oss); } /*} catch (exception &e) @@ -181,7 +183,7 @@ static int processStdIn(istream* in_p) { "oastat: Last error will be ignored" << endl; }*/ } - cout << "returned" << endl; + //cout << "returned" << endl; } } } @@ -190,7 +192,7 @@ static int processStdIn(istream* in_p) { If there is an error write it in the log and try again continue */ cerr << "oastat: Crashed (NEAR FATAL EXCEPTION) at line: \"" << line << "\"" << endl << - "oastat: Error is: " << e2.what(); + "oastat: Error is: " << e2.what() << endl; done = false; } if (!done) diff --git a/src/oss2db/Harvester2Db.cpp b/src/oss2db/Harvester2Db.cpp new file mode 100644 index 0000000..1f01c91 --- /dev/null +++ b/src/oss2db/Harvester2Db.cpp @@ -0,0 +1,37 @@ +/* + * File: Harvester2Db.cpp + * Author: poul + * + * Created on 25. februar 2011, 22:01 + */ + +#include "Harvester2Db.hpp" + +string Harvester2Db::getCommand() { + return "HARVESTER"; +} + +bool Harvester2Db::canProcess(OaStatStruct oss) { + if(oss.command != getCommand() || oss.parameters.size()<5 ) + return false; + return true; +} + +void Harvester2Db::process(OaStatStruct oss) { + if(!canProcess(oss)) + return; //Invalid oss + + string player1 = ""; //Parameter 0 + string player2 = ""; //Parameter 3 + + if(oss.parameters.at(0)>-1 && oss.parameters.at(0)-1 && oss.parameters.at(3)addHarvester(oss.second,player1,player2,oss.parameters.at(1) /*team*/,oss.parameters.at(2) /*event*/, oss.parameters.at(4) /*score*/ ); +} + diff --git a/src/oss2db/Harvester2Db.hpp b/src/oss2db/Harvester2Db.hpp new file mode 100644 index 0000000..fbedefd --- /dev/null +++ b/src/oss2db/Harvester2Db.hpp @@ -0,0 +1,25 @@ +/* + * File: Harvester2Db.hpp + * Author: poul + * + * Created on 25. februar 2011, 22:01 + */ + +#ifndef _HARVESTER2DB_HPP +#define _HARVESTER2DB_HPP + +#include "struct2db.h" +#include "../local.h" + +class Harvester2Db : public Struct2Db { +public: + string getCommand(); + bool canProcess(OaStatStruct oss); + + void process(OaStatStruct oss); +private: + +}; + +#endif /* _HARVESTER2DB_HPP */ +