Completely broken minor changes, just caching changes while moving machines

This commit is contained in:
Jett 2023-10-10 13:55:58 +00:00
parent d61d3b0ce2
commit 44a5d83b1d
4 changed files with 65 additions and 28 deletions

View File

@ -90,6 +90,11 @@ public:
// Mail Delete
virtual void DeleteMail(uint64_t id) = 0;
// Property Get
virtual uint64_t GetPropertyFromTemplateAndClone(uint32_t templateId, uint32_t cloneId) = 0;
virtual std::vector<uint32_t> GetBBBModlesForProperty(uint32_t propertyId) = 0;
virtual std::istream GetLXFMLFromID(uint32_t id) = 0;
private:
};

View File

@ -102,7 +102,8 @@ std::unique_ptr<sql::PreparedStatement> MySQLDatabase::CreatePreppedStmtUnique(c
}
std::unique_ptr<sql::ResultSet> MySQLDatabase::GetResultsOfStatement(sql::Statement* stmt) {
std::unique_ptr<sql::ResultSet> result(stmt->executeQuery());
auto* res = stmt->executeQuery();
std::unique_ptr<sql::ResultSet> result(res);
return result;
}
@ -604,4 +605,47 @@ void MySQLDatabase::RemoveAttachmentFromMail(uint64_t id) {
auto stmt = CreatePreppedStmtUnique("UPDATE mail SET attachment_lot = 0 WHERE id = ?;");
stmt->setUInt64(1, id);
stmt->execute();
}
uint64_t MySQLDatabase::GetPropertyFromTemplateAndClone(uint32_t templateId, uint32_t cloneId) {
auto stmt = CreatePreppedStmtUnique("SELECT id FROM properties WHERE template_id = ? AND clone_id = ? LIMIT 1;");
stmt->setUInt(1, templateId);
stmt->setUInt(2, cloneId);
auto res = GetResultsOfStatement(stmt.get());
while (res->next()) {
return res->getUInt64("id");
}
return 0;
}
std::vector<uint32_t> MySQLDatabase::GetBBBModlesForProperty(uint32_t propertyId) {
auto stmt = CreatePreppedStmtUnique("SELECT ugc_id FROM properties_contents WHERE lot = 14 AND property_id = ?;");
stmt->setUInt(1, propertyId);
auto res = GetResultsOfStatement(stmt.get());
std::vector<uint32_t> models;
while (res->next()) {
models.push_back(res->getUInt("ugc_id"));
}
return models;
}
std::istream* MySQLDatabase::GetLXFMLFromID(uint32_t id) {
auto stmt = CreatePreppedStmtUnique("SELECT lxfml FROM ugc WHERE id = ? LIMIT 1;");
stmt->setUInt(1, id);
auto res = GetResultsOfStatement(stmt.get());
while (res->next()) {
std::istream* blob = res->getBlob("lxfml");
return blob;
}
return new std::istream();
}

View File

@ -83,6 +83,10 @@ public:
void RemoveAttachmentFromMail(uint64_t id) override;
void DeleteMail(uint64_t id) override;
uint64_t GetPropertyFromTemplateAndClone(uint32_t templateId, uint32_t cloneId) override;
std::vector<uint32_t> GetBBBModlesForProperty(uint32_t propertyId) override;
std::istream GetLXFMLFromID(uint32_t id) override;
private:
std::string m_Host;
std::string m_Database;

View File

@ -1061,35 +1061,19 @@ void HandlePacket(Packet* packet) {
goto noBBB;
}
//Check for BBB models:
auto stmt = Database::CreatePreppedStmt("SELECT ugc_id FROM properties_contents WHERE lot=14 AND property_id=?");
int32_t templateId = result.getIntField(0);
uint64_t propertyId = Database::Connection->GetPropertyFromTemplateAndClone(result.getIntField(0), g_CloneID);
result.finalize();
auto* propertyLookup = Database::CreatePreppedStmt("SELECT * FROM properties WHERE template_id = ? AND clone_id = ?;");
// Check for BBB models
auto models = Database::Connection->GetBBBModlesForProperty(propertyId);
propertyLookup->setInt(1, templateId);
propertyLookup->setInt64(2, g_CloneID);
for (const auto& modelId : models) {
Game::logger->Log("UGC", "Getting lxfml ugcID: %u", modelId);
auto* propertyEntry = propertyLookup->executeQuery();
uint64_t propertyId = 0;
if (propertyEntry->next()) {
propertyId = propertyEntry->getUInt64(1);
}
delete propertyLookup;
stmt->setUInt64(1, propertyId);
auto res = stmt->executeQuery();
while (res->next()) {
Game::logger->Log("UGC", "Getting lxfml ugcID: %u", res->getUInt(1));
//Get lxfml:
// Get lxfml data
auto stmtL = Database::CreatePreppedStmt("SELECT lxfml from ugc where id=?");
stmtL->setUInt(1, res->getUInt(1));
stmtL->setUInt(1, modelId);
auto lxres = stmtL->executeQuery();
@ -1100,15 +1084,15 @@ void HandlePacket(Packet* packet) {
size_t lxfmlSize = lxfml->tellg();
lxfml->seekg(0);
//Send message:
// Send message
{
LWOOBJID blueprintID = res->getUInt(1);
LWOOBJID blueprintID = modelId;
GeneralUtils::SetBit(blueprintID, eObjectBits::CHARACTER);
GeneralUtils::SetBit(blueprintID, eObjectBits::PERSISTENT);
CBITSTREAM;
BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, eClientMessageType::BLUEPRINT_SAVE_RESPONSE);
bitStream.Write<LWOOBJID>(LWOOBJID_EMPTY); //always zero so that a check on the client passes
bitStream.Write<LWOOBJID>(LWOOBJID_EMPTY); // always zero so that a check on the client passes
bitStream.Write(eBlueprintSaveResponseType::EverythingWorked);
bitStream.Write<uint32_t>(1);
bitStream.Write(blueprintID);
@ -1120,7 +1104,7 @@ void HandlePacket(Packet* packet) {
SystemAddress sysAddr = packet->systemAddress;
SEND_PACKET;
PacketUtils::SavePacket("lxfml packet " + std::to_string(res->getUInt(1)) + ".bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed());
PacketUtils::SavePacket("lxfml packet " + std::to_string(modelId) + ".bin", (char*)bitStream.GetData(), bitStream.GetNumberOfBytesUsed());
}
}