git repos / oastat

commit 33e01c82

sago007 · 2010-06-07 18:48
33e01c82c9f40d25e94c78a59703f7d60c8fd8aa patch · browse files
parent 766323e5eae104a7aec2b133bd3546c4c718f362

Added award


git-svn-id: http://oastat.googlecode.com/svn/trunk@6 a36be8df-c75f-1e49-46ad-4f0ee64bdc62

Changed files

M src/Makefile before
M src/db/Db2PostgreSQL.cpp before
M src/oastat.cpp before
A src/oss2db/Award2Db.cpp
A src/oss2db/Award2Db.h
diff --git a/src/Makefile b/src/Makefile index 496d60a..0a69b8c 100644 --- a/src/Makefile +++ b/src/Makefile
@@ -5,7 +5,7 @@ USESTDOUT=0
BASE_LIBS=-lgcrypt
BASE_CFLAGS=-c -g
-O_FILES=build/oastat.o build/oastatstruct.o build/kill2db.o build/init2db.o build/shutdown2db.o build/userinfo2db.o build/disconnect2db.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
ifeq ($(USESTDOUT),1)
O_FILES+= build/db2stdout.o
@@ -52,3 +52,5 @@ build/userinfo2db.o: oss2db/userinfo2db.cpp oss2db/userinfo2db.h
build/disconnect2db.o: oss2db/Disconnect2Db.cpp oss2db/Disconnect2Db.h
g++ $(BASE_CFLAGS) oss2db/Disconnect2Db.cpp -o build/disconnect2db.o
+build/award2db.o: oss2db/Award2Db.cpp oss2db/Award2Db.h
+ g++ $(BASE_CFLAGS) oss2db/Award2Db.cpp -o build/award2db.o
diff --git a/src/db/Db2PostgreSQL.cpp b/src/db/Db2PostgreSQL.cpp index 1835dd7..ee5ce6a 100644 --- a/src/db/Db2PostgreSQL.cpp +++ b/src/db/Db2PostgreSQL.cpp
@@ -103,6 +103,7 @@ Db2PostgreSQL::Db2PostgreSQL() {
conn = PQconnectdb("dbname=oastat"); //Connect to the database
if (PQstatus(conn) == CONNECTION_BAD)
throw "Failed to open connection to DB!";
+ gamenumber = -1;
cout << "CONNECTED" << endl;
}
diff --git a/src/oastat.cpp b/src/oastat.cpp index 4b50a4a..0d50654 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp
@@ -44,6 +44,7 @@ using namespace std;
#include "oss2db/shutdown2db.h"
#include "oss2db/userinfo2db.h"
#include "oss2db/Disconnect2Db.h"
+#include "oss2db/Award2Db.h"
string clientIdMap[MAX_ID];
@@ -65,6 +66,7 @@ void addCommands()
commands.push_back(new Shutdown2Db());
commands.push_back(new Userinfo2Db());
commands.push_back(new Disconnect2Db());
+ commands.push_back(new Award2Db());
//Add more commands just above here
for(int i=0;i<commands.size();i++) {
diff --git a/src/oss2db/Award2Db.cpp b/src/oss2db/Award2Db.cpp new file mode 100644 index 0000000..e16130f --- /dev/null +++ b/src/oss2db/Award2Db.cpp
@@ -0,0 +1,32 @@
+/*
+ * File: Award2Db.cpp
+ * Author: poul
+ *
+ * Created on 7. juni 2010, 19:41
+ */
+
+#include "Award2Db.h"
+
+Award2Db::Award2Db() {
+}
+
+Award2Db::Award2Db(const Award2Db& orig) {
+}
+
+Award2Db::~Award2Db() {
+}
+
+
+
+string Award2Db::getCommand() {
+ return "Award";
+}
+
+void Award2Db::process(OaStatStruct oss) {
+ if(oss.command != getCommand() || oss.parameters.size()<2 || oss.parameters.at(0)<0)
+ return; //Invalid oss
+
+ string player = clientIdMap[oss.parameters.at(0)];
+
+ dp->addAward(oss.second,player,oss.parameters.at(1));
+}
\ No newline at end of file
diff --git a/src/oss2db/Award2Db.h b/src/oss2db/Award2Db.h new file mode 100644 index 0000000..7d9fe9a --- /dev/null +++ b/src/oss2db/Award2Db.h
@@ -0,0 +1,28 @@
+/*
+ * File: Award2Db.h
+ * Author: poul
+ *
+ * Created on 7. juni 2010, 19:41
+ */
+
+#ifndef _AWARD2DB_H
+#define _AWARD2DB_H
+
+#include "struct2db.h"
+#include "../local.h"
+
+class Award2Db : public Struct2Db {
+public:
+ Award2Db();
+ Award2Db(const Award2Db& orig);
+ virtual ~Award2Db();
+
+ string getCommand();
+
+ void process(OaStatStruct oss);
+private:
+
+};
+
+#endif /* _AWARD2DB_H */
+