mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 10:53:44 +00:00
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>
112 lines
3.6 KiB
C++
112 lines
3.6 KiB
C++
#ifndef __DASHBOARDMESSAGES__H__
|
|
#define __DASHBOARDMESSAGES__H__
|
|
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "BitStream.h"
|
|
#include "BitStreamUtils.h"
|
|
#include "MessageType/Master.h"
|
|
#include "dCommonVars.h"
|
|
|
|
namespace DashboardMessages {
|
|
// Length-prefixed string, capped so a bad packet can't ask for huge allocations
|
|
inline void WriteText(RakNet::BitStream& stream, const std::string& text, uint16_t max) {
|
|
const auto length = static_cast<uint16_t>(std::min<size_t>(text.size(), max));
|
|
stream.Write(length);
|
|
stream.Write(text.data(), length);
|
|
}
|
|
|
|
inline bool ReadText(RakNet::BitStream& stream, std::string& text, uint16_t max) {
|
|
uint16_t length{};
|
|
if (!stream.Read(length) || length > max) return false;
|
|
text.resize(length);
|
|
return length == 0 || stream.Read(text.data(), length);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* PLAYER_POSITIONS (world -> master -> dashboard): where each player in a world instance is, sent every
|
|
* second while anyone is online and once more when the world empties.
|
|
*/
|
|
struct PlayerPositions : public LUBitStream {
|
|
PlayerPositions() : LUBitStream(ServiceType::MASTER, MessageType::Master::PLAYER_POSITIONS) {}
|
|
|
|
struct Player {
|
|
LWOOBJID characterId{};
|
|
float x{}, y{}, z{};
|
|
};
|
|
|
|
static constexpr uint16_t MAX_PLAYERS = 1000;
|
|
|
|
uint32_t zoneId{};
|
|
uint32_t instanceId{};
|
|
uint32_t cloneId{};
|
|
std::vector<Player> players;
|
|
|
|
void Serialize(RakNet::BitStream& stream) const override {
|
|
stream.Write(zoneId);
|
|
stream.Write(instanceId);
|
|
stream.Write(cloneId);
|
|
const auto count = static_cast<uint16_t>(std::min<size_t>(players.size(), MAX_PLAYERS));
|
|
stream.Write(count);
|
|
for (uint16_t i = 0; i < count; i++) {
|
|
stream.Write(players[i].characterId);
|
|
stream.Write(players[i].x);
|
|
stream.Write(players[i].y);
|
|
stream.Write(players[i].z);
|
|
}
|
|
}
|
|
|
|
bool Deserialize(RakNet::BitStream& stream) override {
|
|
uint16_t count{};
|
|
if (!stream.Read(zoneId) || !stream.Read(instanceId) || !stream.Read(cloneId) || !stream.Read(count) || count > MAX_PLAYERS) return false;
|
|
players.resize(count);
|
|
for (auto& player : players) {
|
|
if (!stream.Read(player.characterId) || !stream.Read(player.x) || !stream.Read(player.y) || !stream.Read(player.z)) return false;
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* ANNOUNCE (dashboard -> master -> worlds): a message shown to every player online, or only to those in the listed
|
|
* zones (master only forwards it to worlds of those zones).
|
|
*/
|
|
struct Announcement : public LUBitStream {
|
|
Announcement() : LUBitStream(ServiceType::MASTER, MessageType::Master::ANNOUNCE) {}
|
|
|
|
static constexpr uint16_t MAX_TITLE = 100;
|
|
static constexpr uint16_t MAX_MESSAGE = 1000;
|
|
static constexpr uint16_t MAX_ZONES = 200;
|
|
|
|
std::string title;
|
|
std::string message;
|
|
std::vector<uint32_t> zones; // empty: every world
|
|
|
|
void Serialize(RakNet::BitStream& stream) const override {
|
|
DashboardMessages::WriteText(stream, title, MAX_TITLE);
|
|
DashboardMessages::WriteText(stream, message, MAX_MESSAGE);
|
|
const auto count = static_cast<uint16_t>(std::min<size_t>(zones.size(), MAX_ZONES));
|
|
stream.Write(count);
|
|
for (uint16_t i = 0; i < count; i++) stream.Write(zones[i]);
|
|
}
|
|
|
|
bool Deserialize(RakNet::BitStream& stream) override {
|
|
if (!DashboardMessages::ReadText(stream, title, MAX_TITLE) || !DashboardMessages::ReadText(stream, message, MAX_MESSAGE)) return false;
|
|
uint16_t count{};
|
|
if (!stream.Read(count) || count > MAX_ZONES) return false;
|
|
zones.resize(count);
|
|
for (auto& zone : zones) if (!stream.Read(zone)) return false;
|
|
return true;
|
|
}
|
|
|
|
bool ShownIn(uint32_t zoneId) const {
|
|
return zones.empty() || std::find(zones.begin(), zones.end(), zoneId) != zones.end();
|
|
}
|
|
};
|
|
|
|
#endif //!__DASHBOARDMESSAGES__H__
|