feat: UGC server that makes and serves player models' meshes and icons

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>
This commit is contained in:
Aaron Kimbrell
2026-09-27 03:52:22 -05:00
parent 90ded73596
commit abf1cc1d80
52 changed files with 3869 additions and 14 deletions

View File

@@ -46,5 +46,55 @@ namespace ZCompression {
inflateEnd(&zInfo); // zlib function
return(nRet);
}
}
namespace {
// Inflate everything in `data` with zlib's `windowBits` (31: gzip, -15: raw); nullopt on any error
std::optional<std::string> Inflate(std::string_view data, int windowBits, size_t sizeHint) {
z_stream stream{};
if (inflateInit2(&stream, windowBits) != Z_OK) return std::nullopt;
std::string out;
out.reserve(sizeHint);
stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(data.data()));
stream.avail_in = static_cast<uInt>(data.size());
char buffer[65536];
int result = Z_OK;
while (result == Z_OK) {
stream.next_out = reinterpret_cast<Bytef*>(buffer);
stream.avail_out = sizeof(buffer);
result = inflate(&stream, Z_NO_FLUSH);
if (result != Z_OK && result != Z_STREAM_END) break;
out.append(buffer, sizeof(buffer) - stream.avail_out);
if (result == Z_OK && stream.avail_in == 0 && stream.avail_out != 0) break; // truncated
}
inflateEnd(&stream);
if (result != Z_STREAM_END) return std::nullopt;
return out;
}
}
std::string Gzip(std::string_view data) {
z_stream stream{};
// 31: a gzip header and trailer instead of zlib's
if (deflateInit2(&stream, Z_BEST_COMPRESSION, Z_DEFLATED, 31, 8, Z_DEFAULT_STRATEGY) != Z_OK) return {};
std::string out;
out.resize(deflateBound(&stream, static_cast<uLong>(data.size())) + 32);
stream.next_in = reinterpret_cast<Bytef*>(const_cast<char*>(data.data()));
stream.avail_in = static_cast<uInt>(data.size());
stream.next_out = reinterpret_cast<Bytef*>(out.data());
stream.avail_out = static_cast<uInt>(out.size());
const auto result = deflate(&stream, Z_FINISH);
out.resize(stream.total_out);
deflateEnd(&stream);
return result == Z_STREAM_END ? out : std::string{};
}
std::optional<std::string> Gunzip(std::string_view data) {
return Inflate(data, 31, data.size() * 4);
}
std::optional<std::string> InflateRaw(std::string_view data, size_t size) {
auto out = Inflate(data, -15, size);
if (!out || out->size() != size) return std::nullopt;
return out;
}
}