mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-04 17:54:01 +00:00
Address Brick-By-Brick builds not properly saving and make migrations automatic (#725)
* Properly store BBB in database
Store the BBB data in the database as the received SD0 packet as opposed to just the raw lxfml. Addressed several memory leaks as well.
* Add Sd0Conversion
Add brick by brick conversion commands with 2 parameters to tell the program what to do with the data.
Add zlib -> sd0 conversion. Files look good at a glance but should be tested in game to ensure stability. Tests to come.
* moving to laptop
ignore this commit. I need to move this to my laptop
* Add functionality to delete bad models
Adds functionality to delete bad models. Models are batched together and deleted in one commit.
More testing is needed to ensure data safety. Positive tests on a live database reveal the broken models were truncated and complete ones were kept around successfully. Tests should be done to ensure larger sd0 models are properly saved and not truncated since this command should be able to be run any time.
Valgrind tests need to be run as well to ensure no memory leaks exist.
* Delete from query change
Changed from delete to delete cascade and instead deleting from properties_contents as opposed to ugc.
* Address numerous bugs
DELETE CASCADE is not a valid SQL command so this was changed to a better delete statement.
Added user confirmation before deleting a broken model.
Address appending the string model appending bad data, causing excess deletion.
Addressed memory leaks with sql::Blob
* Error handling for string
* Even more proper handling...
* Add bounds check for cli command
Output a message if a bad command is used.
Update MasterServer.cpp
* Remove user interference
-Add back in mariadb build jobs so i dont nuke others systems
- Remove all user interference and consolidate work into one command since 1 depends on the next.
* Add comments
test
Revert "test"
This reverts commit fb831f268b7a2f0ccd20595aff64902ab4f4b4ee.
* Update CMakeMariaDBLists.txt
Test
* Improve migration runner
Migration runner now runs automatically.
- Resolved an issue where extremely large sql queries caused the database to go into an invalid state.
- Made migrations run automatically on server start.
- Resolved a tiny memory leak in migration runner? (discarded returned pointer)
- Moved sd0 migrations of brick models to be run automatically with migration runner.
- Created dummy file to tell when brick migrations have been run.
* Update README
Updated the README to reflect the new server migration state.
* Make model deleter actually delete models
My complicated sql actually did nothing... Tested that this new SQL properly gets rid of bad data.
* Revert "Update CMakeMariaDBLists.txt"
This reverts commit 8b859d8529
.
This commit is contained in:
@@ -2401,63 +2401,25 @@ void GameMessages::HandleControlBehaviors(RakNet::BitStream* inStream, Entity* e
|
||||
}
|
||||
|
||||
void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {
|
||||
/*
|
||||
___ ___
|
||||
/\ /\___ _ __ ___ / __\ ___ / \_ __ __ _ __ _ ___ _ __ ___
|
||||
/ /_/ / _ \ '__/ _ \ /__\/// _ \ / /\ / '__/ _` |/ _` |/ _ \| '_ \/ __|
|
||||
/ __ / __/ | | __/ / \/ \ __/ / /_//| | | (_| | (_| | (_) | | | \__ \
|
||||
\/ /_/ \___|_| \___| \_____/\___| /___,' |_| \__,_|\__, |\___/|_| |_|___/
|
||||
|___/
|
||||
___ _
|
||||
/ __\ _____ ____ _ _ __ ___ / \
|
||||
/__\/// _ \ \ /\ / / _` | '__/ _ \/ /
|
||||
/ \/ \ __/\ V V / (_| | | | __/\_/
|
||||
\_____/\___| \_/\_/ \__,_|_| \___\/
|
||||
|
||||
<>=======()
|
||||
(/\___ /|\\ ()==========<>_
|
||||
\_/ | \\ //|\ ______/ \)
|
||||
\_| \\ // | \_/
|
||||
\|\/|\_ // /\/
|
||||
(oo)\ \_// /
|
||||
//_/\_\/ / |
|
||||
@@/ |=\ \ |
|
||||
\_=\_ \ |
|
||||
\==\ \|\_ snd
|
||||
__(\===\( )\
|
||||
(((~) __(_/ |
|
||||
(((~) \ /
|
||||
______/ /
|
||||
'------'
|
||||
*/
|
||||
|
||||
//First, we have Wincent's clean methods of reading in the data received from the client.
|
||||
LWOOBJID localId;
|
||||
uint32_t timeTaken;
|
||||
|
||||
inStream->Read(localId);
|
||||
|
||||
uint32_t ld0Size;
|
||||
inStream->Read(ld0Size);
|
||||
for (auto i = 0; i < 5; ++i) {
|
||||
uint8_t c;
|
||||
inStream->Read(c);
|
||||
}
|
||||
uint32_t sd0Size;
|
||||
inStream->Read(sd0Size);
|
||||
std::shared_ptr<char[]> sd0Data(new char[sd0Size]);
|
||||
|
||||
uint32_t lxfmlSize;
|
||||
inStream->Read(lxfmlSize);
|
||||
uint8_t* inData = static_cast<uint8_t*>(std::malloc(lxfmlSize));
|
||||
|
||||
if (inData == nullptr) {
|
||||
if (sd0Data == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < lxfmlSize; ++i) {
|
||||
for (uint32_t i = 0; i < sd0Size; ++i) {
|
||||
uint8_t c;
|
||||
inStream->Read(c);
|
||||
inData[i] = c;
|
||||
sd0Data[i] = c;
|
||||
}
|
||||
|
||||
uint32_t timeTaken;
|
||||
inStream->Read(timeTaken);
|
||||
|
||||
/*
|
||||
@@ -2469,6 +2431,8 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
|
||||
Note, in the live client it'll still display the bricks going out as they're being used, but on relog/world change,
|
||||
they reappear as we didn't take them.
|
||||
|
||||
TODO Apparently the bricks are supposed to be taken via MoveInventoryBatch?
|
||||
*/
|
||||
|
||||
////Decompress the SD0 from the client so we can process the lxfml properly
|
||||
@@ -2513,9 +2477,7 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
|
||||
auto result = query.execQuery();
|
||||
|
||||
if (result.eof() || result.fieldIsNull(0)) {
|
||||
return;
|
||||
}
|
||||
if (result.eof() || result.fieldIsNull(0)) return;
|
||||
|
||||
int templateId = result.getIntField(0);
|
||||
|
||||
@@ -2533,6 +2495,7 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
propertyId = propertyEntry->getUInt64(1);
|
||||
}
|
||||
|
||||
delete propertyEntry;
|
||||
delete propertyLookup;
|
||||
|
||||
//Insert into ugc:
|
||||
@@ -2543,7 +2506,7 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
ugcs->setInt(4, 0);
|
||||
|
||||
//whacky stream biz
|
||||
std::string s((char*)inData, lxfmlSize);
|
||||
std::string s(sd0Data.get(), sd0Size);
|
||||
std::istringstream iss(s);
|
||||
std::istream& stream = iss;
|
||||
|
||||
@@ -2558,14 +2521,14 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
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);
|
||||
stmt->setDouble(9, 0.0f);
|
||||
stmt->setDouble(10, 0.0f);
|
||||
stmt->setDouble(11, 0.0f);
|
||||
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->execute();
|
||||
delete stmt;
|
||||
|
||||
@@ -2591,38 +2554,22 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
|
||||
//Tell the client their model is saved: (this causes us to actually pop out of our current state):
|
||||
CBITSTREAM;
|
||||
PacketUtils::WriteHeader(bitStream, CLIENT, MSG_CLIENT_BLUEPRINT_SAVE_RESPONSE);
|
||||
PacketUtils::WriteHeader(bitStream, CLIENT, CLIENT::MSG_CLIENT_BLUEPRINT_SAVE_RESPONSE);
|
||||
bitStream.Write(localId);
|
||||
bitStream.Write<unsigned int>(0);
|
||||
bitStream.Write<unsigned int>(1);
|
||||
bitStream.Write(blueprintID);
|
||||
|
||||
bitStream.Write(lxfmlSize + 9);
|
||||
bitStream.Write<uint32_t>(sd0Size);
|
||||
|
||||
//Write a fake sd0 header:
|
||||
bitStream.Write<unsigned char>(0x73); //s
|
||||
bitStream.Write<unsigned char>(0x64); //d
|
||||
bitStream.Write<unsigned char>(0x30); //0
|
||||
bitStream.Write<unsigned char>(0x01); //1
|
||||
bitStream.Write<unsigned char>(0xFF); //end magic
|
||||
|
||||
bitStream.Write(lxfmlSize);
|
||||
|
||||
for (size_t i = 0; i < lxfmlSize; ++i)
|
||||
bitStream.Write(inData[i]);
|
||||
for (size_t i = 0; i < sd0Size; ++i) {
|
||||
bitStream.Write(sd0Data[i]);
|
||||
}
|
||||
|
||||
SEND_PACKET;
|
||||
PacketUtils::SavePacket("MSG_CLIENT_BLUEPRINT_SAVE_RESPONSE.bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed());
|
||||
// PacketUtils::SavePacket("MSG_CLIENT_BLUEPRINT_SAVE_RESPONSE.bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed());
|
||||
|
||||
//Now we have to construct this object:
|
||||
/*
|
||||
* This needs to be sent as config data, but I don't know how to right now.
|
||||
'blueprintid': (9, 1152921508346399522),
|
||||
'componentWhitelist': (1, 1),
|
||||
'modelType': (1, 2),
|
||||
'propertyObjectID': (7, True),
|
||||
'userModelID': (9, 1152921510759098799)
|
||||
*/
|
||||
|
||||
EntityInfo info;
|
||||
info.lot = 14;
|
||||
@@ -2653,6 +2600,7 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream* inStream, Entity* ent
|
||||
//there was an issue with builds not appearing since it was placed above ConstructEntity.
|
||||
PropertyManagementComponent::Instance()->AddModel(newEntity->GetObjectID(), newIDL);
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user