Files

176 lines
11 KiB
C++

#pragma once
#include <set>
#include <optional>
#include "gateway/protocol.hpp"
#include "gateway/roster_translation.hpp"
#include <map>
namespace gateway {
// The legacy roster is server-filtered, including officer-note visibility.
// Area IDs are retained in their source namespace until an area mapping is proven.
struct GuildRosterMember {
uint64_t guid = 0;
uint32_t rank = 0, source_area = 0;
uint8_t online = 0, level = 0, class_id = 0;
float offline_days = 0;
std::string name, note, officer_note;
};
struct GuildRoster {
std::string welcome, info;
std::vector<uint32_t> source_rank_rights;
std::vector<GuildRosterMember> members;
};
// A valid legacy roster can exceed the original native string storage.
// Holding its presentation must not discard the server's rank permissions.
struct GuildRosterHold : Error {using Error::Error;};
GuildRoster turtle_guild_roster(std::span<const uint8_t>);
struct GuildRosterDetails {
std::string name;
uint32_t accounts = 0, packed_date = 0x7fffffff;
};
GuildRosterDetails turtle_guild_details(std::span<const uint8_t>);
Bytes forever_guild_roster(const GuildRoster&, RosterRealm, const GuildRosterDetails* = nullptr);
Bytes turtle_say(std::span<const uint8_t>,uint8_t source_race=0);
// Native CMSG_CHAT_MESSAGE_AFK/DND {11-bit length, text} -> Tortoise CMSG_MESSAGECHAT type 0x14/0x15.
Bytes turtle_away_request(std::span<const uint8_t>,bool dnd);
bool source_player_chat_type(uint8_t legacy_type);
Bytes turtle_chat_request(std::span<const uint8_t>,uint8_t legacy_type,uint8_t source_race=0);
Bytes turtle_whisper_request(std::span<const uint8_t>,uint16_t realm,uint32_t virtual_address);
Bytes forever_chat(std::span<const uint8_t>,const std::vector<Character>&,RosterRealm,uint32_t account,bool account_optional=false,uint32_t guild_id=0);
struct GuildInvitation { std::string inviter,name; };
struct GuildInvitationHold : Error {using Error::Error;};
Bytes turtle_guild_invite_request(std::span<const uint8_t>);
GuildInvitation turtle_guild_invitation(std::span<const uint8_t>);
Bytes forever_guild_invitation(const GuildInvitation&,uint32_t virtual_address);
Bytes forever_guild_command_result(std::span<const uint8_t>);
struct GuildInfo { uint32_t id; std::string name; std::array<std::string,10> ranks; std::array<uint32_t,5> emblem; };
GuildInfo turtle_guild_info(std::span<const uint8_t>);
Bytes forever_guild_info(const GuildInfo&,RosterRealm);
// W15 opt-in wire prototype: Trinity 70334 layout, native acceptance pending.
Bytes forever_guild_ranks(const GuildInfo&,std::span<const uint32_t> source_rights);
Character turtle_chat_player(std::span<const uint8_t>);
struct SelfAddonMessage { std::string prefix,text; };
// #151 Turtle hardcore chat (CHAT_MSG_HARDCORE 0x5E, Tortoise ChatHandler: hardcore players and GMs only). 70334 has no
// such chat type, so lines reach the OctoHardcore add-on as local addon messages "<name>\t<tag>\t<text>" and /h
// sends through the GWTURTLE channel ("hardcore <text>").
inline constexpr std::string_view HardcorePrefix="OctoHC";
struct HardcoreLine { uint64_t sender=0; uint8_t tag=0; std::string text; };
HardcoreLine turtle_hardcore_message(std::span<const uint8_t>); // Tortoise SMSG_MESSAGECHAT type 0x5E body
Bytes turtle_hardcore_request(std::string_view text,uint32_t language); // Tortoise CMSG_MESSAGECHAT 0x95 body
std::string octo_hardcore_line(const HardcoreLine&,std::string_view sender_name);
SelfAddonMessage forever_self_addon_request(std::span<const uint8_t>,const Character&,uint16_t realm);
inline constexpr std::string_view GraveRequestPrefix = "GWGRAVE";
Bytes turtle_grave_request(const SelfAddonMessage&, uint8_t source_race);
// Peer addon traffic (Tortoise 1.12 SendAddonMessage PARTY/RAID/GUILD/OFFICER and the raid-leader
// stream). Reviewed TW_* service prefixes keep their own server routes and are never peer traffic.
struct PeerAddonMessage {
uint8_t native_type; // native ChatMsg: 2 party, 3 raid, 4 guild, 5 officer, 0x27 raid leader
uint64_t sender;
uint8_t tag;
std::string prefix,text;
};
std::optional<PeerAddonMessage> turtle_peer_addon_message(std::span<const uint8_t>);
Bytes forever_peer_addon_message(const PeerAddonMessage&,const Character& sender,RosterRealm);
// Texts over 255 bytes (TWThreat replies) as \1/\2 pieces.
std::vector<Bytes> forever_peer_addon_messages(const PeerAddonMessage&,const Character& sender,RosterRealm);
// Actual70334 CMSG_CHAT_ADDON_MESSAGE (0x2d002a): untargeted party/raid/guild/officer channel.
struct PeerAddonRequest { uint8_t native_type; std::string prefix,text; };
PeerAddonRequest forever_peer_addon_request(std::span<const uint8_t>);
Bytes turtle_peer_addon_request(const PeerAddonRequest&); // Tortoise CMSG_MESSAGECHAT 0x95 body
// BigWigs pull timer (Octo Hapto/Bigwigs Plugins/Pulltimer.lua): raid addon prefix "BigWigs",
// "PulltimerSync <s>", "PulltimerBroadcastSync <s>", "PulltimerStopSync" (returns 0 = stop).
std::optional<uint32_t> bigwigs_pull_seconds(const PeerAddonMessage&);
// Native SMSG_START_TIMER (Classic 0x47003e): Type 2 PlayerCountdown, seconds; 0 left cancels.
Bytes forever_start_timer(uint32_t total,uint32_t left,const Guid128* player);
// OctoBossMods feed: one server combat fact as a local addon message to the built-in boss mods
// ("OctoBM" "sub;spell;src;dst;amount;extra", actor "-" | "P<name>" | "C<entry>:<low>").
// A local addon message to the selected character's own add-ons (private prefix, never sent to the Source).
Bytes forever_local_addon(const Character& self,RosterRealm realm,std::string_view prefix,std::string text);
struct BossFeedActor {char kind='-';uint32_t id=0,low=0;std::string name;};
Bytes forever_boss_feed(const Character& self,RosterRealm realm,std::string_view sub,uint32_t spell,
const BossFeedActor& src,const BossFeedActor& dst,uint32_t amount,std::string_view extra);
Bytes turtle_transmog_request(const SelfAddonMessage&);
Bytes forever_transmog_reply(std::span<const uint8_t>,const Character&,RosterRealm);
// Reviewed guild-channel server services. Peer addon transports remain separate.
Bytes turtle_server_addon_request(const SelfAddonMessage&);
struct ServerAddonMessage {
uint64_t sender;
uint8_t tag;
std::string prefix,text;
};
ServerAddonMessage turtle_server_addon_message(std::span<const uint8_t>);
Bytes forever_server_addon_reply(const ServerAddonMessage&,const Character&,RosterRealm);
std::vector<Bytes> forever_server_addon_replies(const ServerAddonMessage&,const Character&,RosterRealm);
Bytes forever_inspect_equipment_reply(const Character& self,RosterRealm,uint32_t peer,
const std::array<std::optional<uint32_t>,19>& values, unsigned layer = 0);
// One or two bounded addon messages containing the exact original item name.
std::vector<Bytes> forever_inspect_item_name(const Character&,RosterRealm,uint32_t peer,
unsigned slot,uint32_t entry,std::string_view name);
inline constexpr std::string_view InspectTalentPrefix="GWInspectTalent";
Bytes turtle_inspect_talents_request(const Character& peer);
bool is_inspect_talent_reply(const ServerAddonMessage&);
// Original Octo InspectPaperDollFrame transmog query (answered by the inspected player's client):
// INSTransmogs;start;0;0 then INSTransmogs;<slot>;<appearance item>;<real item> per transmogged slot.
Bytes turtle_inspect_transmogs_request(const Character& peer);
struct InspectTransmog {bool start=false;unsigned slot=0;uint32_t appearance=0,real=0;};
std::optional<InspectTransmog> inspect_transmog_reply(const ServerAddonMessage&);
// GWInspectGear "X <realm> <peer> <slot> <appearance> <real>"; slot 0 resets the inspected peer's data.
Bytes forever_inspect_transmog_reply(const Character& self,RosterRealm,uint32_t peer,const InspectTransmog&);
Bytes forever_inspect_talents_reply(const ServerAddonMessage&,const Character& peer,RosterRealm);
// Answering a peer's INSShowTransmogs (Octo players inspecting us). The server only relays it;
// the inspected client answers. The gateway hands the asker's name to the client addon as
// OctoTmogAsk and turns each OctoTmogAns "<name>;INSTransmogs;..." back into the Octo whisper.
inline constexpr std::string_view InspectTransmogAskPrefix="OctoTmogAsk";
inline constexpr std::string_view InspectTransmogAnswerPrefix="OctoTmogAns";
bool is_inspect_transmog_query(const ServerAddonMessage&);
Bytes forever_inspect_transmog_query(const Character& self,RosterRealm,std::string_view asker);
struct InspectTransmogAnswer {std::string asker;InspectTransmog value;Bytes packet;};
InspectTransmogAnswer turtle_inspect_transmog_answer(std::string_view text);
// Source channels are named, session-scoped memberships, not invented GUIDs.
// Well-framed, unproved semantic fields are held separately from malformed wire.
struct ChannelHold : Error {using Error::Error;};
enum class ChannelCommand {Join,Leave,List,DisplayList,Message};
// native_id: the client's own ChatChannels ID (built-in zone/city channels); echoed, never invented.
struct ChannelRequest {uint32_t opcode=0;Bytes body;std::string channel;ChannelCommand command=ChannelCommand::List;int32_t native_id=0;};
struct ChannelPacket {uint32_t opcode=0;Bytes body;};
struct ChannelNotice {
uint8_t type=0,old_flags=0,new_flags=0;
uint32_t flags=0,source_label=0;
uint64_t sender=0,target=0;
std::string channel,sender_name;
};
ChannelNotice turtle_channel_notice(std::span<const uint8_t>);
// Sender is0 only for a genuine source system/channel announcement; unsupported layouts throw.
uint64_t turtle_chat_sender(std::span<const uint8_t>);
std::string turtle_chat_channel(std::span<const uint8_t>);
struct ChannelState {
struct Membership {std::string name;uint32_t flags=0;uint8_t own_flags=0;int32_t native_id=0;};
std::map<std::string,Membership> joined;
std::map<std::string,ChannelCommand> pending;
std::map<std::string,int32_t> pending_native_ids;
// 1.12-client zone follow (Tortoise Player::UpdateLocalChannels is client-side):
// source leaves whose native notice is replaced by the matching join, and
// city-only channels auto-left outside a capital (prefix -> native ID).
std::set<std::string> rehome_leaves;
// new key -> the membership it replaces (native left if the Source join fails).
std::map<std::string,Membership> rehome_joins;
std::map<std::string,int32_t> parked;
// City-only leaves acknowledged while the last Source zone was a capital: parked only if
// the next zone is not one (the native client's own exit leave), dropped otherwise.
std::map<std::string,int32_t> city_left;
std::optional<bool> zone_capital;
// Source requests that move joined built-in zone channels to the Source zone's
// names ("General - <zone>", city-only "Trade - City"); caller queues then sent()s.
std::vector<ChannelRequest> follow_zone(std::optional<std::string_view> zone,bool capital);
bool contains(const std::string&) const;
ChannelRequest request(ChannelCommand,std::span<const uint8_t>) const;
// Call only after actual source queue acceptance, never prepare/sizing.
void sent(const ChannelRequest&);
std::vector<ChannelPacket> notify(std::span<const uint8_t>,RosterRealm,uint64_t self);
ChannelPacket list(std::span<const uint8_t>,RosterRealm);
void clear(){joined.clear();pending.clear();pending_native_ids.clear();rehome_leaves.clear();rehome_joins.clear();parked.clear();city_left.clear();zone_capital.reset();}
};
}