mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-11-23 05:57:20 +00:00
3222e78815
Brick building as of right now does not implement the undo action properly. This commit addresses the issue with undoing button being non-functional server side and implements the GM needed for addressing further issues. Implement GameMessage UnUseModel which is called when a model in BrickBuilding is UnUsed. Important for UGC content down the line. Final code has been tested as follows: 1. Placed a model in brick build 2. saved placed a brick 3. repeat 2 and 3 twice more for 6 total models 4. Place a new model in brick mode and then edit all 7 models into one brick model instance 5. Pressing undo returns the converted model to the inventory and properly discards the other 6 without crashing. Intended live behavior is to store this in the inventory instead however behind the scenes work is needed to implement UGC models properly. Implement enum Implement the BlueprintSaveResponseType enum so there are less magic numbers sent via packets. Correct int sizes from unsigned int to uint32_t Add deserialize test Add a test for de-serializing a GM that is sent to the client. Assertions verify the data is in the correct order and has no extra information.
72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
#include "ObjectIDManager.h"
|
|
|
|
// Custom Classes
|
|
#include "Database.h"
|
|
#include "dLogger.h"
|
|
|
|
// Static Variables
|
|
ObjectIDManager* ObjectIDManager::m_Address = nullptr;
|
|
|
|
//! Initializes the manager
|
|
void ObjectIDManager::Initialize(dLogger* logger) {
|
|
this->mLogger = logger;
|
|
this->currentPersistentID = 1;
|
|
|
|
try {
|
|
sql::PreparedStatement* stmt = Database::CreatePreppedStmt(
|
|
"SELECT last_object_id FROM object_id_tracker");
|
|
|
|
sql::ResultSet* result = stmt->executeQuery();
|
|
auto next = result->next();
|
|
|
|
if (!next) {
|
|
sql::PreparedStatement* insertStmt = Database::CreatePreppedStmt(
|
|
"INSERT INTO object_id_tracker VALUES (1)");
|
|
|
|
insertStmt->execute();
|
|
|
|
delete insertStmt;
|
|
|
|
return;
|
|
}
|
|
|
|
while (next) {
|
|
this->currentPersistentID =
|
|
result->getInt(1) > 0 ? result->getInt(1) : 1;
|
|
next = result->next();
|
|
}
|
|
|
|
delete result;
|
|
delete stmt;
|
|
} catch (sql::SQLException& e) {
|
|
mLogger->Log("ObjectIDManager", "Unable to fetch max persistent object "
|
|
"ID in use. Defaulting to 1.");
|
|
mLogger->Log("ObjectIDManager", "SQL error: %s", e.what());
|
|
this->currentPersistentID = 1;
|
|
}
|
|
}
|
|
|
|
//! Generates a new persistent ID
|
|
uint32_t ObjectIDManager::GeneratePersistentID(void) {
|
|
uint32_t toReturn = ++this->currentPersistentID;
|
|
|
|
// So we peroidically save our ObjID to the database:
|
|
// if (toReturn % 25 == 0) { // TEMP: DISABLED FOR DEBUG / DEVELOPMENT!
|
|
sql::PreparedStatement* stmt = Database::CreatePreppedStmt(
|
|
"UPDATE object_id_tracker SET last_object_id=?");
|
|
stmt->setUInt(1, toReturn);
|
|
stmt->execute();
|
|
delete stmt;
|
|
// }
|
|
|
|
return toReturn;
|
|
}
|
|
|
|
void ObjectIDManager::SaveToDatabase() {
|
|
sql::PreparedStatement* stmt = Database::CreatePreppedStmt(
|
|
"UPDATE object_id_tracker SET last_object_id=?");
|
|
stmt->setUInt(1, currentPersistentID);
|
|
stmt->execute();
|
|
delete stmt;
|
|
}
|