refactor: master packets as structs

Every MASTER service packet is now an LUBitStream struct (docs/PacketArchitecture.md,
PR 14) and the master server's switch is a dispatch map (PacketDispatcher), as are the
master handlers of the world, chat and dashboard servers.

- dNet/MasterPackets.h: RequestZoneTransfer, RequestZoneTransferResponse, ServerInfo,
  RequestSessionKey, SetSessionKey, SessionKeyResponse, NewSessionAlert, PlayerAdded /
  PlayerRemoved, CreatePrivateZone, RequestPrivateZone (passwords still cut to 50
  characters when read), WorldReady, WorldReadyInfo (WORLD_READY to the dashboard),
  PrepZone, Shutdown, ShutdownResponse, WorldShutDown (SHUTDOWN_RESPONSE to the
  dashboard), ShutdownUniverse, AffirmTransferRequest/Response, RequestServerList,
  ServerListResponse, DashboardShutdown, ConfigReload, InstanceShutdown. The Send*
  functions are gone; MasterPackets::SendToMaster(msg) and SendTo(sysAddr, msg) send a
  struct.
- The dashboard and instance migration structs (PlayerAction, DataChanged, Dashboard
  messages, MessageCapture, InstanceMigration) are LUBitStreams of the MASTER service now
  and moved to dNet/master/, included by MasterPackets.h. Their payloads are unchanged;
  master forwards them by re-serializing the struct instead of copying raw bytes.
- InstanceManager, ZoneInstanceManager, MigrationCoordinator, dServer (server info, zone
  transfer response), auth (SET_SESSION_KEY), the world (session keys, player added and
  removed, world ready, shutdown response, affirmations, prep zone, shutdown universe) and
  the dashboard (server list, instance shutdown, config reload, announcements, player
  actions, message capture) send and read structs.
- The login stamps are a `stamps` field of RequestZoneTransfer and
  RequestZoneTransferResponse (read leniently as before: a message without them reads as
  empty); master adds its stamps in the REQUEST_ZONE_TRANSFER handler and when it answers,
  as it did.
- InstanceManager::GetInstanceBySysAddr takes a const address.

Verified: tests/dGameTests/dNetTests/Legacy/MasterPacketsLegacy.h is a verbatim copy of
the old writers and readers; MasterPacketsTests requires identical bytes for a grid of
inputs, checks the old readers read what the structs write, round trips and truncation,
hand written golden packets, that zone transfers without stamps still read, that the dashboard/migration structs write what
"header + Serialize" wrote, and that the dispatcher drops truncated packets. No wire
bytes changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-26 23:34:47 -05:00
parent 796fd1b941
commit 5a9a3e380b
54 changed files with 2275 additions and 1248 deletions

61
dNet/master/DataChanged.h Normal file
View File

@@ -0,0 +1,61 @@
#ifndef __DATACHANGED__H__
#define __DATACHANGED__H__
#include <algorithm>
#include <cstdint>
#include <string>
#include <vector>
#include "BitStream.h"
#include "BitStreamUtils.h"
#include "MessageType/Master.h"
#include "dCommonVars.h"
/**
* DATA_CHANGED payload: the tables and rows a game server just wrote. The dashboard turns each entry into a
* table_changed event so open pages refresh without waiting for its periodic database check.
*/
struct DataChanged : public LUBitStream {
DataChanged() : LUBitStream(ServiceType::MASTER, MessageType::Master::DATA_CHANGED) {}
struct Entry {
std::string table; // dashboard table name, e.g. "characters", "mail", "economy"
LWOOBJID id{}; // row the change is about, 0 for the table as a whole
};
static constexpr size_t MAX_ENTRIES = 1024;
static constexpr size_t MAX_TABLE_NAME = 32;
std::vector<Entry> entries;
void Serialize(RakNet::BitStream& stream) const override {
const auto count = static_cast<uint16_t>(std::min(entries.size(), MAX_ENTRIES));
stream.Write(count);
for (size_t i = 0; i < count; i++) {
const auto& entry = entries[i];
const auto length = static_cast<uint8_t>(std::min(entry.table.size(), MAX_TABLE_NAME));
stream.Write(length);
stream.Write(entry.table.data(), length);
stream.Write(entry.id);
}
}
bool Deserialize(RakNet::BitStream& stream) override {
uint16_t count{};
if (!stream.Read(count) || count > MAX_ENTRIES) return false;
entries.clear();
entries.reserve(count);
for (uint16_t i = 0; i < count; i++) {
uint8_t length{};
if (!stream.Read(length) || length > MAX_TABLE_NAME) return false;
Entry entry;
entry.table.resize(length);
if (length > 0 && !stream.Read(entry.table.data(), length)) return false;
if (!stream.Read(entry.id)) return false;
entries.push_back(std::move(entry));
}
return true;
}
};
#endif //!__DATACHANGED__H__