54 lines
4.1 KiB
C++
54 lines
4.1 KiB
C++
// Use a synthetic 0x96 and 0x51 by default. Supplied files retain the original replay mode.
|
|
#include "world_translation.hpp"
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <iterator>
|
|
#include <stdexcept>
|
|
using namespace gateway;
|
|
static void check(bool value,const char* text){if(!value)throw Error(text);}
|
|
static Bytes read(const char* path){std::ifstream file(path,std::ios::binary);return Bytes((std::istreambuf_iterator<char>(file)),{});}
|
|
static NativeWorldTranslation world(uint64_t owner){NativeWorldTranslation w;w.selected.guid=owner;w.realm=70;w.location=WorldLocation{};w.self_created=true;return w;}
|
|
static Bytes addon(uint64_t sender, std::string_view prefix){
|
|
Bytes body{3}; le(body,0xffffffffu,4); le(body,sender,8);
|
|
const std::string text=std::string(prefix)+"\tfixture";
|
|
le(body,text.size()+1,4); cstring(body,text); le(body,0,1);
|
|
return body;
|
|
}
|
|
static Bytes name_reply(uint64_t sender){
|
|
Bytes body;
|
|
le(body,sender,8); cstring(body,"TestPeer"); cstring(body,"");
|
|
le(body,1,4); le(body,0,4); le(body,1,4);
|
|
return body;
|
|
}
|
|
int main(int argc,char**argv){try{
|
|
uint64_t owner=7001;
|
|
Bytes name, bad;
|
|
if (argc==1) {
|
|
constexpr uint64_t sender=7002;
|
|
name=name_reply(sender);
|
|
bad=addon(sender,"TW_CHAT_MSG_WHISPER");
|
|
} else {
|
|
check(argc==4 || argc==5,"expected name, framed chat and owner files");
|
|
name=read(argv[1]);
|
|
auto framed=read(argv[2]); Reader input(framed);
|
|
(void)input.le(8); auto size=input.le(4); bad=input.take(size); input.end();
|
|
std::ifstream owner_file(argv[3]); check(bool(owner_file>>owner),"owner fixture unavailable");
|
|
}
|
|
auto player=turtle_chat_player(name);auto actual=turtle_server_addon_message(bad);
|
|
check(owner && owner!=player.guid && actual.sender==player.guid && actual.prefix.size()==19,"addon fixture identity/prefix");
|
|
bool old=argc==5 && std::string(argv[4])=="--expect-old";
|
|
if(old){auto w=world(owner);w.pending_chats.push_back(bad);w.chat_name_queries.insert(player.guid);bool failed=false;try{(void)w.translate({0x51,name},0x46010046,0,nullptr);}catch(const Error&e){failed=std::string(e.what())=="native addon prefix exceeds16-byte limit";}check(failed,"r3 must reproduce exact queued-projection failure");std::cout<<"PASS captured r3 queued-addon failure reproduced\n";return 0;}
|
|
for(bool known:{false,true}){auto w=world(owner);if(known)w.chat_players[player.guid]=player;
|
|
auto output=w.translate({0x96,bad},0x46010046,0,nullptr);check(output==Bytes(4,0),"unsupported immediate projection must emit no native packet");
|
|
check(w.pending_chats.empty() && w.chat_name_queries.empty() && w.requests.empty(),"unsupported prefix must not start deferred/name-query work");
|
|
check(w.channel_semantic_holds==1 && w.self_created && !w.logout_complete,"immediate hold must preserve world continuation");}
|
|
auto w=world(owner);w.pending_chats.push_back(bad);w.pending_chats.push_back(addon(player.guid,"TW_GUILDBANK"));w.chat_name_queries.insert(player.guid);
|
|
auto output=w.translate({0x51,name},0x46010046,0,nullptr);Reader native(output);check(native.le(4)==1 && native.le(4)==0x4c0001,"later representable control must continue into native chat output");auto n=native.le(4);auto payload=native.take(n);native.end();
|
|
const std::string rendered(payload.begin(),payload.end());check(rendered.find("TW_GUILDBANK")!=std::string::npos && rendered.find(actual.prefix)==std::string::npos,"unsupported prefix must not be truncated or emitted");
|
|
check(w.chat_players.contains(player.guid) && w.chat_players.at(player.guid).name==player.name,"valid actual name reply must be retained");
|
|
check(w.chat_name_queries.empty() && w.pending_chats.empty() && w.requests.empty(),"queued hold must consume work without retry");
|
|
check(w.channel_semantic_holds==1 && w.self_created && !w.logout_complete,"queued hold must preserve active world state");
|
|
check(w.translate({0x51,name},0x46010046,0,nullptr)==Bytes(4,0),"duplicate unrequested name response must continue safely");
|
|
std::cout<<"PASS immediate/deferred addon holds, accepted name and native continuation control\n";return 0;
|
|
}catch(const std::exception&e){std::cerr<<e.what()<<'\n';return 1;}}
|