refactor(chat): decompose into modular architecture, add GM commands, fix protocol

- Extract ChatPanel monolith into 15+ focused modules under ui/chat/
  (ChatInput, ChatTabManager, ChatTabCompleter, ChatMarkupParser,
  ChatMarkupRenderer, ChatCommandRegistry, ChatBubbleManager,
  ChatSettings, MacroEvaluator, GameStateAdapter, InputModifierAdapter)
- Split 2700-line chat_panel_commands.cpp into 11 command modules
- Add GM command handling: 190-command data table, dot-prefix interception,
  tab-completion, /gmhelp with category filter
- Fix ChatType enum to match WoW wire protocol (SAY=0x01 not 0x00);
  values 0x00-0x1B shared across Vanilla/TBC/WotLK
- Fix BG_SYSTEM_* values from 82-84 (UB in bitmask shifts) to 0x24-0x26
- Fix infinite Enter key loop after teleport (disable TOGGLE_CHAT repeat,
  add 2-frame input cooldown)
- Add tests: chat_markup_parser, chat_tab_completer, gm_commands,
  macro_evaluator

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
This commit is contained in:
Pavel Okhlopkov 2026-04-12 14:59:56 +03:00
parent 09c4a9a04a
commit 42f1bb98ea
54 changed files with 7363 additions and 3856 deletions

View file

@ -0,0 +1,230 @@
// Emote/stance commands: /sit, /stand, /kneel, /dismount, /cancelform,
// /cancelaura, /cancellogout, /logout, /camp, /quit, /exit,
// pet commands (/petattack, /petfollow, etc.)
// Moved from ChatPanel::sendChatMessage() if/else chain (Phase 3).
#include "ui/chat/i_chat_command.hpp"
#include "ui/chat_panel.hpp"
#include "game/game_handler.hpp"
#include "rendering/renderer.hpp"
#include "rendering/animation_controller.hpp"
#include <algorithm>
#include <cctype>
namespace wowee { namespace ui {
// --- /sit ---
class SitCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.setStandState(1);
return {};
}
std::vector<std::string> aliases() const override { return {"sit"}; }
std::string helpText() const override { return "Sit down"; }
};
// --- /stand ---
class StandCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.setStandState(0);
return {};
}
std::vector<std::string> aliases() const override { return {"stand"}; }
std::string helpText() const override { return "Stand up"; }
};
// --- /kneel ---
class KneelCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.setStandState(8);
return {};
}
std::vector<std::string> aliases() const override { return {"kneel"}; }
std::string helpText() const override { return "Kneel"; }
};
// --- /logout, /camp, /quit, /exit ---
class LogoutEmoteCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.requestLogout();
return {};
}
std::vector<std::string> aliases() const override { return {"camp", "quit", "exit"}; }
std::string helpText() const override { return "Logout / quit game"; }
};
// --- /cancellogout ---
class CancelLogoutCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.cancelLogout();
return {};
}
std::vector<std::string> aliases() const override { return {"cancellogout"}; }
std::string helpText() const override { return "Cancel pending logout"; }
};
// --- /dismount ---
class DismountCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.dismount();
return {};
}
std::vector<std::string> aliases() const override { return {"dismount"}; }
std::string helpText() const override { return "Dismount"; }
};
// --- /cancelform, /cancelshapeshift ---
class CancelFormCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
for (const auto& aura : ctx.gameHandler.getPlayerAuras()) {
if (aura.spellId == 0) continue;
if (aura.flags & 0x20) {
ctx.gameHandler.cancelAura(aura.spellId);
break;
}
}
return {};
}
std::vector<std::string> aliases() const override { return {"cancelform", "cancelshapeshift"}; }
std::string helpText() const override { return "Cancel shapeshift form"; }
};
// --- /cancelaura ---
class CancelAuraCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
if (ctx.args.empty()) return {false, false};
std::string auraArg = ctx.args;
while (!auraArg.empty() && auraArg.front() == ' ') auraArg.erase(auraArg.begin());
while (!auraArg.empty() && auraArg.back() == ' ') auraArg.pop_back();
// Try numeric ID first
{
std::string numStr = auraArg;
if (!numStr.empty() && numStr.front() == '#') numStr.erase(numStr.begin());
bool isNum = !numStr.empty() &&
std::all_of(numStr.begin(), numStr.end(),
[](unsigned char c){ return std::isdigit(c); });
if (isNum) {
uint32_t spellId = 0;
try { spellId = static_cast<uint32_t>(std::stoul(numStr)); } catch (...) {}
if (spellId) ctx.gameHandler.cancelAura(spellId);
return {};
}
}
// Name match against player auras
std::string argLow = auraArg;
for (char& c : argLow) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
for (const auto& aura : ctx.gameHandler.getPlayerAuras()) {
if (aura.spellId == 0) continue;
std::string sn = ctx.gameHandler.getSpellName(aura.spellId);
for (char& c : sn) c = static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
if (sn == argLow) {
ctx.gameHandler.cancelAura(aura.spellId);
break;
}
}
return {};
}
std::vector<std::string> aliases() const override { return {"cancelaura"}; }
std::string helpText() const override { return "Cancel a specific aura/buff"; }
};
// --- Pet commands ---
class PetAttackCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
uint64_t target = ctx.gameHandler.hasTarget() ? ctx.gameHandler.getTargetGuid() : 0;
ctx.gameHandler.sendPetAction(5, target);
return {};
}
std::vector<std::string> aliases() const override { return {"petattack"}; }
std::string helpText() const override { return "Pet: attack target"; }
};
class PetFollowCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.sendPetAction(2, 0);
return {};
}
std::vector<std::string> aliases() const override { return {"petfollow"}; }
std::string helpText() const override { return "Pet: follow owner"; }
};
class PetStayCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.sendPetAction(3, 0);
return {};
}
std::vector<std::string> aliases() const override { return {"petstay", "pethalt"}; }
std::string helpText() const override { return "Pet: stay"; }
};
class PetPassiveCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.sendPetAction(1, 0);
return {};
}
std::vector<std::string> aliases() const override { return {"petpassive"}; }
std::string helpText() const override { return "Pet: passive mode"; }
};
class PetDefensiveCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.sendPetAction(4, 0);
return {};
}
std::vector<std::string> aliases() const override { return {"petdefensive"}; }
std::string helpText() const override { return "Pet: defensive mode"; }
};
class PetAggressiveCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.sendPetAction(6, 0);
return {};
}
std::vector<std::string> aliases() const override { return {"petaggressive"}; }
std::string helpText() const override { return "Pet: aggressive mode"; }
};
class PetDismissCommand : public IChatCommand {
public:
ChatCommandResult execute(ChatCommandContext& ctx) override {
ctx.gameHandler.dismissPet();
return {};
}
std::vector<std::string> aliases() const override { return {"petdismiss"}; }
std::string helpText() const override { return "Dismiss pet"; }
};
// --- Registration ---
void registerEmoteCommands(ChatCommandRegistry& reg) {
reg.registerCommand(std::make_unique<SitCommand>());
reg.registerCommand(std::make_unique<StandCommand>());
reg.registerCommand(std::make_unique<KneelCommand>());
reg.registerCommand(std::make_unique<LogoutEmoteCommand>());
reg.registerCommand(std::make_unique<CancelLogoutCommand>());
reg.registerCommand(std::make_unique<DismountCommand>());
reg.registerCommand(std::make_unique<CancelFormCommand>());
reg.registerCommand(std::make_unique<CancelAuraCommand>());
reg.registerCommand(std::make_unique<PetAttackCommand>());
reg.registerCommand(std::make_unique<PetFollowCommand>());
reg.registerCommand(std::make_unique<PetStayCommand>());
reg.registerCommand(std::make_unique<PetPassiveCommand>());
reg.registerCommand(std::make_unique<PetDefensiveCommand>());
reg.registerCommand(std::make_unique<PetAggressiveCommand>());
reg.registerCommand(std::make_unique<PetDismissCommand>());
}
} // namespace ui
} // namespace wowee