mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
A new server (dUgcServer, started by master with enable_ugc_server=1) that takes unprocessed ugc and ugc_modular_build rows from the database and makes what the client downloads with UGCUSE3DSERVICES: an optimized NIF (hidden faces removed, ambient occlusion baked into vertex colors) and a 128px DDS icon for player models, rendered by a software rasterizer from the client's LDD brick primitives, and icons for cars and rockets assembled from their modules per ModularBuildComponent/ModuleComponent. It serves them, with the models' LXFML, over HTTP in the client's UGCC<dc>/3DOPTIMIZED and IMAGE128DDS layout with .gz and .checksum files, and keeps its folder under a size cap. Processing state lives in ugc.is_optimized plus new processed_at, process_attempts and process_error columns (and the same on ugc_modular_build). ServiceType::UGC is appended. NifFile moves to dCommon and records named node transforms for the modules' attach points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
4.4 KiB
C++
93 lines
4.4 KiB
C++
#include "SQLiteDatabase.h"
|
|
|
|
#include <chrono>
|
|
|
|
namespace {
|
|
IUgc::ProcessInfo ReadModularProcessInfo(CppSQLite3Query& result, bool modular) {
|
|
IUgc::ProcessInfo info;
|
|
info.id = result.getInt64Field("id");
|
|
info.characterId = result.getInt64Field("character_id");
|
|
info.characterName = result.getStringField("character_name", "");
|
|
info.state = static_cast<IUgc::eProcessState>(result.getIntField("is_optimized"));
|
|
info.attempts = static_cast<uint32_t>(result.getIntField("process_attempts"));
|
|
info.processedAt = result.getInt64Field("processed_at");
|
|
info.error = result.getStringField("process_error", "");
|
|
if (modular) info.details = result.getStringField("ldf_config", "");
|
|
else info.bakeAo = result.getIntField("bake_ao") != 0;
|
|
return info;
|
|
}
|
|
|
|
int64_t UnixNow() {
|
|
return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
}
|
|
}
|
|
|
|
void SQLiteDatabase::InsertUgcBuild(const std::string& modules, const LWOOBJID bigId, const std::optional<LWOOBJID> characterId) {
|
|
ExecuteInsert("INSERT INTO ugc_modular_build (ugc_id, ldf_config, character_id) VALUES (?,?,?)", bigId, modules, characterId);
|
|
}
|
|
|
|
void SQLiteDatabase::DeleteUgcBuild(const LWOOBJID bigId) {
|
|
ExecuteDelete("DELETE FROM ugc_modular_build WHERE ugc_id = ?;", bigId);
|
|
}
|
|
|
|
std::vector<IUgcModularBuild::PendingBuild> SQLiteDatabase::GetModularBuildsToProcess(const uint32_t limit) {
|
|
auto [_, result] = ExecuteSelect("SELECT ugc_id, ldf_config, process_attempts FROM ugc_modular_build WHERE is_optimized = 0 ORDER BY process_attempts ASC, ugc_id DESC LIMIT ?;", limit);
|
|
std::vector<PendingBuild> builds;
|
|
while (!result.eof()) {
|
|
builds.push_back({ result.getInt64Field("ugc_id"), result.getStringField("ldf_config", ""), static_cast<uint32_t>(result.getIntField("process_attempts")) });
|
|
result.nextRow();
|
|
}
|
|
return builds;
|
|
}
|
|
|
|
void SQLiteDatabase::SetModularBuildProcessed(const LWOOBJID id, const IUgc::eProcessState state, const uint32_t attempts, const std::string_view error) {
|
|
ExecuteUpdate("UPDATE ugc_modular_build SET is_optimized = ?, process_attempts = ?, process_error = ?, processed_at = ? WHERE ugc_id = ?;",
|
|
static_cast<int32_t>(state), attempts, error, UnixNow(), id);
|
|
}
|
|
|
|
namespace {
|
|
const std::string MODULAR_SELECT =
|
|
"SELECT b.ugc_id AS id, b.character_id, c.name AS character_name, b.is_optimized, b.process_attempts, b.processed_at, b.process_error, b.ldf_config "
|
|
"FROM ugc_modular_build AS b LEFT JOIN charinfo AS c ON c.id = b.character_id ";
|
|
}
|
|
|
|
std::optional<IUgc::ProcessInfo> SQLiteDatabase::GetModularBuildProcessInfo(const LWOOBJID id) {
|
|
auto [_, result] = ExecuteSelect(MODULAR_SELECT + "WHERE b.ugc_id = ? LIMIT 1;", id);
|
|
if (result.eof()) return std::nullopt;
|
|
return ReadModularProcessInfo(result, true);
|
|
}
|
|
|
|
uint64_t SQLiteDatabase::ResetModularBuildProcessing(const std::optional<LWOOBJID> id, const bool failedOnly) {
|
|
if (id) return ExecuteUpdate("UPDATE ugc_modular_build SET is_optimized = 0, process_attempts = 0, process_error = '' WHERE ugc_id = ?;", *id);
|
|
if (failedOnly) return ExecuteUpdate("UPDATE ugc_modular_build SET is_optimized = 0, process_attempts = 0, process_error = '' WHERE is_optimized = 2;");
|
|
return ExecuteUpdate("UPDATE ugc_modular_build SET is_optimized = 0, process_attempts = 0, process_error = '';");
|
|
}
|
|
|
|
std::vector<IUgc::ProcessInfo> SQLiteDatabase::GetModularBuildProcessList(const std::optional<IUgc::eProcessState> state, const uint32_t offset, const uint32_t limit) {
|
|
std::vector<IUgc::ProcessInfo> list;
|
|
auto read = [&list](CppSQLite3Query& result) {
|
|
while (!result.eof()) {
|
|
list.push_back(ReadModularProcessInfo(result, true));
|
|
result.nextRow();
|
|
}
|
|
};
|
|
if (state) {
|
|
auto [_, result] = ExecuteSelect(MODULAR_SELECT + "WHERE b.is_optimized = ? ORDER BY b.ugc_id DESC LIMIT ? OFFSET ?;", static_cast<int32_t>(*state), limit, offset);
|
|
read(result);
|
|
} else {
|
|
auto [_, result] = ExecuteSelect(MODULAR_SELECT + "ORDER BY b.ugc_id DESC LIMIT ? OFFSET ?;", limit, offset);
|
|
read(result);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
std::vector<std::pair<IUgc::eProcessState, uint64_t>> SQLiteDatabase::GetModularBuildProcessCounts() {
|
|
auto [_, result] = ExecuteSelect("SELECT is_optimized, COUNT(*) AS count FROM ugc_modular_build GROUP BY is_optimized;");
|
|
std::vector<std::pair<IUgc::eProcessState, uint64_t>> counts;
|
|
while (!result.eof()) {
|
|
counts.emplace_back(static_cast<IUgc::eProcessState>(result.getIntField("is_optimized")), static_cast<uint64_t>(result.getInt64Field("count")));
|
|
result.nextRow();
|
|
}
|
|
return counts;
|
|
}
|