git repos / oastat

commit 9399fb87

sago007 · 2013-12-08 22:31
9399fb8790009d90bdc1a1ba02049c89890b0766 patch · browse files
parent 5ccb3196f39e761e562bafc101fb6401d1f2f28c

Changed style with "astyle -A10 -t -r. This is of course a rather big change. Better to do now before people fork of

Changed files

M src/db/Db2DbiXX.cpp before
M src/db/Db2Xml.cpp before
M src/oastat.cpp before
M src/oastatstruct.cpp before
M src/oss2db/Accuracy2Db.cpp before
M src/oss2db/Award2Db.cpp before
M src/oss2db/Challenge2Db.cpp before
M src/oss2db/Ctf1f2Db.cpp before
M src/oss2db/Ctf2Db.cpp before
M src/oss2db/CtfElimination2Db.cpp before
M src/oss2db/Disconnect2Db.cpp before
M src/oss2db/Elimination2Db.cpp before
M src/oss2db/Harvester2Db.cpp before
M src/oss2db/Point2Db.cpp before
M src/oss2db/Warmup2Db.cpp before
M src/oss2db/init2db.cpp before
M src/oss2db/kill2db.cpp before
M src/oss2db/shutdown2db.cpp before
M src/oss2db/userinfo2db.cpp before
diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp index 258eceb..3f3e4e5 100644 --- a/src/db/Db2DbiXX.cpp +++ b/src/db/Db2DbiXX.cpp
@@ -28,12 +28,10 @@ http://code.google.com/p/oastat/
void Db2DbiXX::InitStrings(const string &backend)
{
last_value = false;
- if(backend == "pgsql")
- {
+ if (backend == "pgsql") {
last_value = true; //Now also use last for PostgreSQL
}
- if(backend == "mysql")
- {
+ if (backend == "mysql") {
last_value = true;
}
sql_backend = backend;
@@ -45,14 +43,12 @@ void Db2DbiXX::ReadConfigFromDb()
row r;
string value;
*sql<<"SELECT thekey FROM oastat_config_uservars2save",res;
- while(res.next(r))
- {
+ while (res.next(r)) {
r >> value;
uservars2save.insert(value);
}
*sql<< "SELECT cvar FROM oastat_config_gamevars2save",res;
- while(res.next(r))
- {
+ while (res.next(r)) {
r >> value;
cvars2save.insert(value);
}
@@ -62,10 +58,11 @@ bool Db2DbiXX::IsDuplicate(const string &servername,const tm &thetime)
{
result res;
*sql << "SELECT 'X' FROM oastat_games WHERE servername = ? AND time = ?",servername,thetime,res;
- if(res.rows())
+ if (res.rows()) {
return true;
- else
+ } else {
return false;
+ }
}
Db2DbiXX::Db2DbiXX()
@@ -87,11 +84,9 @@ Db2DbiXX::Db2DbiXX(const string &dbargs)
stream >> holder;
sql = new session(holder);
InitStrings(holder);
- while(!stream.eof())
- {
+ while (!stream.eof()) {
stream >> holder;
- if(!stream.eof())
- {
+ if (!stream.eof()) {
string param;
stream >> param;
sql->param(holder,param);
@@ -126,43 +121,39 @@ void Db2DbiXX::startGame(int gametype, const string &mapname, const string &base
Rollback(); //in case there was some garbage that could be comitted (like warmup or an unfinished game)
SetOk(true);
timestamp = oss.getDateTime();
- if(oss.restOfLine.find("\\isWarmup\\1") != string::npos)
- {
+ if (oss.restOfLine.find("\\isWarmup\\1") != string::npos) {
SetOk(false);
cout << "Warmup: " << servername << ", " << oss.getTimeStamp() << endl;
return;
}
- if(IsDuplicate(servername,timestamp))
- {
+ if (IsDuplicate(servername,timestamp)) {
SetOk(false);
cout << "Duplicate:" << servername << ", " << oss.getTimeStamp() << endl;
return;
}
- if(last_value)
- {
+ if (last_value) {
*sql << "INSERT INTO oastat_games(gametype, mapname, basegame,servername,time) VALUES (?,LOWER(?),?,?,?)",gametype,mapname,basegame,servername,timestamp,exec();
gamenumber = getLastGameNumber();
- if(gamenumber < 1)
- {
+ if (gamenumber < 1) {
SetOk(false);
cout << "Must FAIL!" << endl;
}
- }
- else
- {
+ } else {
gamenumber = getNextGameNumber();
*sql << "INSERT INTO oastat_games(gamenumber,gametype, mapname, basegame,servername,time) VALUES (?,?,LOWER(?),?,?,?)",
- gamenumber,gametype,mapname,basegame,servername,timestamp,exec();
+ gamenumber,gametype,mapname,basegame,servername,timestamp,exec();
}
DebugMessage("startGame");
}
void Db2DbiXX::addGameCvar(const std::string &cvar, const std::string &value)
{
- if(!isok)
+ if (!isok) {
return;
- if(cvars2save.find(cvar) == cvars2save.end())
- return; //not to be saved
+ }
+ if (cvars2save.find(cvar) == cvars2save.end()) {
+ return; //not to be saved
+ }
*sql << "INSERT INTO oastat_gamecvars(gamenumber,cvar,value,numericvalue) VALUES (?,LOWER(?),?,?)",gamenumber,cvar,value,0,exec();
DebugMessage("addCvar");
}
@@ -172,8 +163,9 @@ void Db2DbiXX::addGameCvar(const std::string &cvar, const std::string &value)
*/
void Db2DbiXX::endGame(int second)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "UPDATE oastat_games SET second=? WHERE gamenumber = ?",second,gamenumber,exec();
Commit(); //Game have ended, transaction is in a stable state
DebugMessage("endgame");
@@ -186,31 +178,25 @@ int Db2DbiXX::getGameNumber()
void Db2DbiXX::setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill)
{
- if(!isok)
+ if (!isok) {
return;
- if(team>-1)
- {
- try
- {
+ }
+ if (team>-1) {
+ try {
*sql << "SAVEPOINT SETPLAYER",exec();
*sql << "INSERT INTO oastat_players(guid,nickname,lastseen,isBot, model, headmodel) VALUES (?,?,?,?,?,?)",guid,nickname,timestamp,(isBot? "y":"n"),model,headmodel,exec();
*sql << "RELEASE SAVEPOINT SETPLAYER",exec(); //Needed by postgresql
- }
- catch (dbixx_error &e)
- {
+ } catch (dbixx_error &e) {
DebugMessage("Already inserted? "+(string)e.what());
*sql << "ROLLBACK TO SAVEPOINT SETPLAYER",exec();
}
*sql << "UPDATE oastat_players SET nickname = ?,lastseen = ?,isBot = ?, model = ?, headmodel = ? WHERE guid = ? AND lastseen < ?",nickname,timestamp,(isBot? "y":"n"),model,headmodel,guid,timestamp,exec();
}
- try
- {
+ try {
*sql << "SAVEPOINT SETUSERINFO",exec();
*sql << "INSERT INTO oastat_userinfo(gamenumber,second,player,team,model,skill) VALUES (?,?,?,?,?,?)",gamenumber,second,getPlayerId(guid),team,model,skill,exec();
*sql << "RELEASE SAVEPOINT SETUSERINFO",exec(); //Needed by postgresql
- }
- catch (dbixx_error &e)
- {
+ } catch (dbixx_error &e) {
*sql << "ROLLBACK TO SAVEPOINT SETUSERINFO",exec();
*sql << "UPDATE oastat_userinfo SET team = ?, model = ?, skill = ? WHERE gamenumber = ? AND second = ? AND player = ?",team,model,skill,gamenumber,second,getPlayerId(guid),exec();
}
@@ -219,98 +205,107 @@ void Db2DbiXX::setPlayerInfo(const std::string &guid, const std::string &nicknam
void Db2DbiXX::addKill(int second, const std::string &attackerID, const std::string &targetID, int type)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql<< "INSERT INTO oastat_kills(gamenumber,second,attacker,target,modtype) VALUES(?,?,?,?,?)",gamenumber,second,getPlayerId(attackerID),getPlayerId(targetID),type,exec();
DebugMessage("addKill");
}
void Db2DbiXX::addAward(int second, const std::string &player, int award)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_awards(gamenumber,second,player,award) VALUES (?,?,?,?)",gamenumber,second,getPlayerId(player),award,exec();
DebugMessage("addAward");
}
void Db2DbiXX::addScoreInfo(int second, const std::string &player, int score)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_points(gamenumber,second,player,score) VALUES (?,?,?,?)",gamenumber,second,getPlayerId(player),score,exec();
DebugMessage("addScoreInfo");
}
void Db2DbiXX::addCtf(int second, const std::string &player, int team, int event)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_team_events(gamenumber,second,team,player,gametype,eventtype) VALUES (?,?,?,?,'ctf',?)",gamenumber,second,team,getPlayerId(player),event,exec();
DebugMessage("addCtf");
}
void Db2DbiXX::addCtf1f(int second, const std::string &player, int team, int event)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_team_events(gamenumber,second,team,player,gametype,eventtype) VALUES (?,?,?,?,'1fctf',?)",gamenumber,second,team,getPlayerId(player),event,exec();
DebugMessage("addCtf1f");
}
void Db2DbiXX::addElimination(int second, int roundnumber, int team, int event)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_team_events(gamenumber,second,team,eventtype,generic1,gametype) VALUES (?,?,?,?,?,'elimination')",
- gamenumber,second,team,event,roundnumber,exec();
+ gamenumber,second,team,event,roundnumber,exec();
DebugMessage("addElimination");
}
void Db2DbiXX::addCtfElimination(int second, int roundnumber, const std::string &player, int team, int event)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_team_events(gamenumber,second,team,player,eventtype,generic1,gametype) VALUES (?,?,?,?,?,?,'ctfelim')",gamenumber,second,team,getPlayerId(player),event,roundnumber,exec();
DebugMessage("addCtfElimination");
}
void Db2DbiXX::addHarvester(int second, const std::string &player1, const std::string &player2, int team, int event, int score)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_team_events(gamenumber,second,team,player,player2,eventtype,amount,gametype) VALUES (?,?,?,?,?,?,?,'harvester')",
- gamenumber,second,team,getPlayerId(player1),getPlayerId(player2),event,score,exec();
+ gamenumber,second,team,getPlayerId(player1),getPlayerId(player2),event,score,exec();
DebugMessage("addHarvester");
}
-void Db2DbiXX::addGenericTeamEvent(int second, int team, int amount, const std::string &gametype, const std::string &player1, const std::string &player2, int event, int generic1) {
- if(!isok)
+void Db2DbiXX::addGenericTeamEvent(int second, int team, int amount, const std::string &gametype, const std::string &player1, const std::string &player2, int event, int generic1)
+{
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_team_events(gamenumber,second,team,player,player2,eventtype,amount,generic1,gametype) VALUES (?,?,?,?,?,?,?,?,?)",
- gamenumber,second,team,getPlayerId(player1),getPlayerId(player2),event,amount,generic1, gametype,exec();
+ gamenumber,second,team,getPlayerId(player1),getPlayerId(player2),event,amount,generic1, gametype,exec();
DebugMessage("addGenericTeamEvent");
}
void Db2DbiXX::addChallenge(int second, const std::string &player, int challenge, int amount)
{
- if(!isok)
+ if (!isok) {
return;
+ }
*sql << "INSERT INTO oastat_challenges(gamenumber,player,challenge,amount) VALUES (?,?,?,?)",gamenumber,getPlayerId(player),challenge,amount,exec();
DebugMessage("addChallenge");
}
void Db2DbiXX::addAccuracy(int second, const std::string &player, int type, int shotsFired, int shotsHit)
{
- if(!isok)
+ if (!isok) {
return;
- try
- {
+ }
+ try {
*sql << "SAVEPOINT SETACCURACY",exec();
*sql << "INSERT INTO oastat_accuracy(gamenumber,player,shotsfired,shotshit,modtype) VALUES (?,?,?,?,?)",gamenumber,getPlayerId(player),shotsFired,shotsHit,type,exec();
*sql << "RELEASE SAVEPOINT SETACCURACY",exec(); //Needed by postgresql
- }
- catch (dbixx_error &e)
- {
+ } catch (dbixx_error &e) {
*sql << "ROLLBACK TO SAVEPOINT SETACCURACY",exec();
*sql << "UPDATE oastat_accuracy SET shotsfired = ?, shotshit = ?, modtype = ? WHERE player = ? AND gamenumber = ?",shotsFired,shotsHit,type,getPlayerId(player),gamenumber,exec();
}
@@ -322,13 +317,10 @@ int Db2DbiXX::getNextGameNumber()
row r;
*sql<< "SELECT nextval('oastat_games_gamenumber_seq')";
DebugMessage("Gettings next game number");
- if(sql->single(r))
- {
+ if (sql->single(r)) {
r>> result;
return result;
- }
- else
- {
+ } else {
throw runtime_error("Could not get next gamenumber");
}
}
@@ -337,19 +329,17 @@ int Db2DbiXX::getLastGameNumber()
{
int result = -1;
row r;
- if(sql_backend == "mysql")
+ if (sql_backend == "mysql") {
*sql << "SELECT LAST_INSERT_ID() FROM DUAL";
- else
+ } else {
*sql<< "SELECT currval('oastat_games_gamenumber_seq')";
+ }
DebugMessage("Gettings last game number");
- if(sql->single(r))
- {
+ if (sql->single(r)) {
r>> result;
cout << "Game number: " << result << endl;
return result;
- }
- else
- {
+ } else {
throw runtime_error("Could not get last gamenumber");
}
}
@@ -360,8 +350,7 @@ int Db2DbiXX::getLastGameNumber()
*/
void Db2DbiXX::Commit()
{
- if(!isok)
- {
+ if (!isok) {
Rollback();
return;
}
@@ -396,8 +385,7 @@ void Db2DbiXX::doNotCommit()
void Db2DbiXX::DebugMessage(const string &msg)
{
- if(debug)
- {
+ if (debug) {
cout << "oastat: " << msg << endl;
}
}
@@ -405,16 +393,12 @@ void Db2DbiXX::DebugMessage(const string &msg)
int Db2DbiXX::getPlayerId(const string& guid)
{
int ret = 0;
- if(playerids.count(guid))
- {
+ if (playerids.count(guid)) {
ret = playerids[guid];
- }
- else
- {
+ } else {
row r;
*sql << "SELECT playerid FROM oastat_players WHERE guid = ?",guid;
- if(sql->single(r))
- {
+ if (sql->single(r)) {
r >> ret;
playerids[guid] = ret;
}
diff --git a/src/db/Db2Xml.cpp b/src/db/Db2Xml.cpp index 4043c77..05ee609 100644 --- a/src/db/Db2Xml.cpp +++ b/src/db/Db2Xml.cpp
@@ -34,8 +34,9 @@ Db2Xml::Db2Xml()
boost::format fmkdir("mkdir -p %1%");
fmkdir % p_output_dir;
int fmkdir_ret = system(fmkdir.str().c_str());
- if(fmkdir_ret)
+ if (fmkdir_ret) {
cout << "Attemting to create \"" << path << "\" with \"" << fmkdir.str() << "\", but return code was: " << fmkdir_ret << endl;
+ }
}
Db2Xml::Db2Xml(string dbargs)
{
@@ -51,24 +52,25 @@ Db2Xml::Db2Xml(string dbargs)
stream << dbargs;
string holder;
//stream >> holder;
- while(!stream.eof())
- {
+ while (!stream.eof()) {
stream >> holder;
- if(!stream.eof())
- {
+ if (!stream.eof()) {
string param;
stream >> param;
- if(holder == "outputdir")
+ if(holder == "outputdir") {
p_output_dir = param;
- if(holder == "postscript")
+ }
+ if(holder == "postscript") {
p_postscript = param;
+ }
}
}
boost::format fmkdir("mkdir -p %1%");
fmkdir % p_output_dir;
int fmkdir_ret = system(fmkdir.str().c_str());
- if(fmkdir_ret)
+ if (fmkdir_ret) {
cout << "Attemting to create \"" << path << "\" with \"" << fmkdir.str() << "\", but return code was: " << fmkdir_ret << endl;
+ }
}
Db2Xml::Db2Xml(const Db2Xml& orig)
{
@@ -95,8 +97,9 @@ void Db2Xml::startGame(int gametype, const string &mapname, const string &basega
}
void Db2Xml::addGameCvar(const std::string &cvar, const std::string &value)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <cvar>\n";
p_xmlcontent += (boost::format(" <key>%1%</key>\n") % getXmlEscaped(cvar) ).str();
p_xmlcontent += (boost::format(" <value>%1%</value>\n") % getXmlEscaped(value) ).str();
@@ -104,8 +107,7 @@ void Db2Xml::addGameCvar(const std::string &cvar, const std::string &value)
}
void Db2Xml::endGame(int second)
{
- if(isOk)
- {
+ if (isOk) {
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += "</OaStatGame>\n";
string filename = (boost::format("%1%/%2%_%3%-%4%-%5%_%6%-%7%-%8%.xml") % p_output_dir % p_servername
@@ -113,8 +115,9 @@ void Db2Xml::endGame(int second)
% (p_gametime.tm_hour) % (p_gametime.tm_min) % (p_gametime.tm_sec) ).str();
ofstream outfile;
outfile.open (filename.c_str());
- if(outfile.fail())
+ if (outfile.fail()) {
cout << "could not create " << filename << endl;
+ }
outfile << p_xmlcontent;
outfile.close();
cout << "End game at " << second << "with size " << p_xmlcontent.length() << " written to " << filename << endl;
@@ -126,8 +129,9 @@ int Db2Xml::getGameNumber()
}
void Db2Xml::setPlayerInfo(const std::string &guid, const std::string &nickname, bool isBot, int second, int team, const std::string &model, const std::string &headmodel, int skill)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <playerinfo>\n";
p_xmlcontent += (boost::format(" <hashedguid>%1%</hashedguid>\n") % guid).str();
p_xmlcontent += (boost::format(" <playerid>%1%</playerid>\n") % getPsoudoId(guid)).str();
@@ -142,8 +146,9 @@ void Db2Xml::setPlayerInfo(const std::string &guid, const std::string &nickname,
}
void Db2Xml::addKill(int second, const std::string &attackerID, const std::string &targetID, int type)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <kill>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <attacker>%1%</attacker>\n") % attackerID).str();
@@ -154,8 +159,9 @@ void Db2Xml::addKill(int second, const std::string &attackerID, const std::strin
//void addCapture(int second, string player, int team);
void Db2Xml::addAward(int second, const std::string &player, int award)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <award>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <player>%1%</player>\n") % player).str();
@@ -164,8 +170,9 @@ void Db2Xml::addAward(int second, const std::string &player, int award)
}
void Db2Xml::addScoreInfo(int second, const std::string &player, int score)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <score>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <player>%1%</player>\n") % player).str();
@@ -174,8 +181,9 @@ void Db2Xml::addScoreInfo(int second, const std::string &player, int score)
}
void Db2Xml::addCtf(int second, const std::string &player, int team, int event)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <ctf>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <player>%1%</player>\n") % player).str();
@@ -185,8 +193,9 @@ void Db2Xml::addCtf(int second, const std::string &player, int team, int event)
}
void Db2Xml::addCtf1f(int second, const std::string &player, int team, int event)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <ctf1flag>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <player>%1%</player>\n") % player).str();
@@ -196,8 +205,9 @@ void Db2Xml::addCtf1f(int second, const std::string &player, int team, int event
}
void Db2Xml::addElimination(int second, int roundnumber, int team, int event)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <elimination>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <roundnumber>%1%</roundnumber>\n") % roundnumber).str();
@@ -207,8 +217,9 @@ void Db2Xml::addElimination(int second, int roundnumber, int team, int event)
}
void Db2Xml::addCtfElimination(int second, int roundnumber, const std::string &player, int team, int event)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <ctfelimination>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <roundnumber>%1%</roundnumber>\n") % roundnumber).str();
@@ -219,8 +230,9 @@ void Db2Xml::addCtfElimination(int second, int roundnumber, const std::string &p
}
void Db2Xml::addHarvester(int second, const std::string &player1, const std::string &player2, int team, int event, int score)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <harvester>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <player1>%1%</player1>\n") % player1).str();
@@ -231,9 +243,11 @@ void Db2Xml::addHarvester(int second, const std::string &player1, const std::str
p_xmlcontent += " </harvester>\n";
}
-void Db2Xml::addGenericTeamEvent(int second, int team, int amount, const std::string &gametype, const std::string &player1, const std::string &player2, int event, int generic1) {
- if(!isOk)
+void Db2Xml::addGenericTeamEvent(int second, int team, int amount, const std::string &gametype, const std::string &player1, const std::string &player2, int event, int generic1)
+{
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <generic_team_event>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <team>%1%</team>\n") % team).str();
@@ -248,8 +262,9 @@ void Db2Xml::addGenericTeamEvent(int second, int team, int amount, const std::st
void Db2Xml::addChallenge(int second, const std::string &player, int challenge, int amount)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <challenge>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <player>%1%</player>\n") % player).str();
@@ -258,10 +273,11 @@ void Db2Xml::addChallenge(int second, const std::string &player, int challenge,
p_xmlcontent += " </challenge>\n";
}
-void Db2Xml::addAccuracy(int second, const std::string &player, int type, int shotsFired, int shotsHit)
+void Db2Xml::addAccuracy(int second, const std::string &player, int type, int shotsFired, int shotsHit)
{
- if(!isOk)
+ if (!isOk) {
return;
+ }
p_xmlcontent += " <accuracy>\n";
p_xmlcontent += (boost::format(" <second>%1%</second>\n") % second).str();
p_xmlcontent += (boost::format(" <player>%1%</player>\n") % player).str();
@@ -279,11 +295,13 @@ void Db2Xml::doNotCommit()
int Db2Xml::getPsoudoId(const string &guid)
{
int ret = psoudo_playerids[guid];
- if(ret > 0)
+ if (ret > 0) {
return ret;
+ }
ret = nextId++;
- if(ret == 1022) //world
+ if (ret == 1022) { //world
ret = nextId++;
+ }
psoudo_playerids[guid] = ret;
return ret;
}
diff --git a/src/oastat.cpp b/src/oastat.cpp index a384ca0..0130f50 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp
@@ -71,16 +71,15 @@ static int processStdIn(istream &in_p,vector<shared_ptr<Struct2Db> > &commands);
/**
* This function adds objects that are inherited from the Struct2Db class
* to the vector commands.
- *
+ *
* @param[in] db The database object. May not be freed once given as an argument to this function
*/
static void addCommands(shared_ptr<Database> &db,vector<shared_ptr<Struct2Db> > &commands)
{
- if(!db)
- {
+ if(!db) {
throw runtime_error("db was uninizialized in addCommands");
}
-
+
//Add new commands here
commands.push_back(shared_ptr<Struct2Db>(new Kill2Db() ) );
commands.push_back(shared_ptr<Struct2Db>(new Init2Db() ) );
@@ -99,8 +98,7 @@ static void addCommands(shared_ptr<Database> &db,vector<shared_ptr<Struct2Db> >
commands.push_back(shared_ptr<Struct2Db>(new Accuracy2Db()) );
//Add more commands just above here
- for(unsigned int i=0; i<commands.size(); i++)
- {
+ for(unsigned int i=0; i<commands.size(); i++) {
commands.at(i)->setDb(db);
}
}
@@ -112,39 +110,32 @@ static int processStdIn(istream &in_p,vector<shared_ptr<Struct2Db> > &commands)
bool done = true;
OaStatStruct *startstruct;
startstruct = NULL;
- do
- {
+ do {
string line = "";
OaStatStruct oss;
list<OaStatStruct> osslist;
- try
- {
- while( getline(in_p,line) )
- {
+ try {
+ while( getline(in_p,line) ) {
oss.clear();
oss.parseLine(line);
osslist.push_back(oss);
- if(oss.command=="InitGame")
+ if(oss.command=="InitGame") {
startstruct = &osslist.back();
- if(oss.command=="Warmup" && startstruct)
- {
+ }
+ if(oss.command=="Warmup" && startstruct) {
//Workaround to stop warmup
//If we spot a warmup command we add a cvar to the start struct
//Warmup is a attribute that affect he whole game
- startstruct->restOfLine += "\\isWarmup\\1";
+ startstruct->restOfLine += "\\isWarmup\\1";
}
- if(oss.command=="ShutdownGame")
- {
- while(!osslist.empty())
- {
+ if(oss.command=="ShutdownGame") {
+ while(!osslist.empty()) {
oss = osslist.front();
osslist.pop_front();
- for(unsigned int i=0; i<commands.size(); i++)
- {
+ for(unsigned int i=0; i<commands.size(); i++) {
//try {
//cout << "checking " << commands.at(i)->getCommand() << endl;
- if(commands.at(i)->canProcess(oss))
- {
+ if(commands.at(i)->canProcess(oss)) {
//cout << "Execturedg by " << commands.at(i)->getCommand();
commands.at(i)->process(oss);
}
@@ -160,9 +151,7 @@ static int processStdIn(istream &in_p,vector<shared_ptr<Struct2Db> > &commands)
startstruct = NULL;
}
}
- }
- catch (std::exception &e2)
- {
+ } catch (std::exception &e2) {
/*
If there is an error write it in the log and try again continue
*/
@@ -171,8 +160,7 @@ static int processStdIn(istream &in_p,vector<shared_ptr<Struct2Db> > &commands)
"oastat: Error is: " << e2.what() << endl;
done = false;
}
- }
- while (!done);
+ } while (!done);
return 0;
}
@@ -192,8 +180,7 @@ string getHashedId(string unhashedID)
char *p = out;
gcry_md_hash_buffer( GCRY_MD_SHA1, hash_binary, unhashedID.c_str(), msg_len );
- for ( int i = 0; i < hash_len; i++, p += 2 )
- {
+ for ( int i = 0; i < hash_len; i++, p += 2 ) {
snprintf ( p, 3, "%02x", hash_binary[i] );
}
@@ -217,66 +204,50 @@ int main (int argc, const char* argv[])
f % getenv("HOME");
filename = f.str();
////////////
- for(int i=1; i<argc; i++)
- {
+ for(int i=1; i<argc; i++) {
bool onemore = i+1<argc;
- if (string(argv[i]) == "-dbarg" && onemore )
- {
+ if (string(argv[i]) == "-dbarg" && onemore ) {
i++;
dbargs = string(argv[i]);
}
- if (string(argv[i]) == "-f" && onemore)
- {
+ if (string(argv[i]) == "-f" && onemore) {
i++;
filename = string(argv[i]);
}
- if (string(argv[i]) == "-tail")
- {
+ if (string(argv[i]) == "-tail") {
useTail = true;
}
- if (string(argv[i]) == "-backend" && onemore)
- {
+ if (string(argv[i]) == "-backend" && onemore) {
i++;
backend = string(argv[i]);
}
- if (string(argv[i]) == "--integration-test")
- {
+ if (string(argv[i]) == "--integration-test") {
doIntegrationTest = true;
}
}
- try
- {
+ try {
shared_ptr<Database> db;
#if USEDBIXX
- if(backend == "DbiXX")
- {
+ if(backend == "DbiXX") {
cout << "Using DBI" << endl;
- if(dbargs.length()<1)
- {
+ if(dbargs.length()<1) {
db = shared_ptr<Database>(new Db2DbiXX() );
- }
- else
- {
+ } else {
db = shared_ptr<Database>(new Db2DbiXX(dbargs) );
}
}
#endif
- if(backend == "Xml")
- {
+ if(backend == "Xml") {
cout << "Using XML" << endl;
- if(dbargs.length()<1)
- {
+ if(dbargs.length()<1) {
db = shared_ptr<Database>(new Db2Xml() );
- }
- else
- {
+ } else {
db = shared_ptr<Database>(new Db2Xml(dbargs) );
}
}
- if(!db)
- {
+ if(!db) {
string error("Failed to find backend: ");
error += backend;
throw runtime_error(error);
@@ -284,8 +255,7 @@ int main (int argc, const char* argv[])
addCommands(db,commands);
- if (doIntegrationTest)
- {
+ if (doIntegrationTest) {
OaStatStruct oss_test;
oss_test.setTimeStamp("2013-12-08 20:42:30");
db->startGame(1,"oasago2","baseoa-mod","testserver",oss_test);
@@ -293,28 +263,20 @@ int main (int argc, const char* argv[])
cerr << "Test called" << endl;
return 1;
}
-
- if(filename.length()>0)
- {
- if(useTail)
- {
+
+ if(filename.length()>0) {
+ if(useTail) {
redi::ipstream in("tail -s 1 -f "+filename);
processStdIn(in,commands);
- }
- else
- {
+ } else {
ifstream in(filename.c_str(),ifstream::in);
processStdIn(in,commands);
}
- }
- else
- {
+ } else {
processStdIn(cin,commands);
}
- }
- catch (std::exception &e)
- {
+ } catch (std::exception &e) {
cout << "Crashed: " << e.what() << endl;
return 2;
}
diff --git a/src/oastatstruct.cpp b/src/oastatstruct.cpp index 43c82c7..eabdd3b 100644 --- a/src/oastatstruct.cpp +++ b/src/oastatstruct.cpp
@@ -31,14 +31,15 @@ using namespace std;
using namespace std;
-namespace {
+namespace
+{
void makeLower(string &x)
{
- for(unsigned int i=0; i<x.length(); i++)
- {
- if(x[i] >= 'A' && x[i] <= 'X')
+ for(unsigned int i=0; i<x.length(); i++) {
+ if(x[i] >= 'A' && x[i] <= 'X') {
x[i] = x[i]-'A'+'a';
+ }
}
}
@@ -92,32 +93,28 @@ void OaStatStruct::parseLine(string line)
//Parse command name:
posColon = line.find(":");
command = line.substr(0,posColon);
- try
- {
+ try {
line = line.substr(posColon+2,line.length()); //Also remove the colon and the first space after it (+2)
posColon = line.find_first_not_of(" -0123456789"); //First non-number or space
stringstream ss;
ss << line.substr(0,posColon);
int counter = 0; //to ensure that we don't go on forever
- while(ss && counter++<10)
- {
+ while(ss && counter++<10) {
int value;
ss >> value;
parameters.push_back(value);
}
- if(line.at(posColon) == ':')
- {
+ if(line.at(posColon) == ':') {
posColon++; //There is some inconsistensy about then there is a colon here
- if(line.at(posColon) == ' ')
- posColon++; //If there is a colon there is likely a space
+ if(line.at(posColon) == ' ') {
+ posColon++; //If there is a colon there is likely a space
+ }
}
line = line.substr(posColon,line.length());
- }
- catch(exception &e)
- {
+ } catch(exception &e) {
//The last part does not always exist... ignore it
restOfLine = "";
return;
@@ -135,24 +132,23 @@ map<string,string> OaStatStruct::GetInfostring(string restOfLine) const
unsigned int lastPos = 0;
bool iskey = true;
string key, value;
- if(restOfLine[0] == '\\')
+ if(restOfLine[0] == '\\') {
lastPos++;
- while(lastPos<restOfLine.length())
- {
+ }
+ while(lastPos<restOfLine.length()) {
curPos = restOfLine.find_first_of("\\", lastPos);
- if(curPos<0)
+ if(curPos<0) {
curPos = restOfLine.length();
- if(iskey)
- {
- key = restOfLine.substr(lastPos,curPos-lastPos);
}
- else
- {
+ if(iskey) {
+ key = restOfLine.substr(lastPos,curPos-lastPos);
+ } else {
value = restOfLine.substr(lastPos,curPos-lastPos);
//list.insert(pair<string,string>(key,value));
makeLower(key);
- if(key.length()>0)
+ if(key.length()>0) {
list[key] = value;
+ }
//cout << key << ":" << value << endl;
}
iskey = !iskey;
diff --git a/src/oss2db/Accuracy2Db.cpp b/src/oss2db/Accuracy2Db.cpp index 4e49e71..78b4689 100644 --- a/src/oss2db/Accuracy2Db.cpp +++ b/src/oss2db/Accuracy2Db.cpp
@@ -32,27 +32,30 @@ string Accuracy2Db::getCommand() const
bool Accuracy2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand())
+ if(oss.command != getCommand()) {
return false;
+ }
return true;
}
void Accuracy2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
- if(oss.parameters.at(0)==-1)
- return; //Not valid player
+ if(oss.parameters.at(0)==-1) {
+ return; //Not valid player
+ }
string player = clientIdMap.at(oss.parameters.at(0));
-
+
map<string,string> arguments = oss.GetInfostring();
-
+
boost::format hformat("h%1%");
boost::format fformat("f%1%");
-
- for(int i=0;i<100;++i) {
+
+ for(int i=0; i<100; ++i) {
unsigned int hits = atoi(arguments[boost::str(hformat % i)].c_str());
unsigned int fired = atoi(arguments[boost::str(fformat % i)].c_str());
if(hits || fired) {
diff --git a/src/oss2db/Award2Db.cpp b/src/oss2db/Award2Db.cpp index e3ae3b9..9821fee 100644 --- a/src/oss2db/Award2Db.cpp +++ b/src/oss2db/Award2Db.cpp
@@ -32,18 +32,21 @@ string Award2Db::getCommand() const
bool Award2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<2 || oss.parameters.at(0)<0)
+ if(oss.command != getCommand() || oss.parameters.size()<2 || oss.parameters.at(0)<0) {
return false;
+ }
return true;
}
void Award2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
- if(oss.parameters.at(0)==-1)
- return; //Not valid player
+ if(oss.parameters.at(0)==-1) {
+ return; //Not valid player
+ }
string player = clientIdMap.at(oss.parameters.at(0));
diff --git a/src/oss2db/Challenge2Db.cpp b/src/oss2db/Challenge2Db.cpp index 326881a..55494b6 100644 --- a/src/oss2db/Challenge2Db.cpp +++ b/src/oss2db/Challenge2Db.cpp
@@ -31,18 +31,21 @@ string Challenge2Db::getCommand() const
bool Challenge2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<3)
+ if(oss.command != getCommand() || oss.parameters.size()<3) {
return false;
+ }
return true;
}
void Challenge2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
- if(oss.parameters.at(0)==-1)
- return; //Not valid player
+ if(oss.parameters.at(0)==-1) {
+ return; //Not valid player
+ }
string player = clientIdMap.at(oss.parameters.at(0));
diff --git a/src/oss2db/Ctf1f2Db.cpp b/src/oss2db/Ctf1f2Db.cpp index cde002a..396b32a 100644 --- a/src/oss2db/Ctf1f2Db.cpp +++ b/src/oss2db/Ctf1f2Db.cpp
@@ -31,19 +31,22 @@ string Ctf1f2Db::getCommand() const
bool Ctf1f2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<3)
+ if(oss.command != getCommand() || oss.parameters.size()<3) {
return false;
+ }
return true;
}
void Ctf1f2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
string player = "";
- if(oss.parameters.at(0)!=-1)
+ if(oss.parameters.at(0)!=-1) {
player= clientIdMap.at(oss.parameters.at(0));
+ }
dp->addCtf1f(oss.second,player,oss.parameters.at(1) /*team*/, oss.parameters.at(2) /*event*/);
}
diff --git a/src/oss2db/Ctf2Db.cpp b/src/oss2db/Ctf2Db.cpp index 0252617..d28973e 100644 --- a/src/oss2db/Ctf2Db.cpp +++ b/src/oss2db/Ctf2Db.cpp
@@ -31,19 +31,22 @@ string Ctf2Db::getCommand() const
bool Ctf2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<3)
+ if(oss.command != getCommand() || oss.parameters.size()<3) {
return false;
+ }
return true;
}
void Ctf2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
string player = "";
- if(oss.parameters.at(0)!=-1)
+ if(oss.parameters.at(0)!=-1) {
player= clientIdMap.at(oss.parameters.at(0));
+ }
dp->addCtf(oss.second,player,oss.parameters.at(1) /*team*/, oss.parameters.at(2) /*event*/);
}
diff --git a/src/oss2db/CtfElimination2Db.cpp b/src/oss2db/CtfElimination2Db.cpp index 7eedda8..96ebd32 100644 --- a/src/oss2db/CtfElimination2Db.cpp +++ b/src/oss2db/CtfElimination2Db.cpp
@@ -30,19 +30,22 @@ string CtfElimination2Db::getCommand() const
bool CtfElimination2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<3 )
+ if(oss.command != getCommand() || oss.parameters.size()<3 ) {
return false;
+ }
return true;
}
void CtfElimination2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
string player = "";
- if(oss.parameters.at(1)!=-1)
+ if(oss.parameters.at(1)!=-1) {
player= clientIdMap.at(oss.parameters.at(1));
+ }
dp->addCtfElimination(oss.second,oss.parameters.at(0) /*roundnumber*/,
player,oss.parameters.at(2) /*team*/, oss.parameters.at(3) /*event*/);
diff --git a/src/oss2db/Disconnect2Db.cpp b/src/oss2db/Disconnect2Db.cpp index d69af61..212a97d 100644 --- a/src/oss2db/Disconnect2Db.cpp +++ b/src/oss2db/Disconnect2Db.cpp
@@ -31,15 +31,17 @@ string Disconnect2Db::getCommand() const
bool Disconnect2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<1)
+ if(oss.command != getCommand() || oss.parameters.size()<1) {
return false;
+ }
return true;
}
void Disconnect2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
string player = clientIdMap.at(oss.parameters.at(0));
diff --git a/src/oss2db/Elimination2Db.cpp b/src/oss2db/Elimination2Db.cpp index cb88d18..5dfc520 100644 --- a/src/oss2db/Elimination2Db.cpp +++ b/src/oss2db/Elimination2Db.cpp
@@ -31,15 +31,17 @@ string Elimination2Db::getCommand() const
bool Elimination2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<3 )
+ if(oss.command != getCommand() || oss.parameters.size()<3 ) {
return false;
+ }
return true;
}
void Elimination2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
dp->addElimination(oss.second,oss.parameters.at(0) /*roundnumber*/,oss.parameters.at(1) /*team*/, oss.parameters.at(2) /*event*/);
}
\ No newline at end of file
diff --git a/src/oss2db/Harvester2Db.cpp b/src/oss2db/Harvester2Db.cpp index 0747a6a..6543bba 100644 --- a/src/oss2db/Harvester2Db.cpp +++ b/src/oss2db/Harvester2Db.cpp
@@ -30,34 +30,30 @@ string Harvester2Db::getCommand() const
bool Harvester2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<5 )
+ if(oss.command != getCommand() || oss.parameters.size()<5 ) {
return false;
+ }
return true;
}
void Harvester2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid 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)<(int)clientIdMap.size() && oss.parameters.at(0)!=1022)
- {
+ if(oss.parameters.at(0)>-1 && oss.parameters.at(0)<(int)clientIdMap.size() && oss.parameters.at(0)!=1022) {
player1 = clientIdMap.at(oss.parameters.at(0));
- }
- else
- {
+ } else {
player1 = "WORLD";
}
- if(oss.parameters.at(3)>-1 && oss.parameters.at(3)<(int)clientIdMap.size() && oss.parameters.at(3)!=1022)
- {
+ if(oss.parameters.at(3)>-1 && oss.parameters.at(3)<(int)clientIdMap.size() && oss.parameters.at(3)!=1022) {
player2 = clientIdMap.at(oss.parameters.at(3));
- }
- else
- {
+ } else {
player2 = "WORLD";
}
diff --git a/src/oss2db/Point2Db.cpp b/src/oss2db/Point2Db.cpp index 7a0e46a..84544e8 100644 --- a/src/oss2db/Point2Db.cpp +++ b/src/oss2db/Point2Db.cpp
@@ -31,15 +31,17 @@ string Point2Db::getCommand() const
bool Point2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<2 || oss.parameters.at(0)<0)
+ if(oss.command != getCommand() || oss.parameters.size()<2 || oss.parameters.at(0)<0) {
return false;
+ }
return true;
}
void Point2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
string player = clientIdMap.at(oss.parameters.at(0));
diff --git a/src/oss2db/Warmup2Db.cpp b/src/oss2db/Warmup2Db.cpp index 25c1fe0..14df5b9 100644 --- a/src/oss2db/Warmup2Db.cpp +++ b/src/oss2db/Warmup2Db.cpp
@@ -30,15 +30,17 @@ string Warmup2Db::getCommand() const
bool Warmup2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand())
+ if(oss.command != getCommand()) {
return false;
+ }
return true;
}
void Warmup2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
dp->doNotCommit();
}
\ No newline at end of file
diff --git a/src/oss2db/init2db.cpp b/src/oss2db/init2db.cpp index d645b87..34732bf 100644 --- a/src/oss2db/init2db.cpp +++ b/src/oss2db/init2db.cpp
@@ -32,16 +32,18 @@ string Init2Db::getCommand() const
bool Init2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand())
+ if(oss.command != getCommand()) {
return false;
+ }
return true;
}
void Init2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
- OaStatStruct oss_copy(oss);
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
+ OaStatStruct oss_copy(oss);
map<string,string> arguments = oss_copy.GetInfostring();
int gametype = atoi(arguments["g_gametype"].c_str());
string basegame = arguments["gamename"];
@@ -51,16 +53,16 @@ void Init2Db::process(const OaStatStruct &oss)
dp->startGame(gametype,mapname,basegame,servername,oss_copy);
map<string,string>::iterator it;
- for(it = arguments.begin(); it != arguments.end(); it++)
- {
+ for(it = arguments.begin(); it != arguments.end(); it++) {
if(
it->first == "g_gametype" ||
it->first == "gamename" ||
it->first == "mapname" ||
it->first == "sv_hostname" /*||
it->first == "g_timestamp" do not skip this one*/
- )
- continue; //Skip the ones on the games-table
+ ) {
+ continue; //Skip the ones on the games-table
+ }
dp->addGameCvar(it->first,it->second);
}
}
diff --git a/src/oss2db/kill2db.cpp b/src/oss2db/kill2db.cpp index 5ee6f51..60742d8 100644 --- a/src/oss2db/kill2db.cpp +++ b/src/oss2db/kill2db.cpp
@@ -31,31 +31,31 @@ string Kill2Db::getCommand() const
bool Kill2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<=3)
+ if(oss.command != getCommand() || oss.parameters.size()<=3) {
return false;
+ }
return true;
}
void Kill2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
- return; //Invalid oss
+ if(!canProcess(oss)) {
+ return; //Invalid oss
+ }
string target = ""; //Parameter 1
string killer = ""; //Parameter 0
//mod is parameter 2
- if(oss.parameters.at(1)>-1 && oss.parameters.at(1)<(int)clientIdMap.size() && oss.parameters.at(1)!=1022 )
- {
+ if(oss.parameters.at(1)>-1 && oss.parameters.at(1)<(int)clientIdMap.size() && oss.parameters.at(1)!=1022 ) {
target = clientIdMap.at(oss.parameters.at(1));
+ } else {
+ target ="WORLD"; //Should not be possible... except maybe for NPC-creatures
}
- else
- target ="WORLD"; //Should not be possible... except maybe for NPC-creatures
- if(oss.parameters.at(0)>-1 && oss.parameters.at(0)<(int)clientIdMap.size() && oss.parameters.at(0)!=1022)
- {
+ if(oss.parameters.at(0)>-1 && oss.parameters.at(0)<(int)clientIdMap.size() && oss.parameters.at(0)!=1022) {
killer = clientIdMap.at(oss.parameters.at(0));
- }
- else
+ } else {
killer ="WORLD";
+ }
dp->addKill(oss.second,killer,target,oss.parameters.at(2));
}
diff --git a/src/oss2db/shutdown2db.cpp b/src/oss2db/shutdown2db.cpp index 20879c1..182ece2 100644 --- a/src/oss2db/shutdown2db.cpp +++ b/src/oss2db/shutdown2db.cpp
@@ -32,15 +32,17 @@ string Shutdown2Db::getCommand() const
bool Shutdown2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand())
+ if(oss.command != getCommand()) {
return false;
+ }
return true;
}
void Shutdown2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
+ if(!canProcess(oss)) {
return;
+ }
dp->endGame(oss.second);
}
diff --git a/src/oss2db/userinfo2db.cpp b/src/oss2db/userinfo2db.cpp index 7bcb209..2acf537 100644 --- a/src/oss2db/userinfo2db.cpp +++ b/src/oss2db/userinfo2db.cpp
@@ -34,31 +34,34 @@ string Userinfo2Db::getCommand() const
bool Userinfo2Db::canProcess(const OaStatStruct &oss) const
{
- if(oss.command != getCommand() || oss.parameters.size()<1)
+ if (oss.command != getCommand() || oss.parameters.size()<1) {
return false;
+ }
return true;
}
void Userinfo2Db::process(const OaStatStruct &oss)
{
- if(!canProcess(oss))
+ if (!canProcess(oss)) {
return; //Invalid oss
+ }
bool isBot = false;
map<string,string> arguments = oss.GetInfostring();
//grow clientIdMap until oss.parameters.at(0)+1
- while((int)clientIdMap.size() < oss.parameters.at(0)+2)
+ while ((int)clientIdMap.size() < oss.parameters.at(0)+2) {
clientIdMap.push_back("");
+ }
- if(arguments["id"].length()>0 || arguments["hashedid"].length() > 0) //Not bot
- {
- if(arguments["id"].length()>0)
+ if (arguments["id"].length()>0 || arguments["hashedid"].length() > 0) {
+ //Not bot
+ if(arguments["id"].length()>0) {
clientIdMap[oss.parameters.at(0)] = getHashedId(arguments["id"]);
- else
+ } else {
clientIdMap[oss.parameters.at(0)] = arguments["hashedid"];
- }
- else //bot
- {
+ }
+ } else {
+ //bot
clientIdMap[oss.parameters.at(0)] = (boost::format("%1%_client%2%") % arguments["n"] % oss.parameters.at(0) ).str();
isBot = true;
}