344 lines
23 KiB
C++
344 lines
23 KiB
C++
#include "world_translation.hpp"
|
|
#include <chrono>
|
|
#include <iostream>
|
|
#include <limits>
|
|
#include <stdexcept>
|
|
|
|
using namespace gateway;
|
|
using namespace std::chrono_literals;
|
|
|
|
namespace {
|
|
void check(bool ok,const char* why){if(!ok)throw std::runtime_error(why);}
|
|
|
|
struct Box {
|
|
MailboxActor actor;
|
|
MailboxTemplateEvidence evidence;
|
|
Bytes request;
|
|
explicit Box(uint32_t counter) {
|
|
actor.entry=42;actor.generation=1;actor.map=1;actor.realm=1;
|
|
actor.source_guid=(uint64_t{0xf110}<<48)|(uint64_t{42}<<24)|counter;
|
|
actor.native_guid=forever_game_object_guid(actor.source_guid,actor.entry,actor.realm,actor.map);
|
|
actor.sent=actor.eligible=true;
|
|
evidence.source_guid=actor.source_guid;evidence.generation=1;evidence.map=1;evidence.realm=1;
|
|
evidence.source.found=true;evidence.source.entry=42;evidence.source.type=19;
|
|
request=pack_guid(actor.native_guid);
|
|
}
|
|
void send(MailboxTranslation& state) const {state.sent(request,actor,evidence);}
|
|
};
|
|
|
|
Bytes list(std::initializer_list<uint32_t> text_ids,std::string_view subject="Title"){
|
|
Bytes b{uint8_t(text_ids.size())};uint32_t mail=0;
|
|
for(auto id:text_ids){
|
|
le(b,++mail,4);le(b,3,1);le(b,10,4);cstring(b,std::string(subject));
|
|
le(b,id,4);le(b,0,4);le(b,41,4);
|
|
b.resize(b.size()+16+1+12+12,0);
|
|
le(b,std::bit_cast<uint32_t>(1.0f),4);le(b,0,4);
|
|
}
|
|
return b;
|
|
}
|
|
Bytes response(uint32_t id,std::string_view text){Bytes b;le(b,id,4);cstring(b,std::string(text));return b;}
|
|
void expect_list(const MailboxProjection& p,std::initializer_list<std::string_view> texts){
|
|
check(p.native_opcode==0x470201 && p.native_body && p.holds.empty(),"expected native mail list");
|
|
Reader r(*p.native_body);
|
|
check(r.le(4)==texts.size() && r.le(4)==texts.size(),"mail counts");
|
|
uint32_t mail=0;
|
|
for(auto text:texts){
|
|
check(r.le(8)==++mail && r.le(4)==3,"mail header");
|
|
r.take(8+4+8+4+4+4);check(r.le(4)==0 && r.le(4)==10,"no attachment, matching sender");
|
|
auto title_length=r.le(1);auto high=r.le(1);auto low=r.le(1);
|
|
auto text_length=(high<<5)|(low>>3);
|
|
auto title=r.take(title_length);auto actual=r.take(text_length);
|
|
check(std::string_view(reinterpret_cast<const char*>(title.data()),title.size())=="Title","subject");
|
|
check(std::string_view(reinterpret_cast<const char*>(actual.data()),actual.size())==text,"body bytes");
|
|
}
|
|
r.end();
|
|
}
|
|
|
|
void check_pending_mail(){
|
|
NativeWorldTranslation world;
|
|
world.self_created=true;
|
|
world.realm=1;
|
|
world.selected.guid=42;
|
|
const auto query=world.gameplay(0x3f00de,{});
|
|
check(query.opcode==0x284 && query.body.empty(),"stock next-mail query requires no mailbox");
|
|
|
|
auto source_time=[](float seconds){
|
|
Bytes body;
|
|
le(body,std::bit_cast<uint32_t>(seconds),4);
|
|
return body;
|
|
};
|
|
auto expect_summary=[&](float seconds,bool unread){
|
|
const auto batch=world.translate({0x284,source_time(seconds)},0x10001,0,nullptr);
|
|
Reader r(batch);
|
|
check(r.le(4)==1 && r.le(4)==0x470202,"stock mail query reply");
|
|
const auto length=r.le(4);
|
|
check(length==r.left() && r.f32()==seconds,"mail summary length and time");
|
|
check(r.le(4)==(unread ? 1u : 0u),"70334 requires a nonempty list for waiting mail");
|
|
if(unread){
|
|
check(unpack_guid(r,16)==Bytes(16,0),"source supplies no player sender");
|
|
check(r.f32()==0 && r.le(4)==0 && r.le(4)==0 && r.le(4)==0,
|
|
"unread entry is delivered and has no alternate sender or stationery");
|
|
}
|
|
r.end();
|
|
};
|
|
expect_summary(-86400.0f,false);
|
|
const auto delivery=world.translate({0x285,Bytes(4)},0x10001,0,nullptr);
|
|
Reader notice(delivery);
|
|
check(notice.le(4)==1 && notice.le(4)==0x4700e6 && notice.le(4)==4 && notice.f32()==0,
|
|
"online delivery sends the stock immediate mail notification");
|
|
notice.end();
|
|
expect_summary(0.0f,true);
|
|
expect_summary(-86400.0f,false);
|
|
expect_summary(90.0f,false);
|
|
|
|
for(const Bytes& invalid:{Bytes(3),Bytes(5),source_time(std::numeric_limits<float>::quiet_NaN()),
|
|
source_time(std::numeric_limits<float>::infinity()),source_time(-1.0f)}){
|
|
try{
|
|
check(world.translate({0x284,invalid},0x10001,0,nullptr)==Bytes(4),"invalid mail timer published");
|
|
}catch(const Error&){ /* Truncated or trailing data. */ }
|
|
}
|
|
expect_summary(0.0f,true);
|
|
}
|
|
}
|
|
|
|
int main(){try {
|
|
check_pending_mail();
|
|
{ // Source SendMailResult always includes item/count for TAKE_ITEM unless EQUIP_ERROR.
|
|
NativeWorldTranslation world;world.realm=1;world.selected.guid=42;
|
|
auto result=[](uint32_t action,uint32_t error){Bytes b;le(b,73,4);le(b,action,4);le(b,error,4);return b;};
|
|
auto expected=[](uint32_t action,uint32_t error,uint32_t count){
|
|
Bytes body;le(body,73,8);le(body,action,4);le(body,error,4);le(body,0,4);
|
|
le(body,action==2?73:0,8);le(body,count,4);
|
|
Bytes batch;le(batch,1,4);le(batch,0x4700e5,4);le(batch,body.size(),4);append(batch,body);return batch;
|
|
};
|
|
auto translate=[&](const Bytes& b){return world.translate({0x239,b},0x10001,0,nullptr);};
|
|
auto taken=result(2,0);le(taken,61409,4);le(taken,8,4);
|
|
check(translate(taken)==expected(2,0,8),"mail take: full native result preserves quantity and listed attachment identity");
|
|
for(auto error:{0u,2u,3u}){
|
|
auto complete=result(2,error);le(complete,error?0:61409,4);le(complete,error?0:8,4);
|
|
check(translate(complete)==expected(2,error,error?0:8),"mail take success/error required suffix");
|
|
for(size_t size=0;size<complete.size();++size){
|
|
Bytes prefix(complete.begin(),complete.begin()+size);bool refused=false;
|
|
try{refused=translate(prefix)==Bytes(4);}catch(const Error&){refused=true;}
|
|
check(refused,"truncated take-item result must not become a native confirmation");
|
|
}
|
|
complete.push_back(0);bool refused=false;try{refused=translate(complete)==Bytes(4);}catch(const Error&){refused=true;}
|
|
check(refused,"trailing mail result byte refused");
|
|
check(translate(taken)==expected(2,0,8),"valid mail result recovers after malformed input");
|
|
}
|
|
auto equip=result(2,1);le(equip,0,4);
|
|
check(translate(equip)==expected(2,1,0),"equipment error has only equipment suffix");
|
|
for(auto action:{0u,1u,3u,4u,5u})
|
|
check(translate(result(action,0))==expected(action,0,0),"other mail commands retain exact short framing");
|
|
}
|
|
Box a{1},b{2};
|
|
MailboxTranslation m;auto now=std::chrono::steady_clock::time_point{}+1h;
|
|
a.send(m);
|
|
expect_list(m.receive_list(Bytes{0},a.actor,now),{});
|
|
check(!m.pending() && !m.next_text(a.actor,now),"empty inbox completed immediately");
|
|
a.send(m);expect_list(m.receive_list(list({0}),a.actor,now),{""});
|
|
|
|
a.send(m);
|
|
check(!m.receive_list(list({91,92,91}),a.actor,now).native_body,"wait for both unique bodies");
|
|
check(!m.receive_text(response(91,"early"),a.actor,now).native_body,"text before its sent request");
|
|
auto first=m.next_text(a.actor,now);
|
|
check(first && first->first==91 && first->second==1,"first request");
|
|
check(m.next_text(a.actor,now)==first,"uncommitted transport retry retains request");
|
|
m.text_sent(91,now);
|
|
auto second=m.next_text(a.actor,now);
|
|
check(second && second->first==92 && second->second==2,"second request");
|
|
m.text_sent(92,now);
|
|
check(!m.receive_text(response(92,""),a.actor,now).native_body,"empty authoritative response held for peer");
|
|
check(!m.receive_text(response(92,"duplicate"),a.actor,now).native_body,"ignore duplicate");
|
|
check(!m.receive_list(list({0}),a.actor,now).native_body,"duplicate list cannot displace bodies");
|
|
check(!m.next_text(a.actor,now+4s),"bounded retry timing");
|
|
check(m.next_text(a.actor,now+5s)==first,"only missing body re-requested");
|
|
m.text_sent(91,now+5s);
|
|
check(!m.next_text(a.actor,now+10s),"no third attempt");
|
|
expect_list(m.receive_text(response(91,"One\r\nTwo\nThree"),a.actor,now+11s),
|
|
{"One\r\nTwo\nThree","","One\r\nTwo\nThree"});
|
|
check(!m.receive_text(response(91,"late"),a.actor,now+12s).native_body,"no duplicate list emission");
|
|
|
|
a.send(m);m.receive_list(list({93}),a.actor,now);m.text_sent(93,now);
|
|
// An inaccessible actor cannot replace the current list.
|
|
auto invalid=b;invalid.actor.eligible=false;
|
|
bool rejected=false;try{invalid.send(m);}catch(const Error&){rejected=true;}
|
|
check(rejected,"switch guard");
|
|
// A valid retry can start immediately while the old body's reply is outstanding.
|
|
a.send(m);
|
|
check(!m.receive_text(response(93,"old"),a.actor,now).native_body,"old reply before refreshed list");
|
|
m.receive_list(list({94}),a.actor,now);m.text_sent(94,now);
|
|
b.send(m);
|
|
check(!m.receive_text(response(94,"old"),b.actor,now).native_body,"delayed old-box response");
|
|
m.receive_list(list({95}),b.actor,now);m.text_sent(95,now);
|
|
check(!m.receive_text(response(94,"old"),b.actor,now).native_body,"unlisted id after switch");
|
|
expect_list(m.receive_text(response(95,"There is no info for this item"),b.actor,now),
|
|
{"There is no info for this item"});
|
|
|
|
b.send(m);m.receive_list(list({96}),b.actor,now);m.text_sent(96,now);
|
|
check(!m.receive_text(response(96,std::string(8192,'x')),b.actor,now).native_body,"oversize reply ignored");
|
|
check(!m.receive_text(Bytes{96},b.actor,now).native_body,"truncated reply ignored");
|
|
check(!m.next_text(b.actor,now+16s) && !m.pending(),"missing response retires expired request");
|
|
check(!m.receive_text(response(96,"late"),b.actor,now+17s).native_body,"missing body never fabricated");
|
|
b.send(m);expect_list(m.receive_list(Bytes{0},b.actor,now+18s),{});
|
|
b.send(m);auto invalid_title=m.receive_list(list({0},"two\nlines"),b.actor,now);
|
|
check(invalid_title.native_body && invalid_title.holds.empty() && invalid_title.omitted.size()==1 &&
|
|
Reader(*invalid_title.native_body).le(4)==0,"multi-line subject omits only that mail");
|
|
b.send(m);m.receive_list(list({97}),b.actor,now);m.text_sent(97,now);
|
|
auto stale=b.actor;++stale.generation;
|
|
check(!m.receive_text(response(97,"old"),stale,now).native_body && !m.pending(),"stale actor/retirement");
|
|
NativeWorldTranslation world{};
|
|
world.self_created=true;world.realm=1;world.selected.guid=41;world.location=WorldLocation{1,{}};
|
|
for(const Box* box:{&a,&b}){
|
|
auto& actor=world.entities.actors[box->actor.source_guid];
|
|
actor.kind=5;actor.entry=box->actor.entry;actor.generation=1;actor.sent=actor.eligible=true;
|
|
actor.modern=box->actor.native_guid;actor.presentation_map=1;actor.presentation_realm=1;
|
|
world.mailbox_templates[box->actor.source_guid]=box->evidence;
|
|
}
|
|
const auto list_op=0x3f00dbu;
|
|
auto initial=world.gameplay(list_op,a.request);
|
|
check(initial.opcode==0x23a && Reader(initial.body).le(8)==a.actor.source_guid,"real source mailbox request");
|
|
world.gameplay_sent(list_op,a.request);
|
|
check(world.coalesce_mailbox_list(a.request) && !world.next_mailbox_actor,"rapid same-box clicks coalesced");
|
|
check(world.coalesce_mailbox_list(b.request) && !world.next_mailbox_list(),"switched box waits for untagged prior list");
|
|
{
|
|
NativeWorldTranslation lost{};
|
|
lost.self_created=true;lost.realm=1;lost.selected.guid=41;lost.location=WorldLocation{1,{}};
|
|
for(const Box* box:{&a,&b}){
|
|
auto& actor=lost.entities.actors[box->actor.source_guid];
|
|
actor.kind=5;actor.entry=box->actor.entry;actor.generation=1;actor.sent=actor.eligible=true;
|
|
actor.modern=box->actor.native_guid;actor.presentation_map=1;actor.presentation_realm=1;
|
|
lost.mailbox_templates[box->actor.source_guid]=box->evidence;
|
|
}
|
|
check(lost.gameplay(list_op,a.request).opcode==0x23a,"first mailbox request sent");
|
|
lost.gameplay_sent(list_op,a.request);
|
|
lost.mailbox_list.clear();
|
|
lost.mailbox_list.sent(a.request,a.actor,a.evidence,std::chrono::steady_clock::now()-11s);
|
|
// The first Source reply was dropped. A later mailbox open after
|
|
// travel must not remain behind that untagged pending list.
|
|
lost.location=WorldLocation{1,{500.f,500.f,0.f,0.f}};
|
|
check(!lost.coalesce_mailbox_list(b.request),"expired list does not swallow the new open");
|
|
check(lost.gameplay(list_op,b.request).opcode==0x23a,"new mailbox source list requested");
|
|
lost.gameplay_sent(list_op,b.request);
|
|
auto fresh=lost.translate({0x23b,list({})},1,1,nullptr);
|
|
Reader inbox(fresh);check(inbox.le(4)==1 && inbox.le(4)==0x470201,"fresh Inbox emitted after lost reply");
|
|
}
|
|
auto stale_list=world.translate({0x23b,list({111})},1,1,nullptr);
|
|
check(stale_list==Bytes(4,0),"old list produced no native result or fresh text queries");
|
|
auto switched=world.next_mailbox_list();
|
|
check(switched && Reader(switched->source_body).le(8)==b.actor.source_guid,"switched source request");
|
|
world.gameplay_sent(list_op,b.request);
|
|
check(world.translate({0x23b,list({112})},1,2,nullptr)==Bytes(4,0),"wait for correct new list text");
|
|
auto q=world.mailbox_list.next_text(world.current_mailbox_actor());
|
|
check(q && q->first==112 && q->second==1,"world route requests the new list's body");
|
|
world.mailbox_list.text_sent(q->first);
|
|
check(world.translate({0x244,response(111,"retired")},1,3,nullptr)==Bytes(4,0),"late unlisted world reply ignored");
|
|
auto bundle=world.translate({0x244,response(112,"first\nsecond")},1,4,nullptr);
|
|
Reader br(bundle);check(br.le(4)==1 && br.le(4)==0x470201,"world native mail opcode");
|
|
auto length=br.le(4);auto native=br.take(length);br.end();
|
|
MailboxProjection result;result.native_body.emplace(native.begin(),native.end());
|
|
expect_list(result,{"first\nsecond"});
|
|
check(world.translate({0x244,response(112,"duplicate")},1,5,nullptr)==Bytes(4,0),"completed reply emitted only once");
|
|
{
|
|
// Another spawn of the same entry: the client queried the template once (for a), so it shares that evidence.
|
|
Box c{3};auto& actor=world.entities.actors[c.actor.source_guid];
|
|
actor.kind=5;actor.entry=42;actor.generation=1;actor.sent=actor.eligible=true;
|
|
actor.modern=c.actor.native_guid;actor.presentation_map=1;actor.presentation_realm=1;
|
|
auto shared=world.gameplay(list_op,c.request);
|
|
check(shared.opcode==0x23a && Reader(shared.body).le(8)==c.actor.source_guid,"same-entry mailbox without its own query");
|
|
// Send from that mailbox: native SendMail (packed box, stationery, money, cod, 9/9/11/5 bits, strings).
|
|
Bytes send=c.request;le(send,41,4);le(send,0,8);le(send,0,8);
|
|
const std::string to="Blasphemy",subject="hi",text="body";
|
|
uint64_t bits=(uint64_t(to.size())<<31)|(uint64_t(subject.size())<<22)|(uint64_t(text.size())<<11);
|
|
for(int i=4;i>=0;--i)send.push_back(uint8_t(bits>>(i*8)));
|
|
send.insert(send.end(),to.begin(),to.end());send.insert(send.end(),subject.begin(),subject.end());send.insert(send.end(),text.begin(),text.end());
|
|
auto sent=world.gameplay(0x440026,send);
|
|
Reader sr(sent.body);check(sent.opcode==0x238 && sr.le(8)==c.actor.source_guid && sr.cstring(64)==to && sr.cstring(64)==subject && sr.cstring(600)==text,"send mail from shared-entry mailbox");
|
|
{ // Owner 2026-11-27 (OCTO): native mail with 2 attachments was refused; Source mail carries one item each.
|
|
namespace F=gateway::turtle_entity_fields;
|
|
const uint64_t i1=0x4000000000000901ull,i2=0x4000000000000902ull;
|
|
for(auto [slot,g]:{std::pair{0,i1},std::pair{1,i2}}){
|
|
world.inventory.player_fields[F::PLAYER_FIELD_PACK_SLOT_1+2*slot]=uint32_t(g);world.inventory.player_fields[F::PLAYER_FIELD_PACK_SLOT_1+2*slot+1]=uint32_t(g>>32);
|
|
LegacyObjectUpdate u;u.guid=g;u.type=1;u.fields[3]=2589;u.fields[14]=1;world.inventory.items[g]=u;}
|
|
const auto& own=world.inventory.owned_bindings();
|
|
auto multi=[&](uint64_t money,uint64_t cod){
|
|
Bytes m=c.request;le(m,41,4);le(m,money,8);le(m,cod,8);
|
|
uint64_t mb=(uint64_t(to.size())<<31)|(uint64_t(subject.size())<<22)|(uint64_t(text.size())<<11)|(uint64_t(2)<<6);
|
|
for(int i=4;i>=0;--i)m.push_back(uint8_t(mb>>(i*8)));
|
|
m.insert(m.end(),to.begin(),to.end());m.insert(m.end(),subject.begin(),subject.end());m.insert(m.end(),text.begin(),text.end());
|
|
for(int s=0;s<2;++s){m.push_back(uint8_t(s));append(m,pack_guid(own.at(s?i2:i1)));}
|
|
return m;};
|
|
const auto two=multi(500,0);
|
|
bool ok=true;try{(void)world.gameplay(0x440026,two);}catch(const Error&){ok=false;}
|
|
check(ok,"two-item native mail is sent");
|
|
const auto mails=world.mail_send_packets(two);
|
|
auto field=[&](const LegacyPacket& p,uint64_t& item,uint32_t& money){Reader q(p.body);(void)q.le(8);(void)q.cstring(64);(void)q.cstring(64);(void)q.cstring(600);
|
|
(void)q.le(4);(void)q.le(4);item=q.le(8);money=uint32_t(q.le(4));};
|
|
uint64_t a=0,b=0;uint32_t ma=0,mb2=0;
|
|
if(mails.size()==2){field(mails[0],a,ma);field(mails[1],b,mb2);}
|
|
check(mails.size()==2 && a==i1 && b==i2 && ma==500 && mb2==0,"one Source mail per attachment, money on the first");
|
|
bool cod_refused=false;try{(void)world.mail_send_packets(multi(0,100));}catch(const Error&){cod_refused=true;}
|
|
check(cod_refused,"multi-item COD stays refused (receiver would pay per mail)");
|
|
}
|
|
// Entry never queried this session (client answered from gameobjectcache.wdb): reviewed type-19 row.
|
|
Box d{4};d.actor.entry=77;d.actor.source_guid=(uint64_t{0xf110}<<48)|(uint64_t{77}<<24)|4;
|
|
d.actor.native_guid=forever_game_object_guid(d.actor.source_guid,77,1,1);d.request=pack_guid(d.actor.native_guid);
|
|
auto& cached=world.entities.actors[d.actor.source_guid];
|
|
cached.kind=5;cached.entry=77;cached.generation=1;cached.sent=cached.eligible=true;
|
|
cached.modern=d.actor.native_guid;cached.presentation_map=1;cached.presentation_realm=1;
|
|
bool refused=false;try{(void)world.gameplay(list_op,d.request);}catch(const Error&){refused=true;}
|
|
check(refused,"unreviewed cached entry stays held");
|
|
world.gameobject_template_authority=[](const GameObjectTemplateReply& r)->std::optional<GameObjectTemplateAuthority>{
|
|
if(r.entry!=77)return std::nullopt;GameObjectTemplateAuthority a;a.entry=77;a.type=19;a.source_display=2128;
|
|
a.source_name="Horde Mailbox";a.provenance="test";return a;};
|
|
auto from_cache=world.gameplay(list_op,d.request);
|
|
check(from_cache.opcode==0x23a && Reader(from_cache.body).le(8)==d.actor.source_guid,"cached reviewed mailbox");
|
|
world.gameobject_template_authority=[](const GameObjectTemplateReply& r)->std::optional<GameObjectTemplateAuthority>{
|
|
GameObjectTemplateAuthority a;a.entry=r.entry;a.type=3;a.provenance="test";return a;};
|
|
refused=false;try{(void)world.gameplay(list_op,d.request);}catch(const Error&){refused=true;}
|
|
check(refused,"cached non-mailbox row refused");
|
|
}
|
|
{ // Report 20261128-121851-177f1b: an auction mail whose item has a random property ("of Intellect") hid the
|
|
// whole mailbox (empty native bonus-list profile -> AttachmentAuthority hold). It is now listed with the
|
|
// property's enchantment in slot 3, like the bag path; an unknown property still holds.
|
|
auto auction=[](uint32_t property){
|
|
Bytes b{1};le(b,500,4);le(b,2,1);le(b,7,4);cstring(b,"15215:5:1");le(b,0,4);le(b,0,4);le(b,62,4);
|
|
le(b,15215,4);le(b,0,4);le(b,property,4);le(b,0,4);le(b,1,1);le(b,0,4);le(b,50,4);le(b,50,4);
|
|
le(b,0,4);le(b,0,4);le(b,0,4);le(b,std::bit_cast<uint32_t>(30.0f),4);le(b,0,4);return b;};
|
|
Box e{5};MailboxTranslation mb;auto t0=std::chrono::steady_clock::time_point{}+1h;
|
|
e.send(mb);auto p=mb.receive_list(auction(5),e.actor,t0);
|
|
check(p.native_body && p.holds.empty(),"random-property auction mail listed");
|
|
Reader r(*p.native_body);check(r.le(4)==1 && r.le(4)==1,"one mail");
|
|
check(r.le(8)==500 && r.le(4)==2,"auction header");r.take(8+4+8+4+4+4);
|
|
check(r.le(4)==1 && r.le(4)==7,"one attachment, auction house sender");
|
|
check(r.le(1)==0 && r.le(8)==500 && r.le(4)==15215 && r.le(1)==0 && r.le(1)==0,"base item, no bonus list");
|
|
check(r.le(4)==1 && r.le(4)==0 && r.le(4)==50 && r.le(4)==50,"count/charges/durability");
|
|
check(r.le(1)==((1u<<4)|(1u<<1)),"one enchantment");
|
|
check(r.le(4)==79 && r.le(4)==0 && r.le(4)==0 && r.le(1)==3,"of Intellect enchantment 79 in slot 3");
|
|
// Shop items with unlimited charges: Turtle Item::GetSpellCharges() is int32 -1, sent as uint32.
|
|
auto infinite=auction(0);infinite[1+4+1+4+10+4+4+4+4+4+4+4+1]=0xff;
|
|
for(size_t i=0;i<4;++i)infinite[1+4+1+4+10+4+4+4+4+4+4+4+1+i]=0xff;
|
|
e.send(mb);auto charges=mb.receive_list(infinite,e.actor,t0);
|
|
check(charges.native_body && charges.holds.empty(),"charges -1 attachment listed");
|
|
{Reader q(*charges.native_body);q.take(4+4+8+4+8+4+8+4+4+4+4+4+1+8+4+1+1+4);check(q.le(4)==0xffffffffu,"charges -1 kept");}
|
|
e.send(mb);auto unknown=mb.receive_list(auction(999999),e.actor,t0);
|
|
check(unknown.native_body && unknown.omitted.size()==1 && unknown.omitted[0].first==500 &&
|
|
Reader(*unknown.native_body).le(4)==0,"unknown random property omits only that mail");
|
|
// Mixed list: a system-written player mail (sender GUID 0) and an unusable mail beside a good one.
|
|
Bytes mixed{3};
|
|
auto add=[&](uint32_t id,uint8_t type,uint64_t sender,uint32_t property){
|
|
le(mixed,id,4);le(mixed,type,1);if(type==0)le(mixed,sender,8);else le(mixed,sender,4);cstring(mixed,"s");
|
|
le(mixed,0,4);le(mixed,0,4);le(mixed,41,4);
|
|
le(mixed,property?15215:0,4);le(mixed,0,4);le(mixed,property,4);le(mixed,0,4);le(mixed,property?1:0,1);le(mixed,0,4);le(mixed,0,4);le(mixed,0,4);
|
|
le(mixed,0,4);le(mixed,0,4);le(mixed,0,4);le(mixed,std::bit_cast<uint32_t>(10.0f),4);le(mixed,0,4);};
|
|
add(601,0,0,0);add(602,2,7,999999);add(603,3,4968,0);
|
|
e.send(mb);auto m3=mb.receive_list(mixed,e.actor,t0);
|
|
check(m3.native_body && m3.holds.empty() && m3.omitted.size()==1 && m3.omitted[0].first==602,"bad mail omitted, others shown");
|
|
Reader q(*m3.native_body);check(q.le(4)==2 && q.le(4)==2,"two mails listed");
|
|
check(q.le(8)==601 && q.le(4)==0,"system mail first");q.take(8+4+8+4+4+4);
|
|
check(q.le(4)==0 && q.le(1)==0 && q.le(1)==0,"no item; empty sender GUID");
|
|
}
|
|
std::cout<<"PASS normal world request/receive, untagged list switch and state-machine cases; empty, plain, multiline, missing, empty text, duplicate lists and text, retry, switch, stale actor and deadline\n";
|
|
return 0;
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|