diff --git a/sql/create_tables/oastat_create_tables_common.sql b/sql/create_tables/oastat_create_tables_common.sql index 7f91e53..104a7d8 100644 --- a/sql/create_tables/oastat_create_tables_common.sql +++ b/sql/create_tables/oastat_create_tables_common.sql @@ -8,7 +8,7 @@ SET table_type=INNODB; -- RESTRICT2MYSQL CREATE TABLE oastat_awards ( eventNumber SERIAL PRIMARY KEY, - gamenumber integer NOT NULL, + gamenumber bigint NOT NULL, second integer, player character varying(64), award integer NOT NULL @@ -51,9 +51,16 @@ CREATE TABLE oastat_games ( COMMENT ON TABLE oastat_games IS 'Has the information common for an entire match/map'; -- RESTRICT2POSTGRESQL +CREATE TABLE oastat_gamecvars ( + gamenumber bigint NOT NULL, -- will be used as primary key later + cvar character varying(100) NOT NULL, -- will be used as primary key later + value character varying(256), -- defined as MAX_CVAR_VALUE_STRING in q_shared.h + numericvalue float -- if value is a float or int, then the value will also be stored here for easier comparison +); + CREATE TABLE oastat_kills ( eventnumber SERIAL PRIMARY KEY, - gamenumber integer NOT NULL, + gamenumber bigint NOT NULL, second integer NOT NULL, attacker character varying(64) NOT NULL, target character varying(64) NOT NULL, @@ -92,6 +99,13 @@ CREATE TABLE oastat_userinfo ( second integer NOT NULL ); +CREATE TABLE oastat_uservars ( + userinfoevent bigint NOT NULL, -- will be used as primary key + key character varying(100) NOT NULL, -- will be used as primary key later + value character varying(256), + numericvalue float -- if value is a float or int, then the value will also be stored here for easier comparison +); + -- CHECKS START ALTER TABLE oastat_games @@ -105,6 +119,12 @@ ALTER TABLE oastat_games ALTER TABLE oastat_players ADD CONSTRAINT oastat_players_pk PRIMARY KEY (guid); +ALTER TABLE oastat_gamecvars + ADD CONSTRAINT oastat_gamecvars_pk PRIMARY KEY (gamenumber,cvar); + +ALTER TABLE oastat_uservars + ADD CONSTRAINT oastat_gamevars_pk PRIMARY KEY (userinfoevent,key); + -- PRIMARY KEYS END @@ -125,7 +145,7 @@ ALTER TABLE oastat_challenges -- RESTRICT2POSTGRESQL ALTER TABLE oastat_challenges -- RESTRICT2POSTGRESQL - ADD CONSTRAINT oastat_challenges_fk2 FOREIGN KEY (player) REFERENCES oastat_players(guid) ON UPDATE CASCADE ON DELETE CASCADE; -- RESTRICT2POSTGRESQL + ADD CONSTRAINT oastat_challenges_fk2 FOREIGN KEY (player) REFERENCES oastat_players(guid) ON UPDATE CASCADE ON DELETE RESTRICT; -- RESTRICT2POSTGRESQL ALTER TABLE oastat_kills -- RESTRICT2POSTGRESQL @@ -137,12 +157,18 @@ ALTER TABLE oastat_points -- RESTRICT2POSTGRESQL ALTER TABLE oastat_points -- RESTRICT2POSTGRESQL - ADD CONSTRAINT oastat_points_fk2 FOREIGN KEY (player) REFERENCES oastat_players(guid) ON UPDATE CASCADE ON DELETE CASCADE; -- RESTRICT2POSTGRESQL + ADD CONSTRAINT oastat_points_fk2 FOREIGN KEY (player) REFERENCES oastat_players(guid) ON UPDATE CASCADE ON DELETE RESTRICT; -- RESTRICT2POSTGRESQL ALTER TABLE oastat_userinfo -- RESTRICT2POSTGRESQL ADD CONSTRAINT oastat_userinfo_gn_fk FOREIGN KEY (gamenumber) REFERENCES oastat_games(gamenumber) ON UPDATE CASCADE ON DELETE CASCADE; -- RESTRICT2POSTGRESQL +ALTER TABLE oastat_gamecvars -- RESTRICT2POSTGRESQL + ADD CONSTRAINT oastat_gamecvars_gn_fk FOREIGN KEY (gamenumber) REFERENCES oastat_games(gamenumber) ON UPDATE CASCADE ON DELETE CASCADE; -- RESTRICT2POSTGRESQL + +ALTER TABLE oastat_uservars -- RESTRICT2POSTGRESQL + ADD CONSTRAINT oastat_uservars_ui_fk FOREIGN KEY (userinfoevent) REFERENCES oastat_userinfo(eventNumber) ON UPDATE CASCADE ON DELETE CASCADE; -- RESTRICT2POSTGRESQL + set foreign_key_checks = 1 ; -- RESTRICT2MYSQL -- FOREIGN KEYS END diff --git a/src/Makefile b/src/Makefile index 4cf59e0..c22765e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -4,7 +4,7 @@ USEDBIXX=1 USESTDOUT=0 BASE_LIBS=-lgcrypt -BASE_CFLAGS=-c -g +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 diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp index 105afa5..e8cab62 100644 --- a/src/db/Db2DbiXX.cpp +++ b/src/db/Db2DbiXX.cpp @@ -14,6 +14,7 @@ #define GETLASTGAMENUMBER_MYSQL "SELECT LAST_INSERT_ID() FROM DUAL" #define STARTGAME "INSERT INTO oastat_games(gamenumber,gametype, mapname, basegame,servername,time) VALUES (?,?,LOWER(?),?,?,?)" +#define ADDCVAR "INSERT INTO oastat_gamecvars(gamenumber,cvar,value,numericvalue) VALUES (?,LOWER(?),?,?)" #define STARTGAME_LASTVALUE "INSERT INTO oastat_games(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 = ? AND lastseen < ?" @@ -29,6 +30,7 @@ static string S_GETLASTGAMENUMBER = GETLASTGAMENUMBER; static string S_STARTGAME = STARTGAME; +static string S_ADDCVAR = ADDCVAR; static string S_STARTGAME_LASTVALUE = STARTGAME_LASTVALUE; static string S_PLAYERSINSERT = PLAYERSINSERT; static string S_PLAYERSUPDATE = PLAYERSUPDATE; @@ -118,6 +120,11 @@ void Db2DbiXX::startGame(int gametype, string mapname, string basegame, string s DebugMessage("startGame"); } +void Db2DbiXX::addGameCvar(string cvar, string value) { + *sql << S_ADDCVAR,gamenumber,cvar,value,0,exec(); + DebugMessage("addCvar"); +} + /* endGame is called then we finnish the game. This also means that it is safe to commit */ diff --git a/src/db/Db2DbiXX.hpp b/src/db/Db2DbiXX.hpp index 9a07b39..73e1186 100644 --- a/src/db/Db2DbiXX.hpp +++ b/src/db/Db2DbiXX.hpp @@ -25,6 +25,7 @@ public: virtual ~Db2DbiXX(); void createTables(); void startGame(int gametype, string mapname, string basegame, string servername, OaStatStruct *oss); + 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, OaStatStruct *oss); diff --git a/src/db/database.hpp b/src/db/database.hpp index d4cda6b..6309689 100644 --- a/src/db/database.hpp +++ b/src/db/database.hpp @@ -45,6 +45,14 @@ class Database { virtual void startGame(int gametype, string mapname, string basegame, string servername, OaStatStruct *oss) = 0; /** + * Adds information about a cvar to the last started game + * + * @param cvar - The name of the cvar (limited to 100 chars) + * @param value - The value of the cvar as a string + */ + virtual void addGameCvar(string cvar, string value) = 0; + + /** * Called then a game ends. * * @param second - relative time since game start diff --git a/src/oastat.cpp b/src/oastat.cpp index 64df048..17af8d1 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp @@ -22,6 +22,7 @@ Copyright (C) 2010 Poul Sander (oastat@poulsander.com) #define VERSION "0.2 BETA" #include +#include #include #include #include @@ -53,10 +54,11 @@ using namespace std; #include "oss2db/Ctf1f2Db.hpp" #include "oss2db/Point2Db.hpp" #include "oss2db/Elimination2Db.hpp" +#include "oss2db/CtfElimination2Db.hpp" string clientIdMap[MAX_ID]; -static int processStdIn(); +static int processStdIn(istream* in_p); Database *db; @@ -79,6 +81,7 @@ void addCommands() commands.push_back(new Point2Db()); commands.push_back(new Ctf1f2Db()); commands.push_back(new Elimination2Db()); + commands.push_back(new CtfElimination2Db()); //Add more commands just above here for(int i=0;i0) { + ifstream in(filename.c_str(),ifstream::in); + processStdIn(&in); + } else + processStdIn(&cin); }catch (const char *s) { cout << "Crashed: " << s << endl; @@ -130,13 +146,13 @@ int main (int argc, const char* argv[]) return 0; } -static int processStdIn() { +static int processStdIn(istream* in_p) { string line; OaStatStruct oss; list osslist; bool done = true; try{ - while( getline(cin,line) ) + while( getline(*in_p,line) ) { oss.clear(); oss.parseLine(line); @@ -145,12 +161,19 @@ static int processStdIn() { { while(!osslist.empty()) { + cout << "next: " << oss.command << endl; oss = osslist.front(); + cout << "gotten, now popping" << endl; osslist.pop_front(); + cout << "popping complete" << endl; for(int i=0;iprocess(oss); + cout << "checking " << commands.at(i)->getCommand() << endl; + if(commands.at(i)->canProcess(oss)) { + cout << "Exectured by " << commands.at(i)->getCommand(); + commands.at(i)->process(oss); + } /*} catch (exception &e) { cerr << "oastat: Sql_error at line: \"" << line << "\"" << endl << @@ -158,6 +181,7 @@ static int processStdIn() { "oastat: Last error will be ignored" << endl; }*/ } + cout << "returned" << endl; } } } @@ -170,7 +194,7 @@ static int processStdIn() { done = false; } if (!done) - return processStdIn(); + return processStdIn(in_p); return 0; } diff --git a/src/oss2db/CtfElimination2Db.hpp b/src/oss2db/CtfElimination2Db.hpp index 4587fa2..2b009d5 100644 --- a/src/oss2db/CtfElimination2Db.hpp +++ b/src/oss2db/CtfElimination2Db.hpp @@ -12,7 +12,7 @@ #include "struct2db.h" #include "../local.h" -class CtfElimination2Db : Struct2Db { +class CtfElimination2Db : public Struct2Db { public: string getCommand(); bool canProcess(OaStatStruct oss); diff --git a/src/oss2db/userinfo2db.cpp b/src/oss2db/userinfo2db.cpp index a865451..cd09172 100644 --- a/src/oss2db/userinfo2db.cpp +++ b/src/oss2db/userinfo2db.cpp @@ -42,6 +42,7 @@ void Userinfo2Db::process(OaStatStruct oss) { clientIdMap[oss.parameters.at(0)] = getHashedId(arguments["id"]); else //bot clientIdMap[oss.parameters.at(0)] = arguments["n"]; + string player = clientIdMap[oss.parameters.at(0)]; - dp->setPlayerInfo(clientIdMap[oss.parameters.at(0)],arguments["n"],arguments["id"]=="",oss.second,atoi(arguments["t"].c_str()), arguments["model"],arguments["hmodel"],-1,&oss); + dp->setPlayerInfo(player,arguments["n"],arguments["id"]=="",oss.second,atoi(arguments["t"].c_str()), arguments["model"],arguments["hmodel"],-1,&oss); }