feat(master): an edit mode flag on a private instance, down to its world server

CreatePrivateZone carries editMode as one more byte, written only when set, so
a plain private zone is sent as before. Master keeps it on the instance, starts
the world server with -editmode 1, and gives a private instance's replacement
(a reload or a live update) the same flag. Nothing sets it yet.

A capped string now skips the characters it cut, so what follows it is read
from the right place. A request to join a private instance that is still
starting is answered once its world server is ready, instead of at once with
an address nothing listens on yet.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-11-10 17:34:13 -06:00
parent 78b2c0f406
commit 4cf0909d52
12 changed files with 68 additions and 14 deletions

View File

@@ -16,7 +16,12 @@ namespace {
uint32_t length{};
VALIDATE_READ(bitStream.Read(length));
value.resize(std::min(length, maxLength));
return value.empty() || bitStream.ReadBits(reinterpret_cast<unsigned char*>(value.data()), BYTES_TO_BITS(value.size()), true);
if (!value.empty() && !bitStream.ReadBits(reinterpret_cast<unsigned char*>(value.data()), BYTES_TO_BITS(value.size()), true)) return false;
const uint32_t rest = length - static_cast<uint32_t>(value.size());
if (rest == 0) return true;
if (BITS_TO_BYTES(bitStream.GetNumberOfUnreadBits()) < rest) return false;
bitStream.IgnoreBits(BYTES_TO_BITS(rest));
return true;
}
}
@@ -147,12 +152,15 @@ namespace MasterPackets {
bitStream.Write(zoneID);
bitStream.Write(cloneID);
BitStreamUtils::WriteLengthPrefixed<uint32_t>(bitStream, password);
if (editMode != 0) bitStream.Write(editMode);
}
bool CreatePrivateZone::Deserialize(RakNet::BitStream& bitStream) {
VALIDATE_READ(bitStream.Read(zoneID));
VALIDATE_READ(bitStream.Read(cloneID));
VALIDATE_READ(ReadCappedString(bitStream, password, MAX_PASSWORD_LENGTH));
editMode = 0;
if (bitStream.GetNumberOfUnreadBits() >= 8) VALIDATE_READ(bitStream.Read(editMode));
return true;
}

View File

@@ -146,6 +146,9 @@ namespace MasterPackets {
uint32_t zoneID{};
uint32_t cloneID{};
std::string password; // u32 length, then 1 byte per character
// A GM's edit mode: the instance's world server constructs none of the zone's objects (docs/EditMode.md). Written
// only when set, so a plain private zone stays as it always was
uint8_t editMode{};
CreatePrivateZone() : LUBitStream(ServiceType::MASTER, MessageType::Master::CREATE_PRIVATE_ZONE) {}
void Serialize(RakNet::BitStream& bitStream) const override;

View File

@@ -1009,6 +1009,7 @@ json ToJson(const MasterPackets::CreatePrivateZone& m) {
json j = json::object();
j["zoneID"] = ToJson(m.zoneID);
j["cloneID"] = ToJson(m.cloneID);
j["editMode"] = ToJson(m.editMode);
return j;
}
json ToJson(const MasterPackets::RequestPrivateZone& m) {

View File

@@ -35,11 +35,12 @@ void ZoneInstanceManager::HandleRequestZoneTransferResponse(const MasterPackets:
}
}
void ZoneInstanceManager::CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password) {
void ZoneInstanceManager::CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password, const bool editMode) {
MasterPackets::CreatePrivateZone request;
request.zoneID = zoneID;
request.cloneID = zoneClone;
request.password = password;
request.editMode = editMode ? 1 : 0;
MasterPackets::SendToMaster(request, server);
}

View File

@@ -62,7 +62,8 @@ public:
*/
void HandleRequestZoneTransferResponse(const MasterPackets::RequestZoneTransferResponse& response);
void CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password);
// editMode: a GM's edit mode instance, whose world server constructs none of the zone's objects
void CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password, bool editMode = false);
void RequestPrivateZone(dServer* server, bool mythranShift, const std::string& password, TransferCallback callback);
};