mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-22 21:43:35 +00:00
a60865cd19
* simplify leaderboard code, fully abstract database * update exception catching * update exception catching and sql references, remove ugc from gamemessages fix deleting model remove unrelated changes Update GameMessages.cpp * remove ugc from gamemessages * Update GameMessages.cpp * Update Leaderboard.cpp * bug fixes * fix racing leaderboard * remove extra stuff * update * add sqlite * use a default for optimizations * update sqlite * Fix limits on update and delete * fix bugs * use definition to switch between databases * add switch for different backends * fix include guard and includes * always build both * add mysql if block * Update Database.cpp * add new options and add check to prevent overriding mysql * correct config names * Update README.md * Update README.md * merge to 1 sql file for sqlite database * move to sqlite folder * add back mysql migrations * Update README.md * add migration to correct the folder name or mysql * yes aron * updates * Update CMakeLists.txt * dont use paths at all, add where check to only update if folder name still exist check also doesnt check for slashes and assumes one will be there since it will be. * default dont auto create account for releases we can change this flag * default 0 * add times played query * fix leaderboard not incrementing on a not better score * add env vars with defaults for docker * use an "enum" * default to mariadb * Update .env.example
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
#include "SQLiteDatabase.h"
|
|
|
|
#include "Database.h"
|
|
#include "Game.h"
|
|
#include "dConfig.h"
|
|
#include "Logger.h"
|
|
#include "dPlatforms.h"
|
|
|
|
// Static Variables
|
|
|
|
// Status Variables
|
|
namespace {
|
|
CppSQLite3DB* con = nullptr;
|
|
bool isConnected = false;
|
|
};
|
|
|
|
void SQLiteDatabase::Connect() {
|
|
LOG("Using SQLite database");
|
|
con = new CppSQLite3DB();
|
|
con->open(Game::config->GetValue("sqlite_database_path").c_str());
|
|
isConnected = true;
|
|
|
|
// Make sure wal is enabled for the database.
|
|
con->execQuery("PRAGMA journal_mode = WAL;");
|
|
}
|
|
|
|
void SQLiteDatabase::Destroy(std::string source) {
|
|
if (!con) return;
|
|
|
|
if (source.empty()) LOG("Destroying SQLite connection!");
|
|
else LOG("Destroying SQLite connection from %s!", source.c_str());
|
|
|
|
con->close();
|
|
delete con;
|
|
con = nullptr;
|
|
}
|
|
|
|
void SQLiteDatabase::ExecuteCustomQuery(const std::string_view query) {
|
|
con->compileStatement(query.data()).execDML();
|
|
}
|
|
|
|
CppSQLite3Statement SQLiteDatabase::CreatePreppedStmt(const std::string& query) {
|
|
return con->compileStatement(query.c_str());
|
|
}
|
|
|
|
void SQLiteDatabase::Commit() {
|
|
if (!con->IsAutoCommitOn()) con->compileStatement("COMMIT;").execDML();
|
|
}
|
|
|
|
bool SQLiteDatabase::GetAutoCommit() {
|
|
return con->IsAutoCommitOn();
|
|
}
|
|
|
|
void SQLiteDatabase::SetAutoCommit(bool value) {
|
|
if (value) {
|
|
if (GetAutoCommit()) con->compileStatement("BEGIN;").execDML();
|
|
} else {
|
|
if (!GetAutoCommit()) con->compileStatement("COMMIT;").execDML();
|
|
}
|
|
}
|
|
|
|
void SQLiteDatabase::DeleteCharacter(const uint32_t characterId) {
|
|
ExecuteDelete("DELETE FROM charxml WHERE id=?;", characterId);
|
|
ExecuteDelete("DELETE FROM command_log WHERE character_id=?;", characterId);
|
|
ExecuteDelete("DELETE FROM friends WHERE player_id=? OR friend_id=?;", characterId, characterId);
|
|
ExecuteDelete("DELETE FROM leaderboard WHERE character_id=?;", characterId);
|
|
ExecuteDelete("DELETE FROM properties_contents WHERE property_id IN (SELECT id FROM properties WHERE owner_id=?);", characterId);
|
|
ExecuteDelete("DELETE FROM properties WHERE owner_id=?;", characterId);
|
|
ExecuteDelete("DELETE FROM ugc WHERE character_id=?;", characterId);
|
|
ExecuteDelete("DELETE FROM activity_log WHERE character_id=?;", characterId);
|
|
ExecuteDelete("DELETE FROM mail WHERE receiver_id=?;", characterId);
|
|
ExecuteDelete("DELETE FROM charinfo WHERE id=?;", characterId);
|
|
}
|