44 lines
5.2 KiB
C++
44 lines
5.2 KiB
C++
#include "world_translation.hpp"
|
|
#include "gateway/chat.hpp"
|
|
#include "gateway/guild_bank.hpp"
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
namespace {
|
|
void require(bool ok,const char* why){if(!ok)throw Error(why);}
|
|
template<class F> void reject(F f){bool failed=false;try{f();}catch(const Error&){failed=true;}require(failed,"invalid ranks input accepted");}
|
|
GuildInfo info(){GuildInfo g{};g.id=22;g.name="ThunderClan Warriors";g.ranks={"Guild Master","Officer","Veteran","Member","Initiate"};return g;}
|
|
const std::vector<uint32_t> rights{1044991,1044991,67,67,67};
|
|
Bytes source_info(const GuildInfo& g){Bytes b;le(b,g.id,4);cstring(b,g.name);for(const auto& n:g.ranks)cstring(b,n);for(auto v:g.emblem)le(b,v,4);return b;}
|
|
Bytes source_roster(){Bytes b;le(b,1,4);cstring(b,"");cstring(b,"");le(b,rights.size(),4);for(auto v:rights)le(b,v,4);le(b,4509,8);le(b,1,1);cstring(b,"Gatewaytest");le(b,0,4);le(b,60,1);le(b,1,1);le(b,12,4);cstring(b,"");cstring(b,"");return b;}
|
|
Bytes expected(){const std::string hex="050000000000000000fff10900ffffffff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000184775696c64204d61737465720101000000fff1090000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4f66666963657202020000004300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e5665746572616e03030000004300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c4d656d626572040400000043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010496e697469617465";Bytes b;for(size_t i=0;i<hex.size();i+=2)b.push_back(uint8_t(std::stoul(hex.substr(i,2),nullptr,16)));return b;}
|
|
std::vector<LegacyPacket> packets(const Bytes& bytes){Reader r(bytes);std::vector<LegacyPacket> out;auto count=r.le(4);for(size_t i=0;i<count;++i){auto op=r.le(4);auto body=r.take(r.le(4));out.push_back({uint32_t(op),Bytes(body.begin(),body.end())});}r.end();return out;}
|
|
NativeWorldTranslation world(){NativeWorldTranslation w{};w.realm=70;w.virtual_realm_address=0x46010046;w.guild_id=22;w.guild_rank=0;w.selected.guid=4509;w.self_created=true;return w;}
|
|
void ranks(const std::vector<LegacyPacket>& ps,size_t index){require(ps.at(index).opcode==0x530010 && ps.at(index).body==expected(),"native rank packet differs from independent Claude reference");}
|
|
}
|
|
int main(){try{
|
|
const auto guild=info();require(forever_guild_ranks(guild,rights)==expected(),"434-byte independent reference differs");
|
|
require(expected().size()==434,"reference size differs");
|
|
auto broken=guild;broken.ranks[2].clear();reject([&]{forever_guild_ranks(broken,rights);});
|
|
broken=guild;broken.ranks[0].assign(128,'a');reject([&]{forever_guild_ranks(broken,rights);});
|
|
reject([&]{forever_guild_ranks(guild,std::span(rights).first(4));});
|
|
auto w=world();auto request=pack_guid(forever_guild_guid(22,70));
|
|
unsetenv("GW_GUILD_RANKS_PROTOTYPE");reject([&]{w.gameplay(0x2f000e,request);});
|
|
auto off=packets(w.translate({0x8a,source_roster()},0x46010046,0,nullptr));require(off.size()==1 && off[0].opcode==0x530003 && !w.guild_roster_rights,"disabled prototype changed roster");
|
|
setenv("GW_GUILD_RANKS_PROTOTYPE","1",1);
|
|
require(w.gameplay(0x2f000e,request).opcode==0x89,"rank query not mapped to authenticated Source roster");
|
|
auto foreign=pack_guid(forever_guild_guid(23,70));reject([&]{w.gameplay(0x2f000e,foreign);});
|
|
auto trailing=request;trailing.push_back(0);reject([&]{w.gameplay(0x2f000e,trailing);});
|
|
w.gameplay_sent(0x2f000e,request);require(w.requests.size()==2 && w.requests[0].opcode==0x87 && w.requests[0].body.empty() &&
|
|
w.requests[1].opcode==0x54 && w.requests[1].body==Bytes({22,0,0,0}),"guild detail/name refresh not source-backed");
|
|
auto a=packets(w.translate({0x8a,source_roster()},0x46010046,0,nullptr));require(a.size()==1,"rank names were invented");
|
|
auto b=packets(w.translate({0x55,source_info(guild)},0x46010046,0,nullptr));require(b.size()==2,"roster-first path missing ranks");ranks(b,1);
|
|
auto w2=world();auto c=packets(w2.translate({0x55,source_info(guild)},0x46010046,0,nullptr));require(c.size()==1,"rank rights were invented");
|
|
auto d=packets(w2.translate({0x8a,source_roster()},0x46010046,0,nullptr));require(d.size()==2 && d[1].opcode==0x530003,"names-first path missing roster");ranks(d,0);
|
|
auto wrong=guild;wrong.id=23;require(packets(w2.translate({0x55,source_info(wrong)},0x46010046,0,nullptr)).empty(),"foreign guild published ranks");
|
|
broken=guild;broken.ranks[5]="New rank";require(packets(w2.translate({0x55,source_info(broken)},0x46010046,0,nullptr)).size()==1,"mismatched counts published ranks");
|
|
w2.translate({0x4d,{}},0x46010046,0,nullptr);require(!w2.guild_rank_info && !w2.guild_roster_rights,"logout retained rank presentation state");
|
|
unsetenv("GW_GUILD_RANKS_PROTOTYPE");
|
|
std::cout<<"PASS independent434-byte vector, opt-in, Source reply orders, identity, bounds and logout\n";
|
|
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}
|