mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-14 07:47:13 +00:00
When the data of a model could not be inflated, the two later position migrations went on with an empty model and wrote the result back. All three now log the model and leave its row alone. The first migration's log line also gets the model ID it formats. The client's own sd0 reader has no limit on the chunks or on the inflated size, so the limits of the reader here stay well above any model: a chunk inflates to at most 256 KiB, and 64 MiB is 256 full chunks. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
87 lines
3.7 KiB
C++
87 lines
3.7 KiB
C++
#include "ModelNormalizeMigration.h"
|
|
|
|
#include "Database.h"
|
|
#include "Lxfml.h"
|
|
#include "Sd0.h"
|
|
|
|
void ModelNormalizeMigration::Run() {
|
|
const auto oldCommit = Database::Get()->GetAutoCommit();
|
|
Database::Get()->SetAutoCommit(false);
|
|
for (auto& [lxfmlData, id, modelID] : Database::Get()->GetAllUgcModels()) {
|
|
const auto model = Database::Get()->GetModel(modelID);
|
|
// only BBB models (lot 14) and models with a position of NiPoint3::ZERO need to have their position fixed.
|
|
if (!model || model->position != NiPoint3Constant::ZERO || model->lot != 14) continue;
|
|
|
|
Sd0 sd0(lxfmlData);
|
|
const auto asStr = sd0.GetAsStringUncompressed();
|
|
if (asStr.empty()) {
|
|
// Nothing to work from, so the model stays as it is stored
|
|
LOG("Could not read the data of model %llu, leaving it as it is.", modelID);
|
|
continue;
|
|
}
|
|
const auto [newLxfml, newCenter] = Lxfml::NormalizePositionOnlyFirstPart(asStr);
|
|
if (newCenter == NiPoint3Constant::ZERO) {
|
|
LOG("Failed to update model %llu due to failure reading xml.", modelID);
|
|
continue;
|
|
}
|
|
|
|
LOG("Updated model %llu to have a center of %f %f %f", modelID, newCenter.x, newCenter.y, newCenter.z);
|
|
sd0.FromData(reinterpret_cast<const uint8_t*>(newLxfml.data()), newLxfml.size());
|
|
auto asStream = sd0.GetAsStream();
|
|
Database::Get()->UpdateModel(model->id, newCenter, model->rotation, model->behaviors);
|
|
Database::Get()->UpdateUgcModelData(id, asStream, 0);
|
|
}
|
|
Database::Get()->SetAutoCommit(oldCommit);
|
|
}
|
|
|
|
void ModelNormalizeMigration::RunAfterFirstPart() {
|
|
const auto oldCommit = Database::Get()->GetAutoCommit();
|
|
Database::Get()->SetAutoCommit(false);
|
|
for (auto& [lxfmlData, id, modelID] : Database::Get()->GetAllUgcModels()) {
|
|
const auto model = Database::Get()->GetModel(modelID);
|
|
// only BBB models (lot 14) need to have their position fixed from the above blunder
|
|
if (!model || model->lot != 14) continue;
|
|
|
|
Sd0 sd0(lxfmlData);
|
|
const auto asStr = sd0.GetAsStringUncompressed();
|
|
if (asStr.empty()) {
|
|
// Nothing to work from, so the model stays as it is stored
|
|
LOG("Could not read the data of model %llu, leaving it as it is.", modelID);
|
|
continue;
|
|
}
|
|
const auto [newLxfml, newCenter] = Lxfml::NormalizePositionAfterFirstPart(asStr, model->position);
|
|
|
|
sd0.FromData(reinterpret_cast<const uint8_t*>(newLxfml.data()), newLxfml.size());
|
|
auto asStream = sd0.GetAsStream();
|
|
Database::Get()->UpdateModel(model->id, newCenter, model->rotation, model->behaviors);
|
|
Database::Get()->UpdateUgcModelData(id, asStream, 0);
|
|
}
|
|
Database::Get()->SetAutoCommit(oldCommit);
|
|
}
|
|
|
|
void ModelNormalizeMigration::RunBrickBuildGrid() {
|
|
const auto oldCommit = Database::Get()->GetAutoCommit();
|
|
Database::Get()->SetAutoCommit(false);
|
|
for (auto& [lxfmlData, id, modelID] : Database::Get()->GetAllUgcModels()) {
|
|
const auto model = Database::Get()->GetModel(modelID);
|
|
// only BBB models (lot 14) need to have their position fixed from the above blunder
|
|
if (!model || model->lot != 14) continue;
|
|
|
|
Sd0 sd0(lxfmlData);
|
|
const auto asStr = sd0.GetAsStringUncompressed();
|
|
if (asStr.empty()) {
|
|
// Nothing to work from, so the model stays as it is stored
|
|
LOG("Could not read the data of model %llu, leaving it as it is.", modelID);
|
|
continue;
|
|
}
|
|
const auto [newLxfml, newCenter] = Lxfml::NormalizePosition(asStr, model->position);
|
|
|
|
sd0.FromData(reinterpret_cast<const uint8_t*>(newLxfml.data()), newLxfml.size());
|
|
LOG("Updated model %llu to have a center of %f %f %f", modelID, newCenter.x, newCenter.y, newCenter.z);
|
|
auto asStream = sd0.GetAsStream();
|
|
Database::Get()->UpdateModel(model->id, newCenter, model->rotation, model->behaviors);
|
|
Database::Get()->UpdateUgcModelData(id, asStream, 0);
|
|
}
|
|
Database::Get()->SetAutoCommit(oldCommit);
|
|
}
|