feat(capture): record whole packets of an account, a character or everything on every server

Staff arm a packet capture on the dashboard; master passes MESSAGE_CAPTURE_CONTROL ARM to
every world, auth and chat and arms its own. Each server's PacketCapture tap (dServer receive,
and a send hook in RakPeer::Send so replica constructions are seen too) records into one
preallocated chunk per server and ships sealed chunks through master on the main loop when
capture_flush_bytes or capture_flush_interval_ms is reached; past capture_buffer_max_mb the
oldest chunks are dropped and the dashboard records a gap. Nothing is armed: one flag check.

- targets: an account (from its login; packets before the login are kept per connection
  and added once auth or the world knows whose they are), a character (from when it is
  picked), or everything; up to 8 at once (a bit each in the record mask)
- worlds and auth record their clients' packets and the master link messages of a captured
  player (session keys by name, zone transfers by request, player added/removed, migration);
  chat finds the player in each packet; master records server traffic for everything
- secrets are never recorded: structs that carry them (login request, login response user
  key, world validation session key, session key messages between servers) are read,
  blanked and written again before recording; auth keeps only the handshake and login
- PacketDecoder: a registry by service and message id names every packet and decodes the
  registered structs; CaptureBundle is the file format (DLUBNDL1, metadata, records);
  CaptureTools orders records on one timeline, pulls movement out, makes bundles portable
  or anonymous and diffs replays
- the dashboard keeps packet captures in message_capture_sessions (capture_kind 1) and
  their packets in a file under capture_dir, one write per batch; arming is audited
- MESSAGE_CAPTURE_CONTROL/DATA only gain appended enum values and trailing fields

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-27 08:45:12 -05:00
parent fb6d73e4bd
commit 332bc04ce8
35 changed files with 3207 additions and 15 deletions

View File

@@ -76,6 +76,7 @@
#include "Inspector.h"
#include "CDClientBrowser.h"
#include "master/MessageCapture.h"
#include "CaptureReplay.h"
#include "PublicRoutes.h"
#include "Showcase.h"
#include "ContrabandRoutes.h"
@@ -341,7 +342,10 @@ namespace {
handlers.On<MasterPackets::PlayerAdded>(Master::PLAYER_ADDED, OnPlayerAdded);
handlers.On<MasterPackets::PlayerRemoved>(Master::PLAYER_REMOVED, OnPlayerRemoved);
handlers.On<PlayerPositions>(Master::PLAYER_POSITIONS, [](const PlayerPositions& positions, const SystemAddress&) { LiveWorld::HandlePlayerPositions(positions); });
handlers.On<MessageCaptureData>(Master::MESSAGE_CAPTURE_DATA, [](const MessageCaptureData& data, const SystemAddress&) { Inspector::HandleData(data); });
handlers.On<MessageCaptureData>(Master::MESSAGE_CAPTURE_DATA, [](const MessageCaptureData& data, const SystemAddress&) {
if (data.status == eMessageCaptureStatus::PACKETS) CaptureReplay::HandleData(data);
else Inspector::HandleData(data);
});
handlers.On<DataChanged>(Master::DATA_CHANGED, [](const DataChanged& changed, const SystemAddress&) { BroadcastDataChanged(changed); });
handlers.On<PlayerActionResult>(Master::PLAYER_ACTION_RESULT, [](const PlayerActionResult& result, const SystemAddress&) { PlayerActions::HandleResult(result); });
handlers.On<MasterPackets::WorldShutDown>(Master::SHUTDOWN_RESPONSE, OnWorldShutDown);
@@ -512,6 +516,7 @@ int main(int argc, char** argv) {
RegisterReportViewTask();
RegisterCharacterTasks();
Inspector::Initialize();
CaptureReplay::Initialize();
Scheduler::Initialize();
// Register global middleware
@@ -555,6 +560,7 @@ int main(int argc, char** argv) {
LiveWorld::RegisterRoutes();
LiveUpdateRoutes::RegisterRoutes();
Inspector::RegisterRoutes();
CaptureReplay::RegisterRoutes();
RegisterCDClientBrowserRoutes();
RegisterSettingsRoutes();
SettingsHistory::RegisterRoutes();
@@ -630,6 +636,7 @@ int main(int argc, char** argv) {
{ Profiler::Scope scope("LiveWorld::Update"); LiveWorld::Update(); }
{ Profiler::Scope scope("LiveUpdateRoutes::Update"); LiveUpdateRoutes::Update(); }
{ Profiler::Scope scope("Inspector::Update"); Inspector::Update(); }
{ Profiler::Scope scope("CaptureReplay::Update"); CaptureReplay::Update(); }
{ Profiler::Scope scope("Announcements::Update"); Announcements::Update(); }
{ Profiler::Scope scope("EventsCalendar::Update"); EventsCalendar::Update(); }
{ Profiler::Scope scope("LiveEventRoutes::Update"); LiveEventRoutes::Update(); }
@@ -655,6 +662,7 @@ int main(int argc, char** argv) {
Game::web.Shutdown();
ApiKeyService::Flush();
Inspector::Shutdown();
CaptureReplay::Shutdown();
EmailService::Shutdown();
ModeratorHelper::Shutdown();
Background::Shutdown();