git repos / oastat

commit cc41c7f8

sago007 · 2018-12-20 20:00
cc41c7f871882b6b065c864be0760844c056cfd2 patch · browse files
parent 806dd25fa0fef63516b393669484690c8ab7e344

It is now possible to load games even if g_timestamp is missing. This can be used for non OA 0.8.8 based games.

Changed files

M src/db/Db2CppDb.cpp before
M src/db/Db2CppDb.hpp before
M src/oastat.cpp before
M src/oastatstruct.cpp before
M src/oastatstruct.h before
diff --git a/src/db/Db2CppDb.cpp b/src/db/Db2CppDb.cpp index f85589c..985db6f 100644 --- a/src/db/Db2CppDb.cpp +++ b/src/db/Db2CppDb.cpp
@@ -30,12 +30,6 @@ https://github.com/sago007/oastat/
void Db2CppDb::InitStrings(const std::string &backend)
{
last_value = true;
- if (backend == "pgsql") {
- last_value = true; //Now also use last for PostgreSQL
- }
- if (backend == "mysql") {
- last_value = true;
- }
sql_backend = backend;
}
@@ -84,6 +78,7 @@ Db2CppDb::Db2CppDb(const std::string &dbargs)
InitStrings(holder);
ReadConfigFromDb();
debug = false;
+ ignoreMissingTimestamp = std::getenv(OASTAT_CPPDB_IGNORE_MISSING_TIMESTAMP);
}
@@ -104,6 +99,10 @@ void Db2CppDb::startGame(int gametype, const std::string &mapname, const std::st
Rollback(); //in case there was some garbage that could be comitted (like warmup or an unfinished game)
SetOk(false);
timestamp = oss.getDateTime();
+ if (!ignoreMissingTimestamp && oss.restOfLine.find("\\g_timestamp\\") == std::string::npos) {
+ std::cout << "g_timestamp not set! Skipping!\n";
+ return;
+ }
if (oss.restOfLine.find("\\isWarmup\\1") != std::string::npos) {
std::cout << "Warmup: " << servername << ", " << oss.getTimeStamp() << "\n";
return;
diff --git a/src/db/Db2CppDb.hpp b/src/db/Db2CppDb.hpp index 01038af..a3eec4f 100644 --- a/src/db/Db2CppDb.hpp +++ b/src/db/Db2CppDb.hpp
@@ -29,6 +29,8 @@ https://github.com/sago007/oastat/
#include <set>
#include <cppdb/frontend.h>
+#define OASTAT_CPPDB_IGNORE_MISSING_TIMESTAMP "OASTAT_CPPDB_IGNORE_MISSING_TIMESTAMP"
+
class Db2CppDb : public Database {
public:
Db2CppDb();
@@ -77,6 +79,7 @@ private:
std::map<std::string,int> playerids;
std::string sql_backend;
bool last_value = false;
+ bool ignoreMissingTimestamp = false;
std::set<std::string> cvars2save;
std::set<std::string> uservars2save;
};
diff --git a/src/oastat.cpp b/src/oastat.cpp index 0bc8664..1b974f8 100644 --- a/src/oastat.cpp +++ b/src/oastat.cpp
@@ -217,7 +217,10 @@ int main (int argc, const char* argv[])
std::cout << "cat \"~/.openarena/baseoa/games.log\" |" << argv[0] << " -f \"\" --backend \"CppDb\" --dbarg \"pgsql:database=oastat;username=openarena\"\n";
std::cout << argv[0] << " -f %APPDATA%/OpenArena/baseoa/games.log --backend \"CppDb\" --dbarg \"sqlite3:db=defoastat.db3\"\n";
std::cout << "\n";
- std::cout << "Look at https://github.com/sago007/oastat for more help and more details\n";
+ std::cout << "CppDb backend options:\n";
+ std::cout << "If the environment variable " << OASTAT_CPPDB_IGNORE_MISSING_TIMESTAMP << " is set and g_gametime is missing then oastat will use current time as timestamp\n";
+ std::cout << "Deplicate elimination will not work with " << OASTAT_CPPDB_IGNORE_MISSING_TIMESTAMP << " set\n";
+ std::cout << "\nLook at https://github.com/sago007/oastat for more help and more details\n";
return 1;
}
if (vm.count("backend")) {
diff --git a/src/oastatstruct.cpp b/src/oastatstruct.cpp index 7bfc61b..c835816 100644 --- a/src/oastatstruct.cpp +++ b/src/oastatstruct.cpp
@@ -147,6 +147,11 @@ std::string OaStatStruct::getTimeStamp() const
void OaStatStruct::setTimeStamp(const std::string &timestring)
{
+ if (timestring.empty()) {
+ std::time_t t = std::time(0);
+ _datetime = *std::gmtime(&t);
+ return;
+ }
std::stringstream ss(timestring);
std::string tmp;
getline(ss,tmp,'-');
diff --git a/src/oastatstruct.h b/src/oastatstruct.h index 3951095..758b5fe 100644 --- a/src/oastatstruct.h +++ b/src/oastatstruct.h
@@ -71,10 +71,12 @@ public:
/*
Sets _datetime. Requires input in the format: "YYYY-MM-DD HH:MM:SS"
+ * If input is blank the timestamp will be set to current UTC time.
+ * For any other input the behavior is unspecified.
*/
void setTimeStamp(const std::string &timestring);
private:
- tm _datetime = {};
+ tm _datetime = {};
};
#endif /* _OASTATSTRUCT_H */