109 lines
7.7 KiB
C++
109 lines
7.7 KiB
C++
// An optional external roster fixture and a fully synthetic custom-race regression.
|
|
#include "world_translation.hpp"
|
|
#include "gateway/group.hpp"
|
|
#include <algorithm>
|
|
#include <dlfcn.h>
|
|
#include <fstream>
|
|
#include <filesystem>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <source_location>
|
|
using namespace gateway;
|
|
static void expect(bool v, const std::source_location at = std::source_location::current()) {
|
|
if (!v) throw Error("Party projection assertion at line " + std::to_string(at.line()));
|
|
}
|
|
static Bytes read(const char* path){std::ifstream f(path,std::ios::binary);if(!f)throw Error("private roster unavailable");return Bytes(std::istreambuf_iterator<char>(f),{});}
|
|
struct PartyHeader{uint16_t flags;uint8_t index,type;uint32_t my,sequence,count;uint64_t low,high;Bytes body;};
|
|
static PartyHeader header(const Bytes& bundle){Reader outer(bundle);expect(outer.le(4)==1 && outer.le(4)==0x470097);auto bytes=outer.le(4);auto body=outer.take(bytes);outer.end();Reader r(body);PartyHeader h{};h.body=body;h.flags=r.le(2);h.index=r.le(1);h.type=r.le(1);h.my=r.le(4);auto raw=unpack_guid(r,16);Reader id(raw);h.low=id.le(8);h.high=id.le(8);h.sequence=r.le(4);expect(r.le(1)==1);auto leader=unpack_guid(r,16);(void)leader;auto faction=r.le(1);r.le(4);expect(r.le(8)==0);h.count=r.le(4);expect(h.index==0 && h.high==(uint64_t(27)<<58));if(h.type)expect(faction==5);return h;}
|
|
static bool contains(const Bytes& b,std::string_view text){return std::search(b.begin(),b.end(),text.begin(),text.end())!=b.end();}
|
|
static constexpr uint64_t fixture_self = 100, fixture_peer = 101;
|
|
static Bytes synthetic_roster(bool raid, uint64_t leader) {
|
|
Bytes body{uint8_t(raid), 0};
|
|
le(body, 1, 4);
|
|
cstring(body, "SyntheticPeer");
|
|
le(body, fixture_peer, 8);
|
|
le(body, 1, 1); // Connected
|
|
le(body, 0, 1); // Subgroup 0
|
|
le(body, leader, 8);
|
|
le(body, 0, 1); // Free for all
|
|
le(body, 0, 8);
|
|
le(body, 2, 1);
|
|
le(body, 0, 1);
|
|
return body;
|
|
}
|
|
|
|
static void expect_faction(const Bytes& bundle, bool raid, uint8_t leader_faction) {
|
|
Reader envelope(bundle);
|
|
expect(envelope.le(4) == 1 && envelope.le(4) == 0x470097);
|
|
auto body = envelope.take(size_t(envelope.le(4)));
|
|
envelope.end();
|
|
Reader r(body);
|
|
expect(r.le(2) == (raid ? 2u : 0u));
|
|
expect(r.le(1) == 0 && r.le(1) == 1 && r.le(4) == 0);
|
|
unpack_guid(r, 16);
|
|
r.le(4);
|
|
expect(r.le(1) == 1);
|
|
unpack_guid(r, 16);
|
|
expect(r.le(1) == leader_faction);
|
|
r.le(4);
|
|
expect(r.le(8) == 0);
|
|
expect(r.le(4) == 2);
|
|
}
|
|
|
|
static void custom_race_rosters(const NativeWorldTranslation& seeded, decltype(&gw_codec_serialize) codec) {
|
|
// Clone a previously accepted roster so that its party GUID and sequence
|
|
// are identical in the real serialized controls and the custom-race cases.
|
|
for (bool raid : {false, true}) {
|
|
for (uint64_t leader : {fixture_self, fixture_peer}) {
|
|
const auto roster = synthetic_roster(raid, leader);
|
|
auto render = [&](uint8_t self_race, uint8_t peer_race) {
|
|
auto world = seeded;
|
|
world.selected.race = self_race;
|
|
world.chat_players.at(fixture_peer).race = peer_race;
|
|
return world.translate({0x7d, roster}, 0x10046, 0, codec);
|
|
};
|
|
auto horde_alliance = render(2, 1);
|
|
auto alliance_horde = render(1, 2);
|
|
expect_faction(horde_alliance, raid, leader == fixture_self ? 5 : 3);
|
|
expect_faction(alliance_horde, raid, leader == fixture_self ? 3 : 5);
|
|
if (render(9, 10) != horde_alliance || render(10, 9) != alliance_horde)
|
|
throw Error("custom-race PartyUpdate differs from the matching source-team control");
|
|
expect(render(11, 1) == Bytes(4, 0));
|
|
expect(render(2, 11) == Bytes(4, 0));
|
|
}
|
|
}
|
|
}
|
|
|
|
int main(int argc,char** argv){try{
|
|
if(argc!=3)throw Error("roster fixture or --synthetic-custom-races, and matching codec path required");
|
|
const bool synthetic=std::string_view(argv[1])=="--synthetic-custom-races";
|
|
if(synthetic && !std::filesystem::exists(argv[2])) { std::cout<<"Source codec unavailable\n";return 77; }
|
|
auto actual=synthetic?synthetic_roster(true,fixture_self):read(argv[1]);auto group=turtle_group_list(actual);expect(!group.explicit_solo && group.type==TurtleGroupType::raid && !group.members.empty());
|
|
void* lib=dlopen(argv[2],RTLD_NOW|RTLD_LOCAL);if(!lib)throw Error("matching codec unavailable");auto codec=reinterpret_cast<decltype(&gw_codec_serialize)>(dlsym(lib,"gw_codec_serialize"));expect(codec);
|
|
NativeWorldTranslation world{};world.selected.guid=group.leader;world.selected.name="SyntheticReceiver";world.selected.race=6;world.selected.cls=1;world.realm=70;world.self_created=true;world.location=WorldLocation{1,{0,0,0,0}};
|
|
const Bytes empty(4,0);expect(world.translate({0x7d,actual},0x10046,0,codec)==empty);expect(world.party.pending && world.requests.size()==group.members.size());
|
|
const auto queued=world.requests.size();expect(world.translate({0x7d,actual},0x10046,0,codec)==empty && world.requests.size()==queued); // Same outstanding identity does not requery.
|
|
world.requests.clear();Bytes rendered;
|
|
for(const auto& m:group.members){Bytes name;le(name,m.guid,8);cstring(name,m.name);cstring(name,"");le(name,6,4);le(name,0,4);le(name,1,4);rendered=world.translate({0x51,name},0x10046,0,codec);}
|
|
if (synthetic) {
|
|
expect(world.party.shown && !world.party.pending);
|
|
custom_race_rosters(world, codec);
|
|
std::cout << "PASS synthetic Goblin/High Elf self, peer and leader in party and raid; unknown races held\n";
|
|
return 0;
|
|
}
|
|
auto first=header(rendered);expect(first.flags==2 && first.type==1 && first.my==0 && first.sequence==1 && first.count==group.members.size()+1);
|
|
auto leave=world.gameplay(0x440075,Bytes{0});expect(leave.opcode==0x7b && leave.body.empty() && world.party.shown);
|
|
expect(world.gameplay(0x440075,Bytes{0x80,0}).body.empty());
|
|
bool wrong_category=false;try{(void)world.gameplay(0x440075,Bytes{0x80,1});}catch(const Error&){wrong_category=true;}expect(wrong_category);
|
|
Bytes method{0,2};append(method,pack_guid(forever_player_guid(group.leader,70)));le(method,2,4);
|
|
auto policy=world.gameplay(0x440074,method);expect(policy.opcode==0x7a);Reader policy_body(policy.body);expect(policy_body.le(4)==2 && policy_body.le(8)==group.leader && policy_body.le(4)==2);policy_body.end();
|
|
auto other=world;other.loot.group->leader=group.members.front().guid;bool not_leader=false;try{(void)other.gameplay(0x440074,method);}catch(const Error&){not_leader=true;}expect(not_leader);
|
|
expect(contains(first.body,"SyntheticReceiver"));for(const auto& m:group.members)expect(contains(first.body,m.name));expect(world.party.shown && !world.party.pending);
|
|
auto normal=actual;normal[0]=0;auto normal_h=header(world.translate({0x7d,normal},0x10046,0,codec));expect(!normal_h.flags && normal_h.type==1 && normal_h.low==first.low && normal_h.sequence==2);
|
|
auto clear=header(world.translate({0x7d,Bytes(24,0)},0x10046,0,codec));expect(clear.flags==16 && !clear.type && clear.my==UINT32_MAX && clear.low==first.low && clear.sequence==3 && clear.count==0);expect(!world.party.shown && !world.party.counter);
|
|
auto recreated=header(world.translate({0x7d,actual},0x10046,0,codec));expect(recreated.low!=first.low && recreated.sequence==4 && recreated.type==1);
|
|
auto held=world;held.chat_players.at(group.members.front().guid).race=11;expect(held.translate({0x7d,actual},0x10046,0,codec)==empty && held.party.pending); // Unknown Source race must still hold the roster.
|
|
std::cout << "PASS source roster, receiver inclusion, lifecycle and unknown-race hold\n";
|
|
return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|