883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
70 lines
6.4 KiB
C++
70 lines
6.4 KiB
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#include "world_translation.hpp"
|
|
#include "gateway/chat.hpp"
|
|
#include <algorithm>
|
|
#include <source_location>
|
|
using namespace gateway;
|
|
namespace {
|
|
void check(bool v,const std::source_location& at=std::source_location::current()){if(!v)throw Error("social integration line "+std::to_string(at.line()));}
|
|
template<class F>void rejects(F f){bool held=false;try{f();}catch(const Error&){held=true;}check(held);}
|
|
Bytes friends(std::initializer_list<uint64_t> ids){Bytes b;le(b,ids.size(),1);for(auto id:ids){le(b,id,8);le(b,1,1);le(b,12,4);le(b,60,4);le(b,1,4);}return b;}
|
|
Bytes ignores(std::initializer_list<uint64_t> ids){Bytes b;le(b,ids.size(),1);for(auto id:ids)le(b,id,8);return b;}
|
|
Bytes query(std::initializer_list<uint64_t> ids){Bytes b;le(b,ids.size(),4);for(auto id:ids)append(b,pack_guid(forever_player_guid(id,70)));return b;}
|
|
Bytes name(uint64_t id,std::string value="J\xc3\xbcrgen",uint32_t race=1){Bytes b;le(b,id,8);cstring(b,value);cstring(b,"");le(b,race,4);le(b,0,4);le(b,1,4);return b;}
|
|
int dto_codec(uint32_t mode,const uint8_t* p,uint32_t n,uint32_t,uint8_t* out,uint32_t cap,uint32_t* count){
|
|
check(mode==GW_CODEC_SOCIAL_PACKET||mode==GW_CODEC_CONTACT_NAMES);*count=n;if(cap<n)return GW_CODEC_CAPACITY;std::copy(p,p+n,out);return GW_CODEC_OK;
|
|
}
|
|
RosterRealm context(){RosterRealm r;r.realm_id=70;r.virtual_address=0x46010046;return r;}
|
|
}
|
|
int main(){
|
|
const auto realm=context();NativeWorldTranslation world{};world.selected.guid=4509;world.realm=70;
|
|
auto out=world.translate({0x67,friends({42})},realm.virtual_address,0,dto_codec);check(out==Bytes(4)&&!world.local_presentation_pending());
|
|
world.translate({0x6b,ignores({43})},realm.virtual_address,0,dto_codec);
|
|
check(world.social.contact_name_ids()==std::set<uint64_t>({42,43}));check(world.entities.actors.empty()&&world.chat_players.empty());
|
|
world.self_created=true;world.location=WorldLocation{0,0,0,0,0};
|
|
auto initial=world.local_presentation(realm.virtual_address,dto_codec);Reader first(initial);check(first.le(4)==3);
|
|
check(first.le(4)==NativeSocialMirrorVars);
|
|
auto config=social_projection_from_input(first.take(first.le(4)));
|
|
check(config.kind==SocialProjection::Kind::LegacyConfiguration&&config.contacts.empty()&&config.flags==0);
|
|
for(unsigned i=0;i<2;++i){check(first.le(4)==NativeContactList);auto p=social_projection_from_input(first.take(first.le(4)));check(p.contacts.size()==1);}first.end();
|
|
auto refresh=world.translate({0x67,friends({42})},realm.virtual_address,0,dto_codec);
|
|
Reader refresh_reader(refresh);check(refresh_reader.le(4)==1&&refresh_reader.le(4)==NativeContactList);
|
|
refresh_reader.take(refresh_reader.le(4));refresh_reader.end(); // One config per World, not every list refresh.
|
|
NativeWorldTranslation ignore_only{};ignore_only.selected.guid=4509;ignore_only.realm=70;
|
|
ignore_only.translate({0x6b,ignores({43})},realm.virtual_address,0,dto_codec);
|
|
check(!ignore_only.social_legacy_queued); // A client action/ignore snapshot cannot invent friend-service authority.
|
|
auto prepared=world.contact_names.client(query({42,43,99,42}),world.social,realm);check(prepared.source.size()==2&&prepared.held&&prepared.native.empty());
|
|
check(world.contact_names.client(query({42}),world.social,realm).source.size()==1); // Preparation/capacity failure grants no sent authority.
|
|
check(!world.contact_names.receive(name(42),world.social,realm)); // Unsolicited before actual Source50 serialization.
|
|
world.contact_names.sent(prepared);check(world.contact_names.client(query({42}),world.social,realm).source.empty());
|
|
world.chat_name_queries.insert(42);auto reply=world.translate({0x51,name(42)},realm.virtual_address,0,dto_codec);
|
|
check(world.chat_players.at(42).name=="J\xc3\xbcrgen"&&world.entities.actors.empty());
|
|
Reader r(reply);check(r.le(4)==1&&r.le(4)==NativeContactNameReply);auto rows=contact_names_from_input(r.take(r.le(4)));r.end();
|
|
check(rows.size()==1&&rows[0].level==60&&rows[0].pvp_faction==1&&rows[0].guid==forever_player_guid(42,70));
|
|
auto cached=world.contact_names.client(query({42}),world.social,realm);check(cached.source.empty()&&cached.native.size()==1);
|
|
|
|
// Role loss/re-add cannot relabel the old generation's sent response.
|
|
world.translate({0x6b,ignores({})},realm.virtual_address,0,dto_codec);
|
|
world.translate({0x6b,ignores({43})},realm.virtual_address,0,dto_codec);
|
|
check(world.contact_names.client(query({43}),world.social,realm).source.empty());
|
|
check(!world.contact_names.receive(name(43),world.social,realm));
|
|
auto fresh=world.contact_names.client(query({43}),world.social,realm);check(fresh.source.size()==1);world.contact_names.sent(fresh);
|
|
auto horde=world.contact_names.receive(name(43,"Durotan",2),world.social,realm);check(horde&&horde->pvp_faction==0&&horde->level==0);
|
|
auto unknown=world.contact_names.client(query({99}),world.social,realm);check(unknown.held&&unknown.source.empty()&&unknown.native.empty());
|
|
|
|
// Prepare -> role removal invalidates the commit, even before any reply.
|
|
world.translate({0x6b,ignores({44})},realm.virtual_address,0,dto_codec);
|
|
auto retired=world.contact_names.client(query({44}),world.social,realm);
|
|
world.translate({0x6b,ignores({})},realm.virtual_address,0,dto_codec);
|
|
check(!world.contact_names.current(retired));rejects([&]{world.contact_names.sent(retired);});
|
|
world.translate({0x6b,ignores({44})},realm.virtual_address,0,dto_codec);auto pending=world.contact_names.client(query({44}),world.social,realm);world.contact_names.sent(pending);
|
|
NativeContactNames next;next.hold_retired(world.contact_names.retired_queries());next.sync(world.social,4510,70);
|
|
check(next.client(query({44}),world.social,realm).source.empty());check(!next.receive(name(44),world.social,realm));
|
|
auto again=next.client(query({44}),world.social,realm);check(again.source.size()==1);next.sent(again);
|
|
check(!next.receive(name(44,std::string("\xc0\xaf")),world.social,realm));
|
|
again=next.client(query({44}),world.social,realm);next.sent(again);auto high_elf=next.receive(name(44,"Quel",10),world.social,realm);check(high_elf&&high_elf->pvp_faction==1&&high_elf->race==10);
|
|
rejects([&]{next.sync(world.social,4509,70);});next.reset();rejects([&]{next.client(query({44}),world.social,realm);});
|
|
Bytes too_many;le(too_many,51,4);rejects([&]{native_contact_name_query(too_many);});
|
|
check(world.spells.empty()); // No social action changes knowledge/gameplay state.
|
|
}
|