Files
WoW-Hybrid-gateway/tests/native_guild_rank_assignment_world_test.cpp
2026-11-23 03:28:32 +02:00

28 lines
3.5 KiB
C++

#include "world_translation.hpp"
#include <algorithm>
#include <cstdlib>
#include <iostream>
using namespace gateway;
void check(bool x,const char* s){if(!x)throw Error(s);}
Bytes source_roster(unsigned rank){Bytes b;le(b,2,4);cstring(b,"");cstring(b,"");le(b,5,4);for(unsigned i=0;i<5;++i)le(b,i?0:0xffffffff,4);for(unsigned i=0;i<2;++i){le(b,i?4513:4509,8);le(b,1,1);cstring(b,i?"Chatpeer":"Gatewaytest");le(b,i?rank:0,4);le(b,60,1);le(b,1,1);le(b,12,4);cstring(b,"");cstring(b,"");}return b;}
int main(){try{
setenv("GW_GUILD_MANAGEMENT_PROTOTYPE","1",1);unsetenv("GW_GUILD_RANKS_PROTOTYPE");
NativeWorldTranslation w{};w.realm=70;w.selected.guid=4509;w.selected.name="Gatewaytest";w.self_created=true;w.guild_id=21;w.guild_rank=0;w.location=WorldLocation{};
GuildInfo info{};info.id=21;info.name="HybridLocalTest";info.ranks={"Guild Master","Officer","Veteran","Member","Initiate"};w.guild_rank_info=info;w.guild_management_roster=turtle_guild_roster(source_roster(4));
auto input=pack_guid(forever_player_guid(4513,70));le(input,2,4);
auto first=w.gameplay(0x2f0002,input);check(first.opcode==0x8b&&!w.guild_rank_assignment,"planning must not mark unsent mutation pending");
w.gameplay_sent(0x2f0002,input);check(w.guild_management_pending&&w.guild_rank_assignment&&w.requests.size()==1&&w.requests.front().opcode==0x89,"sent step must queue one actual Source roster refresh");w.requests.clear();
w.translate({0x8a,source_roster(4)},0x46010046,0,nullptr);check(w.requests.size()==1&&w.requests.front().opcode==0x87&&w.guild_management_pending,"stale roster replayed or falsely completed request");w.requests.clear();
w.translate({0x8a,source_roster(3)},0x46010046,0,nullptr);check(w.requests.size()==2&&w.requests[0].opcode==0x8b&&w.requests[1].opcode==0x89&&w.guild_management_pending,"real first-step result did not queue ordered next step/refresh");w.requests.clear();
w.translate({0x8a,source_roster(2)},0x46010046,0,nullptr);check(w.requests.empty()&&!w.guild_rank_assignment&&!w.guild_management_pending&&w.guild_management_roster->members[1].rank==2,"final real rank not published/retired");
auto down=pack_guid(forever_player_guid(4513,70));le(down,4,4);check(w.gameplay(0x2f0002,down).opcode==0x8c,"world demotion direction");w.gameplay_sent(0x2f0002,down);w.requests.clear();
Bytes failure;le(failure,1,4);cstring(failure,"Chatpeer");le(failure,8,4);w.translate({0x93,failure},0x46010046,0,nullptr);check(!w.guild_rank_assignment&&!w.guild_management_pending,"Source rejection did not cancel continuation");
// Leadership moved: rank update before or after the roster; management stays blocked until a roster shows the new rank.
{auto a=w;a.requests.clear();a.guild_management_roster=turtle_guild_roster(source_roster(2));a.guild_rank=0;
a.observe_guild_rank(1);check(!a.guild_management_roster && !a.guild_management_pending && !a.requests.empty() && a.requests.back().opcode==0x89,"rank first: stale roster dropped, refresh queued");
bool blocked=false;try{a.gameplay(0x2f0002,input);}catch(const Error&){blocked=true;}check(blocked,"management blocked until fresh roster");}
{auto b=w;b.requests.clear();b.guild_rank=0;b.translate({0x8a,source_roster(2)},0x46010046,0,nullptr); // roster (self rank 0) then rank 1
b.observe_guild_rank(1);check(!b.guild_management_roster && b.requests.size()>=1,"roster first: retired on the rank transition");}
std::cout<<"PASS native rank dispatch, Source-only progression, ordered refresh, stale no-replay, actual final cache and Source failure cancellation\n";
}catch(const std::exception& e){std::cerr<<e.what()<<'\n';return 1;}}