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:
Aaron Kimbrell
2026-09-27 17:46:47 -05:00
parent ceec638e52
commit 79235702b3
33 changed files with 706 additions and 14 deletions

View File

@@ -717,3 +717,35 @@ TEST_F(WorldPacketsTests, SmallRequestsMatchLegacy) {
ASSERT_TRUE(mailRead.Deserialize(mailBytes));
EXPECT_PACKET_EQ(FromBitStream(mail.data), FromBitStream(mailRead.data));
}
// The layouts the 1.10.64 client uses without 3D services (UGCUSE3DSERVICES=7:0): it sends 16 bytes after the 0x53
// (SendRequestUGCManifestInfoPacket) and only reads an answer that is exactly 37 bytes after it
// (PacketHandler_MSG_CLIENT_UGC_MANIFEST_RESPONSE: 21 bytes of manifest info after the blueprint and type).
TEST_F(WorldPacketsTests, UgcManifestPacketsMatchTheClient) {
WorldPackets::RequestUgcManifestInfo request;
request.blueprintId = 0x0102030405060708;
request.resourceType = eUgcResourceType::DDS;
RakNet::BitStream requestBytes;
request.WritePacket(requestBytes);
EXPECT_PACKET_EQ(FromHex("53 04 00 1b 00 00 00 00 08 07 06 05 04 03 02 01 03"), FromBitStream(requestBytes));
EXPECT_EQ(requestBytes.GetNumberOfBytesUsed() - 1, 16);
EXPECT_EQ(RoundTrip(request).blueprintId, request.blueprintId);
ExpectTruncatedFails(request);
ClientPackets::UgcManifestResponse response;
response.blueprintId = 0x0102030405060708;
response.resourceType = eUgcResourceType::DDS;
response.valid = true;
response.fileSize = 65664;
for (size_t i = 0; i < response.md5.size(); i++) response.md5[i] = static_cast<uint8_t>(0xa0 + i);
RakNet::BitStream responseBytes;
response.WritePacket(responseBytes);
EXPECT_PACKET_EQ(FromHex("53 05 00 3c 00 00 00 00 08 07 06 05 04 03 02 01 03 01 80 00 01 00 "
"a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aa ab ac ad ae af"), FromBitStream(responseBytes));
EXPECT_EQ(responseBytes.GetNumberOfBytesUsed() - 1, 37);
const auto read = RoundTrip(response);
EXPECT_TRUE(read.valid);
EXPECT_EQ(read.fileSize, 65664u);
EXPECT_EQ(read.md5, response.md5);
ExpectTruncatedFails(response);
}