62 lines
5.1 KiB
C++
62 lines
5.1 KiB
C++
// Synthetic: a pending native search pages the Source sequentially, waits for every real
|
|
// template, then publishes one TC-ordered bucket window. Holds publish nothing.
|
|
#include "world_translation.hpp"
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
static void expect(bool ok,const char* what){if(!ok)throw Error(what);}
|
|
static int fake_codec(uint32_t mode,const uint8_t* in,uint32_t size,uint32_t,uint8_t* out,uint32_t capacity,uint32_t* written){
|
|
if(mode!=GW_CODEC_AUCTION_BUCKETS)return GW_CODEC_PACKET;
|
|
*written=size;if(capacity<size)return GW_CODEC_CAPACITY;std::copy(in,in+size,out);return GW_CODEC_OK;
|
|
}
|
|
static Bytes page(uint32_t first,uint32_t count,uint32_t total,uint32_t entry){
|
|
Bytes b;le(b,count,4);
|
|
for(uint32_t i=0;i<count;++i){le(b,first+i,4);le(b,entry+(first+i)%2,4);le(b,0,4);le(b,0,4);le(b,0,4);le(b,1,4);le(b,0,4);le(b,7,8);
|
|
le(b,10,4);le(b,5,4);le(b,100+first+i,4);le(b,60000,4);le(b,0,8);le(b,0,4);}
|
|
le(b,total,4);return b;
|
|
}
|
|
static std::vector<std::pair<uint32_t,Bytes>> unbundle(const Bytes& bundle){
|
|
std::vector<std::pair<uint32_t,Bytes>> 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;
|
|
}
|
|
int main(){try{
|
|
NativeWorldTranslation w{};w.realm=70;w.selected.guid=4509;w.selected.race=1;w.selected.name="Receiver";
|
|
w.self_created=true;w.location=WorldLocation{0,{0,0,0,0}};w.virtual_realm_address=0x10046;
|
|
NativeWorldTranslation::AuctionBrowseState s;s.auctioneer=0xF130000000000042ull;s.awaiting=true;s.query.sorts={{0,false}};
|
|
w.auction_browse=s;
|
|
// Page 1 of 2 (52 rows): the next Source page is requested at listfrom 50, nothing published.
|
|
auto first=unbundle(w.translate({0x25c,page(1,50,52,200)},0x10046,0,fake_codec));
|
|
expect(std::none_of(first.begin(),first.end(),[](auto& p){return p.first==0x4702f6;}),"no buckets before a complete snapshot");
|
|
expect(!w.requests.empty() && w.requests.back().opcode==0x258,"next Source page queued");
|
|
{Reader r(w.requests.back().body);r.le(8);expect(r.le(4)==50,"listfrom 50");}
|
|
// Page 2 completes; templates are unknown, so they are requested and nothing is published yet.
|
|
auto second=unbundle(w.translate({0x25c,page(51,2,52,200)},0x10046,0,fake_codec));
|
|
expect(std::none_of(second.begin(),second.end(),[](auto& p){return p.first==0x4702f6;}),"templates pending");
|
|
expect(w.auction_browse && w.auction_browse->snapshot.complete && !w.auction_browse->awaiting,"snapshot complete");
|
|
expect(w.inventory.queries.contains(200) && w.inventory.queries.contains(201),"real template queries issued");
|
|
// Real templates arrive (nonstackable armor and weapon): the bucket window is published once.
|
|
for(uint32_t e:{200u,201u}){ItemTemplateReply t;t.entry=e;t.found=true;t.cls=e==200?4:2;t.item_level=e==200?30:40;t.required_level=20;t.stack=1;t.name="Item";
|
|
w.inventory.peer_templates[e]=t;w.inventory.queries.erase(e);w.inventory.peer_template_queries.erase(e);}
|
|
auto third=unbundle(w.translate({0x1d1,Bytes(8,0)},0x10046,0,fake_codec));
|
|
auto b=std::find_if(third.begin(),third.end(),[](auto& p){return p.first==0x4702f6;});
|
|
expect(b!=third.end(),"bucket result published");
|
|
auto dto=auction_buckets_from_input(b->second);
|
|
expect(dto.total_count==2 && dto.buckets.size()==2 && dto.buckets[0].min_price<=dto.buckets[1].min_price,"two TC-ordered buckets");
|
|
expect(dto.buckets[0].total_quantity+dto.buckets[1].total_quantity==52,"every Source row counted once");
|
|
auto fourth=unbundle(w.translate({0x1d1,Bytes(8,0)},0x10046,0,fake_codec));
|
|
expect(std::none_of(fourth.begin(),fourth.end(),[](auto& p){return p.first==0x4702f6;}),"published once");
|
|
// Commodity (Codex 2026-11-21): a stackable whole-buyout stack with an exact unit price is published as a
|
|
// commodity bucket next to the regular one; the search no longer holds.
|
|
NativeWorldTranslation h=w;h.auction_browse=s;h.inventory.peer_templates[200].stack=20;
|
|
auto mixed=unbundle(h.translate({0x25c,page(1,2,2,200)},0x10046,0,fake_codec));
|
|
auto pub=std::find_if(mixed.begin(),mixed.end(),[](auto& p){return p.first==0x4702f6;});
|
|
expect(pub!=mixed.end() && h.auction_browse && h.auction_browse->ordered && h.auction_holds==0 && h.auction_commodity_omitted==0,"commodity published");
|
|
{auto cdto=auction_buckets_from_input(pub->second);expect(cdto.buckets.size()==2,"mixed buckets");
|
|
auto c=std::find_if(h.auction_browse->ordered->begin(),h.auction_browse->ordered->end(),[](const AuctionBucket& b){return b.commodity;});
|
|
expect(c!=h.auction_browse->ordered->end() && c->key.item==200 && c->min_price==102 && c->total_quantity==1,"commodity bucket by unit price");}
|
|
// Unsolicited list results are ignored.
|
|
NativeWorldTranslation u=w;u.auction_browse.reset();u.translate({0x25c,page(1,1,1,200)},0x10046,0,fake_codec);expect(!u.auction_browse,"unsolicited ignored");
|
|
std::cout<<"PASS auction browse pipeline (paging, templates, publish once, holds)\n";return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|