mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-19 11:12:49 +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:
@@ -8,6 +8,7 @@
|
||||
#include "CDClientManager.h"
|
||||
#include "Game.h"
|
||||
#include "InstanceManager.h"
|
||||
#include "MasterPackets.h"
|
||||
#include "Logger.h"
|
||||
#include "MessageType/Master.h"
|
||||
#include "ServiceType.h"
|
||||
@@ -114,10 +115,7 @@ namespace {
|
||||
order.targetZone = migration.zone;
|
||||
order.targetInstance = migration.target;
|
||||
order.targetPort = 0;
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::MIGRATE_PLAYERS);
|
||||
order.Serialize(bitStream);
|
||||
Game::server->Send(bitStream, source->GetSysAddr(), false);
|
||||
MasterPackets::SendTo(source->GetSysAddr(), order);
|
||||
}
|
||||
|
||||
// Ends a migration. The source goes back to taking players unless it is being shut down.
|
||||
@@ -153,10 +151,7 @@ namespace {
|
||||
// Without a loading screen the "dimensional shift" notice would be the only sign; leave it out then
|
||||
order.seamless = migration.seamless;
|
||||
order.mythranShift = !migration.seamless;
|
||||
CBITSTREAM;
|
||||
BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::MIGRATE_PLAYERS);
|
||||
order.Serialize(bitStream);
|
||||
Game::server->Send(bitStream, source.GetSysAddr(), false);
|
||||
MasterPackets::SendTo(source.GetSysAddr(), order);
|
||||
|
||||
migration.state = migration.warnSeconds > 0 ? eState::WARNING : eState::MOVING;
|
||||
migration.deadline = Clock::now() + std::chrono::seconds(migration.warnSeconds) + MOVE_TIMEOUT;
|
||||
@@ -257,15 +252,14 @@ void MigrationCoordinator::HandleStatus(const SystemAddress& from, const Migrati
|
||||
Report(migration, status.state, status.message, status.remaining);
|
||||
}
|
||||
|
||||
void MigrationCoordinator::HandleCarriedState(const SystemAddress& from, const CarriedPlayerState& state, const unsigned char* data, uint32_t length) {
|
||||
void MigrationCoordinator::HandleCarriedState(const SystemAddress& from, const CarriedPlayerState& state) {
|
||||
for (const auto& [id, migration] : g_Active) {
|
||||
if (migration.zone != state.targetZone || migration.target != state.targetInstance) continue;
|
||||
const auto& source = FindInstance(migration.zone, migration.source);
|
||||
if (!source || source->GetSysAddr() != from) continue;
|
||||
const auto& target = FindInstance(migration.zone, migration.target);
|
||||
if (!target) return;
|
||||
RakNet::BitStream forward(const_cast<unsigned char*>(data), length, false);
|
||||
Game::server->Send(forward, target->GetSysAddr(), false);
|
||||
MasterPackets::SendTo(target->GetSysAddr(), state);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user