From 02b2572908c4a3c103c644d07cd869781b77e71e Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Tue, 3 Dec 2024 22:09:57 -0800 Subject: [PATCH] update exception catching and sql references, remove ugc from gamemessages fix deleting model remove unrelated changes Update GameMessages.cpp --- dDatabase/GameDatabase/GameDatabase.h | 3 ++- dDatabase/GameDatabase/ITables/IUgcModularBuild.h | 14 ++++++++++++++ dDatabase/GameDatabase/MySQL/MySQLDatabase.h | 3 +++ dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt | 1 + .../GameDatabase/MySQL/Tables/UgcModularBuild.cpp | 9 +++++++++ dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h | 2 ++ dGame/dGameMessages/GameMessages.cpp | 12 ++++-------- 7 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 dDatabase/GameDatabase/ITables/IUgcModularBuild.h create mode 100644 dDatabase/GameDatabase/MySQL/Tables/UgcModularBuild.cpp diff --git a/dDatabase/GameDatabase/GameDatabase.h b/dDatabase/GameDatabase/GameDatabase.h index f52c8c4e..dcfac4a2 100644 --- a/dDatabase/GameDatabase/GameDatabase.h +++ b/dDatabase/GameDatabase/GameDatabase.h @@ -24,6 +24,7 @@ #include "IIgnoreList.h" #include "IAccountsRewardCodes.h" #include "IBehaviors.h" +#include "IUgcModularBuild.h" namespace sql { class Statement; @@ -42,7 +43,7 @@ class GameDatabase : public IPropertyContents, public IProperty, public IPetNames, public ICharXml, public IMigrationHistory, public IUgc, public IFriends, public ICharInfo, public IAccounts, public IActivityLog, public IAccountsRewardCodes, public IIgnoreList, - public IBehaviors { + public IBehaviors, public IUgcModularBuild { public: virtual ~GameDatabase() = default; // TODO: These should be made private. diff --git a/dDatabase/GameDatabase/ITables/IUgcModularBuild.h b/dDatabase/GameDatabase/ITables/IUgcModularBuild.h new file mode 100644 index 00000000..4aa2e312 --- /dev/null +++ b/dDatabase/GameDatabase/ITables/IUgcModularBuild.h @@ -0,0 +1,14 @@ +#ifndef IUGCMODULARBUILD_H +#define IUGCMODULARBUILD_H + +#include +#include +#include + +class IUgcModularBuild { +public: + virtual void InsertUgcBuild(const std::string& modules, const LWOOBJID bigId, const std::optional characterId) = 0; + virtual void DeleteUgcBuild(const LWOOBJID bigId) = 0; +}; + +#endif //!IUGCMODULARBUILD_H diff --git a/dDatabase/GameDatabase/MySQL/MySQLDatabase.h b/dDatabase/GameDatabase/MySQL/MySQLDatabase.h index 1bb2ce46..bdbdf851 100644 --- a/dDatabase/GameDatabase/MySQL/MySQLDatabase.h +++ b/dDatabase/GameDatabase/MySQL/MySQLDatabase.h @@ -7,6 +7,7 @@ #include "GameDatabase.h" typedef std::unique_ptr& UniquePreppedStmtRef; +typedef std::unique_ptr UniqueResultSet; // Purposefully no definition for this to provide linker errors in the case someone tries to // bind a parameter to a type that isn't defined. @@ -120,6 +121,8 @@ public: void UpdateScore(const uint32_t playerId, const uint32_t gameId, const Score& score) override; std::optional GetPlayerScore(const uint32_t playerId, const uint32_t gameId) override; void IncrementNumWins(const uint32_t playerId, const uint32_t gameId) override; + void InsertUgcBuild(const std::string& modules, const LWOOBJID bigId, const std::optional characterId) override; + void DeleteUgcBuild(const LWOOBJID bigId) override; private: // Generic query functions that can be used for any query. diff --git a/dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt b/dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt index 47cd220e..2f1fa6de 100644 --- a/dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt +++ b/dDatabase/GameDatabase/MySQL/Tables/CMakeLists.txt @@ -20,6 +20,7 @@ set(DDATABASES_DATABASES_MYSQL_TABLES_SOURCES "PropertyContents.cpp" "Servers.cpp" "Ugc.cpp" + "UgcModularBuild.cpp" PARENT_SCOPE ) diff --git a/dDatabase/GameDatabase/MySQL/Tables/UgcModularBuild.cpp b/dDatabase/GameDatabase/MySQL/Tables/UgcModularBuild.cpp new file mode 100644 index 00000000..a9573515 --- /dev/null +++ b/dDatabase/GameDatabase/MySQL/Tables/UgcModularBuild.cpp @@ -0,0 +1,9 @@ +#include "MySQLDatabase.h" + +void MySQLDatabase::InsertUgcBuild(const std::string& modules, const LWOOBJID bigId, const std::optional characterId) { + ExecuteInsert("INSERT INTO ugc_modular_build (ugc_id, ldf_config, character_id) VALUES (?,?,?)", bigId, modules, characterId); +} + +void MySQLDatabase::DeleteUgcBuild(const LWOOBJID bigId) { + ExecuteDelete("DELETE FROM ugc_modular_build WHERE ugc_id = ?;", bigId); +} diff --git a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h index ee9c8a70..933abf53 100644 --- a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h +++ b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h @@ -98,6 +98,8 @@ class TestSQLDatabase : public GameDatabase { void UpdateScore(const uint32_t playerId, const uint32_t gameId, const Score& score) override {}; std::optional GetPlayerScore(const uint32_t playerId, const uint32_t gameId) override {return {};}; void IncrementNumWins(const uint32_t playerId, const uint32_t gameId) override {}; + void InsertUgcBuild(const std::string& modules, const LWOOBJID bigId, const std::optional characterId) override {}; + void DeleteUgcBuild(const LWOOBJID bigId) override {}; }; #endif //!TESTSQLDATABASE_H diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index fc77e690..be034e46 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -5066,9 +5066,7 @@ void GameMessages::HandleModularBuildConvertModel(RakNet::BitStream& inStream, E item->Disassemble(TEMP_MODELS); - std::unique_ptr stmt(Database::Get()->CreatePreppedStmt("DELETE FROM ugc_modular_build where ugc_id = ?")); - stmt->setUInt64(1, item->GetSubKey()); - stmt->execute(); + Database::Get()->DeleteUgcBuild(item->GetSubKey()); item->SetCount(item->GetCount() - 1, false, false, true, eLootSourceType::QUICKBUILD); } @@ -5394,6 +5392,8 @@ void GameMessages::HandleRemoveItemFromInventory(RakNet::BitStream& inStream, En const auto itemType = static_cast(item->GetInfo().itemType); if (itemType == eItemType::MODEL || itemType == eItemType::LOOT_MODEL) { item->DisassembleModel(iStackCount); + } else if (itemType == eItemType::VEHICLE) { + Database::Get()->DeleteUgcBuild(item->GetSubKey()); } auto lot = item->GetLot(); item->SetCount(item->GetCount() - iStackCount, true); @@ -5569,12 +5569,8 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream& inStream, Entity* inv->AddItem(8092, 1, eLootSourceType::QUICKBUILD, eInventoryType::MODELS, config, LWOOBJID_EMPTY, true, false, newIdBig); } - std::unique_ptr stmt(Database::Get()->CreatePreppedStmt("INSERT INTO ugc_modular_build (ugc_id, ldf_config, character_id) VALUES (?,?,?)")); - stmt->setUInt64(1, newIdBig); - stmt->setString(2, GeneralUtils::UTF16ToWTF8(modules).c_str()); auto* pCharacter = character->GetCharacter(); - pCharacter ? stmt->setUInt(3, pCharacter->GetID()) : stmt->setNull(3, sql::DataType::BIGINT); - stmt->execute(); + Database::Get()->InsertUgcBuild(GeneralUtils::UTF16ToWTF8(modules), newIdBig, pCharacter ? std::optional(character->GetCharacter()->GetID()) : std::nullopt); auto* missionComponent = character->GetComponent();