mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 10:14:06 +00:00
refactor: Database abstraction and organization of files (#1274)
* Database: Convert to proper namespace * Database: Use base class and getter * Database: Move files around * Database: Add property Management query Database: Move over user queries Tested at gm 0 that pre-approved names are pre-approved, unapproved need moderator approval deleting characters deletes the selcted one refreshing the character page shows the last character you logged in as tested all my characters show up when i login tested that you can delete all 4 characters and the correct character is selected each time tested renaming, approving names as gm0 Database: Add ugc model getter Hey it works, look I got around the mariadb issue. Database: Add queries Database: consolidate name query Database: Add friends list query Update name of approved names query Documentation Database: Add name check Database: Add BFF Query Database: Move BFF Setter Database: Move new friend query Database: Add remove friend queries Database: Add activity log Database: Add ugc & prop content removal Database: Add model update Database: Add migration queries Database: Add character and xml queries Database: Add user queries Untested, but compiling code Need to test that new character names are properly assigned in the following scenarios gm 0 and pre-approved name gm 0 and unapproved name gm 9 and pre-approved name gm 9 and unapproved name Database: constify function arguments Database: Add pet queries * Database: Move property model queries Untested. Need to test placing a new model moving existing one removing ugc model placing ugc model moving ugc model(?) changing privacy option variously change description and name approve property can properly travel to property * Property: Move stale reference deletion * Database: Move performance update query * Database: Add bug report query * Database: Add cheat detection query * Database: Add mail send query * Untested code need to test mailing from slash command, from all users of SendMail, getting bbb of a property and sending messages to bffs * Update CDComponentsRegistryTable.h Database: Rename and add further comments Datavbase: Add comments Add some comments Build: Fix PCH directories Database: Fix time thanks apple Database: Fix compiler warnings Overload destructor Define specialty for time_t Use string instead of string_view for temp empty string Update CDTable.h Property: Update queries to use mapId Database: Reorganize Reorganize into CDClient folder and GameDatabase folder for clearer meanings and file structure Folders: Rename to GameDatabase MySQL: Remove MySQL Specifier from table Database: Move Tables to Interfaces Database: Reorder functions in header Database: Simplify property queries Database: Remove unused queries Remove extra query definitions as well Database: Consolidate User getters Database: Comment logs Update MySQLDatabase.cpp Database: Use generic code Playkey: Fix bad optional access Database: Move stuff around WorldServer: Update queries Ugc reduced by many scopes use new queries very fast tested that ugc still loads Database: Add auth queries I tested that only the correct password can sign into an account. Tested that disabled playkeys do not allow the user to play the game Database: Add donation query Database: add objectId queries Database: Add master queries Database: Fix mis-named function Database: Add slash command queries Mail: Fix itemId type CharFilter: Use new query ObjectID: Remove duplicate code SlashCommand: Update query with function Database: Add mail queries Ugc: Fix issues with saving models Resolve large scope blocks as well * Database: Add debug try catch rethrow macro * General fixes * fix play key not working * Further fixes --------- Co-authored-by: Aaron Kimbre <aronwk.aaron@gmail.com>
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "GameMessages.h"
|
||||
#include "../dDatabase/CDClientDatabase.h"
|
||||
#include "CDClientDatabase.h"
|
||||
|
||||
enum class eGameMessageType : uint16_t;
|
||||
|
||||
|
@@ -2577,70 +2577,23 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
const auto cloneId = worldId.GetCloneID();
|
||||
|
||||
auto query = CDClientDatabase::CreatePreppedStmt(
|
||||
"SELECT id FROM PropertyTemplate WHERE mapID = ?;");
|
||||
query.bind(1, (int)zoneId);
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) return;
|
||||
|
||||
int templateId = result.getIntField(0);
|
||||
|
||||
auto* propertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE template_id = ? AND clone_id = ?;");
|
||||
|
||||
propertyLookup->setInt(1, templateId);
|
||||
propertyLookup->setInt64(2, cloneId);
|
||||
|
||||
auto* propertyEntry = propertyLookup->executeQuery();
|
||||
uint64_t propertyId = 0;
|
||||
|
||||
if (propertyEntry->next()) {
|
||||
propertyId = propertyEntry->getUInt64(1);
|
||||
}
|
||||
|
||||
delete propertyEntry;
|
||||
delete propertyLookup;
|
||||
auto propertyInfo = Database::Get()->GetPropertyInfo(zoneId, cloneId);
|
||||
LWOOBJID propertyId = LWOOBJID_EMPTY;
|
||||
if (propertyInfo) propertyId = propertyInfo->id;
|
||||
|
||||
//Insert into ugc:
|
||||
auto ugcs = Database::CreatePreppedStmt("INSERT INTO `ugc`(`id`, `account_id`, `character_id`, `is_optimized`, `lxfml`, `bake_ao`, `filename`) VALUES (?,?,?,?,?,?,?)");
|
||||
ugcs->setUInt(1, blueprintIDSmall);
|
||||
ugcs->setInt(2, entity->GetParentUser()->GetAccountID());
|
||||
ugcs->setInt(3, entity->GetCharacter()->GetID());
|
||||
ugcs->setInt(4, 0);
|
||||
|
||||
//whacky stream biz
|
||||
std::string s(sd0Data.get(), sd0Size);
|
||||
std::istringstream iss(s);
|
||||
|
||||
ugcs->setBlob(5, &iss);
|
||||
ugcs->setBoolean(6, false);
|
||||
ugcs->setString(7, "weedeater.lxfml");
|
||||
ugcs->execute();
|
||||
delete ugcs;
|
||||
std::string str(sd0Data.get(), sd0Size);
|
||||
std::istringstream sd0DataStream(str);
|
||||
Database::Get()->InsertNewUgcModel(sd0DataStream, blueprintIDSmall, entity->GetParentUser()->GetAccountID(), entity->GetCharacter()->GetID());
|
||||
|
||||
//Insert into the db as a BBB model:
|
||||
auto* stmt = Database::CreatePreppedStmt("INSERT INTO `properties_contents` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||
stmt->setUInt64(1, newIDL);
|
||||
stmt->setUInt64(2, propertyId);
|
||||
stmt->setUInt(3, blueprintIDSmall);
|
||||
stmt->setUInt(4, 14); // 14 is the lot the BBB models use
|
||||
stmt->setDouble(5, 0.0f); // x
|
||||
stmt->setDouble(6, 0.0f); // y
|
||||
stmt->setDouble(7, 0.0f); // z
|
||||
stmt->setDouble(8, 0.0f); // rx
|
||||
stmt->setDouble(9, 0.0f); // ry
|
||||
stmt->setDouble(10, 0.0f); // rz
|
||||
stmt->setDouble(11, 0.0f); // rw
|
||||
stmt->setString(12, "Objects_14_name"); // Model name. TODO make this customizable
|
||||
stmt->setString(13, ""); // Model description. TODO implement this.
|
||||
stmt->setDouble(14, 0); // behavior 1. TODO implement this.
|
||||
stmt->setDouble(15, 0); // behavior 2. TODO implement this.
|
||||
stmt->setDouble(16, 0); // behavior 3. TODO implement this.
|
||||
stmt->setDouble(17, 0); // behavior 4. TODO implement this.
|
||||
stmt->setDouble(18, 0); // behavior 5. TODO implement this.
|
||||
stmt->execute();
|
||||
delete stmt;
|
||||
IPropertyContents::Model model;
|
||||
model.id = newIDL;
|
||||
model.ugcId = blueprintIDSmall;
|
||||
model.position = NiPoint3::ZERO;
|
||||
model.rotation = NiQuaternion(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
model.lot = 14;
|
||||
Database::Get()->InsertNewPropertyModel(propertyId, model, "Objects_14_name");
|
||||
|
||||
/*
|
||||
Commented out until UGC server would be updated to use a sd0 file instead of lxfml stream.
|
||||
@@ -4232,20 +4185,12 @@ void GameMessages::HandleUpdatePropertyPerformanceCost(RakNet::BitStream* inStre
|
||||
if (performanceCost == 0.0f) return;
|
||||
|
||||
auto zone = Game::zoneManager->GetZone();
|
||||
const auto& worldId = zone->GetZoneID();
|
||||
const auto cloneId = worldId.GetCloneID();
|
||||
const auto zoneId = worldId.GetMapID();
|
||||
if (!zone) {
|
||||
LOG("If you see this message, something is very wrong.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto updatePerformanceCostQuery = Database::CreatePreppedStmt("UPDATE properties SET performance_cost = ? WHERE clone_id = ? AND zone_id = ?");
|
||||
|
||||
updatePerformanceCostQuery->setDouble(1, performanceCost);
|
||||
updatePerformanceCostQuery->setInt(2, cloneId);
|
||||
updatePerformanceCostQuery->setInt(3, zoneId);
|
||||
|
||||
updatePerformanceCostQuery->executeUpdate();
|
||||
|
||||
delete updatePerformanceCostQuery;
|
||||
updatePerformanceCostQuery = nullptr;
|
||||
Database::Get()->UpdatePerformanceCost(zone->GetZoneID(), performanceCost);
|
||||
}
|
||||
|
||||
void GameMessages::HandleVehicleNotifyHitImaginationServer(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {
|
||||
@@ -5126,7 +5071,7 @@ void GameMessages::HandleModularBuildConvertModel(RakNet::BitStream* inStream, E
|
||||
|
||||
item->Disassemble(TEMP_MODELS);
|
||||
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::CreatePreppedStmt("DELETE FROM ugc_modular_build where ugc_id = ?"));
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::Get()->CreatePreppedStmt("DELETE FROM ugc_modular_build where ugc_id = ?"));
|
||||
stmt->setUInt64(1, item->GetSubKey());
|
||||
stmt->execute();
|
||||
|
||||
@@ -5629,7 +5574,7 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream* inStream, Entity*
|
||||
inv->AddItem(8092, 1, eLootSourceType::QUICKBUILD, eInventoryType::MODELS, config, LWOOBJID_EMPTY, true, false, newIdBig);
|
||||
}
|
||||
|
||||
std::unique_ptr<sql::PreparedStatement> stmt(Database::CreatePreppedStmt("INSERT INTO ugc_modular_build (ugc_id, ldf_config, character_id) VALUES (?,?,?)"));
|
||||
std::unique_ptr<sql::PreparedStatement> 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));
|
||||
auto* pCharacter = character->GetCharacter();
|
||||
@@ -5986,31 +5931,27 @@ void GameMessages::SendGetHotPropertyData(RakNet::BitStream* inStream, Entity* e
|
||||
|
||||
void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity) {
|
||||
//Definitely not stolen from autogenerated code, no sir:
|
||||
std::u16string body;
|
||||
std::string clientVersion;
|
||||
std::string nOtherPlayerID;
|
||||
std::string selection;
|
||||
uint32_t messageLength;
|
||||
int32_t reporterID = 0;
|
||||
IBugReports::Info reportInfo;
|
||||
|
||||
//Reading:
|
||||
uint32_t messageLength;
|
||||
inStream->Read(messageLength);
|
||||
|
||||
for (uint32_t i = 0; i < (messageLength); ++i) {
|
||||
uint16_t character;
|
||||
inStream->Read(character);
|
||||
body.push_back(character);
|
||||
reportInfo.body.push_back(static_cast<char>(character));
|
||||
}
|
||||
|
||||
auto character = entity->GetCharacter();
|
||||
if (character) reporterID = character->GetID();
|
||||
if (character) reportInfo.characterId = character->GetID();
|
||||
|
||||
uint32_t clientVersionLength;
|
||||
inStream->Read(clientVersionLength);
|
||||
for (unsigned int k = 0; k < clientVersionLength; k++) {
|
||||
unsigned char character;
|
||||
inStream->Read(character);
|
||||
clientVersion.push_back(character);
|
||||
reportInfo.clientVersion.push_back(character);
|
||||
}
|
||||
|
||||
uint32_t nOtherPlayerIDLength;
|
||||
@@ -6018,32 +5959,18 @@ void GameMessages::HandleReportBug(RakNet::BitStream* inStream, Entity* entity)
|
||||
for (unsigned int k = 0; k < nOtherPlayerIDLength; k++) {
|
||||
unsigned char character;
|
||||
inStream->Read(character);
|
||||
nOtherPlayerID.push_back(character);
|
||||
reportInfo.otherPlayer.push_back(character);
|
||||
}
|
||||
// Convert other player id from LWOOBJID to the database id.
|
||||
uint32_t otherPlayer = LWOOBJID_EMPTY;
|
||||
if (nOtherPlayerID != "") otherPlayer = std::atoi(nOtherPlayerID.c_str());
|
||||
|
||||
uint32_t selectionLength;
|
||||
inStream->Read(selectionLength);
|
||||
for (unsigned int k = 0; k < selectionLength; k++) {
|
||||
unsigned char character;
|
||||
inStream->Read(character);
|
||||
selection.push_back(character);
|
||||
reportInfo.selection.push_back(character);
|
||||
}
|
||||
|
||||
try {
|
||||
sql::PreparedStatement* insertBug = Database::CreatePreppedStmt("INSERT INTO `bug_reports`(body, client_version, other_player_id, selection, reporter_id) VALUES (?, ?, ?, ?, ?)");
|
||||
insertBug->setString(1, GeneralUtils::UTF16ToWTF8(body));
|
||||
insertBug->setString(2, clientVersion);
|
||||
insertBug->setString(3, std::to_string(otherPlayer));
|
||||
insertBug->setString(4, selection);
|
||||
insertBug->setInt(5, reporterID);
|
||||
insertBug->execute();
|
||||
delete insertBug;
|
||||
} catch (sql::SQLException& e) {
|
||||
LOG("Couldn't save bug report! (%s)", e.what());
|
||||
}
|
||||
Database::Get()->InsertNewBugReport(reportInfo);
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user