feat(zone): checking, keeping and locking a zone's edited files

Three pieces that know nothing of how a set of files arrives:
- ZonePublish reads every file of a set with the server's own readers and says, file
  by file, what is wrong; a set is good only when every file is.
- ZoneOverrideStore keeps a good set in the override folder: built in a staging
  folder, flushed, swapped in with a rename, the set before it kept as a backup.
  Restoring a backup and clearing a zone's set are the same swap.
- ZoneEditLock has the rules for a zone's editors and its one lock holder, and for
  holding a reload while players are in the zone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-10 18:25:44 -06:00
parent 0e57b95229
commit f34577b5a2
11 changed files with 1657 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
#include "Raw.h"
#include "Sd0.h"
#include "ZoneFile.h"
#include "ZonePublish.h"
/**
* Reads every zone (.luz), scene (.lvl) and terrain (.raw) file of the clients on disk: each must read in full, as it
@@ -158,3 +159,29 @@ TEST_F(ClientZoneFilesTests, EverySceneFileReads) {
EXPECT_TRUE(!threw || IsDamaged(path)) << path;
}
}
// The checks a set of edited zone files goes through (ZonePublish) must take the files the game itself ships:
// nothing the clients have reads as damaged, apart from the files that are
TEST_F(ClientZoneFilesTests, PublishChecksTakeEveryClientFile) {
std::set<std::tuple<std::string, uintmax_t>> seen;
size_t checked = 0;
for (const auto* extension : { ".luz", ".lvl", ".raw", ".lutriggers" }) {
for (const auto& path : FilesWithExtension(extension)) {
std::error_code error;
auto name = path.filename().string();
std::ranges::transform(name, name.begin(), ::tolower);
if (!seen.insert({ name, std::filesystem::file_size(path, error) }).second || IsDamaged(path)) continue;
checked++;
uint32_t version = 0;
for (const auto& problem : ZonePublish::CheckContents(name, Contents(path), &version)) {
// What must never happen is a file the game ships reading as damaged. Triggers and object settings
// the server doesn't know are in shipped files (a misspelt command in one live zone, more in test
// maps), and so are test maps' zone files from before launch with bytes after their last part.
if (problem.code != "parse_failed") continue;
if (name.ends_with(".luz") && version < static_cast<uint32_t>(ZoneFile::FileFormatVersion::Launch)) continue;
ADD_FAILURE() << path << ": " << problem.code << ": " << problem.message << (problem.offset ? " at " + std::to_string(*problem.offset) : "");
}
}
}
if (checked == 0) GTEST_SKIP() << "No client zone files under " << ClientsDir();
}