mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-01 11:13:51 +00:00
Extract domain-specific logic from the monolithic GameHandler into
dedicated handler classes, each owning its own opcode registration,
state, and packet parsing:
- CombatHandler: combat, XP, kill, PvP, loot roll (~26 methods)
- SpellHandler: spells, auras, pet stable, talent (~3+ methods)
- SocialHandler: friends, guild, groups, BG, RAF, PvP AFK (~14+ methods)
- ChatHandler: chat messages, channels, GM tickets, server messages,
defense/area-trigger messages (~7+ methods)
- InventoryHandler: items, trade, loot, mail, vendor, equipment sets,
read item (~3+ methods)
- QuestHandler: gossip, quests, completed quest response (~5+ methods)
- MovementHandler: movement, follow, transport (~2 methods)
- WardenHandler: Warden anti-cheat module
Each handler registers its own dispatch table entries via
registerOpcodes(DispatchTable&), called from
GameHandler::registerOpcodeHandlers(). GameHandler retains core
orchestration: auth/session handshake, update-object parsing,
opcode routing, and cross-handler coordination.
game_handler.cpp reduced from ~10,188 to ~9,432 lines.
Also add a POST_BUILD CMake step to symlink Data/ next to the
executable so expansion profiles and opcode tables are found at
runtime when running from build/bin/.
73 lines
2.5 KiB
C++
73 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "game/world_packets.hpp"
|
|
#include "game/opcode_table.hpp"
|
|
#include "game/handler_types.hpp"
|
|
#include "network/packet.hpp"
|
|
#include <deque>
|
|
#include <functional>
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace wowee {
|
|
namespace game {
|
|
|
|
class GameHandler;
|
|
|
|
class ChatHandler {
|
|
public:
|
|
using PacketHandler = std::function<void(network::Packet&)>;
|
|
using DispatchTable = std::unordered_map<LogicalOpcode, PacketHandler>;
|
|
|
|
explicit ChatHandler(GameHandler& owner);
|
|
|
|
void registerOpcodes(DispatchTable& table);
|
|
|
|
// --- Public API (delegated from GameHandler) ---
|
|
void sendChatMessage(ChatType type, const std::string& message, const std::string& target = "");
|
|
void sendTextEmote(uint32_t textEmoteId, uint64_t targetGuid = 0);
|
|
void joinChannel(const std::string& channelName, const std::string& password = "");
|
|
void leaveChannel(const std::string& channelName);
|
|
std::string getChannelByIndex(int index) const;
|
|
int getChannelIndex(const std::string& channelName) const;
|
|
const std::vector<std::string>& getJoinedChannels() const { return joinedChannels_; }
|
|
void autoJoinDefaultChannels();
|
|
void addLocalChatMessage(const MessageChatData& msg);
|
|
void addSystemChatMessage(const std::string& message);
|
|
void toggleAfk(const std::string& message);
|
|
void toggleDnd(const std::string& message);
|
|
void replyToLastWhisper(const std::string& message);
|
|
|
|
// ---- Methods moved from GameHandler ----
|
|
void submitGmTicket(const std::string& text);
|
|
void handleMotd(network::Packet& packet);
|
|
void handleNotification(network::Packet& packet);
|
|
|
|
// --- State accessors ---
|
|
std::deque<MessageChatData>& getChatHistory() { return chatHistory_; }
|
|
const std::deque<MessageChatData>& getChatHistory() const { return chatHistory_; }
|
|
size_t getMaxChatHistory() const { return maxChatHistory_; }
|
|
void setMaxChatHistory(size_t n) { maxChatHistory_ = n; }
|
|
|
|
// Chat auto-join settings (aliased from handler_types.hpp)
|
|
using ChatAutoJoin = game::ChatAutoJoin;
|
|
ChatAutoJoin chatAutoJoin;
|
|
|
|
private:
|
|
// --- Packet handlers ---
|
|
void handleMessageChat(network::Packet& packet);
|
|
void handleTextEmote(network::Packet& packet);
|
|
void handleChannelNotify(network::Packet& packet);
|
|
void handleChannelList(network::Packet& packet);
|
|
|
|
GameHandler& owner_;
|
|
|
|
// --- State ---
|
|
std::deque<MessageChatData> chatHistory_;
|
|
size_t maxChatHistory_ = 100;
|
|
std::vector<std::string> joinedChannels_;
|
|
};
|
|
|
|
} // namespace game
|
|
} // namespace wowee
|