Files
DarkflameServer/dMasterServer/MigrationCoordinator.h
Aaron Kimbrell 5a9a3e380b 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>
2026-09-28 22:30:50 -05:00

38 lines
1.4 KiB
C++

#ifndef __MIGRATIONCOORDINATOR__H__
#define __MIGRATIONCOORDINATOR__H__
#include <functional>
#include "master/InstanceMigration.h"
#include "RakNetTypes.h"
class Instance;
/**
* Master's side of instance migrations (InstanceMigration.h): picks or starts the target instance, holds seats
* there, tells the source world to send its players over and passes progress on to whoever asked. The source
* instance is "draining" meanwhile, so no new player is sent to it.
*/
namespace MigrationCoordinator {
// Where statuses go (every world, so the GM who asked hears about it wherever they are); set once at startup
void SetReporter(std::function<void(const MigrationStatus&)> reporter);
// A migration was asked for (a GM command, or later a dashboard); anything but NONE means it was refused (and
// reported as FAILED)
InstanceMigration::eRefusal Start(const InstanceMigrationRequest& request);
// A world reported progress on a migration it is running
void HandleStatus(const SystemAddress& from, const MigrationStatus& status);
// A source world sent state to carry over for one player: passed on to the target world as is
void HandleCarriedState(const SystemAddress& from, const CarriedPlayerState& state);
// A world server went away; migrations it was part of end
void OnInstanceGone(const Instance& instance);
// Every master frame: waits for targets to be ready and times out stuck migrations
void Update();
}
#endif //!__MIGRATIONCOORDINATOR__H__