AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
AddonChannelCommandHandler Class Reference

#include "Chat.h"

Inheritance diagram for AddonChannelCommandHandler:
ChatHandler

Public Member Functions

bool ParseCommands (std::string_view str) override
 
void SendSysMessage (std::string_view str, bool escapeCharacters) override
 
bool IsHumanReadable () const override
 
 ChatHandler (WorldSession *session)
 
 ChatHandler ()
 
virtual void SendSysMessage (std::string_view str, bool escapeCharacters=false)
 
void SendSysMessage (uint32 entry)
 
- Public Member Functions inherited from ChatHandler
 ChatHandler (WorldSession *session)
 
virtual ~ChatHandler ()
 
void SendNotification (std::string_view str)
 
template<typename... Args>
void SendNotification (uint32 strId, Args &&... args)
 
template<typename... Args>
void SendNotification (char const *fmt, Args &&... args)
 
void SendGMText (std::string_view str)
 
template<typename... Args>
void SendGMText (uint32 strId, Args &&... args)
 
template<typename... Args>
void SendGMText (char const *fmt, Args &&... args)
 
void SendWorldText (std::string_view str)
 
template<typename... Args>
void SendWorldText (uint32 strId, Args &&... args)
 
template<typename... Args>
void SendWorldText (char const *fmt, Args &&... args)
 
void SendWorldTextOptional (std::string_view str, uint32 flag)
 
template<typename... Args>
void SendWorldTextOptional (uint32 strId, uint32 flag, Args &&... args)
 
template<typename... Args>
void SendWorldTextOptional (char const *fmt, uint32 flag, Args &&... args)
 
virtual char const * GetAcoreString (uint32 entry) const
 
virtual void SendSysMessage (std::string_view str, bool escapeCharacters=false)
 
void SendSysMessage (uint32 entry)
 
void PSendSysMessage (std::string_view str, bool escapeCharacters=false)
 
template<typename... Args>
void PSendSysMessage (char const *fmt, Args &&... args)
 
template<typename... Args>
void PSendSysMessage (uint32 entry, Args &&... args)
 
template<typename... Args>
std::string PGetParseString (uint32 entry, Args &&... args) const
 
std::string const * GetModuleString (std::string module, uint32 id) const
 
template<typename... Args>
void PSendModuleSysMessage (std::string module, uint32 id, Args &&... args)
 
template<typename... Args>
std::string PGetParseModuleString (std::string module, uint32 id, Args &&... args) const
 
void SendErrorMessage (uint32 entry)
 
void SendErrorMessage (std::string_view str, bool escapeCharacters)
 
template<typename... Args>
void SendErrorMessage (char const *fmt, Args &&... args)
 
template<typename... Args>
void SendErrorMessage (uint32 entry, Args &&... args)
 
bool _ParseCommands (std::string_view text)
 
virtual bool ParseCommands (std::string_view text)
 
void SendGlobalSysMessage (const char *str)
 
virtual bool IsHumanReadable () const
 
virtual std::string GetNameLink () const
 
virtual bool needReportToTarget (Player *chr) const
 
virtual LocaleConstant GetSessionDbcLocale () const
 
virtual int GetSessionDbLocaleIndex () const
 
bool HasLowerSecurity (Player *target, ObjectGuid guid=ObjectGuid::Empty, bool strong=false)
 
bool HasLowerSecurityAccount (WorldSession *target, uint32 account, bool strong=false)
 
void SendGlobalGMSysMessage (const char *str)
 
PlayergetSelectedPlayer () const
 
CreaturegetSelectedCreature () const
 
UnitgetSelectedUnit () const
 
WorldObjectgetSelectedObject () const
 
PlayergetSelectedPlayerOrSelf () const
 
virtual bool HasSession () const
 
void DoForAllValidSessions (std::function< void(Player *)> exec)
 
char * extractKeyFromLink (char *text, char const *linkType, char **something1=nullptr)
 
char * extractKeyFromLink (char *text, char const *const *linkTypes, int *found_idx, char **something1=nullptr)
 
char * extractQuotedArg (char *args)
 
uint32 extractSpellIdFromLink (char *text)
 
ObjectGuid::LowType extractLowGuidFromLink (char *text, HighGuid &guidHigh)
 
bool GetPlayerGroupAndGUIDByName (const char *cname, Player *&player, Group *&group, ObjectGuid &guid, bool offline=false)
 
std::string extractPlayerNameFromLink (char *text)
 
bool extractPlayerTarget (char *args, Player **player, ObjectGuid *player_guid=nullptr, std::string *player_name=nullptr)
 
std::string playerLink (std::string const &name) const
 
std::string GetNameLink (Player *chr) const
 
GameObjectGetNearbyGameObject () const
 
GameObjectGetObjectFromPlayerMapByDbGuid (ObjectGuid::LowType lowguid)
 
CreatureGetCreatureFromPlayerMapByDbGuid (ObjectGuid::LowType lowguid)
 
bool HasSentErrorMessage () const
 
void SetSentErrorMessage (bool val)
 
bool IsConsole () const
 
PlayerGetPlayer () const
 
WorldSessionGetSession ()
 
bool IsAvailable (uint32 securityLevel) const
 

Private Member Functions

void Send (std::string const &msg)
 
void SendAck ()
 
void SendOK ()
 
void SendFailed ()
 

Private Attributes

std::string echo
 
bool hadAck = false
 
bool humanReadable = false
 

Additional Inherited Members

- Static Public Member Functions inherited from ChatHandler
static std::size_t BuildChatPacket (WorldPacket &data, ChatMsg chatType, Language language, ObjectGuid senderGUID, ObjectGuid receiverGUID, std::string_view message, uint8 chatTag, std::string const &senderName="", std::string const &receiverName="", uint32 achievementId=0, bool gmMessage=false, std::string const &channelName="")
 
static std::size_t BuildChatPacket (WorldPacket &data, ChatMsg chatType, Language language, WorldObject const *sender, WorldObject const *receiver, std::string_view message, uint32 achievementId=0, std::string const &channelName="", LocaleConstant locale=DEFAULT_LOCALE)
 
static char * LineFromMessage (char *&pos)
 
- Protected Member Functions inherited from ChatHandler
 ChatHandler ()
 

Detailed Description

Member Function Documentation

◆ ChatHandler() [1/2]

ChatHandler::ChatHandler ( )
inlineexplicit
247: m_session(nullptr), sentErrorMessage(false) {} // for CLI subclass
WorldSession * m_session
Definition: Chat.h:250
bool sentErrorMessage
Definition: Chat.h:253

◆ ChatHandler() [2/2]

ChatHandler::ChatHandler ( WorldSession session)
inlineexplicit
41: m_session(session), sentErrorMessage(false) {}

◆ IsHumanReadable()

bool AddonChannelCommandHandler::IsHumanReadable ( ) const
inlineoverridevirtual

Reimplemented from ChatHandler.

286{ return humanReadable; }
bool humanReadable
Definition: Chat.h:296

◆ ParseCommands()

bool AddonChannelCommandHandler::ParseCommands ( std::string_view  str)
overridevirtual

Reimplemented from ChatHandler.

981{
982 if (memcmp(str.data(), "AzerothCore\t", 12))
983 return false;
984 char opcode = str[12];
985 if (!opcode) // str[12] is opcode
986 return false;
987 if (!str[13] || !str[14] || !str[15] || !str[16]) // str[13] through str[16] is 4-character command counter
988 return false;
989 echo = str.substr(13);
990
991 switch (opcode)
992 {
993 case 'p': // p Ping
994 SendAck();
995 return true;
996 case 'h': // h Issue human-readable command
997 case 'i': // i Issue command
998 if (!str[17])
999 return false;
1000 humanReadable = (opcode == 'h');
1001 if (_ParseCommands(str.substr(17))) // actual command starts at str[17]
1002 {
1003 if (!hadAck)
1004 SendAck();
1005 if (HasSentErrorMessage())
1006 SendFailed();
1007 else
1008 SendOK();
1009 }
1010 else
1011 {
1013 SendFailed();
1014 }
1015 return true;
1016 default:
1017 return false;
1018 }
1019}
@ LANG_CMD_INVALID
Definition: Language.h:38
bool HasSentErrorMessage() const
Definition: Chat.h:239
bool _ParseCommands(std::string_view text)
Definition: Chat.cpp:230
void SendAck()
Definition: Chat.cpp:1028
void SendSysMessage(std::string_view str, bool escapeCharacters) override
Definition: Chat.cpp:1060
bool hadAck
Definition: Chat.h:295
void SendOK()
Definition: Chat.cpp:1039
std::string echo
Definition: Chat.h:294
void SendFailed()
Definition: Chat.cpp:1049

References ChatHandler::_ParseCommands(), echo, hadAck, ChatHandler::HasSentErrorMessage(), humanReadable, LANG_CMD_INVALID, SendAck(), SendFailed(), SendOK(), and SendSysMessage().

◆ Send()

void AddonChannelCommandHandler::Send ( std::string const &  msg)
private
1022{
1023 WorldPacket data;
1025 GetSession()->SendPacket(&data);
1026}
@ CHAT_MSG_WHISPER
Definition: SharedDefines.h:3159
@ LANG_ADDON
Definition: SharedDefines.h:753
static std::size_t BuildChatPacket(WorldPacket &data, ChatMsg chatType, Language language, ObjectGuid senderGUID, ObjectGuid receiverGUID, std::string_view message, uint8 chatTag, std::string const &senderName="", std::string const &receiverName="", uint32 achievementId=0, bool gmMessage=false, std::string const &channelName="")
Definition: Chat.cpp:267
WorldSession * GetSession()
Definition: Chat.h:244
Player * GetPlayer() const
Definition: Chat.cpp:38
Definition: WorldPacket.h:27
void SendPacket(WorldPacket const *packet)
Send a packet to the client.
Definition: WorldSession.cpp:214

References ChatHandler::BuildChatPacket(), CHAT_MSG_WHISPER, ChatHandler::GetPlayer(), ChatHandler::GetSession(), LANG_ADDON, and WorldSession::SendPacket().

Referenced by SendAck(), SendFailed(), SendOK(), and SendSysMessage().

◆ SendAck()

void AddonChannelCommandHandler::SendAck ( )
private
1029{
1030 ASSERT(echo.size());
1031 std::string ack = "AzerothCore\ta";
1032 ack.resize(18);
1033 memcpy(&ack[13], echo.data(), 4);
1034 ack[17] = '\0';
1035 Send(ack);
1036 hadAck = true;
1037}
#define ASSERT
Definition: Errors.h:68
void Send(std::string const &msg)
Definition: Chat.cpp:1021

References ASSERT, echo, hadAck, and Send().

Referenced by ParseCommands(), and SendSysMessage().

◆ SendFailed()

void AddonChannelCommandHandler::SendFailed ( )
private
1050{
1051 ASSERT(echo.size());
1052 std::string fail = "AzerothCore\tf";
1053 fail.resize(18);
1054 memcpy(&fail[13], echo.data(), 4);
1055 fail[17] = '\0';
1056 Send(fail);
1057}

References ASSERT, echo, and Send().

Referenced by ParseCommands().

◆ SendOK()

void AddonChannelCommandHandler::SendOK ( )
private
1040{
1041 ASSERT(echo.size());
1042 std::string ok = "AzerothCore\to";
1043 ok.resize(18);
1044 memcpy(&ok[13], echo.data(), 4);
1045 ok[17] = '\0';
1046 Send(ok);
1047}

References ASSERT, echo, and Send().

Referenced by ParseCommands().

◆ SendSysMessage() [1/3]

void AddonChannelCommandHandler::SendSysMessage ( std::string_view  str,
bool  escapeCharacters 
)
overridevirtual

Reimplemented from ChatHandler.

1061{
1062 ASSERT(echo.size());
1063 if (!hadAck)
1064 SendAck();
1065
1066 std::string msg = "AzerothCore\tm";
1067 msg.append(echo.data(), 4);
1068 std::string body(str);
1069 if (escapeCharacters)
1070 boost::replace_all(body, "|", "||");
1071 std::size_t pos, lastpos;
1072 for (lastpos = 0, pos = body.find('\n', lastpos); pos != std::string::npos; lastpos = pos + 1, pos = body.find('\n', lastpos))
1073 {
1074 std::string line(msg);
1075 line.append(body, lastpos, pos - lastpos);
1076 Send(line);
1077 }
1078 msg.append(body, lastpos, pos - lastpos);
1079 Send(msg);
1080}

References ASSERT, echo, hadAck, Send(), and SendAck().

Referenced by ParseCommands().

◆ SendSysMessage() [2/3]

void ChatHandler::SendSysMessage ( std::string_view  str,
bool  escapeCharacters = false 
)
virtual

Reimplemented from ChatHandler.

163{
164 std::string msg{ str };
165
166 // Replace every "|" with "||" in msg
167 if (escapeCharacters && msg.find('|') != std::string::npos)
168 {
169 std::vector<std::string_view> tokens = Acore::Tokenize(msg, '|', true);
170 std::ostringstream stream;
171
172 for (std::size_t i = 0; i < tokens.size() - 1; ++i)
173 stream << tokens[i] << "||";
174
175 stream << tokens[tokens.size() - 1];
176
177 msg = stream.str();
178 }
179
180 WorldPacket data;
181 for (std::string_view line : Acore::Tokenize(str, '\n', true))
182 {
183 BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
184 m_session->SendPacket(&data);
185 }
186}
@ CHAT_MSG_SYSTEM
Definition: SharedDefines.h:3152
@ LANG_UNIVERSAL
Definition: SharedDefines.h:735
std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition: Tokenize.cpp:20

◆ SendSysMessage() [3/3]

void ChatHandler::SendSysMessage ( uint32  entry)
209{
211}
virtual char const * GetAcoreString(uint32 entry) const
Definition: Chat.cpp:43

References ChatHandler::BuildChatPacket(), CHAT_MSG_SYSTEM, LANG_UNIVERSAL, ChatHandler::m_session, and WorldSession::SendPacket().

Member Data Documentation

◆ echo

std::string AddonChannelCommandHandler::echo
private

◆ hadAck

bool AddonChannelCommandHandler::hadAck = false
private

◆ humanReadable

bool AddonChannelCommandHandler::humanReadable = false
private

Referenced by ParseCommands().