mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-25 06:02:49 +00:00
feat(ugc): answer the client's UGC manifest requests without 3D services
With UGCUSE3DSERVICES=7:0 (the client's default) the client asks its world for a blueprint file's MD5 and size (REQUEST_UGC_MANIFEST_INFO, world 27) and then downloads BrickModels/UserMade/<id % 1000>/<id>.<ext>.sd0. Layouts checked in the 1.10.64 client: the request is a u64 blueprint id and a u8 resource type; the answer (UGC_MANIFEST_RESPONSE, client 60) repeats them and adds a u8 valid, the u32 size and the 16 byte MD5 of the inflated file, 37 bytes after the 0x53 exactly or the client drops it. - dNet: WorldPackets::RequestUgcManifestInfo, ClientPackets::UgcManifestResponse (eUgcResourceType), with byte tests against the client's layouts. - Database: ugc_file_checksums (per model or module combination and file) and ugc_modular_build.combination_id (migrations 89 / 72), GetUgcFileChecksum looks a blueprint up as a model, else as a build through its combination. - UGC server: every download is also written as .sd0 (Sd0::Compress); workers hand the checksums back and the main thread stores them; old items get their sd0 icon and checksum, and builds their combination id, once at start-up, a few per tick; serves <dir>/BrickModels/UserMade/<bucket>/<id>.<ext>.sd0 under client_path, /<folder>/UserBrickModels and the root (.hkx 404). - World: UgcManifest answers on the main thread with one indexed query per request; files not made yet are answered when they are (looked at again every 5 seconds), and a model in its quiet period is made right away. No worker threads, HTTP or file reads in the world. Off by default (ugc_manifest=0): checked in game, the client then downloads from http://127.0.0.1:80/lwoclient/UserBrickModels/ whatever its boot.cfg says and logs the player out when it can't connect, so icons need the UGC server on port 80 of each player's machine. docs/UgcServer.md has the details. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -107,5 +107,26 @@ public:
|
||||
|
||||
// How many models are in each state
|
||||
virtual std::vector<std::pair<eProcessState, uint64_t>> GetUgcProcessCounts() = 0;
|
||||
|
||||
// ---- Checksums of the files the UGC server made (ugc_file_checksums), for the client's manifest requests ----
|
||||
|
||||
// What the files are stored under: a player model's ugc id, or a combination of car or rocket modules
|
||||
enum class eFileOwner : int32_t {
|
||||
MODEL = 0,
|
||||
COMBINATION = 1
|
||||
};
|
||||
|
||||
// A made file as the client has it after inflating the download: its MD5 (32 lowercase hex digits) and size
|
||||
struct FileChecksum {
|
||||
std::string md5;
|
||||
uint32_t size{};
|
||||
};
|
||||
|
||||
// Records (or replaces) the checksum of a made file, e.g. "icon.dds" or "model.nif"
|
||||
virtual void SetUgcFileChecksum(const eFileOwner owner, const LWOOBJID storageId, const std::string_view file, const std::string_view md5, const uint32_t size) = 0;
|
||||
|
||||
// The checksum of a blueprint's file: a player model's (the blueprint is its ugc id), else a car or rocket build's
|
||||
// (the blueprint is its ugc_modular_build id; the file is its combination's)
|
||||
virtual std::optional<FileChecksum> GetUgcFileChecksum(const LWOOBJID blueprintId, const std::string_view file) = 0;
|
||||
};
|
||||
#endif //!__IUGC__H__
|
||||
|
||||
@@ -29,6 +29,12 @@ public:
|
||||
virtual std::vector<IUgc::ProcessInfo> GetModularBuildProcessList(const std::optional<IUgc::eProcessState> state, const std::string_view search, const uint32_t offset, const uint32_t limit) = 0;
|
||||
virtual std::vector<std::pair<IUgc::eProcessState, uint64_t>> GetModularBuildProcessCounts() = 0;
|
||||
|
||||
// The combination of modules a build was made as (UgcModularKey::StorageId of its modules), whose files it shares
|
||||
virtual void SetModularBuildCombination(const LWOOBJID id, const LWOOBJID combinationId) = 0;
|
||||
|
||||
// Up to `limit` builds whose combination isn't recorded yet (combination_id 0): their ids and modules
|
||||
virtual std::vector<PendingBuild> GetModularBuildsWithoutCombination(const uint32_t limit) = 0;
|
||||
|
||||
// How many builds there are of each ldf_config as stored (the same modules may be written differently)
|
||||
virtual std::vector<std::pair<std::string, uint64_t>> GetModularBuildConfigCounts() = 0;
|
||||
|
||||
|
||||
@@ -429,6 +429,10 @@ public:
|
||||
void DeleteUgcIconSettings(const std::string_view target) override;
|
||||
void SetUgcModelProcessed(const LWOOBJID id, const eProcessState state, const uint32_t attempts, const std::string_view error, const bool bakeAo) override;
|
||||
void SetUgcModelStats(const LWOOBJID id, const uint32_t bricks, const uint32_t triangles) override;
|
||||
void SetUgcFileChecksum(const eFileOwner owner, const LWOOBJID storageId, const std::string_view file, const std::string_view md5, const uint32_t size) override;
|
||||
std::optional<IUgc::FileChecksum> GetUgcFileChecksum(const LWOOBJID blueprintId, const std::string_view file) override;
|
||||
void SetModularBuildCombination(const LWOOBJID id, const LWOOBJID combinationId) override;
|
||||
std::vector<IUgcModularBuild::PendingBuild> GetModularBuildsWithoutCombination(const uint32_t limit) override;
|
||||
std::optional<IUgc::ProcessInfo> GetUgcProcessInfo(const LWOOBJID id) override;
|
||||
uint64_t ResetUgcModelProcessing(const std::optional<LWOOBJID> id, const bool failedOnly) override;
|
||||
std::vector<IUgc::ProcessInfo> GetUgcProcessList(const std::optional<eProcessState> state, const std::string_view search, const uint32_t offset, const uint32_t limit) override;
|
||||
|
||||
@@ -181,3 +181,16 @@ void MySQLDatabase::ExpediteUgcModels(const LWOOBJID characterId) {
|
||||
void MySQLDatabase::SetUgcModelStats(const LWOOBJID id, const uint32_t bricks, const uint32_t triangles) {
|
||||
ExecuteUpdate("UPDATE ugc SET brick_count = ?, triangle_count = ? WHERE id = ?;", bricks, triangles, id);
|
||||
}
|
||||
|
||||
void MySQLDatabase::SetUgcFileChecksum(const eFileOwner owner, const LWOOBJID storageId, const std::string_view file, const std::string_view md5, const uint32_t size) {
|
||||
ExecuteInsert("INSERT INTO ugc_file_checksums (kind, storage_id, file, md5, size) VALUES (?, ?, ?, ?, ?) "
|
||||
"ON DUPLICATE KEY UPDATE md5 = VALUES(md5), size = VALUES(size);", static_cast<int32_t>(owner), storageId, file, md5, size);
|
||||
}
|
||||
|
||||
std::optional<IUgc::FileChecksum> MySQLDatabase::GetUgcFileChecksum(const LWOOBJID blueprintId, const std::string_view file) {
|
||||
auto result = ExecuteSelect("SELECT md5, size FROM ugc_file_checksums WHERE kind = 0 AND storage_id = ? AND file = ? "
|
||||
"UNION ALL SELECT f.md5, f.size FROM ugc_modular_build b JOIN ugc_file_checksums f ON f.kind = 1 AND f.storage_id = b.combination_id AND f.file = ? "
|
||||
"WHERE b.ugc_id = ? AND b.combination_id != 0 LIMIT 1;", blueprintId, file, file, blueprintId);
|
||||
if (!result->next()) return std::nullopt;
|
||||
return IUgc::FileChecksum{ std::string(result->getString("md5").c_str()), static_cast<uint32_t>(result->getUInt("size")) };
|
||||
}
|
||||
|
||||
@@ -106,3 +106,16 @@ void MySQLDatabase::SetUgcIconSettings(const std::string_view target, const std:
|
||||
void MySQLDatabase::DeleteUgcIconSettings(const std::string_view target) {
|
||||
ExecuteDelete("DELETE FROM ugc_icon_settings WHERE target = ?;", target);
|
||||
}
|
||||
|
||||
void MySQLDatabase::SetModularBuildCombination(const LWOOBJID id, const LWOOBJID combinationId) {
|
||||
ExecuteUpdate("UPDATE ugc_modular_build SET combination_id = ? WHERE ugc_id = ?;", combinationId, id);
|
||||
}
|
||||
|
||||
std::vector<IUgcModularBuild::PendingBuild> MySQLDatabase::GetModularBuildsWithoutCombination(const uint32_t limit) {
|
||||
auto result = ExecuteSelect("SELECT ugc_id, ldf_config, process_attempts FROM ugc_modular_build WHERE combination_id = 0 LIMIT ?;", limit);
|
||||
std::vector<PendingBuild> builds;
|
||||
while (result->next()) {
|
||||
builds.push_back({ result->getInt64("ugc_id"), std::string(result->getString("ldf_config").c_str()), static_cast<uint32_t>(result->getInt("process_attempts")) });
|
||||
}
|
||||
return builds;
|
||||
}
|
||||
|
||||
@@ -413,6 +413,10 @@ public:
|
||||
void DeleteUgcIconSettings(const std::string_view target) override;
|
||||
void SetUgcModelProcessed(const LWOOBJID id, const eProcessState state, const uint32_t attempts, const std::string_view error, const bool bakeAo) override;
|
||||
void SetUgcModelStats(const LWOOBJID id, const uint32_t bricks, const uint32_t triangles) override;
|
||||
void SetUgcFileChecksum(const eFileOwner owner, const LWOOBJID storageId, const std::string_view file, const std::string_view md5, const uint32_t size) override;
|
||||
std::optional<IUgc::FileChecksum> GetUgcFileChecksum(const LWOOBJID blueprintId, const std::string_view file) override;
|
||||
void SetModularBuildCombination(const LWOOBJID id, const LWOOBJID combinationId) override;
|
||||
std::vector<IUgcModularBuild::PendingBuild> GetModularBuildsWithoutCombination(const uint32_t limit) override;
|
||||
std::optional<IUgc::ProcessInfo> GetUgcProcessInfo(const LWOOBJID id) override;
|
||||
uint64_t ResetUgcModelProcessing(const std::optional<LWOOBJID> id, const bool failedOnly) override;
|
||||
std::vector<IUgc::ProcessInfo> GetUgcProcessList(const std::optional<eProcessState> state, const std::string_view search, const uint32_t offset, const uint32_t limit) override;
|
||||
|
||||
@@ -184,3 +184,16 @@ void SQLiteDatabase::ExpediteUgcModels(const LWOOBJID characterId) {
|
||||
void SQLiteDatabase::SetUgcModelStats(const LWOOBJID id, const uint32_t bricks, const uint32_t triangles) {
|
||||
ExecuteUpdate("UPDATE ugc SET brick_count = ?, triangle_count = ? WHERE id = ?;", bricks, triangles, id);
|
||||
}
|
||||
|
||||
void SQLiteDatabase::SetUgcFileChecksum(const eFileOwner owner, const LWOOBJID storageId, const std::string_view file, const std::string_view md5, const uint32_t size) {
|
||||
ExecuteInsert("INSERT INTO ugc_file_checksums (kind, storage_id, file, md5, size) VALUES (?, ?, ?, ?, ?) "
|
||||
"ON CONFLICT(kind, storage_id, file) DO UPDATE SET md5 = excluded.md5, size = excluded.size;", static_cast<int32_t>(owner), storageId, file, md5, size);
|
||||
}
|
||||
|
||||
std::optional<IUgc::FileChecksum> SQLiteDatabase::GetUgcFileChecksum(const LWOOBJID blueprintId, const std::string_view file) {
|
||||
auto [_, result] = ExecuteSelect("SELECT md5, size FROM ugc_file_checksums WHERE kind = 0 AND storage_id = ? AND file = ? "
|
||||
"UNION ALL SELECT f.md5, f.size FROM ugc_modular_build b JOIN ugc_file_checksums f ON f.kind = 1 AND f.storage_id = b.combination_id AND f.file = ? "
|
||||
"WHERE b.ugc_id = ? AND b.combination_id != 0 LIMIT 1;", blueprintId, file, file, blueprintId);
|
||||
if (result.eof()) return std::nullopt;
|
||||
return IUgc::FileChecksum{ std::string(result.getStringField("md5", "")), static_cast<uint32_t>(result.getInt64Field("size")) };
|
||||
}
|
||||
|
||||
@@ -112,3 +112,17 @@ void SQLiteDatabase::SetUgcIconSettings(const std::string_view target, const std
|
||||
void SQLiteDatabase::DeleteUgcIconSettings(const std::string_view target) {
|
||||
ExecuteDelete("DELETE FROM ugc_icon_settings WHERE target = ?;", target);
|
||||
}
|
||||
|
||||
void SQLiteDatabase::SetModularBuildCombination(const LWOOBJID id, const LWOOBJID combinationId) {
|
||||
ExecuteUpdate("UPDATE ugc_modular_build SET combination_id = ? WHERE ugc_id = ?;", combinationId, id);
|
||||
}
|
||||
|
||||
std::vector<IUgcModularBuild::PendingBuild> SQLiteDatabase::GetModularBuildsWithoutCombination(const uint32_t limit) {
|
||||
auto [_, result] = ExecuteSelect("SELECT ugc_id, ldf_config, process_attempts FROM ugc_modular_build WHERE combination_id = 0 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;
|
||||
}
|
||||
|
||||
@@ -411,6 +411,10 @@ class TestSQLDatabase : public GameDatabase {
|
||||
void DeleteUgcIconSettings(const std::string_view target) override {}
|
||||
void SetUgcModelProcessed(const LWOOBJID id, const eProcessState state, const uint32_t attempts, const std::string_view error, const bool bakeAo) override {}
|
||||
void SetUgcModelStats(const LWOOBJID id, const uint32_t bricks, const uint32_t triangles) override {}
|
||||
void SetUgcFileChecksum(const eFileOwner owner, const LWOOBJID storageId, const std::string_view file, const std::string_view md5, const uint32_t size) override {}
|
||||
std::optional<IUgc::FileChecksum> GetUgcFileChecksum(const LWOOBJID blueprintId, const std::string_view file) override { return std::nullopt; }
|
||||
void SetModularBuildCombination(const LWOOBJID id, const LWOOBJID combinationId) override {}
|
||||
std::vector<IUgcModularBuild::PendingBuild> GetModularBuildsWithoutCombination(const uint32_t limit) override { return {}; }
|
||||
std::optional<IUgc::ProcessInfo> GetUgcProcessInfo(const LWOOBJID id) override { return {}; }
|
||||
uint64_t ResetUgcModelProcessing(const std::optional<LWOOBJID> id, const bool failedOnly) override { return 0; }
|
||||
std::vector<IUgc::ProcessInfo> GetUgcProcessList(const std::optional<eProcessState> state, const std::string_view search, const uint32_t offset, const uint32_t limit) override { return {}; }
|
||||
|
||||
Reference in New Issue
Block a user