76 lines
5.9 KiB
C++
76 lines
5.9 KiB
C++
#include "gateway/chat.hpp"
|
|
#include "gateway/source_feedback.hpp"
|
|
#include "world_translation.hpp"
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
static unsigned checks=0;
|
|
static void check(bool x){++checks;if(!x)throw Error("Source feedback fixture failed");}
|
|
template<class F>void rejects(F f){try{f();}catch(const Error&){++checks;return;}throw Error("Source feedback fixture expected refusal");}
|
|
static Bytes source(uint32_t op,const std::string& text,uint32_t context=0){Bytes b;if(op==0x291||op==0x33b)le(b,context,4);if(op==0x2b8||op==0x33b)le(b,text.size()+1,4);cstring(b,text);return b;}
|
|
static std::string decode(const Bytes& packet){Reader r(packet);check(r.le(1)==0&&r.le(4)==0);for(unsigned j=0;j<3;++j)check(unpack_guid(r,16)==Bytes(16));r.le(2);for(unsigned j=0;j<6;++j)r.le(4);uint64_t bits=0;for(unsigned j=0;j<7;++j)bits=(bits<<8)|r.le(1);check(((bits>>45)&0x7ff)==0);auto text=r.take((bits>>10)&0xfff);r.end();return std::string(text.begin(),text.end());}
|
|
int main(){try{
|
|
RosterRealm realm;realm.realm_id=70;realm.virtual_address=0x46010046;
|
|
for(uint32_t op:{0x1cbu,0x291u,0x2b8u,0x33bu}){
|
|
const std::string text="Synthetic |cffffffffstatus|r UTF8 \xc3\xa9";
|
|
auto m=turtle_source_feedback(op,source(op,text,op==0x291?3:42));check(m&&m->opcode==op&&m->text==text);check(decode(forever_source_system_feedback(*m,realm))==text);
|
|
auto b=source(op,text,op==0x291?3:42);b.pop_back();rejects([&]{turtle_source_feedback(op,b);});b=source(op,text,3);b.push_back(0);rejects([&]{turtle_source_feedback(op,b);});
|
|
}
|
|
for(uint32_t op:{0x2b8u,0x33bu}){auto b=source(op,"Synthetic",4);b[op==0x33b?4:0]++;rejects([&]{turtle_source_feedback(op,b);});}
|
|
for(uint32_t kind:{1u,2u,4u,5u}){auto m=turtle_source_feedback(0x291,source(0x291,kind<3?"15:00":"",kind));check(m&&m->context==kind);rejects([&]{forever_source_system_feedback(*m,realm);});}
|
|
check(!turtle_source_feedback(0x33a,{}));check(!turtle_source_feedback(0x2fa,{}));check(!turtle_source_feedback(0x2fd,Bytes{0}));
|
|
auto max=turtle_source_feedback(0x1cb,source(0x1cb,std::string(4095,'x')));check(max&&decode(forever_source_system_feedback(*max,realm)).size()==4095);
|
|
rejects([&]{turtle_source_feedback(0x1cb,source(0x1cb,std::string(4096,'x')));});
|
|
NativeWorldTranslation world;world.selected.guid=4514;world.selected.name="Synthetic";world.realm=70;
|
|
for(uint32_t op:{0x1cbu,0x291u,0x2b8u,0x33bu}){
|
|
const std::string text="Synthetic Source notification";auto body=source(op,text,op==0x291?3:42);
|
|
auto bundle=world.translate({op,body},realm.virtual_address,0,nullptr);Reader wire(bundle);check(wire.le(4)==1);check(wire.le(4)==0x4c0001);auto size=wire.le(4);auto chat=wire.take(size);wire.end();
|
|
check(decode(chat)==text);check(chat==forever_source_system_feedback(*turtle_source_feedback(op,body),realm));
|
|
}
|
|
// Complete source data picks one original native countdown or cancellation.
|
|
auto dispatch=[&](uint32_t op,const Bytes& input){return world.translate({op,input},realm.virtual_address,0,nullptr);};
|
|
auto only=[&](uint32_t op,const Bytes& input,uint32_t native,const Bytes& expected){
|
|
auto bundle=dispatch(op,input);Reader wire(bundle);check(wire.le(4)==1);check(wire.le(4)==native);
|
|
auto n=wire.le(4);check(wire.take(n)==expected);wire.end();
|
|
};
|
|
// The battleground sender writes a bare CString with an embedded newline.
|
|
// Area and defense senders prefix byte length (including the terminator);
|
|
// only defense adds a zone. The whole authored text must reach the UI.
|
|
const std::string lines="The eye in the sky has found Ryson's Beacon.\nYou may now spy on the enemy base.";
|
|
for (uint32_t op : {0x1cbu,0x2b8u,0x33bu}) {
|
|
auto raw=source(op,lines,42);
|
|
only(op,raw,0x4c0001,forever_source_system_feedback({op,42,lines},realm));
|
|
}
|
|
for(uint32_t type : {1u,2u,4u,5u}){
|
|
std::string param=type<3?"15:00":"";
|
|
Bytes expected;le(expected,type,4);
|
|
expected.push_back(0);expected.push_back(uint8_t(param.size()<<5));
|
|
expected.insert(expected.end(),param.begin(),param.end());
|
|
only(0x291,source(0x291,param,type),0x4c001e,expected);
|
|
}
|
|
const std::string longest(2047,'x');Bytes boundary;le(boundary,1,4);
|
|
boundary.insert(boundary.end(),{255,224});boundary.insert(boundary.end(),longest.begin(),longest.end());
|
|
only(0x291,source(0x291,longest,1),0x4c001e,boundary);
|
|
for(const auto& invalid : {source(0x291,std::string(2048,'x'),1),source(0x291,"",2),
|
|
source(0x291,"unrelated",5),source(0x291,"5:00",6)})
|
|
check(dispatch(0x291,invalid)==Bytes(4));
|
|
rejects([&]{dispatch(0x291,Bytes{4,0,0,0});}); // source writes NUL for an empty parameter
|
|
const std::string restriction="Hardcore characters cannot perform that action.";
|
|
auto notice=turtle_source_feedback(0x2fd,{});check(notice&¬ice->text==restriction);
|
|
only(0x2fd,{},0x4c0001,forever_source_system_feedback(*notice,realm));
|
|
check(dispatch(0x2fd,{0})==Bytes(4));check(dispatch(0x2fd,source(0x1cb,"bot text"))==Bytes(4));
|
|
// One existing positive route keeps its exact original opcode and payload.
|
|
auto prior=world.translate({0xfd,Bytes(32)},realm.virtual_address,0,nullptr);Reader unchanged(prior);check(unchanged.le(4)==1);check(unchanged.le(4)==0x470269);check(unchanged.le(4)==32);check(unchanged.take(32)==Bytes(32));unchanged.end();
|
|
check(dispatch(0x330,Bytes{1,2,3})==Bytes(4));
|
|
check(world.no_native_consumer_drops.at(0x330)==1);
|
|
Bytes removed;le(removed,77,4);le(removed,2589,4);le(removed,0xffffffff,4);
|
|
check(dispatch(0x28d,removed)==Bytes(4));
|
|
check(world.native_presentations.size()==1);
|
|
check(world.native_presentations.front().opcode==0x4c0001);
|
|
check(world.native_presentations.front().body==forever_local_addon(world.selected,realm,"OctoAux","D;77;2589;4294967295"));
|
|
world.native_presentations.clear();
|
|
for(const auto& invalid:{Bytes{},Bytes(11),Bytes(13),Bytes(12)}) {
|
|
check(dispatch(0x28d,invalid)==Bytes(4));check(world.native_presentations.empty());
|
|
}
|
|
std::cout<<"PASS "<<checks<<" source feedback, native timed messages and original chat restriction checks\n";
|
|
}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}}
|