70 lines
6.4 KiB
C++
70 lines
6.4 KiB
C++
// Synthetic: on WSG the gateway polls Source 0x2E9 (team from the player's own Source race, as
|
|
// Tortoise GetTeam()) from inbound and idle presentation, one outstanding poll with bounded retry,
|
|
// translates the carrier into SMSG_BATTLEGROUND_PLAYER_POSITIONS and clears on departure.
|
|
#include <cstring>
|
|
#include "world_translation.hpp"
|
|
#include <algorithm>
|
|
#include <chrono>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
static void expect(bool ok,const char* what){if(!ok)throw Error(what);}
|
|
static std::vector<std::pair<uint32_t,Bytes>> unbundle(const Bytes& bundle){
|
|
std::vector<std::pair<uint32_t,Bytes>> out;if(bundle.empty())return out;Reader r(bundle);auto n=r.le(4);
|
|
for(uint64_t i=0;i<n;++i){auto op=uint32_t(r.le(4));auto size=r.le(4);auto body=r.take(size);out.emplace_back(op,Bytes(body.begin(),body.end()));}
|
|
return out;
|
|
}
|
|
static uint32_t f(float v){uint32_t u;std::memcpy(&u,&v,4);return u;}
|
|
static long polls(const NativeWorldTranslation& w){return std::count_if(w.requests.begin(),w.requests.end(),[](auto& p){return p.opcode==0x2e9 && p.body.empty();});}
|
|
static const Bytes* find(const std::vector<std::pair<uint32_t,Bytes>>& v){auto i=std::find_if(v.begin(),v.end(),[](auto& e){return e.first==0x4d0006;});return i==v.end()?nullptr:&i->second;}
|
|
int main(){try{
|
|
NativeWorldTranslation w{};w.realm=70;w.selected.guid=4509;w.selected.race=1;w.selected.name="Flag";
|
|
w.self_created=true;w.location=WorldLocation{489,{0,0,0,0}};w.virtual_realm_address=0x10046;
|
|
// Team comes from the own Source race; no queue evidence is needed (relog inside the BG).
|
|
w.translate({0x1d1,Bytes(8,0)},0x10046,0,nullptr);expect(polls(w)==1,"poll queued");
|
|
w.translate({0x1d1,Bytes(8,0)},0x10046,0,nullptr);expect(polls(w)==1,"one outstanding poll");
|
|
// Reply: one teammate, carrier 77 at (1.5, -2).
|
|
Bytes reply;le(reply,1,4);le(reply,88,8);le(reply,f(3),4);le(reply,f(4),4);le(reply,1,1);le(reply,77,8);le(reply,f(1.5f),4);le(reply,f(-2),4);
|
|
auto out=unbundle(w.translate({0x2e9,reply},0x10046,0,nullptr));
|
|
auto p=std::find_if(out.begin(),out.end(),[](auto& e){return e.first==0x4d0006;});expect(p!=out.end(),"positions emitted");
|
|
{Reader r(p->second);expect(r.le(4)==1,"one carrier");auto g=unpack_guid(r,16);auto want=forever_player_guid(77,70);expect(g==Bytes(want.begin(),want.end()),"carrier guid");
|
|
expect(r.le(4)==f(1.5f) && r.le(4)==f(-2),"xy");expect(r.le(1)==1 && r.le(1)==1,"alliance carrier holds horde flag; no arena slot");r.end();}
|
|
// No carrier -> empty list clears the icon.
|
|
w.requests.clear();w.bg_positions_next={};w.translate({0x1d1,Bytes(8,0)},0x10046,0,nullptr);expect(w.bg_positions_pending,"next poll");
|
|
Bytes none;le(none,0,4);le(none,0,1);auto cleared=unbundle(w.translate({0x2e9,none},0x10046,0,nullptr));
|
|
auto c=std::find_if(cleared.begin(),cleared.end(),[](auto& e){return e.first==0x4d0006;});expect(c!=cleared.end() && c->second==Bytes({0,0,0,0}),"cleared");
|
|
// Unsolicited / late reply (no outstanding poll) is ignored.
|
|
expect(!find(unbundle(w.translate({0x2e9,reply},0x10046,0,nullptr))),"unsolicited ignored");
|
|
// Idle: once the interval elapses, the poll is due and issued from local presentation.
|
|
w.requests.clear();expect(!w.local_presentation_pending() || polls(w)==0,"not yet due");
|
|
w.bg_positions_next=std::chrono::steady_clock::now()-std::chrono::milliseconds(1);
|
|
expect(w.local_presentation_pending(),"due while idle");w.local_presentation(0x10046,nullptr);expect(polls(w)==1,"idle poll");
|
|
// Still queued (unsent): never appended again, even after the retry deadline.
|
|
w.bg_positions_sent=std::chrono::steady_clock::now()-std::chrono::seconds(11);w.local_presentation(0x10046,nullptr);expect(polls(w)==1,"queued poll not duplicated");
|
|
// No reply: bounded retry after 10 s.
|
|
w.requests.clear();w.bg_positions_sent=std::chrono::steady_clock::now()-std::chrono::seconds(11);w.bg_positions_next={};
|
|
expect(w.local_presentation_pending(),"retry due");w.local_presentation(0x10046,nullptr);expect(polls(w)==1,"retried once");
|
|
// Carrier shown, then departure: one explicit empty list, then nothing.
|
|
w.translate({0x2e9,reply},0x10046,0,nullptr);expect(w.bg_positions_shown,"shown");
|
|
w.location->map=0;expect(w.local_presentation_pending(),"departure pending");
|
|
auto dep=unbundle(w.local_presentation(0x10046,nullptr));expect(find(dep) && *find(dep)==Bytes({0,0,0,0}),"departure clears");
|
|
expect(!w.local_presentation_pending(),"retired");
|
|
expect(!find(unbundle(w.translate({0x2e9,reply},0x10046,0,nullptr))),"late reply after departure ignored");
|
|
// Far transfer out of WSG (Source 0x3E NewWorld): explicit empty list before NewWorld.
|
|
{w.location->map=489;w.bg_positions_next={};w.requests.clear();w.translate({0x1d1,Bytes(8,0)},0x10046,0,nullptr);
|
|
w.translate({0x2e9,reply},0x10046,0,nullptr);expect(w.bg_positions_shown,"shown again");
|
|
// receive_far_transfer(0x3E) sets far_transfer mid-translate; servicing runs at the end of that translate.
|
|
NativeWorldTranslation::FarTransfer ft;ft.owner=w.selected.guid;ft.realm=w.realm;w.far_transfer=ft;
|
|
auto x=unbundle(w.translate({0x1d1,Bytes(8,0)},0x10046,0,nullptr));
|
|
auto q=std::find_if(x.begin(),x.end(),[](auto& e){return e.first==0x4d0006;});expect(q!=x.end() && q->second==Bytes({0,0,0,0}),"transfer clears");
|
|
expect(!w.bg_positions_shown && !w.bg_positions_pending,"retired on transfer");}
|
|
// Exit while a poll is still queued: only that poll is withdrawn; unrelated requests stay.
|
|
{w.far_transfer.reset();w.location->map=489;w.bg_positions_next={};w.requests.clear();w.translate({0x1d1,Bytes(8,0)},0x10046,0,nullptr);
|
|
w.requests.push_back({0x1dc,{1,2}});w.location->map=0;w.local_presentation(0x10046,nullptr);
|
|
expect(polls(w)==0 && w.requests.size()==1 && w.requests.front().opcode==0x1dc,"queued poll withdrawn, others kept");}
|
|
// Horde viewer: the carrier holds the Alliance flag (icon 2).
|
|
NativeWorldTranslation h{};h.realm=70;h.selected.guid=4510;h.selected.race=2;h.selected.name="Horde";h.self_created=true;
|
|
h.location=WorldLocation{489,{0,0,0,0}};h.virtual_realm_address=0x10046;h.translate({0x1d1,Bytes(8,0)},0x10046,0,nullptr);
|
|
{auto o=unbundle(h.translate({0x2e9,reply},0x10046,0,nullptr));auto q=find(o);expect(q,"horde emitted");Reader r(*q);r.le(4);unpack_guid(r,16);r.le(4);r.le(4);expect(r.le(1)==2,"alliance flag icon");}
|
|
std::cout<<"PASS bg flag carrier positions\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|