53 lines
4.0 KiB
C++
53 lines
4.0 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include "world_translation.hpp"
|
|
#include "serializer.h"
|
|
#include "gateway/pvp_statistics.hpp"
|
|
#include <cstring>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
static void check(bool ok,const char* what){if(!ok){std::cerr<<"FAIL "<<what<<"\n";std::exit(1);}}
|
|
static int echo(uint32_t mode,const uint8_t* in,uint32_t size,uint32_t,uint8_t* out,uint32_t cap,uint32_t* written){
|
|
if(mode!=GW_CODEC_PVP_STATISTICS)return GW_CODEC_ARGUMENT;*written=size;if(cap<size)return GW_CODEC_CAPACITY;if(size)std::memcpy(out,in,size);return GW_CODEC_OK;}
|
|
static std::vector<LegacyPacket> run(NativeWorldTranslation& w,uint16_t op,const Bytes& body){
|
|
auto env=w.translate({op,body},0x46010046,0,echo);Reader r(env);std::vector<LegacyPacket> out;auto n=r.le(4);while(n--){auto o=uint32_t(r.le(4));out.push_back({o,r.take(r.le(4))});}r.end();return out;}
|
|
static Bytes status(uint32_t slot,uint32_t map,uint32_t phase){Bytes b;le(b,slot,4);le(b,map,4);if(!map)return b;le(b,0,1);le(b,1,4);le(b,phase,4);le(b,1000,4);if(phase!=2)le(b,0,4);return b;}
|
|
static Bytes board(std::vector<uint64_t> guids,std::vector<uint32_t> fields){Bytes b;le(b,0,1);le(b,guids.size(),4);
|
|
for(auto g:guids){le(b,g,8);le(b,4,4);le(b,3,4);le(b,10,4);le(b,2,4);le(b,50,4);le(b,fields.size(),4);for(auto f:fields)le(b,f,4);}return b;}
|
|
static NativeWorldTranslation fresh(uint32_t map){
|
|
NativeWorldTranslation w{};w.selected.guid=4509;w.selected.name="Selfname";w.selected.race=1;w.selected.cls=1;w.selected.gender=0;w.realm=70;w.self_created=true;
|
|
w.location=WorldLocation{map,{0,0,0,0}};return w;}
|
|
int main(){
|
|
// Objective routing by verified map, not by field count.
|
|
check((*native_pvp_stats(489,{3,1}))[0]==std::pair<int32_t,int32_t>{42,3},"WSG captures");
|
|
check((*native_pvp_stats(529,{3,1}))[0]==std::pair<int32_t,int32_t>{122,3},"AB assaults");
|
|
check(native_pvp_stats(30,{1,2,3,4,5,6,7})->size()==5 && !native_pvp_stats(30,{1,2}) && !native_pvp_stats(9999,{}),"AV omits unmapped, mismatch rejected");
|
|
// Solo queue: self is the queue leader -> Alliance (0); an unknown peer is held.
|
|
{
|
|
auto w=fresh(489);run(w,0x2d4,status(0,489,1));
|
|
Character pal{};pal.guid=812;pal.name="Pal";pal.race=2;pal.cls=3;pal.gender=1;w.chat_players[812]=pal;
|
|
auto out=run(w,0x2e0,board({4509,812,999},{2,1}));check(out.size()==1 && out[0].opcode==0x4d0010,"one board");
|
|
auto rows=pvp_statistics_from_input(out[0].body);check(rows.size()==1 && rows[0].team==0 && rows[0].kills==3 && rows[0].honorable_kills==10 && rows[0].contribution==50,"self row only");
|
|
check(rows[0].stats.size()==2 && rows[0].stats[1]==std::pair<int32_t,int32_t>{44,1},"WSG stats");
|
|
check(w.pvp_held_rows==2,"non-ally rows held");
|
|
}
|
|
// Group enrollment under a Horde leader: the whole BG raid is Horde (cross-faction group).
|
|
{
|
|
auto w=fresh(529);
|
|
Character lead{};lead.guid=812;lead.name="Lead";lead.race=2;lead.cls=1;lead.gender=0;w.chat_players[812]=lead;
|
|
TurtleGroupList g{};g.leader=812;TurtleGroupMember m{};m.guid=812;m.name="Lead";g.members.push_back(m);w.loot.group=g;
|
|
run(w,0x2d4,status(1,529,1));Bytes joined;le(joined,529,4);run(w,0x2e8,joined);
|
|
auto rows=pvp_statistics_from_input(run(w,0x2e0,board({812,4509},{4,2}))[0].body);
|
|
check(rows.size()==2 && rows[0].team==1 && rows[1].team==1 && rows[0].stats[0].first==122,"leader team, order kept, AB stats");
|
|
}
|
|
// No observed queue (Active first, e.g. relog in BG): board stays pending.
|
|
{
|
|
auto w=fresh(489);run(w,0x2d4,status(0,489,3));check(run(w,0x2e0,board({4509},{0,0})).empty(),"unknown team pending");
|
|
run(w,0x2d4,status(0,0,0));check(!w.bg_team[0],"leave clears evidence");
|
|
}
|
|
// Board on another map than the queue's: pending.
|
|
{auto w=fresh(30);run(w,0x2d4,status(0,489,1));check(run(w,0x2e0,board({4509},{})).empty(),"wrong map pending");}
|
|
// Request.
|
|
{auto w=fresh(489);check(w.gameplay(0x3e0029,{}).opcode==0x2e0,"request");}
|
|
std::cout<<"native pvp statistics PASS\n";
|
|
}
|