Files
DarkflameServer/dCaptureTool/Replayer.h
Aaron Kimbrell 3a8838d463 feat(capture): replay bundles against a sandbox stack with a headless client
CaptureTool (built next to the servers) replays packet bundles and compares the answers:

- replay: per bundle a fresh sandbox folder with copied server binaries, rewritten settings
  (replay_sandbox=1, a new SQLite file inside the folder, ports from --port on, no dashboard),
  read back before anything starts; sandbox-setup runs inside it to apply migrations and make
  the replay account and the bundle's characters (setup mode); master is started, the stack is
  stopped as one process group and the folder deleted unless kept
- with replay_sandbox=1 every server refuses a database that isn't SQLite, isn't inside its
  own folder, or is replay_live_sqlite_path (Database::Connect); replay-target against a
  running server needs --i-know-this-is-not-a-sandbox
- the fake client splits the recording into connections, logs in and picks the character
  itself when the recording doesn't, fills in the target's account, session key and IDs,
  learns server-made object IDs from replica constructions by LOT, follows the recorded
  timing and waits for the answers a client waits for; the diff pairs answers by name (and
  constructions by LOT) and ignores fields that differ between runs
- import-live converts the 2014 live captures (folders of *_traffic.zip; pcaps and encrypted
  captures are left alone) into bundles, with secrets removed and CREATE_CHARACTER as setup
- anonymise makes local fixtures; docs/CaptureReplay.md describes capture, the bundle format,
  portability rules, the sandbox and the replay

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 22:34:34 -05:00

52 lines
2.0 KiB
C++

#pragma once
#include <cstdint>
#include <map>
#include <string>
#include <vector>
#include "CaptureBundle.h"
#include "CaptureTools.h"
#include "json.hpp"
/**
* Replays a bundle's client packets against a server with the fake client (docs/CaptureReplay.md) and compares the
* server's answers with the recorded ones.
*
* The recording is split into connections (each starts with the client's VERSION_CONFIRM). The replay logs in on
* the target's auth server itself when the recording has no login, and goes through character select itself when
* the recording starts in a zone. Before a packet goes out, what must differ on the target is filled in: the
* target account's name and password, the session key the target's auth gave, and the target's IDs for the
* characters (the bundle's placeholders). Timing follows the recording (sped up, and never more than a few seconds
* between packets), and the replay waits for the answers a real client waits for (the handshake, the character
* list, the zone to load, the world to transfer to).
*/
namespace Replayer {
struct Options {
std::string host{ "127.0.0.1" };
uint16_t authPort{};
std::string username;
std::string password;
double speed{ 4.0 };
uint32_t maxGapMs{ 3000 };
// Bundle placeholder -> the target's ID (the characters the setup made)
std::map<int64_t, int64_t> ids;
int64_t character{}; // the target's ID of the bundle's first character (character select picks it)
};
struct Result {
bool loggedIn{};
size_t connections{}; // recorded connections
size_t connectionsReached{}; // connections the replay got to
size_t sent{};
size_t received{};
std::string stoppedAt; // why it stopped early, if it did
std::vector<std::string> notes;
std::vector<CaptureBundle::Record> actual; // what the target answered, as records
CaptureTools::DiffReport diff;
nlohmann::json ToJson() const;
};
Result Replay(const CaptureBundle::Bundle& bundle, const Options& options);
}