Files
WoW-Hybrid-gateway/tests/native_object_sound_lifecycle_test.cpp

73 lines
4.3 KiB
C++

// Socket-free SMSG_PLAY_OBJECT_SOUND admission: source distance sounds require
// a currently loaded object, not the general player-GUID synthesis fallback.
#include "world_translation.hpp"
#include <iostream>
using namespace gateway;
static int failures=0,checks=0;
static void check(bool ok,const char* label){++checks;if(!ok){++failures;std::cerr<<"FAIL "<<label<<'\n';}}
static constexpr uint64_t creature=0xf130000001000123ull,go=0xf110000002000124ull,peer=77;
static NativeWorldTranslation world(){
NativeWorldTranslation w{};w.realm=70;w.selected.guid=4509;w.selected.race=1;w.selected.cls=1;
w.selected.name="Fixture";w.self_created=true;w.location=WorldLocation{0,{0,0,0,0}};
for(auto [id,kind]:{std::pair{creature,3},std::pair{go,5},std::pair{peer,4}}){
NativeEntityTranslation::Actor a{};a.kind=kind;a.sent=true;a.eligible=true;a.generation=1;
a.presentation_realm=70;a.presentation_map=0;
a.modern=forever_player_guid(id&0xffff,70);w.entities.actors[id]=a;
}
return w;
}
static Bytes request(uint64_t id){Bytes b;le(b,1234,4);le(b,id,8);return b;}
static std::vector<Bytes> sounds(NativeWorldTranslation& w,const Bytes& body){
auto wire=w.translate({0x278,body},0x10046,0,nullptr);std::vector<Bytes> out;
if(wire.empty())return out;
Reader r(wire);auto count=r.le(4);
while(count--){auto op=r.le(4),size=r.le(4);auto raw=r.take(size);if(op==0x470216)out.emplace_back(raw.begin(),raw.end());}
r.end();return out;
}
static Bytes expected(Guid128 guid){Bytes b;le(b,1234,4);append(b,pack_guid(guid));append(b,pack_guid(guid));b.resize(b.size()+16);return b;}
int main(){try{
auto w=world();
for(auto id:{creature,go,peer,w.selected.guid}){
auto guid=id==w.selected.guid?forever_player_guid(id,70):w.entities.actors.at(id).modern;
check(sounds(w,request(id))==std::vector<Bytes>{expected(guid)},"visible object exact sound payload");
}
check(sounds(w,request(0)).empty(),"zero source is not an object");
check(sounds(w,request(88)).empty(),"unknown player cannot use synthetic binding");
check(sounds(w,request(creature+1)).empty(),"unknown creature held");
for(int state=0;state<5;++state){auto x=world();
if(state==0)x.self_created=false;
if(state==1)x.location.reset();
if(state==2)x.logout_complete=true;
if(state==3)x.pending_teleport=NearTeleport{};
if(state==4)x.far_transfer=NativeWorldTranslation::FarTransfer{};
check(sounds(x,request(creature)).empty(),"inactive world suppresses actor sound");
check(sounds(x,request(x.selected.guid)).empty(),"inactive world suppresses self sound");
}
for(int state=0;state<8;++state){auto x=world();auto& a=x.entities.actors.at(creature);
if(state==0)a.sent=false;
if(state==1)a.eligible=false;
if(state==2)a.generation=0;
if(state==3)a.presentation_realm=71;
if(state==4)a.presentation_map=1;
if(state==5)a.modern={};
if(state==6)a.kind=1;
if(state==7)a.kind=2;
check(sounds(x,request(creature)).empty(),"unloaded or stale actor suppressed");
}
// Explicit destroy/retire then a new presentation of the same source GUID.
Bytes destroy;le(destroy,creature,8);(void)w.translate({0xaa,destroy},0x10046,0,nullptr);
check(!w.entities.actors.contains(creature),"source destroy retires actor");
check(sounds(w,request(creature)).empty(),"retired binding suppressed");
auto replacement=world().entities.actors.at(creature);replacement.generation=2;
replacement.modern=forever_player_guid(999,70);w.entities.actors[creature]=replacement;
check(sounds(w,request(creature))==std::vector<Bytes>{expected(replacement.modern)},"replacement uses only current native GUID");
// Genuine source logout retires even the selected player's fallback GUID.
(void)w.translate({0x4d,{}},0x10046,0,nullptr);
check(sounds(w,request(w.selected.guid)).empty(),"source logout blocks self fallback");
for(int size:{0,4,11,13}){auto x=world();auto bad=request(creature);bad.resize(size);bool rejected=false;
try{(void)sounds(x,bad);}catch(const Error&){rejected=true;}
check(rejected,"malformed source framing rejected");
}
std::cout<<checks<<" object-sound lifecycle checks; failures="<<failures<<'\n';return failures?1:0;
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}