153 lines
6.9 KiB
C++
153 lines
6.9 KiB
C++
#include "gateway/guild_notifications.hpp"
|
|
#include "world_translation.hpp"
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
|
|
namespace {
|
|
void check(bool condition, const char* message) {
|
|
if (!condition) throw Error(message);
|
|
}
|
|
constexpr uint32_t realm = 70, address = 0x01010046;
|
|
constexpr uint64_t charter = 0x400000000000002a;
|
|
Bytes item_wire() { return unhex("01802a0c"); }
|
|
Bytes player_wire(uint32_t counter) { return pack_guid(forever_player_guid(counter,realm)); }
|
|
Bytes u32(uint32_t value) { Bytes b; le(b,value,4); return b; }
|
|
Bytes event(uint8_t type, std::initializer_list<std::string> names, uint64_t guid=0) {
|
|
Bytes body{type,uint8_t(names.size())};
|
|
for (const auto& name : names) cstring(body,name);
|
|
if (guid) le(body,guid,8);
|
|
return body;
|
|
}
|
|
void chars(Bytes& body,std::string_view name) {
|
|
body.insert(body.end(),name.begin(),name.end());
|
|
}
|
|
struct Fixture {
|
|
NativeWorldTranslation world{};
|
|
Fixture() { world.realm=realm; world.selected.guid=7; world.guild_id=10; }
|
|
std::optional<LegacyPacket> send(uint16_t code,const Bytes& payload) {
|
|
auto batch=world.translate({code,payload},address,0,nullptr);
|
|
Reader r(batch);
|
|
auto count=r.le(4);
|
|
if (!count) {r.end(); return {};}
|
|
check(count==1,"unexpected extra world reply");
|
|
uint32_t opcode=r.le(4);
|
|
auto data=r.take(r.le(4)); r.end();
|
|
return LegacyPacket{opcode,std::move(data)};
|
|
}
|
|
void expect(uint16_t code,const Bytes& in,uint32_t native,const Bytes& expected) {
|
|
auto p=send(code,in);
|
|
check(p && p->opcode==native && p->body==expected,"unexpected native world packet");
|
|
}
|
|
void reject(uint16_t code,const Bytes& in) {
|
|
std::optional<LegacyPacket> got;
|
|
try { got=send(code,in); } catch (const Error&) { return; }
|
|
check(!got,"unexpected world packet");
|
|
}
|
|
};
|
|
|
|
void guild_tests(Fixture& fixture) {
|
|
fixture.expect(0x92,event(2,{"Hi"}),0x530035,unhex("00404869"));
|
|
fixture.expect(0x92,event(2,{""}),0x530035,{0,0});
|
|
fixture.expect(0x92,event(8,{}),0x530034,{});
|
|
for (uint8_t id : {3,12,13}) {
|
|
Bytes out=player_wire(8); append(out,u32(address));
|
|
out.push_back(3<<2); out.push_back(id==12 ? 1 : 0); chars(out,"Elm");
|
|
fixture.expect(0x92,event(id,{"Elm"},8),id==3 ? 0x530031 : 0x530036,out);
|
|
}
|
|
Bytes leaver{6,0}; append(leaver,player_wire(8)); append(leaver,u32(address)); chars(leaver,"Elm");
|
|
fixture.expect(0x92,event(4,{"Elm"},8),0x530032,leaver);
|
|
auto removal=event(5,{"Elm","Ash"});
|
|
fixture.reject(0x92,removal); // names alone do not authorize numeric identities
|
|
GuildRoster roster;
|
|
GuildRosterMember a,b; a.name="Elm"; a.guid=8; b.name="Ash"; b.guid=9;
|
|
roster.members={a,b};
|
|
fixture.world.guild_management_roster=roster;
|
|
GuildInfo info{};info.id=10;info.ranks[0]="Master";info.ranks[1]="Member";
|
|
fixture.world.guild_rank_info=info;
|
|
Bytes removed{0x86,0x00,0x0c,0x00};
|
|
append(removed,player_wire(9)); append(removed,u32(address)); chars(removed,"Ash");
|
|
append(removed,player_wire(8)); append(removed,u32(address)); chars(removed,"Elm");
|
|
fixture.expect(0x92,removal,0x530032,removed);
|
|
for (uint8_t id : {0,1}) {
|
|
Bytes rank=player_wire(9); append(rank,player_wire(8)); append(rank,u32(1));
|
|
rank.push_back(id==0 ? 0x80 : 0);
|
|
fixture.expect(0x92,event(id,{"Ash","Elm","Member"}),0x530001,rank);
|
|
}
|
|
Bytes leader{6,0x18};
|
|
append(leader,player_wire(9)); append(leader,u32(address));
|
|
append(leader,player_wire(8)); append(leader,u32(address)); chars(leader,"AshElm");
|
|
fixture.expect(0x92,event(7,{"Ash","Elm"}),0x530033,leader);
|
|
fixture.world.guild_rank_info->ranks[2]="Member";
|
|
fixture.reject(0x92,event(0,{"Ash","Elm","Member"}));
|
|
fixture.world.guild_management_roster->members.push_back(a);
|
|
fixture.reject(0x92,removal);
|
|
fixture.reject(0x92,event(12,{"Elm"}));
|
|
fixture.reject(0x92,event(3,{std::string(64,'A')},8));
|
|
fixture.reject(0x92,{2,1,'x'});
|
|
fixture.reject(0x92,{8,0,1});
|
|
fixture.reject(0x92,Bytes(10,0));
|
|
Bytes disbanded(10,0);disbanded[0]=8;fixture.reject(0x92,disbanded);
|
|
}
|
|
|
|
Bytes identity(uint64_t item=charter) {
|
|
Bytes body; le(body,item,8); le(body,8,8); return body;
|
|
}
|
|
|
|
void petition_tests(Fixture& f) {
|
|
for (uint32_t result : {0,2,4}) f.expect(0x1c5,u32(result),0x4701f9,{uint8_t(result<<4)});
|
|
f.reject(0x1c5,u32(1));
|
|
for (uint32_t result : {0,1,3}) {
|
|
auto in=identity(); append(in,u32(result));
|
|
Bytes out=item_wire(); append(out,player_wire(8)); out.push_back(result<<4);
|
|
f.expect(0x1c1,in,0x4701f7,out);
|
|
}
|
|
auto invalid=identity(42); append(invalid,u32(0)); f.reject(0x1c1,invalid);
|
|
auto in=identity(); append(in,u32(777)); in.push_back(1); le(in,9,8); le(in,0,4);
|
|
Bytes out=item_wire(); append(out,player_wire(8)); append(out,Bytes{0,0});
|
|
append(out,u32(777)); append(out,u32(1)); append(out,player_wire(9)); append(out,u32(0));
|
|
f.expect(0x1bf,in,0x47016c,out);
|
|
in.back()=1; f.reject(0x1bf,in); in.back()=0;
|
|
in[20]=2; le(in,9,8); le(in,0,4); f.reject(0x1bf,in);
|
|
in=identity(); append(in,u32(777)); in.push_back(10); f.reject(0x1bf,in);
|
|
|
|
Bytes query=u32(777);le(query,8,8);cstring(query,"Leaf");cstring(query,"");
|
|
append(query,u32(1));append(query,u32(9));append(query,u32(9));
|
|
query.resize(query.size()+38);
|
|
Bytes expected=u32(777);expected.push_back(0x80);append(expected,u32(777));
|
|
append(expected,player_wire(8));append(expected,u32(9));append(expected,u32(9));
|
|
expected.resize(expected.size()+39);
|
|
expected.push_back(4);expected.resize(expected.size()+11);
|
|
chars(expected,"Leaf");
|
|
f.expect(0x1c7,query,0x4b000d,expected);
|
|
query.back()=1;f.reject(0x1c7,query);
|
|
Bytes invalidate=u32(uint32_t(-777));invalidate.resize(64);f.reject(0x1c7,invalidate);
|
|
|
|
constexpr uint64_t npc=0xf130000042000009;
|
|
Bytes list;le(list,npc,8);list.push_back(1);
|
|
for (uint32_t x : {1,5863,16161,1000,1}) append(list,u32(x));
|
|
f.reject(0x1bc,list);
|
|
Guid128 unit{};unit[0]=9;unit[15]=0x20;
|
|
auto& actor=f.world.entities.actors[npc];actor.sent=true;actor.modern=unit;
|
|
Bytes vendor=pack_guid(unit);append(vendor,u32(1000));
|
|
f.expect(0x1bc,list,0x47016b,vendor);
|
|
list.push_back(2);f.reject(0x1bc,list);
|
|
}
|
|
|
|
void status_tests(Fixture& f) {
|
|
for (uint32_t status : {0,1}) f.expect(0x21b,u32(status),0x47014f,u32(status));
|
|
f.reject(0x21b,u32(2));
|
|
f.reject(0x21b,{0,0,0});
|
|
// No source WHO request token, authorized native decline layout or ticket
|
|
// case conversion. Unknown bodies, including privileged WHOIS, stay opaque.
|
|
for (uint16_t held : {0x63,0x65,0x86,0x206,0x208,0x212,0x218})
|
|
f.reject(held,{0xa5});
|
|
}
|
|
}
|
|
int main() {
|
|
try {
|
|
Fixture world;
|
|
guild_tests(world); petition_tests(world); status_tests(world);
|
|
std::cout<<"PASS guild events, petitions, ticket queue status and held replies\n";
|
|
} catch (const std::exception& e) { std::cerr<<e.what()<<'\n';return 1; }
|
|
}
|