Files
DarkflameServer/dCaptureTool/FakeClient.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

56 lines
1.5 KiB
C++

#pragma once
#include <chrono>
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
#include "RakNetTypes.h"
class RakPeerInterface;
/**
* A headless game client for the capture tool's replay: one RakNet connection to an auth or world server that sends
* packets as given and keeps every packet it receives, with when it came. It speaks only RakNet and the LU packet
* header; what to send comes from the bundle being replayed.
*/
class FakeClient {
public:
struct Received {
std::string bytes;
int64_t timeUs{};
};
FakeClient();
~FakeClient();
FakeClient(const FakeClient&) = delete;
FakeClient& operator=(const FakeClient&) = delete;
bool Connect(const std::string& host, uint16_t port, std::chrono::milliseconds timeout);
void Disconnect();
bool IsConnected() const { return m_Connected; }
void Send(const std::string& bytes);
// Reads what arrived; false once the server closed the connection
bool Pump();
// Pumps until `until` returns true for a received packet (checked from `from` on) or the time is up. Returns
// the index of that packet, or -1.
int64_t WaitFor(const std::function<bool(const Received&)>& until, size_t from, std::chrono::milliseconds timeout);
// Pumps for this long
void Idle(std::chrono::milliseconds time);
const std::vector<Received>& GetReceived() const { return m_Received; }
uint16_t GetLocalPort() const { return m_LocalPort; }
private:
RakPeerInterface* m_Peer{};
SystemAddress m_Server{};
bool m_Connected{};
uint16_t m_LocalPort{};
std::vector<Received> m_Received;
};