mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-28 16:16:27 +00:00
feat(Core/Chat): Provide a fully-formed protocol for addons to intera… (#19305)
* feat(Core/Chat): Provide a fully-formed protocol for addons to interact with GM commands
* Send success/fail state, allow interleaving, and indicate end of output. Add framework for supporting non-human-readable output in commands.
* cherry-pick commit (508c9d2fc1)
This PR implements a well-formed protocol for addons to communicate with the server, outlined below:
- All communication happens over the addon channel (`LANG_ADDON` in terms of the core, `CHAT_MSG_ADDON`/`SendAddonMessage` for the client). The prefix used for all messages is `AzerothCore` (in client terms - in core terms, every message starts with `AzerothCore\t`).
- In each message, the first character is the opcode. The following four characters are a unique identifier for the invocation in question, and will be echoed back by the server in every message related to that invocation. Following is the message body, if any.
- The following opcodes are supported:
- Client to server:
- `p` - Ping request. The core will always respond by ACKing with the passed identifier. No body.
- `i` or `h` - Command invocation. The message body is the command text without prefix. `i` requests machine-readable output, `h` requests human-readable.
- Server to client:
- `a` - ACK. The first message sent in response to any invocation (before any output). No body.
- `m` - Message. Sent once per line of output the server generates. Body = output line.
- `o` - OK. Indicates that the command finished processing with no errors. No body.
- `f` - Failed. Indicates that command processing is done, but there was an error. No body.
Expected overhead is minimal, and this integrates seamlessly with existing command scripts (no changes necessary).
PS: There's also a client-side addon library that exposes this protocol in a developer-friendly way over at https://github.com/azerothcore/LibAzerothCore-1.0
---------
Co-authored-by: Treeston <14020072+Treeston@users.noreply.github.com>
This commit is contained in:
@@ -283,14 +283,22 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
|
||||
if (msg.empty())
|
||||
return;
|
||||
|
||||
if (ChatHandler(this).ParseCommands(msg.c_str()))
|
||||
return;
|
||||
|
||||
if (!_player->CanSpeak())
|
||||
if (lang == LANG_ADDON)
|
||||
{
|
||||
std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime().count());
|
||||
SendNotification(GetAcoreString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str());
|
||||
return;
|
||||
if (AddonChannelCommandHandler(this).ParseCommands(msg.c_str()))
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ChatHandler(this).ParseCommands(msg.c_str()))
|
||||
return;
|
||||
|
||||
if (!_player->CanSpeak())
|
||||
{
|
||||
std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime().count());
|
||||
SendNotification(GetAcoreString(LANG_WAIT_BEFORE_SPEAKING), timeStr.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user