/* =========================================================================== oastat - OpenArena stat program Copyright (C) 2010 Poul Sander (oastat@poulsander.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA =========================================================================== */ #include "db2stdout.h" #include static int gamecount = 1; //Only to standard out, normally this should be read from db!!! /*Note: I use printf instead of cout because that is closest to the format that most databases expect. Most databases want :1,:2 instead of %s,%s and no quetes but still*/ #define STARTGAME "INSERT INTO oastat_games(gametype, mapname, basegame) VALUES (%i,'%s','%s');" #define PLAYERSINSERT "INSERT INTO oastat_players(guid,nickname,lastseen,isBot, model, headmodel) VALUES ('%s','%s',now(),%s,'%s','%s');" #define PLAYERSUPDATE "UPDATE oastat_players SET nickname = '%s',lastseen = now(),isBot = %s, model = '%s', headmodel = '%s' WHERE guid = '%s';" #define USERINFOINSERT "INSERT INTO oastat_userinfo(gamenumber,second,guid,team,model,skill) VALUES (%i,%i,'%s',%i,'%s',%i);" #define ENDGAME "UPDATE oastat_games SET second=%i,time = now() where gamenumber = %i;" #define KILL "INSERT INTO oastat_kills(gamenumber,second,attacker,target,modtype) VALUES(%i,%i,'%s','%s',%i);" #define CAPTURE "INSERT INTO oastat_captures(gamenumber,second,player,team) VALUES (%i,%i,'%s',%i);" #define AWARD "INSERT INTO oastat_awards(gamenumber,second,player,award) VALUES (%i,%i,'%s',%i);" static char* booltext[2] = {"false","true"}; DB2stdout::DB2stdout() { } DB2stdout::~DB2stdout() { } void DB2stdout::createTables() { //Nothing to do cout << "CREATE TABLE(S) ..." << endl; } void DB2stdout::startGame(int gametype, string mapname, string basegame) { printf(STARTGAME,gametype,mapname.c_str(),basegame.c_str()); cout << endl; gamecount++; //Only to standard out, normally this should be read from db!!! } int DB2stdout::getGameNumber() { return gamecount; //Only to standard out, normally this should be read from db!!! } void DB2stdout::setPlayerInfo(string guid, string nickname, bool isBot, int second, int team, string model, string headmodel, int skill) { //If team < 0 then it is a disconnect event that need not to be in if(team>-1) { printf(PLAYERSINSERT,guid.c_str(),nickname.c_str(),booltext[isBot],model.c_str(),headmodel.c_str()); cout << endl; printf(PLAYERSUPDATE,nickname.c_str(),booltext[isBot],model.c_str(),headmodel.c_str(),guid.c_str()); cout << endl; } printf(USERINFOINSERT,getGameNumber(),second,guid.c_str(),team,model.c_str(),skill); cout << endl; } void DB2stdout::addKill(int second, string attackerID, string targetID, int type) { printf(KILL,gamenumber,second,attackerID.c_str(),targetID.c_str(),type); cout << endl; } void DB2stdout::endGame(int second) { printf(ENDGAME,second,gamenumber); cout << endl; } void DB2stdout::addCapture(int second, string player, int team) { printf(CAPTURE,gamenumber,second,player.c_str(),team); cout << endl; } void DB2stdout::addAward(int second, string player, int award) { printf(AWARD,gamenumber,second,player.c_str(),award); cout << endl; }