mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-08 22:03:43 +00:00
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:
@@ -17,40 +17,30 @@ void ZoneInstanceManager::RequestZoneTransfer(dServer* server, uint32_t zoneID,
|
||||
const auto nextID = ++currentRequestID;
|
||||
requests[nextID] = callback;
|
||||
|
||||
MasterPackets::SendZoneTransferRequest(server, nextID, mythranShift, zoneID, zoneClone, stamps);
|
||||
MasterPackets::RequestZoneTransfer request;
|
||||
request.requestID = nextID;
|
||||
request.mythranShift = mythranShift;
|
||||
request.zoneID = zoneID;
|
||||
request.cloneID = zoneClone;
|
||||
request.stamps = stamps;
|
||||
MasterPackets::SendToMaster(request, server);
|
||||
}
|
||||
|
||||
//! Handles a zone transfer response
|
||||
void ZoneInstanceManager::HandleRequestZoneTransferResponse(Packet* packet) {
|
||||
CINSTREAM_SKIP_HEADER;
|
||||
uint64_t requestID;
|
||||
inStream.Read(requestID);
|
||||
bool mythranShift;
|
||||
uint8_t tmp;
|
||||
inStream.Read(tmp);
|
||||
mythranShift = tmp > 0;
|
||||
uint32_t zoneID;
|
||||
inStream.Read(zoneID);
|
||||
uint32_t zoneInstance;
|
||||
inStream.Read(zoneInstance);
|
||||
uint32_t zoneClone;
|
||||
inStream.Read(zoneClone);
|
||||
uint16_t serverPort;
|
||||
inStream.Read(serverPort);
|
||||
LUString serverIP(255);
|
||||
inStream.Read(serverIP);
|
||||
Stamps stamps;
|
||||
if (!stamps.Deserialize(inStream)) stamps = {};
|
||||
|
||||
const auto entry = requests.find(requestID);
|
||||
void ZoneInstanceManager::HandleRequestZoneTransferResponse(const MasterPackets::RequestZoneTransferResponse& response) {
|
||||
const auto entry = requests.find(response.requestID);
|
||||
if (entry != requests.end()) {
|
||||
entry->second(mythranShift, zoneID, zoneInstance, zoneClone, serverIP.string, serverPort, stamps);
|
||||
entry->second(response.mythranShift > 0, response.zoneID, response.zoneInstance, response.zoneClone, response.serverIP.string, response.serverPort, response.stamps);
|
||||
requests.erase(entry);
|
||||
}
|
||||
}
|
||||
|
||||
void ZoneInstanceManager::CreatePrivateZone(dServer* server, uint32_t zoneID, uint32_t zoneClone, const std::string& password) {
|
||||
MasterPackets::SendZoneCreatePrivate(server, zoneID, zoneClone, password);
|
||||
MasterPackets::CreatePrivateZone request;
|
||||
request.zoneID = zoneID;
|
||||
request.cloneID = zoneClone;
|
||||
request.password = password;
|
||||
MasterPackets::SendToMaster(request, server);
|
||||
}
|
||||
|
||||
void ZoneInstanceManager::RequestPrivateZone(
|
||||
@@ -63,5 +53,9 @@ void ZoneInstanceManager::RequestPrivateZone(
|
||||
callback(mythranShift, zoneID, zoneInstance, zoneClone, serverIP, serverPort);
|
||||
};
|
||||
|
||||
MasterPackets::SendZoneRequestPrivate(server, nextID, mythranShift, password);
|
||||
MasterPackets::RequestPrivateZone request;
|
||||
request.requestID = nextID;
|
||||
request.mythranShift = mythranShift;
|
||||
request.password = password;
|
||||
MasterPackets::SendToMaster(request, server);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user