diff --git a/sql/create_tables/oastat_create_tables_common.sql b/sql/create_tables/oastat_create_tables_common.sql
index 1b46944..02a1b60 100644
--- a/sql/create_tables/oastat_create_tables_common.sql
+++ b/sql/create_tables/oastat_create_tables_common.sql
@@ -228,3 +228,23 @@ UPDATE oastat_players SET playerid = 0 WHERE guid = 'WORLD';
COMMIT;
-- STANDARD VALUES END
+
+-- VERSION 2
+
+CREATE TABLE oastat_accuracy (
+ gamenumber bigint unsigned NOT NULL,
+ player bigint unsigned NOT NULL,
+ shotsfired integer NOT NULL,
+ shotshit integer NOT NULL,
+ modtype integer NOT NULL
+);
+
+ALTER TABLE oastat_accuracy
+ ADD CONSTRAINT oastat_accuracy_pk pRIMARY KEY (gamenumber,player);
+
+ALTER TABLE oastat_accuracy
+ ADD CONSTRAINT oastat_accuracy_gn_fk FOREIGN KEY (gamenumber) REFERENCES oastat_games(gamenumber) ON UPDATE CASCADE ON DELETE CASCADE;
+
+ALTER TABLE oastat_accuracy
+ ADD CONSTRAINT oastat_accuracy_pi_fk FOREIGN KEY (player) REFERENCES oastat_players(playerid) ON UPDATE CASCADE ON DELETE RESTRICT;
+
diff --git a/src/Makefile b/src/Makefile
index b0029fb..b50cb08 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 build/harvester2db.o build/challenge2db.o build/warmup2db.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 build/challenge2db.o build/warmup2db.o build/accuracy2db.o
H_FILES=local.h oastatstruct.h oss2db/struct2db.h
@@ -104,3 +104,5 @@ build/challenge2db.o: oss2db/Challenge2Db.cpp oss2db/Challenge2Db.hpp $(H_FILES)
build/warmup2db.o: oss2db/Warmup2Db.cpp oss2db/Warmup2Db.hpp $(H_FILES)
g++ $(BASE_CFLAGS) oss2db/Warmup2Db.cpp -o build/warmup2db.o
+build/accuracy2db.o: oss2db/Accuracy2Db.cpp oss2db/Accuracy2Db.hpp $(H_FILES)
+ g++ $(BASE_CFLAGS) oss2db/Accuracy2Db.cpp -o build/accuracy2db.o
\ No newline at end of file
diff --git a/src/db/Db2DbiXX.cpp b/src/db/Db2DbiXX.cpp
index 24ba381..4222e40 100644
--- a/src/db/Db2DbiXX.cpp
+++ b/src/db/Db2DbiXX.cpp
@@ -70,6 +70,8 @@ static string S_ELIMINATION = ELIMINATION;
static string S_CTF_ELIM = CTF_ELIM;
static string S_HARVESTER = HARVESTER;
static string S_CHALLENGES = CHALLENGES;
+static string S_ACCURACYINSERT = "INSERT INTO oastat_accuracy(gamenumber,player,shotsfired,shotshit,modtype) VALUES (?,(SELECT playerid FROM oastat_players WHERE guid = ?),?,?,?)";
+static string S_ACCURACYUPDATE = "UPDATE oastat_accuracy SET shotsfired = ?, shotshit = ?, modtype = ? WHERE player = (SELECT playerid FROM oastat_players WHERE guid = ?) AND gamenumber = ?";
static string booltext[2] = {"n","y"};
@@ -341,6 +343,23 @@ void Db2DbiXX::addChallenge(int second, string player, int challenge, int amount
DebugMessage("addChallenge");
}
+void Db2DbiXX::addAccuracy(int second, string player, int type, int shotsFired, int shotsHit)
+{
+ if(!isok)
+ return;
+ try
+ {
+ *sql << "SAVEPOINT SETACCURACY",exec();
+ *sql << S_ACCURACYINSERT,gamenumber,player,shotsFired,shotsHit,type,exec();
+ *sql << "RELEASE SAVEPOINT SETACCURACY",exec(); //Needed by postgresql
+ }
+ catch (dbixx_error &e)
+ {
+ *sql << "ROLLBACK TO SAVEPOINT SETACCURACY",exec();
+ *sql << S_ACCURACYUPDATE,shotsFired,shotsHit,type,player,gamenumber,exec();
+ }
+}
+
int Db2DbiXX::getNextGameNumber()
{
int result = -1;
diff --git a/src/db/Db2DbiXX.hpp b/src/db/Db2DbiXX.hpp
index 90c0f4e..8bb282d 100644
--- a/src/db/Db2DbiXX.hpp
+++ b/src/db/Db2DbiXX.hpp
@@ -57,6 +57,7 @@ public:
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);
void addChallenge(int second, string player, int challenge, int amount);
+ void addAccuracy(int secind, string player, int type, int shotsFired, int shotsHit);
void doNotCommit();
private:
session *sql;
diff --git a/src/db/Db2Xml.cpp b/src/db/Db2Xml.cpp
index a10dc1e..e454402 100644
--- a/src/db/Db2Xml.cpp
+++ b/src/db/Db2Xml.cpp
@@ -237,6 +237,20 @@ void Db2Xml::addChallenge(int second, string player, int challenge, int amount)
p_xmlcontent += (boost::format(" %1%\n") % amount).str();
p_xmlcontent += " \n";
}
+
+void Db2Xml::addAccuracy(int second, string player, int type, int shotsFired, int shotsHit)
+{
+ if(!isOk)
+ return;
+ p_xmlcontent += " \n";
+ p_xmlcontent += (boost::format(" %1%\n") % second).str();
+ p_xmlcontent += (boost::format(" %1%\n") % player).str();
+ p_xmlcontent += (boost::format(" %1%\n") % type).str();
+ p_xmlcontent += (boost::format(" %1%\n") % shotsFired).str();
+ p_xmlcontent += (boost::format(" %1%\n") % shotsHit).str();
+ p_xmlcontent += " \n";
+}
+
void Db2Xml::doNotCommit()
{
isOk = false;
diff --git a/src/db/Db2Xml.hpp b/src/db/Db2Xml.hpp
index 85ecdfb..54eb8c3 100644
--- a/src/db/Db2Xml.hpp
+++ b/src/db/Db2Xml.hpp
@@ -59,6 +59,7 @@ public:
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);
void addChallenge(int second, string player, int challenge, int amount);
+ void addAccuracy(int secind, string player, int type, int shotsFired, int shotsHit);
void doNotCommit();
private:
string p_output_dir;
diff --git a/src/db/database.hpp b/src/db/database.hpp
index b30fc0b..72fd4f2 100644
--- a/src/db/database.hpp
+++ b/src/db/database.hpp
@@ -193,6 +193,16 @@ public:
* @param amount normally 1
*/
virtual void addChallenge(int second, string player, int challenge, int amount) = 0;
+
+ /**
+ * adds accuracy information.
+ * @param secind Time the information was given. Usually not logged as the information is for the whole match
+ * @param player Player that the information is recorded for
+ * @param type The weapon type
+ * @param shotsFired Number of shots fired in the match
+ * @param shotsHit Number of hits
+ */
+ virtual void addAccuracy(int secind, string player, int type, int shotsFired, int shotsHit) = 0;
};
#endif //_DATABASE_H
diff --git a/src/oastat.cpp b/src/oastat.cpp
index b3601da..0a4ed5c 100644
--- a/src/oastat.cpp
+++ b/src/oastat.cpp
@@ -55,6 +55,7 @@ using namespace std;
#include "oss2db/shutdown2db.h"
#include "oss2db/userinfo2db.h"
#include "oss2db/Disconnect2Db.h"
+#include "oss2db/Accuracy2Db.hpp"
#include "oss2db/Award2Db.h"
#include "oss2db/Ctf2Db.hpp"
#include "oss2db/Ctf1f2Db.hpp"
@@ -95,6 +96,7 @@ void addCommands()
commands.push_back(new Harvester2Db());
commands.push_back(new Challenge2Db());
commands.push_back(new Warmup2Db());
+ commands.push_back(new Accuracy2Db());
//Add more commands just above here
for(int i=0; i
+
+
+string Accuracy2Db::getCommand()
+{
+ return "Accuracy";
+}
+
+bool Accuracy2Db::canProcess(OaStatStruct oss)
+{
+ if(oss.command != getCommand())
+ return false;
+ return true;
+}
+
+void Accuracy2Db::process(OaStatStruct oss)
+{
+ if(!canProcess(oss))
+ return; //Invalid oss
+
+ if(oss.parameters.at(0)==-1)
+ return; //Not valid player
+
+ string player = clientIdMap.at(oss.parameters.at(0));
+
+ map arguments = oss.GetInfostring();
+
+ boost::format hformat("h%1%");
+ boost::format fformat("f%1%");
+
+ 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) {
+ dp->addAccuracy(oss.second,player,i,fired,hits);
+ }
+ }
+
+}
+
diff --git a/src/oss2db/Accuracy2Db.hpp b/src/oss2db/Accuracy2Db.hpp
new file mode 100644
index 0000000..af77c7b
--- /dev/null
+++ b/src/oss2db/Accuracy2Db.hpp
@@ -0,0 +1,40 @@
+/*
+===========================================================================
+oastat - a program for parsing log files and write the result to a database
+Copyright (C) 2012 Poul Sander
+
+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, see http://www.gnu.org/licenses/
+
+Source information and contacts persons can be found at
+http://code.google.com/p/oastat/
+===========================================================================
+*/
+
+#ifndef ACCURACY2DB_HPP
+#define ACCURACY2DB_HPP
+
+#include "struct2db.h"
+#include "../local.h"
+
+class Accuracy2Db : public Struct2Db {
+public:
+ string getCommand();
+ bool canProcess(OaStatStruct oss);
+
+ void process(OaStatStruct oss);
+private:
+};
+
+#endif /* ACCURACY2DB_HPP */
+