Files
WoW-Hybrid-gateway/native/contact_name_translation.hpp

35 lines
2.1 KiB
C++

// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "social_translation.hpp"
// These grants are names-only and never enter actor, chat or combat bindings.
class NativeContactNames {
struct Pending {uint64_t owner=0,generation=0;uint16_t realm=0;};
uint64_t owner_=0,next_generation_=0;uint16_t realm_=0;
std::map<uint64_t,uint64_t> grants_;
std::set<uint64_t> mail_senders_;
std::map<uint64_t,Pending> pending_;
std::map<uint64_t,uint64_t> attempted_;
std::map<uint64_t,gateway::Character> names_;
gateway::ContactNameProjection projection(const gateway::Character&,const NativeSocialTranslation&,const gateway::RosterRealm&) const;
public:
struct Prepared {
std::vector<gateway::LegacyPacket> source;
std::vector<gateway::ContactNameProjection> native;
std::map<uint64_t,uint64_t> generations;
uint64_t owner=0;uint16_t realm=0;bool held=false;
};
void sync(const NativeSocialTranslation&,uint64_t owner,uint16_t realm);
void mail_senders(std::set<uint64_t> ids,const NativeSocialTranslation&,uint64_t owner,uint16_t realm);
Prepared client(std::span<const uint8_t>,const NativeSocialTranslation&,const gateway::RosterRealm&) const;
// One Source-authoritative unresolved contact dependency. No native UI
// request is required, and preparation grants no sent/reply authority.
std::optional<Prepared> dependency(const gateway::RosterRealm&) const;
bool current(const Prepared&) const;
void sent(const Prepared&);
std::optional<gateway::ContactNameProjection> receive(std::span<const uint8_t>,const NativeSocialTranslation&,const gateway::RosterRealm&);
void invalidate() noexcept {grants_.clear();names_.clear();attempted_.clear();}
std::set<uint64_t> retired_queries() const {std::set<uint64_t> out;for(const auto& [id,p]:pending_){(void)p;out.insert(id);}return out;}
void hold_retired(const std::set<uint64_t>& ids){if(owner_||ids.size()>75)throw gateway::Error("Retired contact-query bound");for(auto id:ids)pending_[id]={};}
void reset() noexcept {*this=NativeContactNames{};}
};