311 lines
15 KiB
C++
311 lines
15 KiB
C++
#include "world_translation.hpp"
|
|
#include <iostream>
|
|
|
|
using namespace gateway;
|
|
|
|
namespace {
|
|
void check(bool ok, const char* message) {
|
|
if (!ok) throw std::runtime_error(message);
|
|
}
|
|
|
|
Bytes words(std::initializer_list<uint32_t> values) {
|
|
Bytes result;
|
|
for (auto value : values) le(result, value, 4);
|
|
return result;
|
|
}
|
|
Bytes guid64(uint64_t id) { Bytes b; le(b, id, 8); return b; }
|
|
Bytes native_player(uint64_t id) { return pack_guid(forever_player_guid(id, 70)); }
|
|
|
|
struct Fixture {
|
|
NativeWorldTranslation world{};
|
|
Fixture() {
|
|
world.selected.guid = 10; world.realm = 70; world.self_created = true;
|
|
world.location = WorldLocation{1, {0, 0, 0, 0}};
|
|
}
|
|
Bytes run(uint32_t opcode, const Bytes& body) {
|
|
return world.translate({opcode, body}, 0x10046, 0, nullptr);
|
|
}
|
|
void expect(uint32_t op, const Bytes& body, uint32_t native, const Bytes& expected) {
|
|
Bytes bundle = run(op, body);
|
|
Reader r(bundle);
|
|
check(r.le(4) == 1 && r.le(4) == native, "native response opcode");
|
|
check(r.take(r.le(4)) == expected, "native response body");
|
|
r.end();
|
|
}
|
|
void silent(uint32_t op, const Bytes& body) {
|
|
check(run(op, body) == words({0}), "held or malformed event emitted a response");
|
|
}
|
|
};
|
|
void auction(Fixture& f) {
|
|
Bytes higher = words({40, 2, 5});
|
|
append(higher, guid64(21)); append(higher, words({700, 35}));
|
|
Bytes expected = words({40, 2, 5, 0}); append(expected, native_player(21));
|
|
le(expected, 35, 8); le(expected, 700, 8); le(expected, 0, 4);
|
|
f.expect(0x25b, higher, 0x47019b, expected);
|
|
for (size_t n = 0; n < higher.size(); ++n)
|
|
f.silent(0x25b, Bytes(higher.begin(), higher.begin() + n));
|
|
higher.push_back(0);
|
|
f.silent(0x25b, higher);
|
|
Bytes bid_result = words({40,2,0,33});
|
|
expected = words({40,2,0,0}); expected.resize(18,0);
|
|
le(expected,33,8); le(expected,0,8); le(expected,0,4);
|
|
f.expect(0x25b,bid_result,0x47019b,expected);
|
|
expected = words({0,0,1,4}); expected.resize(38,0);
|
|
f.expect(0x25b,words({0,0,1,4}),0x47019b,expected);
|
|
f.silent(0x25b,words({0,0,1,256}));
|
|
f.silent(0x25b,words({40,3,0}));
|
|
f.silent(0x25b,words({40,0,23}));
|
|
Bytes bidder = words({7,40}); append(bidder, guid64(21));
|
|
Bytes won = bidder; append(won, words({0,35,119,0}));
|
|
Bytes item = words({119}); item.resize(6, 0);
|
|
expected = words({7,40}); append(expected, native_player(21)); append(expected,item);
|
|
f.expect(0x25e,won,0x47019c,expected);
|
|
Bytes outbid = bidder; append(outbid,words({700,35,119,0}));
|
|
f.silent(0x25e,outbid); // only the losing bid was sent
|
|
won.back() = 0x80;
|
|
f.silent(0x25e,won); // unknown signed suffix has no native bonus list
|
|
Bytes owner = words({40,700,35}); append(owner,guid64(21)); append(owner,words({119,0}));
|
|
expected = words({40}); le(expected,700,8); append(expected,item);
|
|
le(expected,35,8); append(expected,native_player(21));
|
|
f.expect(0x25f,owner,0x47019f,expected);
|
|
for (auto amount : {700u,0u}) {
|
|
owner = words({40,amount,35}); append(owner,guid64(0)); append(owner,words({119,0}));
|
|
expected = words({40}); le(expected,amount,8); append(expected,item);
|
|
le(expected,0,4); le(expected,amount ? 0x80 : 0,1);
|
|
f.expect(0x25f,owner,0x47019e,expected);
|
|
}
|
|
// Unrequested personal lists have no native owner (a closed or retired request): silent.
|
|
// The armed empty/nonempty results are covered by native_auction_request_test.
|
|
f.silent(0x25d,words({0,0}));
|
|
f.silent(0x265,words({0,0}));
|
|
for (auto op : {0x25du,0x265u}) {
|
|
f.silent(op,words({0,51})); // an empty page out of many is not an empty list
|
|
f.silent(op,words({UINT32_MAX,0})); f.silent(op,words({1,1}));
|
|
f.silent(op,words({0,0,0}));
|
|
Bytes populated = words({1}); populated.resize(68,0); append(populated,words({1}));
|
|
f.silent(op,populated);
|
|
}
|
|
}
|
|
void battlefield_list_and_members(Fixture& f) {
|
|
for (auto op : {0x2ecu,0x2edu}) {
|
|
f.expect(op,guid64(20),op == 0x2ec ? 0x4d0009 : 0x4d000a,native_player(20));
|
|
f.silent(op,guid64(0)); f.silent(op,guid64(0xf130000000000033));
|
|
f.silent(op,words({20}));
|
|
}
|
|
constexpr uint64_t npc = 0xf130000001000033;
|
|
auto& actor = f.world.entities.actors[npc];
|
|
actor.kind = 3; actor.sent = true; actor.modern[15] = 0x20; actor.modern[0] = 0x33;
|
|
auto list = [](uint64_t sender, uint32_t map, uint32_t count) {
|
|
Bytes b = guid64(sender); le(b,map,4); le(b,2,1); le(b,count,4); return b;
|
|
};
|
|
for (auto map : {30u,489u,529u}) {
|
|
auto body = list(npc,map,2); append(body,words({501,502}));
|
|
auto expected = pack_guid(actor.modern); le(expected,map==30 ? 1 : map==489 ? 2 : 3,4);
|
|
le(expected,map==30 ? 51 : 0,1); le(expected,60,1);
|
|
append(expected,words({2,501,502})); le(expected,0,1);
|
|
f.expect(0x23d,body,0x4d0005,expected);
|
|
}
|
|
auto expected = Bytes{0,0}; le(expected,2,4); le(expected,0,1); le(expected,60,1);
|
|
le(expected,0,4); le(expected,0x80,1);
|
|
f.expect(0x23d,list(10,489,0),0x4d0005,expected);
|
|
// Turtle's minimap queue (TW_BGQueue) answers with the player's own GUID and accepts the join
|
|
// only with that GUID (BattleGroundHandler queuedAtBGPortal); keep it as the offer.
|
|
check(f.world.battlemaster_offer && f.world.battlemaster_offer->source == 10 &&
|
|
f.world.battlemaster_offer->map == 489, "self-addressed battleground list keeps the player as battlemaster");
|
|
f.silent(0x23d,list(11,489,0)); f.silent(0x23d,list(10,26,0));
|
|
f.silent(0x23d,list(10,489,UINT32_MAX)); f.silent(0x23d,list(10,489,1));
|
|
actor.sent = false;
|
|
f.silent(0x23d,list(npc,489,0));
|
|
}
|
|
void battlefield_requests() {
|
|
Fixture f;
|
|
auto expect = [&](uint32_t opcode, const Bytes& body, uint32_t source, const Bytes& expected) {
|
|
const auto packet = f.world.gameplay(opcode, body);
|
|
check(packet.opcode == source && packet.body == expected, "battleground source request");
|
|
};
|
|
auto reject = [&](uint32_t opcode, const Bytes& body) {
|
|
try { (void)f.world.gameplay(opcode, body); }
|
|
catch (const Error&) { return; }
|
|
throw std::runtime_error("accepted invalid battleground request");
|
|
};
|
|
expect(0x440008, {}, 0x2d3, {});
|
|
reject(0x440008, {0});
|
|
for (auto [list, map] : {std::pair{1u, 30u}, {2u, 489u}, {3u, 529u}}) {
|
|
expect(0x3e002b, words({list}), 0x23c, words({map}));
|
|
f.world.location->map = map;
|
|
expect(0x3e0020, {}, 0x2e1, words({map}));
|
|
}
|
|
reject(0x3e002b, words({4}));
|
|
reject(0x3e002b, words({489}));
|
|
reject(0x3e002b, {2});
|
|
reject(0x3e002b, words({2, 0}));
|
|
reject(0x3e0020, words({489}));
|
|
f.world.location->map = 1;
|
|
reject(0x3e0020, {});
|
|
f.world.location.reset();
|
|
reject(0x3e0020, {});
|
|
f.world.self_created = false;
|
|
reject(0x440008, {});
|
|
}
|
|
|
|
Bytes queue_status(uint32_t slot, uint32_t map, uint32_t instance, uint32_t phase,
|
|
std::initializer_list<uint32_t> times) {
|
|
auto body = words({slot, map});
|
|
body.push_back(0xff); // original template bracket before a match exists
|
|
append(body, words({instance, phase})); append(body, words(times));
|
|
return body;
|
|
}
|
|
|
|
Bytes one_packet(const Bytes& bundle, uint32_t opcode) {
|
|
Reader r(bundle);
|
|
check(r.le(4) == 1 && r.le(4) == opcode, "one battleground status opcode");
|
|
auto packet = r.take(r.le(4)); r.end(); return packet;
|
|
}
|
|
|
|
void queue_lifecycle() {
|
|
Fixture f;
|
|
auto queued_body = queue_status(1, 489, 0, 1, {12345, 2300});
|
|
auto observed = one_packet(f.run(0x2d4, queued_body), 0x4d0002);
|
|
Reader status(observed);
|
|
const auto player = native_player(10);
|
|
check(status.take(player.size()) == player && status.le(4) == 1 && status.le(4) == 1,
|
|
"status ticket recipient/slot/BG type");
|
|
const auto tick = status.le(8);
|
|
check(tick <= UINT32_MAX && !status.le(1), "32-bit join time in the native 64-bit field");
|
|
auto ticket = player; append(ticket, words({1, 1})); le(ticket, tick, 8); ticket.push_back(0);
|
|
auto header = [&](uint32_t instance) {
|
|
auto b = ticket; le(b, 1, 4); b.insert(b.end(), {0,60,0}); le(b, instance, 4);
|
|
le(b, 0x1f10000000000002ULL, 8); b.push_back(0); return b;
|
|
};
|
|
auto queued = header(0); append(queued, words({12345,2300,0})); queued.push_back(0x40);
|
|
check(observed == queued, "complete native queued shape, source elapsed and estimated waits");
|
|
f.expect(0x2d4, queued_body, 0x4d0002, queued);
|
|
auto cancel = ticket; cancel.push_back(0);
|
|
auto accept = ticket; accept.push_back(0x80);
|
|
auto port = [&](const Bytes& b, bool accepted) {
|
|
auto packet = f.world.gameplay(0x3f00ca, b);
|
|
auto expected = words({489}); expected.push_back(accepted ? 1 : 0);
|
|
check(packet.opcode == 0x2d5 && packet.body == expected, "source port bound to queue slot");
|
|
};
|
|
auto reject = [&](const Bytes& b) {
|
|
try { (void)f.world.gameplay(0x3f00ca, b); }
|
|
catch (const Error&) { return; }
|
|
throw std::runtime_error("accepted invalid battleground port");
|
|
};
|
|
port(cancel, false); reject(accept);
|
|
auto wrong = cancel; wrong.front() ^= 1; reject(wrong);
|
|
wrong = cancel; wrong[wrong.size()-3] ^= 1; reject(wrong);
|
|
wrong = cancel; wrong.push_back(0); reject(wrong);
|
|
wrong = cancel; wrong.back() = 0x40; reject(wrong);
|
|
queued.back() = 0xc0;
|
|
f.expect(0x2e8, words({489}), 0x4d0002, queued);
|
|
f.silent(0x2e8, words({489}));
|
|
auto malformed = queued_body; malformed.push_back(0);
|
|
f.silent(0x2d4, malformed);
|
|
f.silent(0x2d4, queue_status(3, 489, 0, 1, {1, 2}));
|
|
f.silent(0x2d4, queue_status(2, 777, 0, 1, {1, 2}));
|
|
f.silent(0x2d4, queue_status(2, 489, 0, 2, {100})); // missing prior ticket
|
|
auto invite = header(713); append(invite, words({489, 9000})); invite.push_back(0);
|
|
f.expect(0x2d4, queue_status(1, 489, 713, 2, {9000}), 0x4d0000, invite);
|
|
port(accept, true); port(cancel, false);
|
|
f.world.selected.guid = 11; reject(accept); f.world.selected.guid = 10;
|
|
f.silent(0x2d4, queue_status(1, 489, 713, 3, {0,500}));
|
|
reject(accept); reject(cancel);
|
|
f.silent(0x2d4, words({1,0,0}));
|
|
f.expect(0x2d4, words({1,0}), 0x4d0003, ticket);
|
|
reject(cancel); f.silent(0x2d4, words({1,0}));
|
|
auto next = one_packet(f.run(0x2d4, queued_body), 0x4d0002);
|
|
reject(cancel); // original slot/guid, but now a retired time
|
|
f.run(0x4d, {}); // authoritative source logout clears the queue context
|
|
f.world.logout_complete = false; f.world.self_created = true;
|
|
f.world.location = WorldLocation{1, {0,0,0,0}};
|
|
next.resize(ticket.size()); next.push_back(0);
|
|
reject(next);
|
|
check(f.world.requests.empty(), "statuses did not initiate source joins or ports");
|
|
}
|
|
|
|
void queue_tick_wrap_and_slot_reuse() {
|
|
gateway::battleground::Queue q;
|
|
const auto self = forever_player_guid(10, 70);
|
|
const auto source = queue_status(0, 489, 0, 1, {16000,50});
|
|
std::vector<LegacyPacket> packets;
|
|
for (auto expected : {UINT32_MAX - 9, UINT32_MAX - 8, UINT32_MAX - 7}) {
|
|
q.status(source, self, 40, packets); // elapsed begins across clock wrap
|
|
Reader r(packets.back().body); r.take(native_player(10).size() + 8);
|
|
check(r.le(8) == expected, "reused slot receives a unique ticket on the same tick");
|
|
q.status(words({0,0}), self, 40, packets);
|
|
check(packets.back().opcode == 0x4d0003, "old slot cleared");
|
|
}
|
|
}
|
|
|
|
void queues(Fixture& f) {
|
|
auto error = [](uint32_t id){auto b = words({id}); b.push_back(0); return b;};
|
|
f.expect(0x297,{},0x470035,error(570)); f.expect(0x298,{},0x470035,error(571));
|
|
f.silent(0x297,{1}); f.silent(0x298,{1});
|
|
for (auto [status, message] : {std::pair{1,578}, {2,573}, {3,579}})
|
|
f.expect(0x2bb,{static_cast<uint8_t>(status)},0x470035,error(message));
|
|
f.silent(0x2bb,{0}); f.silent(0x2bb,{2,1});
|
|
for (auto [status, message] : {std::pair{2,567}, {3,568}, {4,569}}) {
|
|
auto b = words({status == 3 ? 0u : 100u}); le(b,status,1);
|
|
f.expect(0x295,b,0x470035,error(message));
|
|
}
|
|
f.silent(0x295,words({0,5})); f.silent(0x295,words({0})); f.silent(0x295,{0,0,0,0,5});
|
|
f.expect(0x2e8,words({0xfffffffe}),0x470035,error(587));
|
|
f.expect(0x2e8,words({0xffffffff}),0x470035,error(590));
|
|
f.silent(0x2e8,words({30})); f.silent(0x2e8,words({30,0}));
|
|
f.silent(0x299,guid64(20)); // no localized string argument or queue-roster protocol
|
|
f.silent(0x2d4,words({0,0})); // no original native-ticket join time to clear
|
|
f.silent(0x25c,words({0,0})); // browse and item bucket queries are distinct
|
|
f.silent(0x28d,words({40,119,0})); // explicit bidder cancellation is not an owner expiry
|
|
check(f.world.requests.empty(), "inbound service report scheduled a source action");
|
|
f.world.self_created = false;
|
|
f.silent(0x2ec,guid64(21)); f.silent(0x297,{});
|
|
}
|
|
}
|
|
void battlemaster_join() {
|
|
Fixture f;
|
|
auto join = [](uint64_t queue, uint32_t count = 1) {
|
|
Bytes b; le(b, count, 4); b.push_back(0); le(b, 0, 4); le(b, 0, 4);
|
|
for (uint32_t i = 0; i < count; ++i) le(b, queue, 8);
|
|
return b;
|
|
};
|
|
auto expect_join = [&](uint64_t master, uint32_t map, uint8_t group) {
|
|
auto packet = f.world.gameplay(0x3f00c0, join(0x1f10000000000000ULL | (map == 489 ? 2 : map == 529 ? 3 : 1)));
|
|
Bytes expected; le(expected, master, 8); le(expected, map, 4); le(expected, 0, 4); expected.push_back(group);
|
|
check(packet.opcode == 0x2ee && packet.body == expected, "battlemaster join source shape");
|
|
};
|
|
auto reject = [&](const Bytes& b) {
|
|
try { (void)f.world.gameplay(0x3f00c0, b); }
|
|
catch (const Error&) { return; }
|
|
throw std::runtime_error("accepted invalid battlemaster join");
|
|
};
|
|
expect_join(0, 489, 0); // no NPC list: Source tabard path
|
|
f.world.battlemaster_offer = NativeWorldTranslation::BattlemasterOffer{0xf130000000001234ULL, 489};
|
|
expect_join(0xf130000000001234ULL, 489, 0);
|
|
expect_join(0, 529, 0); // offer is for another battleground
|
|
f.world.battlemaster_offer = NativeWorldTranslation::BattlemasterOffer{10, 489}; // minimap queue: own GUID
|
|
expect_join(10, 489, 0);
|
|
f.world.battlemaster_offer = NativeWorldTranslation::BattlemasterOffer{0xf130000000001234ULL, 489};
|
|
TurtleGroupList group; group.leader = 10; group.members.push_back(TurtleGroupMember{"Ally", 11});
|
|
f.world.loot.group = group;
|
|
expect_join(0xf130000000001234ULL, 489, 1); // leader queues the group
|
|
reject(join(0x1f10000000000001ULL)); // Source: no Alterac Valley group queue
|
|
f.world.loot.group->leader = 11;
|
|
reject(join(0x1f10000000000002ULL)); // grouped non-leader: no Source request
|
|
reject(join(0x1f10000000000002ULL, 2));
|
|
reject(join(0x1f10000000100002ULL)); // rated
|
|
reject(join(0x1f10000000000009ULL)); // unknown list
|
|
}
|
|
|
|
int main() {
|
|
try {
|
|
Fixture f;
|
|
auction(f); battlefield_list_and_members(f); queues(f); battlefield_requests();
|
|
queue_lifecycle(); queue_tick_wrap_and_slot_reuse(); battlemaster_join();
|
|
std::cout << "Auction, battleground and meeting-stone receive fixtures passed.\n";
|
|
} catch (const std::exception& e) {
|
|
std::cerr << e.what() << '\n';
|
|
return 1;
|
|
}
|
|
}
|