43 lines
2.4 KiB
C++
43 lines
2.4 KiB
C++
// Every Source SMSG_TRADE_STATUS body Tortoise writes (TradeHandler.cpp SendTradeStatus + BEGIN_TRADE with the
|
|
// proposer GUID) must translate in any trade state, never throw: a throw closes the whole session (owner
|
|
// disconnect 2026-11-25 23:49, Wire close error=15 world-phase=1 world-source=0x120).
|
|
#include "world_translation.hpp"
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
using namespace gateway;
|
|
static int projection(uint32_t mode, const uint8_t* in, uint32_t size, uint32_t, uint8_t* out, uint32_t capacity, uint32_t* written) {
|
|
if (mode != GW_CODEC_TRADE_EVENT) return GW_CODEC_ARGUMENT;
|
|
*written = size; if (capacity < size) return GW_CODEC_CAPACITY; std::memcpy(out, in, size); return GW_CODEC_OK;
|
|
}
|
|
static bool octo_tail = false; // Octo live: bare statuses carry one extra u32 (8-byte OPEN_WINDOW, 2026-11-26)
|
|
static Bytes body(unsigned code, uint64_t guid) {
|
|
Bytes out; le(out, code, 4);
|
|
if (octo_tail && code != 1 && code != 12 && code != 22) le(out, 0, 4);
|
|
if (code == 1) le(out, guid, 8);
|
|
if (code == 12) { le(out, 0, 4); le(out, 0, 1); le(out, 0, 4); }
|
|
if (code == 22) le(out, 0, 1);
|
|
return out;
|
|
}
|
|
int main() {
|
|
int failures = 0;
|
|
// prefix: state reached before the probed status (idle, proposed by peer, proposed with 0 GUID, open window)
|
|
const std::vector<std::vector<std::pair<unsigned, uint64_t>>> prefixes{{}, {{1, 20}}, {{1, 0}}, {{1, 20}, {2, 0}}, {{2, 0}}};
|
|
for (bool tail : {false, true}) { octo_tail = tail;
|
|
for (size_t p = 0; p < prefixes.size(); ++p)
|
|
for (unsigned code = 0; code <= 22; ++code)
|
|
for (uint64_t guid : {uint64_t(20), uint64_t(0), uint64_t(10)}) {
|
|
NativeWorldTranslation w{}; w.selected.guid = 10; w.realm = 70; w.self_created = true;
|
|
w.location = WorldLocation{1, {0, 0, 0, 0}};
|
|
try {
|
|
for (auto [c, g] : prefixes[p]) w.translate({0x120, body(c, g)}, 0x10046, 0, projection);
|
|
w.translate({0x120, body(code, guid)}, 0x10046, 0, projection);
|
|
} catch (const std::exception& e) {
|
|
++failures; std::cout << "FAIL tail " << tail << " prefix " << p << " status " << code << " guid " << guid << ": " << e.what() << "\n";
|
|
}
|
|
}
|
|
}
|
|
if (failures) return 1;
|
|
std::cout << "PASS every Source trade status in every trade state\n";
|
|
}
|