Files

648 lines
40 KiB
C++

#include "gateway/forced_reactions.hpp"
#pragma once
#include <deque>
#include "serializer.h"
#include "entity_translation.hpp"
#include "battleground_queue.hpp"
#include "gateway/auction_browse.hpp"
#include "gateway/pet_stable.hpp"
#include "inspect_request_history.hpp"
#include "inventory_translation.hpp"
#include "equipment_set_manager.hpp"
#include "extended_action_bars.hpp"
#include "aura_translation.hpp"
#include "loot_translation.hpp"
#include "loot_receipt_translation.hpp"
#include "party_translation.hpp"
#include "gateway/world.hpp"
#include "gateway/pet_spellbook.hpp"
#include "gateway/legacy_client.hpp"
#include "gateway/gameplay.hpp"
#include "gateway/npc_text.hpp"
#include "gateway/object_updates.hpp"
#include "gateway/reputation.hpp"
#include "gateway/taxi.hpp"
#include "gateway/guild_bank.hpp"
#include "gateway/chat.hpp"
#include "gateway/guild_control.hpp"
#include "club_service.hpp"
#include "gateway/guild_rank_assignment.hpp"
#include "gateway/guild_permissions.hpp"
#include "gateway/gameobject_queries.hpp"
#include "gateway/page_text_aliases.hpp"
#include "gateway/mailbox_translation.hpp"
#include "quest_translation.hpp"
#include "quest_status_refresh.hpp"
#include "contact_name_translation.hpp"
#include <optional>
#include <chrono>
#include <set>
/* Socket-free presentation state. It never owns an engine pointer, a database,
* an account key, a socket or a subprocess. All gameplay inputs are real packets. */
struct NativeWorldTranslation {
std::optional<gateway::ForcedReactions> forced_reactions;
bool forced_reactions_dirty=false;
// Bounded by the reviewed source drop catalogue; never count arbitrary opcodes.
std::map<uint32_t,uint64_t> no_native_consumer_drops;
gateway::Character selected{};
uint16_t realm;
std::string realm_name; // Same authenticated Source name used by AuthResponse.
uint32_t internal_source_account=0;
uint32_t virtual_realm_address=0; // Actual authenticated engine context, never inferred from a name.
std::optional<gateway::WorldLocation> location;
std::optional<gateway::NearTeleport> pending_teleport;
// Nonseamless source transfer, owned by this authenticated character.
// Native control counters are presentation protocol state, not source IDs.
struct FarTransfer {
uint64_t owner=0,owner_generation=0;uint16_t realm=0;
gateway::WorldLocation destination{};
uint32_t world_counter=0,suspend_sequence=0;
// 0:suspend response,1:NewWorld queued,2:WorldPort response,
// 3:source ACK prepared,4:source ACK actually sent/fresh self pending.
uint8_t phase=0;
gateway::Bytes new_world,resume;
};
std::optional<uint32_t> source_far_map;
bool source_far_transport=false;uint32_t source_far_transport_entry=0; // Turtle TRANSFER_PENDING ship tail: transport entry
std::optional<FarTransfer> far_transfer;
std::deque<gateway::LegacyPacket> transfer_presentation;
uint32_t world_transfer_counter=0,native_movement_counter=0;
uint64_t transfer_holds=0;
std::vector<gateway::LegacyPacket> receive_far_transfer(uint32_t,std::span<const uint8_t>,const NativeEntityTranslation::Codec&);
void suspend_transfer_response(std::span<const uint8_t>);
gateway::LegacyPacket worldport_response(std::span<const uint8_t>)const;
void worldport_prepared();
bool worldport_send_completed();
bool transfer_owned()const noexcept;
std::optional<std::chrono::steady_clock::time_point> undercity_settle;
uint64_t undercity_generation=0;
struct EarlyUndercityCreate { uint64_t guid; gateway::LegacyPacket create; };
std::map<uint32_t,EarlyUndercityCreate> early_undercity;
void stage_early_undercity(const gateway::LegacyPacket&,const std::vector<gateway::LegacyObjectUpdate>&,bool);
std::optional<bool> undercity_position() const noexcept;
bool undercity_due() const noexcept;
bool queue_undercity_template(std::span<const uint8_t>);
void service_undercity(uint32_t,decltype(&gw_codec_serialize),std::vector<gateway::LegacyPacket>&,bool);
bool local_presentation_pending() const noexcept {
return (summon_offer && !summon_offer->presented && self_created && location && !far_transfer && !pending_teleport) ||
!equipment_sets.replies.empty() || (equipment_sets.pending &&
(equipment_sets.pending->next || gateway::equipment_sets::Clock::now() >= equipment_sets.pending->deadline)) || undercity_due() || bg_positions_due() || clubs.pending() || talent_presentation_pending() || !transfer_presentation.empty() ||
(self_created && ((!logout_complete && !native_presentations.empty()) || trade.notify_changed ||
!social_presentations.empty() || (quest_poi_60141_pending.has_value() && !quest_poi_60141_waiting_definition) ||
(!quest_poi_pending.empty() && quest_poi_waiting_definitions.empty())));
}
// Genuine source controller changes only; retain sequence/type/value until
// the original engine generates a matching ACK and transport serializes it.
struct PendingSpeed {uint32_t source_opcode=0;float value=0;};
struct KnockbackAck {uint32_t sequence;gateway::BasicMovement move;};
KnockbackAck knockback_ack(std::span<const uint8_t>,const std::vector<gateway::Character>&) const;
std::map<uint32_t,std::array<float,4>> pending_knockbacks;
std::map<uint32_t,PendingSpeed> pending_speeds;
std::map<uint32_t,uint32_t> pending_modes; // Genuine source sequence -> set/clear opcode.
std::optional<bool> source_ghost;
std::optional<uint32_t> source_health;
struct ReleaseContext {
bool requested=false,corpse_valid=false;
std::optional<gateway::WorldLocation> transfer;
} release;
uint32_t release_diagnostic_rows=0;
void trace_release(const char* stage) noexcept;
bool observe_death_updates(const std::vector<gateway::LegacyObjectUpdate>&);
bool self_created=false;
// Last PlayerData.PartyType[HOME] value published on the native self object.
bool published_home_party=false;
// Last Source zone from INIT_WORLD_STATES; drives the 1.12-client channel follow.
std::optional<uint32_t> source_zone;
void follow_source_zone();
bool logout_complete=false; // Set only by the genuine source completion.
bool logout_countdown=false; // #100: Source LogoutResponse(0,0) started the 20 s camp countdown; cleared by cancel ack/complete.
bool mover_confirmed=false;
std::set<uint32_t> spells;
std::map<uint32_t,int32_t> reputation_values;
unsigned reputation_diagnostic_rows=0;
// Provider snapshots contain only this authenticated character's received
// source state. No engine trait IDs, optimistic ranks or database lookups.
std::optional<uint32_t> talent_level,talent_points,talent_class;
bool talent_spells_ready=false,talent_self_generation=false;
bool needs_class_talent_group=true;
bool talent_snapshot_pending=false,talent_initial_snapshot=false;
uint64_t talent_sequence=0;
std::optional<std::string> talent_notice;
// Only a genuine source MSG_TALENT_WIPE_CONFIRM installs an offer. The
// Creature generation prevents a removed/recreated actor reusing it.
struct TalentResetOffer {uint64_t guid=0,generation=0;uint32_t cost=0;};
std::optional<TalentResetOffer> talent_reset_offer;
struct SpiritHealerOffer {uint64_t guid=0,generation=0;};
std::optional<SpiritHealerOffer> spirit_healer_offer;
// Tortoise SMSG_BINDER_CONFIRM 0x2EB: the innkeeper actually offered to set home.
std::optional<SpiritHealerOffer> binder_offer;
struct CharacterBankInteraction { uint64_t banker, generation; };
std::optional<CharacterBankInteraction> character_bank;
// Tortoise SMSG_PET_UNLEARN_CONFIRM: the pet the server offered to untrain (generation-checked).
// The current hunter pet and the trainer whose gossip preceded it (Source closes gossip first).
struct PetUnlearnOffer {uint64_t pet=0,pet_generation=0,trainer=0,trainer_generation=0;};
std::optional<PetUnlearnOffer> pet_unlearn_offer;
// Last genuine Source gossip menu owner (kept after the menu closes; generation-checked on use).
std::optional<SpiritHealerOffer> last_gossip_npc;
// Battlemaster of the last Source NPC battlefield list (0x23D actor != self), for BATTLEMASTER_JOIN.
struct BattlemasterOffer {uint64_t source=0;uint32_t map=0;};
std::optional<BattlemasterOffer> battlemaster_offer;
bool pet_unlearn_offer_live() const;
// Letter text queried by an owned item (ItemTextQuery): (Source text id, native item GUID) in send order.
std::deque<std::pair<uint32_t,gateway::Guid128>> book_text_pending; // send order, bounded 32
// Page text chains (TC HandleQueryPageText returns every page under the requested ID).
struct PageChainPage {uint32_t id=0,next=0;std::string text;};
struct PageChain {uint32_t root=0, expected=0;std::vector<PageChainPage> pages;};
std::deque<PageChain> page_chains;
uint32_t owned_item_text(std::span<const uint8_t> body,gateway::Guid128* native=nullptr) const;
// Native pet commands name the currently presented pet bar unit (Source pet or charm).
uint64_t current_pet_command_unit(gateway::Reader&) const;
bool pet_bar_spell(uint32_t spell) const noexcept;
bool talent_ready() const noexcept;
bool talent_reset_offer_bound() const noexcept;
void clear_talent_state();
void observe_talent_updates(const std::vector<gateway::LegacyObjectUpdate>&);
bool talent_control(std::string_view,std::optional<gateway::LegacyPacket>&);
void talent_control_sent(const gateway::LegacyPacket&) noexcept;
bool talent_presentation_pending() const noexcept {return talent_snapshot_pending || talent_notice.has_value() || !guild_control_notices.empty() || entities.equipment_visibility.dirty;}
std::vector<gateway::LegacyPacket> take_talent_presentation(uint32_t address);
gateway::Bytes local_presentation(uint32_t address,decltype(&gw_codec_serialize) codec=nullptr);
NativeSocialTranslation social;
NativeContactNames contact_names;
struct InspectTalentRequest {
std::pair<uint64_t,uint64_t> peer;
std::chrono::steady_clock::time_point until;
unsigned messages=0;
bool sent=false;
};
std::optional<InspectTalentRequest> inspect_talents;
// Octo INSShowTransmogs query, sent once per approved inspect; replies carry real item + appearance per slot.
std::optional<InspectTalentRequest> inspect_transmogs;
std::optional<gateway::LegacyPacket> next_inspect_transmogs();
// Peers that asked for our transmogs (INSShowTransmogs): name -> answer deadline and rows sent.
struct TransmogAsker {std::chrono::steady_clock::time_point until;unsigned rows=0;};
std::map<std::string,TransmogAsker> transmog_askers;
std::optional<gateway::Bytes> inspect_transmog_answer(std::string_view text);
void begin_inspect_talents(std::string_view);
std::optional<gateway::LegacyPacket> next_inspect_talents();
// Early real Source snapshots are retained, then published after SELF.
std::deque<std::pair<uint32_t,gateway::Bytes>> social_presentations;
// Explicitly enabled local-only experimental request; revalidated at drain.
std::vector<uint32_t> quest_poi_pending;
std::set<uint32_t> quest_poi_waiting_definitions;
bool queue_quest_poi(std::span<const uint8_t>,bool explicit_opt_in);
std::optional<gateway::LegacyPacket> take_quest_poi();
std::optional<gateway::Bytes> quest_poi_60141_pending;
bool quest_poi_60141_waiting_definition=false;
void observe_quest_poi_updates(const std::vector<gateway::LegacyObjectUpdate>&);
bool queue_quest_poi_60141(std::span<const uint8_t>,bool explicit_opt_in);
std::optional<gateway::LegacyPacket> take_quest_poi_60141();
bool social_legacy_queued=false;
uint64_t social_holds=0;
bool queue_social(uint32_t,const gateway::Bytes&);
std::vector<gateway::LegacyPacket> take_social_presentation(decltype(&gw_codec_serialize));
struct PetBar {
gateway::PetSpellbook state;
uint16_t realm;
uint32_t map;
uint64_t generation=0;
bool shown=false, mode_changed=false;
};
// One current server snapshot, including when its actor still awaits its creature reply.
std::optional<PetBar> pet_bar;
std::optional<gateway::LegacyPacket> take_pet_bar();
NativeEntityTranslation entities;
NativeInventoryTranslation inventory;
bool equipment_bank_open() const {
if (!character_bank || !selected.guid || !realm || !self_created || !location || logout_complete || pending_teleport || far_transfer) return false;
if (character_bank->banker == selected.guid) return true; // GM .bank on the player itself
const auto it = entities.actors.find(character_bank->banker);
return it != entities.actors.end() && it->second.kind == 3 && it->second.sent && it->second.eligible &&
it->second.generation && it->second.generation == character_bank->generation &&
it->second.presentation_realm == realm && it->second.presentation_map == location->map;
}
gateway::equipment_sets::Manager equipment_sets;
// Gitea #15: action slots 120..359 (gamepad/extra bars) stored client-locally per character.
std::filesystem::path extended_action_bar_file() const {
return gateway::extended_action_bars::path(internal_source_account,
gateway::forever_player_guid(selected.guid, realm), gateway::account_data::storage_directory());
}
std::filesystem::path equipment_set_file() const {
return gateway::equipment_sets::path(internal_source_account,
gateway::forever_player_guid(selected.guid, realm), gateway::account_data::storage_directory());
}
// Authenticated Source item creates can arrive in a packet before SELF.
// Keep only owned objects until the real SELF create confirms this session;
// no native object or metadata request is published from this staging map.
std::map<uint64_t,gateway::LegacyObjectUpdate> pre_self_items;
std::optional<uint32_t> pre_self_item_map;
NativeAuraTranslation auras;
NativeLootTranslation loot;
gateway::battleground::Queue battlegrounds;
// Phase-1 auction browse: one native search = one complete Source snapshot (sequential
// 0x258 pages), bucketed with TC rules once every item template is known.
struct AuctionBrowseState {
gateway::NativeAuctionBrowseQuery query;uint64_t auctioneer=0;gateway::AuctionSnapshot snapshot;
bool awaiting=false;std::optional<std::vector<gateway::AuctionBucket>> ordered;
// Sell-frame price lookup (ListItemsByItemID) with no snapshot row: a Source name search for that
// item, published as the by-item result instead of buckets.
std::optional<uint32_t> by_item;std::vector<gateway::AuctionSort> by_item_sorts;
std::optional<gateway::AuctionKey> by_key; // LIST_ITEMS_BY_BUCKET_KEY: the reply must carry this exact key
bool specific_keys=false; // BucketKeys lookup: publish the item's buckets in BrowseMode SpecificKeys
};
std::optional<AuctionBrowseState> auction_browse;
// Owned / bidded lists: one native request = one complete Source snapshot (0x259 / 0x264 pages).
struct AuctionPersonalState {bool owned=true;uint64_t auctioneer=0;std::vector<gateway::AuctionSort> sorts;std::vector<uint32_t> ids;
gateway::AuctionSnapshot snapshot;bool awaiting=false;};
std::optional<AuctionPersonalState> auction_personal;
// Tortoise serves one AH list request per session at a time (ReceivedAHListRequest) and drops
// the others. ah_list_inflight is set by every Source 0x258/0x259/0x264 we queue and cleared by
// any 0x25C/0x25D/0x265 reply; native browse/personal requests made meanwhile wait here (latest per opcode).
bool ah_list_inflight=false;
uint16_t ah_list_reply=0; // the Source reply kind the guard waits for
std::chrono::steady_clock::time_point ah_list_since{}; // a silently declined request never answers
bool ah_list_retired=false; // the in-flight reply belongs to a closed interaction
uint64_t ah_list_npc=0;
void ah_list_arm(uint16_t reply,uint64_t npc);
bool ah_list_busy();
std::map<uint32_t,gateway::Bytes> auction_personal_deferred;
// #108: SMSG_GAMEOBJECT_CUSTOM_ANIM (bobber splash) for an object whose create is not bound yet;
// replayed once in the same world/object lifetime, dropped after 5 s.
struct HeldGoAnim{
uint64_t source;uint32_t anim;std::chrono::steady_clock::time_point until;
uint64_t owner=0,generation=0;uint16_t realm=0;uint32_t map=0;
};
std::vector<HeldGoAnim> held_go_anims;
// Commodity quote / confirm (Codex decisions 2026-11-21): one exact whole stack. A quote is a fresh
// name-scoped Source snapshot; confirm re-snapshots, revalidates the same auction ID/count/buyout
// before one Source buyout (0x25A) and reports exactly the correlated Source 0x25B result.
// bid_queued: the 0x25A is in `requests`; bid_sent: transport actually dispatched it (session hook).
struct AuctionCommodityState {uint64_t auctioneer=0;uint32_t item=0,quantity=0;std::string name;bool confirm=false,awaiting=false,bid_queued=false,bid_sent=false;
gateway::Bytes bid;size_t next_lot=0;uint32_t late_failures=0; // repeat confirms answered (21) after the outstanding result, in TC order
gateway::AuctionSnapshot snapshot;std::optional<gateway::CommodityQuote> quote;
std::chrono::steady_clock::time_point deadline{},bid_since{};};
std::optional<AuctionCommodityState> auction_commodity;
uint32_t auction_commodity_omitted=0;
// Last authoritative Source PLAYER_FIELD_COINAGE of the selected character (unknown until a self
// create or update carries it). Tortoise silently ignores an unaffordable buyout, so commodity quotes
// and confirms are decided on this balance and never without it.
std::optional<uint64_t> self_coinage; // diagnostics: stackable rows absent from the public view
std::deque<gateway::LegacyPacket> native_presentations; // raw native packets answered locally
// OctoAux (ported aux add-on): last Source auctioneer from MSG_AUCTION_HELLO, the awaited Source list reply.
uint64_t aux_auctioneer=0;uint16_t aux_list_reply=0;
std::optional<gateway::LegacyPacket> aux_request(std::string_view text); // Source packet to send, or answered locally
void aux_local(const std::string& text); // one local "OctoAux" message
void addon_local(std::string_view prefix,const std::string& text); // one local add-on message (OctoRadio...)
std::string aux_name(uint64_t guid) const;
// Native commodity requests answered without Source (cancel; confirm without a matching live quote;
// quote for an item with no searchable Source template). true when handled.
bool auction_commodity_local(uint32_t opcode,std::span<const uint8_t> body);
void auction_commodity_fail(bool confirm);
void auction_bid_dispatched(std::span<const uint8_t> body); // session: a queued Source 0x25A left the queue
std::chrono::steady_clock::time_point ordinary_bid_since{}; // last ordinary PLACE_BID sent (zero-ID error attribution)
void auction_commodity_resolve(bool ok);
void cancel_unsent_commodity();
bool defer_personal_list(uint32_t opcode,std::span<const uint8_t> body);
void start_deferred_personal_list();
// Sent CMSG_PET_RENAME names: Tortoise SMSG_PET_NAME_INVALID (0x178) carries no body; native
// PetNameInvalid is TC's shape (empty pet GUID, number 0, the rejected name).
// Outstanding sent renames in send order (Tortoise answers failures in order; success is silent).
struct PetRenameAttempt {uint64_t pet=0;std::string name;};
std::deque<PetRenameAttempt> pet_rename_sent;uint32_t pet_rename_dropped=0; // attempts past the bound, still answerable
uint64_t auction_holds=0;
// Hunter stable: the latest Source 0x26F list for a bound stablemaster, published as
// ActivePlayerData.PetStable once every creature display is known.
struct StableSnapshot {gateway::TurtleStableList list;gateway::Guid128 master{};bool published=false;};
std::optional<StableSnapshot> stable;
uint64_t stable_holds=0;
// CMSG_CLOSE_INTERACTION has no Source message: returns the stable-closed DTO when it names the open stable.
std::optional<gateway::Bytes> close_interaction(std::span<const uint8_t>);
// Native requests answered from the published snapshot: a later browse page (Offset>0)
// and a bucket click. Returns {codec mode, DTO} or nullopt (held).
std::optional<std::pair<uint32_t,gateway::Bytes>> auction_local_request(uint32_t opcode,std::span<const uint8_t>) const;
NativeLootReceipts loot_receipts;
NativePartyTranslation party;
// Presentation-only trade correlation; the Source server owns the trade itself.
struct TradeOfferChanged : gateway::Error { using gateway::Error::Error; };
struct TradeSession {
struct Offer {
uint32_t revision=1, client_index=1; // Native TradeData starts both fields at 1.
gateway::Bytes source;
};
uint32_t id=0, last_revision=1;
uint64_t partner=0;
bool open=false, notify_changed=false;
std::array<Offer,2> offers{}; // Source WhichPlayer 0 = own, 1 = partner.
void close() { open=false; partner=0; notify_changed=false; offers={}; }
} trade;
// A Source invitation qualifies a response only for the visible sender's
// exact actor generation and only after its native presentation exists.
struct PartyInvitation {uint64_t guid,generation;std::chrono::steady_clock::time_point expires;bool accepted=false;std::string name;};
std::optional<PartyInvitation> party_invitation;
bool party_invitation_current() const;
bool party_response_idle(uint32_t,std::span<const uint8_t>) const;
NativeQuestTranslation quests;
std::set<uint32_t> quest_item_waiting_definitions;
QuestStatusRefresh quest_status_refresh;
enum class QuestBindingSet { All, VisibleQuestGivers };
NativeQuestTranslation::Bindings quest_bindings(QuestBindingSet set=QuestBindingSet::All) const;
std::optional<QuestStatusRefresh::Request> next_quest_status_refresh();
uint32_t guild_id=0,guild_rank=0;
enum class OwnGuildJoin { None, Guildless, SourceEventBeforeMembership, AwaitingRoster, Presented };
OwnGuildJoin own_guild_join = OwnGuildJoin::None;
void present_guild(uint32_t address, std::vector<gateway::LegacyPacket>& output);
NativeClubService clubs;
struct {
std::string name;
std::optional<gateway::GuildRosterDetails> details;
std::optional<gateway::GuildRoster> awaiting_details;
bool requested=false;
const gateway::GuildRosterDetails* matched() const {
return details && details->name==name ? &*details : nullptr;
}
} guild_roster_context;
bool club_membership_reply_recorded=false;
std::optional<gateway::GuildRankAssignment> guild_rank_assignment;
gateway::GuildPermissions guild_permissions;
std::optional<gateway::GuildInfo> guild_rank_info;
std::optional<gateway::GuildRoster> guild_management_roster;
bool guild_management_pending=false;
void observe_guild_rank(uint32_t rank); // PLAYER_GUILDRANK from the authoritative self update
uint64_t guild_control_revision=0,guild_control_serial=0;
bool guild_control_subscribed=false;
std::optional<gateway::GuildControlIntent> guild_control_inflight;
std::vector<std::string> guild_control_notices;
std::optional<gateway::GuildControlIntent> guild_control_prepare(std::string_view);
void guild_control_sent(const gateway::GuildControlIntent&);
void guild_control_state();
void guild_control_refresh();
void guild_control_clear();
std::optional<std::vector<uint32_t>> guild_roster_rights;
std::optional<uint32_t> player_guild(uint64_t guid) const;
gateway::GuildBankState guild_bank;
gateway::ChannelState chat_channels;
uint64_t channel_semantic_holds=0;
struct BankWindow {
uint64_t source=0,generation=0;uint32_t guild=0,tab=1;
gateway::Guid128 modern{};bool opened=false;
bool empty=false; // #91 opened while the guild had no bank; the first bought tab is loaded into it
int32_t money_log_tab=-1; // tab id the native UI used for its money log query (echoed back)
};
std::optional<BankWindow> bank_window;
std::optional<std::vector<uint32_t>> bank_rank_rights;
bool bank_roster_pending=false;
std::map<std::string,gateway::Guid128> bank_player_guids; // guild members by name, for bank log rows
uint32_t bank_unmapped_property_rows=0;
bool bank_current() const;
bool bank_gossip(const gateway::GossipMenu&);
std::optional<gateway::LegacyPacket> bank_request(uint32_t,std::span<const uint8_t>) const;
bool bank_duplicate_query(uint32_t,std::span<const uint8_t>) const;
bool bank_idle_query(uint32_t,std::span<const uint8_t>) const;
void bank_sent(uint32_t,std::span<const uint8_t>);
void clear_bank();
bool close_bank(std::span<const uint8_t>);
std::vector<gateway::LegacyPacket> bank_presentation(const gateway::GuildBankChange&);
bool pending_guild_invitation=false;
std::deque<gateway::LegacyPacket> requests;
std::map<uint64_t,gateway::Character> chat_players;
std::set<uint64_t> chat_name_queries;
std::deque<gateway::Bytes> pending_chats;
struct InspectPeer {
uint64_t guid=0,generation=0,owner=0;
uint32_t map=0,world_generation=0;
uint16_t realm=0;
bool operator==(const InspectPeer&) const = default;
};
std::optional<InspectPeer> inspect_selection;
uint64_t inspect_selection_epoch=0;
InspectRequestHistory<InspectPeer> inspect_requests;
std::optional<InspectPeer> inspect_permission;
std::chrono::steady_clock::time_point inspect_permission_until{};
// One public visible entry per slot, captured at the server-approved snapshot.
std::array<uint32_t,19> inspect_name_entries{};
void append_inspect_names(std::vector<gateway::LegacyPacket>&,uint32_t address);
void clear_inspect_selection();
std::optional<gateway::Bytes> inspect_control(std::string_view) const;
// Built-in boss mods: the client addon names the spells it handles ("R" reset+on, "S id id..", "O" off);
// matching server combat facts are then presented to it as local "OctoBM" addon messages.
bool boss_feed_on=false;std::set<uint32_t> boss_feed_spells;
void boss_feed_control(std::string_view);
std::optional<InspectPeer> live_inspect_peer(uint64_t) const;
std::optional<std::pair<uint64_t,uint64_t>> authorized_inspect_peer() const;
std::optional<std::array<gateway::Bytes,3>> inspect_ack(std::span<const uint8_t>,uint32_t);
std::optional<gateway::GossipMenu> gossip;
gateway::npc_text::Queries npc_text_queries;
uint64_t gossip_actor_generation = 0;
// Last unit the client selected (CMSG_SET_SELECTION), legacy GUID; 0 = none. Party-of-target spells use it.
mutable uint64_t current_selection = 0;
// Native RequestPlayedTime.TriggerScriptEvent, echoed on the matching Source 0x1cd.
mutable bool played_trigger = false;
// Silent RequestPlayedTime calls (the client UI asks at every login) whose Turtle "Death counter" line is dropped.
mutable uint8_t played_silent_notes = 0;
// Source CMSG_QUERY_TIME (0x1ce) answers both native QueryTime (false) and
// ServerTimeOffsetRequest (true), FIFO; both native replies are one Timestamp.
mutable std::deque<bool> pending_time_kinds;
// Native WhoRequestPkt.Token for the one outstanding Source CMSG_WHO; a newer
// query or session change replaces it. Rows without a unique genuine identity are held.
struct PendingWho {uint32_t token=0;uint64_t owner=0;uint16_t realm=0;};
std::optional<PendingWho> pending_who;
uint64_t who_held_rows = 0;
// Match-team evidence per Source queue slot (Tortoise GroupQueueInfo.GroupTeam =
// queue-time leader team): solo queue -> self; 0x2e8 group join -> leader then.
// Unknown team keeps the scoreboard pending; leave/new queue/logout clear it.
struct BgTeamEvidence {uint32_t map=0;std::optional<uint8_t> team;};
std::array<std::optional<BgTeamEvidence>,3> bg_team{};
uint64_t pvp_held_rows = 0;
// WSG flag carrier: native receives pushed positions; Tortoise answers MSG_BATTLEGROUND_PLAYER_POSITIONS
// polls (as the 1.12 client did). Next poll time while on map 489 with known team.
std::chrono::steady_clock::time_point bg_positions_next{},bg_positions_sent{};bool bg_positions_pending=false,bg_positions_shown=false;
bool bg_positions_due() const noexcept;
void service_bg_positions(std::vector<gateway::LegacyPacket>& output);
std::optional<uint8_t> source_match_team(uint64_t leader) const;
const gateway::GossipMenu* current_npc_text_menu() const;
std::optional<gateway::TrainerList> trainer;
uint64_t trainer_self_guid=0;
std::optional<uint64_t> merchant;
std::optional<gateway::TaxiMenu> taxi_menu;
uint64_t taxi_vendor_generation=0;
std::optional<gateway::VendorInventory> vendor_inventory;
struct PendingGameObjectQuery {
uint64_t source=0,generation=0;uint32_t entry=0,map=0;uint16_t realm=0;
gateway::Guid128 modern{};
};
// A source reply carries entry only. Keep the old context until its real
// reply arrives: replacing it after removal/map change could misattribute
// a late old reply to a new actor with the same template entry.
std::map<uint32_t,PendingGameObjectQuery> gameobject_queries;
std::set<uint32_t> gameobject_template_replies_logged; // First reply per entry for this session.
struct GameObjectQueryEvidence {
PendingGameObjectQuery request;
bool found=false;uint32_t type=0,display=0;
std::vector<gateway::GameObjectTemplateIssue> presentation_holds;
bool published=false;
std::string authority_provenance;
};
std::optional<GameObjectQueryEvidence> gameobject_query_evidence;
// Only a correlated, current Source type-19 template may arm MailGetList.
std::map<uint64_t,gateway::MailboxTemplateEvidence> mailbox_templates;
gateway::MailboxTranslation mailbox_list;
gateway::MailboxActor current_mailbox_actor() const;
std::optional<gateway::MailboxActor> next_mailbox_actor;
bool coalesce_mailbox_list(std::span<const uint8_t> body);
std::optional<gateway::MailboxPrepared> next_mailbox_list();
// Source GUID of the mailbox most recently listed; Delete/ReturnToSender carry no mailbox natively.
uint64_t mailbox_source=0;
// Source duel: flag (arbiter) game object and the target this client challenged.
uint64_t duel_flag=0,duel_target=0;
// Source pet number -> native unit GUID of an outstanding CMSG_PET_NAME_QUERY.
std::map<uint32_t,gateway::Guid128> pet_name_pending;
// Native GUID for a Source object GUID: bound entities first, then Source player counters.
std::optional<gateway::Guid128> native_guid(uint64_t source) const;
bool source_pet_name_query(std::span<const uint8_t> body) const;
gateway::LegacyPacket mail_request(uint32_t opcode,std::span<const uint8_t> body) const;
struct MailboxBinding {
gateway::MailboxActor actor;
gateway::MailboxTemplateEvidence evidence;
};
MailboxBinding mailbox_binding(std::span<const uint8_t>) const;
void clear_mailbox();
// Set only from the authenticated transport's exact configured local
// endpoint. Remote worlds never borrow a local hidden Size/reference row.
bool local_gameobject_authority=false;
using GameObjectAuthorityProvider=std::function<std::optional<gateway::GameObjectTemplateAuthority>(const gateway::GameObjectTemplateReply&)>;
GameObjectAuthorityProvider gameobject_template_authority;
uint64_t gameobject_query_actor(const gateway::GameObjectQuery&) const;
bool gameobject_query_current(const PendingGameObjectQuery&) const;
void gameobject_query_queued(std::span<const uint8_t>);
std::optional<gateway::GameObjectTemplatePacket> gameobject_query_reply(std::span<const uint8_t>);
struct PendingCast {gateway::ForeverSpellRequest spell;gateway::Guid128 caster;};
std::optional<PendingCast> pending_cast;
void queue_cast(PendingCast);
// #126: the client's spell queue sends the next request while the current cast still runs; Turtle refuses it
// (SPELL_IN_PROGRESS) and completes the running one. Keep the running, already started request here so its
// GO/failure still resolves the client's own cast instead of arriving under a foreign server identity.
struct HeldCast {PendingCast cast;bool prepared=false;};
std::optional<HeldCast> superseded_cast;
// #136: queued next-melee-swing cast (Heroic Strike...), resolved by its own GO/failure at the main-hand swing.
std::optional<HeldCast> melee_cast;
bool select_cast(uint32_t spell);
void release_cast();
// Genuine source state and a sent stand request; no optimistic standing.
std::optional<uint8_t> source_stand;
bool source_stand_pending=false;
struct StandingCast {
gateway::LegacyPacket packet;gateway::Bytes original;
uint64_t owner=0;uint16_t realm=0;uint32_t map=0;
std::map<uint64_t,uint64_t> target_generations;
std::chrono::steady_clock::time_point deadline;
bool acknowledged=false;
// Report 58f1cc: held for the Turtle wand GCD. Sent once the Source confirmed the wand stopped and the
// last shot's GCD ended, or at this time at the latest.
std::optional<std::chrono::steady_clock::time_point> release_at;
};
std::optional<StandingCast> standing_cast;
// Turtle Unit::_UpdateAutoRepeatSpell gives each wand shot a server-only GCD of the ranged timer.
std::optional<std::chrono::steady_clock::time_point> wand_shot,wand_gcd_until;
bool wand_repeating=false; // self Shoot auto-repeat active at the Source (each shot renews the GCD)
std::chrono::milliseconds wand_interval{0};
bool defer_standing_cast(uint32_t,std::span<const uint8_t>,const gateway::LegacyPacket&);
bool cancel_standing_cast(uint32_t,std::span<const uint8_t>);
void stand_state_received(uint8_t);
std::optional<gateway::LegacyPacket> standing_cast_request();
void standing_cast_sent();
// One owner-bound ability, released only after a genuine source form update.
std::optional<uint8_t> source_form;
struct StanceCast:StandingCast {uint32_t stance=0;uint8_t form=0;bool failed=false;};
std::optional<StanceCast> stance_cast;
std::optional<StanceCast> prepare_stance_cast(uint32_t,std::span<const uint8_t>,const gateway::LegacyPacket&) const;
gateway::LegacyPacket stance_switch_packet(const StanceCast&) const;
void stance_switch_sent(StanceCast);
std::optional<gateway::LegacyPacket> stance_cast_request();
void stance_ability_sent();
bool cancel_stance_cast(uint32_t,std::span<const uint8_t>);
void clear_stance_cast();
bool cast_prepared=false;
uint32_t pending_item_entry=0;
// Opt-in bounded public combat diagnostics. No packet bodies, keys,
// account identities or engine pointers are retained or logged.
unsigned combat_diagnostic_rows=0;
void trace_combat(const char*,uint32_t,uint64_t,uint64_t,uint32_t,uint32_t=0,uint32_t=0,uint32_t=0);
void qualify_spell_location(const gateway::ForeverSpellRequest&) const;
void qualify_spell_gameobject(const gateway::Guid128&) const;
// Upper half of the native40-bit counter is reserved for adapter-owned
// server-event correlation; no Turtle spell/item identity is remapped.
uint64_t server_cast_counter=0x8000000000ULL;
struct ObservedCast {
gateway::Guid128 identity{};
uint64_t owner=0,generation=0,target=0,target_generation=0;
uint16_t realm=0;
uint32_t map=0;
std::chrono::steady_clock::time_point expires;
};
// The source supplies no cast serial. At most one START for each
// visible actor/spell may be associated with a later source GO.
std::map<std::pair<uint64_t,uint32_t>,ObservedCast> observed_casts;
// #91: Turtle SPELLDISPELLOG/DISPEL_FAILED omit the dispelling spell; it is the caster's dispel-effect SPELL_GO
// that the source sends immediately before them (Spell::cast -> SendSpellGo -> EffectDispel).
std::map<uint64_t,std::pair<uint32_t,std::chrono::steady_clock::time_point>> dispel_go;
std::optional<uint32_t> recent_dispel(uint64_t caster) const;
// Source may announce a genuine unit self GO before its object/holder.
// Keep one bounded latest ghost event until source state independently
// confirms the holder; never synthesize it from login flags.
std::optional<gateway::TurtleSpellCast> pending_ghost_cast;
unsigned ghost_cast_packet_budget=0;
// Real equip GOs may precede LOGIN_VERIFY_WORLD and the initial player/
// item creates. Keep only reviewed direct-self events within this login;
// later owned equipment, template and source aura state must confirm them.
struct LoginEquipCast {gateway::TurtleSpellCast event;bool ambiguous=false;std::optional<unsigned> slot;};
std::map<uint32_t,LoginEquipCast> login_equip_casts;
unsigned login_equip_packet_budget=0;
std::array<int32_t,64> cooldown_flat{},cooldown_percent{};
uint64_t cooldown_flat_received=0; // Genuine source aggregates retained until native self-create.
// Latest genuine source aggregates by (percent, operation, family bit).
// Entries include zero removals; bounded to 2*34*64 source keys.
std::map<std::tuple<bool,uint8_t,uint8_t>,int32_t> spell_modifier_aggregates;
std::map<uint32_t,uint64_t> item_cooldown_until;
void gameplay_sent(uint32_t,std::span<const uint8_t>);
std::vector<gateway::LegacyPacket> commodity_sell_packets(std::span<const uint8_t>) const;
std::vector<gateway::LegacyPacket> mail_send_packets(std::span<const uint8_t>) const;
bool service_shortcut(const gateway::GossipMenu&) const;
std::map<uint64_t,gateway::Guid128> bindings() const;
gateway::LegacyPacket gameplay(uint32_t,std::span<const uint8_t>) const;
// #87: Source movement packets for the MoveUpdate a native cast carries (empty when none).
std::vector<gateway::LegacyPacket> cast_move_update(uint32_t opcode,std::span<const uint8_t> body,const std::vector<gateway::Character>& owned) const;
// Queues one Source 0x27F per roster target; returns how many were queued.
size_t party_stats_request(std::span<const uint8_t>);
std::optional<gateway::LegacyPacket> area_trigger_request(std::span<const uint8_t>) const;
gateway::LegacyPacket emote_request(uint32_t,std::span<const uint8_t>) const;
std::vector<gateway::LegacyPacket> emote_event(const gateway::LegacyPacket&) const;
bool authorizes_movement(uint64_t guid) const noexcept { return self_created && selected.guid==guid; }
std::vector<gateway::LegacyPacket> player_movement(uint32_t opcode,std::span<const uint8_t> body,const std::vector<gateway::Character>& owned) const;
std::vector<gateway::LegacyPacket> player_movement_checked(uint32_t,std::span<const uint8_t>,const std::vector<gateway::Character>&) const;
// Presented charm GUID while the selected character possesses a unit (Mind Control etc.).
std::optional<gateway::Guid128> possessed_unit() const;
// Source GUID of the possessed unit when the packed native mover GUID names it.
std::optional<uint64_t> possessed_source(std::span<const uint8_t> packed_guid) const;
void movement_sent(uint32_t opcode,std::span<const uint8_t> body,
std::span<const gateway::LegacyPacket> serialized={}) noexcept;
gateway::Bytes translate(const gateway::LegacyPacket&,uint32_t address,uint64_t clock,decltype(&gw_codec_serialize));
// Last genuine Source summon offer; summoner may be outside visibility.
struct SummonOffer {
uint64_t source=0,owner=0;
gateway::Guid128 modern{};
uint16_t realm=0;uint32_t map=0;
std::chrono::steady_clock::time_point expires;
uint32_t zone=0;
bool presented=false;
};
std::optional<SummonOffer> summon_offer;
std::optional<gateway::LegacyPacket> take_summon_presentation(uint32_t address);
std::optional<gateway::LegacyPacket> summon_response(std::span<const uint8_t>) const;
bool summon_decline(uint32_t,std::span<const uint8_t>);
};