TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ChatHandler Class Reference

#include <Chat.h>

Public Member Functions

WorldSessionGetSession ()
 
 ChatHandler (WorldSession *session)
 
virtual ~ChatHandler ()
 
virtual char constGetTrinityString (uint32 entry) const
 
virtual void SendSysMessage (char const *str, bool escapeCharacters=false)
 
void SendSysMessage (uint32 entry)
 
template<typename... Args>
void PSendSysMessage (const char *fmt, Args &&...args)
 
template<typename... Args>
void PSendSysMessage (uint32 entry, Args &&...args)
 
template<typename... Args>
std::string PGetParseString (uint32 entry, Args &&...args) const
 
bool ParseCommands (const char *text)
 
bool isValidChatMessage (const char *msg)
 
void SendGlobalSysMessage (const char *str)
 
bool hasStringAbbr (const char *name, const char *part)
 
virtual bool isAvailable (ChatCommand const &cmd) const
 
virtual bool HasPermission (uint32 permission) 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, bool strong=false)
 
bool HasLowerSecurityAccount (WorldSession *target, uint32 account, bool strong=false)
 
void SendGlobalGMSysMessage (const char *str)
 
PlayergetSelectedPlayer ()
 
CreaturegetSelectedCreature ()
 
UnitgetSelectedUnit ()
 
WorldObjectgetSelectedObject ()
 
PlayergetSelectedPlayerOrSelf ()
 
char * extractKeyFromLink (char *text, char const *linkType, char **something1=NULL)
 
char * extractKeyFromLink (char *text, char const *const *linkTypes, int *found_idx, char **something1=NULL)
 
void extractOptFirstArg (char *args, char **arg1, char **arg2)
 
char * extractQuotedArg (char *args)
 
uint32 extractSpellIdFromLink (char *text)
 
ObjectGuid extractGuidFromLink (char *text)
 
GameTele constextractGameTeleFromLink (char *text)
 
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=NULL, std::string *player_name=NULL)
 
std::string playerLink (std::string const &name) const
 
std::string GetNameLink (Player *chr) const
 
GameObjectGetNearbyGameObject ()
 
GameObjectGetObjectGlobalyWithGuidOrNearWithDbGuid (ObjectGuid::LowType lowguid, uint32 entry)
 
bool HasSentErrorMessage () const
 
void SetSentErrorMessage (bool val)
 
bool ShowHelpForCommand (std::vector< ChatCommand > const &table, const char *cmd)
 

Static Public Member Functions

static char * LineFromMessage (char *&pos)
 
static std::vector
< ChatCommand > const
getCommandTable ()
 
static bool LoadCommandTable ()
 
static void SetLoadCommandTable (bool val)
 

Protected Member Functions

 ChatHandler ()
 
bool ExecuteCommandInTable (std::vector< ChatCommand > const &table, const char *text, std::string const &fullcmd)
 
bool ShowHelpForSubCommands (std::vector< ChatCommand > const &table, char const *cmd, char const *subcmd)
 

Static Protected Member Functions

static bool SetDataForCommandInTable (std::vector< ChatCommand > &table, const char *text, uint32 permission, std::string const &help, std::string const &fullcommand)
 

Private Attributes

WorldSessionm_session
 
bool sentErrorMessage
 

Static Private Attributes

static bool load_command_table = true
 

Constructor & Destructor Documentation

ChatHandler::ChatHandler ( WorldSession session)
inlineexplicit
60 : m_session(session), sentErrorMessage(false) { }
WorldSession * m_session
Definition: Chat.h:150
bool sentErrorMessage
Definition: Chat.h:154
virtual ChatHandler::~ChatHandler ( )
inlinevirtual
61 { }
ChatHandler::ChatHandler ( )
inlineexplicitprotected
144 : m_session(NULL), sentErrorMessage(false) { } // for CLI subclass
arena_t NULL
Definition: jemalloc_internal.h:624
WorldSession * m_session
Definition: Chat.h:150
bool sentErrorMessage
Definition: Chat.h:154

Member Function Documentation

bool ChatHandler::ExecuteCommandInTable ( std::vector< ChatCommand > const table,
const char *  text,
std::string const fullcmd 
)
protected
231 {
232  char const* oldtext = text;
233  std::string cmd = "";
234 
235  while (*text != ' ' && *text != '\0')
236  {
237  cmd += *text;
238  ++text;
239  }
240 
241  while (*text == ' ') ++text;
242 
243  for (uint32 i = 0; i < table.size(); ++i)
244  {
245  if (!hasStringAbbr(table[i].Name, cmd.c_str()))
246  continue;
247 
248  bool match = false;
249  if (strlen(table[i].Name) > cmd.length())
250  {
251  for (uint32 j = 0; j < table.size(); ++j)
252  {
253  if (!hasStringAbbr(table[j].Name, cmd.c_str()))
254  continue;
255 
256  if (strcmp(table[j].Name, cmd.c_str()) == 0)
257  {
258  match = true;
259  break;
260  }
261  }
262  }
263  if (match)
264  continue;
265 
266  // select subcommand from child commands list
267  if (!table[i].ChildCommands.empty())
268  {
269  if (!ExecuteCommandInTable(table[i].ChildCommands, text, fullcmd))
270  {
271  if (text[0] != '\0')
273  else
275 
276  ShowHelpForCommand(table[i].ChildCommands, text);
277  }
278 
279  return true;
280  }
281 
282  // must be available and have handler
283  if (!table[i].Handler || !isAvailable(table[i]))
284  continue;
285 
286  SetSentErrorMessage(false);
287  // table[i].Name == "" is special case: send original command to handler
288  if ((table[i].Handler)(this, table[i].Name[0] != '\0' ? text : oldtext))
289  {
290  if (!m_session) // ignore console
291  return true;
292 
293  Player* player = m_session->GetPlayer();
295  {
296  ObjectGuid guid = player->GetTarget();
297  uint32 areaId = player->GetAreaId();
298  std::string areaName = "Unknown";
299  std::string zoneName = "Unknown";
300  if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(areaId))
301  {
302  areaName = area->AreaName_lang;
303  if (AreaTableEntry const* zone = sAreaTableStore.LookupEntry(area->ParentAreaID))
304  zoneName = zone->AreaName_lang;
305  }
306 
307  sLog->outCommand(m_session->GetAccountId(), "Command: %s [Player: %s (%s) (Account: %u) X: %f Y: %f Z: %f Map: %u (%s) Area: %u (%s) Zone: %s Selected: %s (%s)]",
308  fullcmd.c_str(), player->GetName().c_str(), player->GetGUID().ToString().c_str(),
309  m_session->GetAccountId(), player->GetPositionX(), player->GetPositionY(),
310  player->GetPositionZ(), player->GetMapId(),
311  player->FindMap() ? player->FindMap()->GetMapName() : "Unknown",
312  areaId, areaName.c_str(), zoneName.c_str(),
313  (player->GetSelectedUnit()) ? player->GetSelectedUnit()->GetName().c_str() : "",
314  guid.ToString().c_str());
315  }
316  }
317  // some commands have custom error messages. Don't send the default one in these cases.
318  else if (!HasSentErrorMessage())
319  {
320  if (!table[i].Help.empty())
321  SendSysMessage(table[i].Help.c_str());
322  else
324  }
325 
326  return true;
327  }
328 
329  return false;
330 }
Definition: DBCStructure.h:37
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
bool hasStringAbbr(const char *name, const char *part)
Definition: Chat.cpp:127
bool ShowHelpForCommand(std::vector< ChatCommand > const &table, const char *cmd)
Definition: Chat.cpp:522
virtual bool isAvailable(ChatCommand const &cmd) const
Definition: Chat.cpp:72
AccountTypes GetSecurity() const
Definition: WorldSession.h:921
Definition: Language.h:43
#define sLog
Definition: Log.h:154
uint32 GetAccountId() const
Definition: WorldSession.h:922
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
Definition: Language.h:40
DBCStorage< AreaTableEntry > sAreaTableStore(AreaTablefmt)
uint32_t uint32
Definition: Define.h:150
static bool IsPlayerAccount(uint32 gmlevel)
Definition: AccountMgr.cpp:390
bool ExecuteCommandInTable(std::vector< ChatCommand > const &table, const char *text, std::string const &fullcmd)
Definition: Chat.cpp:230
bool HasSentErrorMessage() const
Definition: Chat.h:137
Definition: ObjectGuid.h:189
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
std::string ToString() const
Definition: ObjectGuid.cpp:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GameTele const * ChatHandler::extractGameTeleFromLink ( char *  text)
854 {
855  // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
856  char* cId = extractKeyFromLink(text, "Htele");
857  if (!cId)
858  return NULL;
859 
860  // id case (explicit or from shift link)
861  if (cId[0] >= '0' || cId[0] >= '9')
862  if (uint32 id = atoi(cId))
863  return sObjectMgr->GetGameTele(id);
864 
865  return sObjectMgr->GetGameTele(cId);
866 }
arena_t NULL
Definition: jemalloc_internal.h:624
#define sObjectMgr
Definition: ObjectMgr.h:1567
uint32_t uint32
Definition: Define.h:150
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ObjectGuid ChatHandler::extractGuidFromLink ( char *  text)
884 {
885  int type = 0;
886 
887  // |color|Hcreature:creature_guid|h[name]|h|r
888  // |color|Hgameobject:go_guid|h[name]|h|r
889  // |color|Hplayer:name|h[name]|h|r
890  char* idS = extractKeyFromLink(text, guidKeys, &type);
891  if (!idS)
892  return ObjectGuid::Empty;
893 
894  switch (type)
895  {
896  case SPELL_LINK_PLAYER:
897  {
898  std::string name = idS;
899  if (!normalizePlayerName(name))
900  return ObjectGuid::Empty;
901 
902  if (Player* player = ObjectAccessor::FindPlayerByName(name))
903  return player->GetGUID();
904 
905  return ObjectMgr::GetPlayerGUIDByName(name);
906  }
907  case SPELL_LINK_CREATURE:
908  {
909  ObjectGuid::LowType lowguid = strtoull(idS, nullptr, 10);
910 
911  if (CreatureData const* data = sObjectMgr->GetCreatureData(lowguid))
912  return ObjectGuid::Create<HighGuid::Creature>(data->mapid, data->id, lowguid);
913  else
914  return ObjectGuid::Empty;
915  }
917  {
918  ObjectGuid::LowType lowguid = strtoull(idS, nullptr, 10);
919 
920  if (GameObjectData const* data = sObjectMgr->GetGOData(lowguid))
921  return ObjectGuid::Create<HighGuid::GameObject>(data->mapid, data->id, lowguid);
922  else
923  return ObjectGuid::Empty;
924  }
925  }
926 
927  // unknown type?
928  return ObjectGuid::Empty;
929 }
Definition: Creature.h:287
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: Chat.cpp:872
Definition: Chat.cpp:871
uint64 LowType
Definition: ObjectGuid.h:199
#define sObjectMgr
Definition: ObjectMgr.h:1567
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
static ObjectGuid GetPlayerGUIDByName(std::string const &name)
Definition: ObjectMgr.cpp:2247
TC_GAME_API Player * FindPlayerByName(std::string const &name)
Definition: ObjectAccessor.cpp:220
Definition: Chat.cpp:870
Definition: GameObject.h:833
static char const *const guidKeys[]
Definition: Chat.cpp:875
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char * ChatHandler::extractKeyFromLink ( char *  text,
char const linkType,
char **  something1 = NULL 
)
642 {
643  // skip empty
644  if (!text)
645  return NULL;
646 
647  // skip spaces
648  while (*text == ' '||*text == '\t'||*text == '\b')
649  ++text;
650 
651  if (!*text)
652  return NULL;
653 
654  // return non link case
655  if (text[0] != '|')
656  return strtok(text, " ");
657 
658  // [name] Shift-click form |color|linkType:key|h[name]|h|r
659  // or
660  // [name] Shift-click form |color|linkType:key:something1:...:somethingN|h[name]|h|r
661 
662  char* check = strtok(text, "|"); // skip color
663  if (!check)
664  return NULL; // end of data
665 
666  char* cLinkType = strtok(NULL, ":"); // linktype
667  if (!cLinkType)
668  return NULL; // end of data
669 
670  if (strcmp(cLinkType, linkType) != 0)
671  {
672  strtok(NULL, " "); // skip link tail (to allow continue strtok(NULL, s) use after retturn from function
674  return NULL;
675  }
676 
677  char* cKeys = strtok(NULL, "|"); // extract keys and values
678  char* cKeysTail = strtok(NULL, "");
679 
680  char* cKey = strtok(cKeys, ":|"); // extract key
681  if (something1)
682  *something1 = strtok(NULL, ":|"); // extract something
683 
684  strtok(cKeysTail, "]"); // restart scan tail and skip name with possible spaces
685  strtok(NULL, " "); // skip link tail (to allow continue strtok(NULL, s) use after return from function
686  return cKey;
687 }
arena_t NULL
Definition: jemalloc_internal.h:624
T check(T value)
Definition: format.h:305
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:524

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char * ChatHandler::extractKeyFromLink ( char *  text,
char const *const linkTypes,
int *  found_idx,
char **  something1 = NULL 
)
690 {
691  // skip empty
692  if (!text)
693  return NULL;
694 
695  // skip spaces
696  while (*text == ' '||*text == '\t'||*text == '\b')
697  ++text;
698 
699  if (!*text)
700  return NULL;
701 
702  // return non link case
703  if (text[0] != '|')
704  return strtok(text, " ");
705 
706  // [name] Shift-click form |color|linkType:key|h[name]|h|r
707  // or
708  // [name] Shift-click form |color|linkType:key:something1:...:somethingN|h[name]|h|r
709  // or
710  // [name] Shift-click form |linkType:key|h[name]|h|r
711 
712  char* tail;
713 
714  if (text[1] == 'c')
715  {
716  char* check = strtok(text, "|"); // skip color
717  if (!check)
718  return NULL; // end of data
719 
720  tail = strtok(NULL, ""); // tail
721  }
722  else
723  tail = text+1; // skip first |
724 
725  char* cLinkType = strtok(tail, ":"); // linktype
726  if (!cLinkType)
727  return NULL; // end of data
728 
729  for (int i = 0; linkTypes[i]; ++i)
730  {
731  if (strcmp(cLinkType, linkTypes[i]) == 0)
732  {
733  char* cKeys = strtok(NULL, "|"); // extract keys and values
734  char* cKeysTail = strtok(NULL, "");
735 
736  char* cKey = strtok(cKeys, ":|"); // extract key
737  if (something1)
738  *something1 = strtok(NULL, ":|"); // extract something
739 
740  strtok(cKeysTail, "]"); // restart scan tail and skip name with possible spaces
741  strtok(NULL, " "); // skip link tail (to allow continue strtok(NULL, s) use after return from function
742  if (found_idx)
743  *found_idx = i;
744  return cKey;
745  }
746  }
747 
748  strtok(NULL, " "); // skip link tail (to allow continue strtok(NULL, s) use after return from function
750  return NULL;
751 }
arena_t NULL
Definition: jemalloc_internal.h:624
T check(T value)
Definition: format.h:305
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:524

+ Here is the call graph for this function:

void ChatHandler::extractOptFirstArg ( char *  args,
char **  arg1,
char **  arg2 
)
999 {
1000  char* p1 = strtok(args, " ");
1001  char* p2 = strtok(NULL, " ");
1002 
1003  if (!p2)
1004  {
1005  p2 = p1;
1006  p1 = NULL;
1007  }
1008 
1009  if (arg1)
1010  *arg1 = p1;
1011 
1012  if (arg2)
1013  *arg2 = p2;
1014 }
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the caller graph for this function:

std::string ChatHandler::extractPlayerNameFromLink ( char *  text)
932 {
933  // |color|Hplayer:name|h[name]|h|r
934  char* name_str = extractKeyFromLink(text, "Hplayer");
935  if (!name_str)
936  return "";
937 
938  std::string name = name_str;
939  if (!normalizePlayerName(name))
940  return "";
941 
942  return name;
943 }
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChatHandler::extractPlayerTarget ( char *  args,
Player **  player,
ObjectGuid player_guid = NULL,
std::string *  player_name = NULL 
)
946 {
947  if (args && *args)
948  {
949  std::string name = extractPlayerNameFromLink(args);
950  if (name.empty())
951  {
953  SetSentErrorMessage(true);
954  return false;
955  }
956 
958 
959  // if allowed player pointer
960  if (player)
961  *player = pl;
962 
963  // if need guid value from DB (in name case for check player existence)
964  ObjectGuid guid = !pl && (player_guid || player_name) ? ObjectMgr::GetPlayerGUIDByName(name) : ObjectGuid::Empty;
965 
966  // if allowed player guid (if no then only online players allowed)
967  if (player_guid)
968  *player_guid = pl ? pl->GetGUID() : guid;
969 
970  if (player_name)
971  *player_name = pl || !guid.IsEmpty() ? name : "";
972  }
973  else
974  {
976  // if allowed player pointer
977  if (player)
978  *player = pl;
979  // if allowed player guid (if no then only online players allowed)
980  if (player_guid)
981  *player_guid = pl ? pl->GetGUID() : ObjectGuid::Empty;
982 
983  if (player_name)
984  *player_name = pl ? pl->GetName() : "";
985  }
986 
987  // some from req. data must be provided (note: name is empty if player not exist)
988  if ((!player || !*player) && (!player_guid || !*player_guid) && (!player_name || player_name->empty()))
989  {
991  SetSentErrorMessage(true);
992  return false;
993  }
994 
995  return true;
996 }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Player * getSelectedPlayerOrSelf()
Definition: Chat.cpp:623
std::string extractPlayerNameFromLink(char *text)
Definition: Chat.cpp:931
static ObjectGuid GetPlayerGUIDByName(std::string const &name)
Definition: ObjectMgr.cpp:2247
TC_GAME_API Player * FindPlayerByName(std::string const &name)
Definition: ObjectAccessor.cpp:220
Definition: ObjectGuid.h:189
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:509
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char * ChatHandler::extractQuotedArg ( char *  args)
1017 {
1018  if (!args || !*args)
1019  return NULL;
1020 
1021  if (*args == '"')
1022  return strtok(args+1, "\"");
1023  else
1024  {
1025  // skip spaces
1026  while (*args == ' ')
1027  {
1028  args += 1;
1029  continue;
1030  }
1031 
1032  // return NULL if we reached the end of the string
1033  if (!*args)
1034  return NULL;
1035 
1036  // since we skipped all spaces, we expect another token now
1037  if (*args == '"')
1038  {
1039  // return an empty string if there are 2 "" in a row.
1040  // strtok doesn't handle this case
1041  if (*(args + 1) == '"')
1042  {
1043  strtok(args, " ");
1044  static char arg[1];
1045  arg[0] = '\0';
1046  return arg;
1047  }
1048  else
1049  return strtok(args + 1, "\"");
1050  }
1051  else
1052  return NULL;
1053  }
1054 }
arena_t NULL
Definition: jemalloc_internal.h:624
internal::NamedArg< char > arg(StringRef name, const T &arg)
Definition: format.h:3248

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 ChatHandler::extractSpellIdFromLink ( char *  text)
807 {
808  // number or [name] Shift-click form |color|Henchant:recipe_spell_id|h[prof_name: recipe_name]|h|r
809  // number or [name] Shift-click form |color|Hglyph:glyph_slot_id:glyph_prop_id|h[%s]|h|r
810  // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
811  // number or [name] Shift-click form |color|Htalent:talent_id, rank|h[name]|h|r
812  // number or [name] Shift-click form |color|Htrade:spell_id, skill_id, max_value, cur_value|h[name]|h|r
813  int type = 0;
814  char* param1_str = NULL;
815  char* idS = extractKeyFromLink(text, spellKeys, &type, &param1_str);
816  if (!idS)
817  return 0;
818 
819  uint32 id = atoul(idS);
820 
821  switch (type)
822  {
823  case SPELL_LINK_SPELL:
824  return id;
825  case SPELL_LINK_TALENT:
826  {
827  // talent
828  TalentEntry const* talentEntry = sTalentStore.LookupEntry(id);
829  if (!talentEntry)
830  return 0;
831 
832  return talentEntry->SpellID;
833  }
834  case SPELL_LINK_ENCHANT:
835  case SPELL_LINK_TRADE:
836  return id;
837  case SPELL_LINK_GLYPH:
838  {
839  uint32 glyph_prop_id = param1_str ? atoul(param1_str) : 0;
840 
841  GlyphPropertiesEntry const* glyphPropEntry = sGlyphPropertiesStore.LookupEntry(glyph_prop_id);
842  if (!glyphPropEntry)
843  return 0;
844 
845  return glyphPropEntry->SpellID;
846  }
847  }
848 
849  // unknown type?
850  return 0;
851 }
Definition: Chat.cpp:793
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Chat.cpp:790
unsigned long atoul(char const *str)
Definition: Common.h:90
uint32 SpellID
Definition: DBCStructure.h:512
uint32_t uint32
Definition: Define.h:150
DBCStorage< GlyphPropertiesEntry > sGlyphPropertiesStore(GlyphPropertiesfmt)
Definition: DBCStructure.h:509
DBCStorage< TalentEntry > sTalentStore(Talentfmt)
Definition: Chat.cpp:791
Definition: Chat.cpp:789
Definition: DBCStructure.h:1255
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:641
static char const *const spellKeys[]
Definition: Chat.cpp:796
Definition: Chat.cpp:792
uint32 SpellID
Definition: DBCStructure.h:1261

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector< ChatCommand > const & ChatHandler::getCommandTable ( )
static
39 {
40  static std::vector<ChatCommand> commandTableCache;
41 
42  if (LoadCommandTable())
43  {
44  SetLoadCommandTable(false);
45 
46  std::vector<ChatCommand> cmds = sScriptMgr->GetChatCommands();
47  commandTableCache.swap(cmds);
48 
51  if (result)
52  {
53  do
54  {
55  Field* fields = result->Fetch();
56  std::string name = fields[0].GetString();
57 
58  SetDataForCommandInTable(commandTableCache, name.c_str(), fields[1].GetUInt16(), fields[2].GetString(), name);
59  }
60  while (result->NextRow());
61  }
62  }
63 
64  return commandTableCache;
65 }
static bool LoadCommandTable()
Definition: Chat.h:139
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Class used to access individual fields of database query result.
Definition: Field.h:56
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Definition: WorldDatabase.h:85
Definition: PreparedStatement.h:74
uint16 GetUInt16() const
Definition: Field.h:108
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
static void SetLoadCommandTable(bool val)
Definition: Chat.h:140
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
static bool SetDataForCommandInTable(std::vector< ChatCommand > &table, const char *text, uint32 permission, std::string const &help, std::string const &fullcommand)
Definition: Chat.cpp:332
#define sScriptMgr
Definition: ScriptMgr.h:837
std::string GetString() const
Definition: Field.h:276

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual std::string ChatHandler::GetNameLink ( ) const
inlinevirtual

Reimplemented in CliHandler.

101 { return GetNameLink(m_session->GetPlayer()); }
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
virtual std::string GetNameLink() const
Definition: Chat.h:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string ChatHandler::GetNameLink ( Player chr) const
1073 {
1074  return playerLink(chr->GetName());
1075 }
std::string playerLink(std::string const &name) const
Definition: Chat.h:132

+ Here is the call graph for this function:

GameObject * ChatHandler::GetNearbyGameObject ( )
754 {
755  if (!m_session)
756  return NULL;
757 
758  Player* pl = m_session->GetPlayer();
759  GameObject* obj = NULL;
762  pl->VisitNearbyGridObject(SIZE_OF_GRIDS, searcher);
763  return obj;
764 }
#define SIZE_OF_GRIDS
Definition: GridDefines.h:39
Definition: GridNotifiers.h:323
Definition: GridNotifiers.h:669
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
Definition: GameObject.h:880
T check(T value)
Definition: format.h:305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GameObject * ChatHandler::GetObjectGlobalyWithGuidOrNearWithDbGuid ( ObjectGuid::LowType  lowguid,
uint32  entry 
)
767 {
768  if (!m_session)
769  return NULL;
770 
771  Player* pl = m_session->GetPlayer();
772 
773  GameObject* obj = pl->GetMap()->GetGameObject(ObjectGuid::Create<HighGuid::GameObject>(pl->GetMapId(), entry, lowguid));
774 
775  if (!obj && sObjectMgr->GetGOData(lowguid)) // guid is DB guid of object
776  {
777  auto bounds = pl->GetMap()->GetGameObjectBySpawnIdStore().equal_range(lowguid);
778  if (bounds.first == bounds.second)
779  return nullptr;
780 
781  return bounds.first->second;
782  }
783 
784  return obj;
785 }
Map * GetMap() const
Definition: Object.h:543
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
#define sObjectMgr
Definition: ObjectMgr.h:1567
Definition: GameObject.h:880
GameObjectBySpawnIdContainer & GetGameObjectBySpawnIdStore()
Definition: Map.h:472
GameObject * GetGameObject(ObjectGuid const &guid)
Definition: Map.cpp:3545

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChatHandler::GetPlayerGroupAndGUIDByName ( const char *  cname,
Player *&  player,
Group *&  group,
ObjectGuid guid,
bool  offline = false 
)
1105 {
1106  player = NULL;
1107  guid.Clear();
1108 
1109  if (cname)
1110  {
1111  std::string name = cname;
1112  if (!name.empty())
1113  {
1114  if (!normalizePlayerName(name))
1115  {
1117  SetSentErrorMessage(true);
1118  return false;
1119  }
1120 
1121  player = ObjectAccessor::FindPlayerByName(name);
1122  if (offline)
1123  guid = ObjectMgr::GetPlayerGUIDByName(name.c_str());
1124  }
1125  }
1126 
1127  if (player)
1128  {
1129  group = player->GetGroup();
1130  if (!guid || !offline)
1131  guid = player->GetGUID();
1132  }
1133  else
1134  {
1135  if (getSelectedPlayer())
1136  player = getSelectedPlayer();
1137  else
1138  player = m_session->GetPlayer();
1139 
1140  if (!guid || !offline)
1141  guid = player->GetGUID();
1142  group = player->GetGroup();
1143  }
1144 
1145  return true;
1146 }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:133
static ObjectGuid GetPlayerGUIDByName(std::string const &name)
Definition: ObjectMgr.cpp:2247
TC_GAME_API Player * FindPlayerByName(std::string const &name)
Definition: ObjectAccessor.cpp:220
Player * getSelectedPlayer()
Definition: Chat.cpp:579
void Clear()
Definition: ObjectGuid.h:215
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:509

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Creature * ChatHandler::getSelectedCreature ( )
616 {
617  if (!m_session)
618  return NULL;
619 
621 }
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
TC_GAME_API Creature * GetCreatureOrPetOrVehicle(WorldObject const &, ObjectGuid const &)
Definition: ObjectAccessor.cpp:198

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

WorldObject * ChatHandler::getSelectedObject ( )
603 {
604  if (!m_session)
605  return NULL;
606 
607  ObjectGuid guid = m_session->GetPlayer()->GetTarget();
608 
609  if (!guid)
610  return GetNearbyGameObject();
611 
612  return ObjectAccessor::GetUnit(*m_session->GetPlayer(), guid);
613 }
TC_GAME_API Unit * GetUnit(WorldObject const &, ObjectGuid const &guid)
Definition: ObjectAccessor.cpp:163
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
Definition: ObjectGuid.h:189
GameObject * GetNearbyGameObject()
Definition: Chat.cpp:753

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Player * ChatHandler::getSelectedPlayer ( )
580 {
581  if (!m_session)
582  return NULL;
583 
584  ObjectGuid selected = m_session->GetPlayer()->GetTarget();
585  if (!selected)
586  return m_session->GetPlayer();
587 
588  return ObjectAccessor::FindConnectedPlayer(selected);
589 }
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
Definition: ObjectGuid.h:189
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Player * ChatHandler::getSelectedPlayerOrSelf ( )
624 {
625  if (!m_session)
626  return NULL;
627 
628  ObjectGuid selected = m_session->GetPlayer()->GetTarget();
629  if (!selected)
630  return m_session->GetPlayer();
631 
632  // first try with selected target
633  Player* targetPlayer = ObjectAccessor::FindConnectedPlayer(selected);
634  // if the target is not a player, then return self
635  if (!targetPlayer)
636  targetPlayer = m_session->GetPlayer();
637 
638  return targetPlayer;
639 }
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
Definition: ObjectGuid.h:189
TC_GAME_API Player * FindConnectedPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:215

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Unit * ChatHandler::getSelectedUnit ( )
592 {
593  if (!m_session)
594  return NULL;
595 
596  if (Unit* selected = m_session->GetPlayer()->GetSelectedUnit())
597  return selected;
598 
599  return m_session->GetPlayer();
600 }
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150
Definition: Unit.h:1305

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

WorldSession* ChatHandler::GetSession ( )
inline
59 { return m_session; }
WorldSession * m_session
Definition: Chat.h:150
LocaleConstant ChatHandler::GetSessionDbcLocale ( ) const
virtual

Reimplemented in CliHandler.

1063 {
1064  return m_session->GetSessionDbcLocale();
1065 }
LocaleConstant GetSessionDbcLocale() const
Definition: WorldSession.h:1059
WorldSession * m_session
Definition: Chat.h:150

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int ChatHandler::GetSessionDbLocaleIndex ( ) const
virtual

Reimplemented in CliHandler.

1068 {
1070 }
LocaleConstant GetSessionDbLocaleIndex() const
Definition: WorldSession.h:1060
WorldSession * m_session
Definition: Chat.h:150

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

char const * ChatHandler::GetTrinityString ( uint32  entry) const
virtual

Reimplemented in CliHandler.

68 {
69  return m_session->GetTrinityString(entry);
70 }
WorldSession * m_session
Definition: Chat.h:150
char const * GetTrinityString(uint32 entry) const
Definition: WorldSession.cpp:689

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChatHandler::HasLowerSecurity ( Player target,
ObjectGuid  guid,
bool  strong = false 
)
78 {
79  WorldSession* target_session = NULL;
80  uint32 target_account = 0;
81 
82  if (target)
83  target_session = target->GetSession();
84  else if (!guid.IsEmpty())
85  target_account = ObjectMgr::GetPlayerAccountIdByGUID(guid);
86 
87  if (!target_session && !target_account)
88  {
90  SetSentErrorMessage(true);
91  return true;
92  }
93 
94  return HasLowerSecurityAccount(target_session, target_account, strong);
95 }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
arena_t NULL
Definition: jemalloc_internal.h:624
uint32_t uint32
Definition: Define.h:150
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition: Chat.cpp:97
static uint32 GetPlayerAccountIdByGUID(ObjectGuid const &guid)
Definition: ObjectMgr.cpp:2302
Player session in the World.
Definition: WorldSession.h:882
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:509
bool IsEmpty() const
Definition: ObjectGuid.h:242

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChatHandler::HasLowerSecurityAccount ( WorldSession target,
uint32  account,
bool  strong = false 
)
98 {
99  uint32 target_sec;
100 
101  // allow everything from console and RA console
102  if (!m_session)
103  return false;
104 
105  // ignore only for non-players for non strong checks (when allow apply command at least to same sec level)
107  return false;
108 
109  if (target)
110  target_sec = target->GetSecurity();
111  else if (target_account)
112  target_sec = AccountMgr::GetSecurity(target_account, realm.Id.Realm);
113  else
114  return true; // caller must report error for (target == NULL && target_account == 0)
115 
116  AccountTypes target_ac_sec = AccountTypes(target_sec);
117  if (m_session->GetSecurity() < target_ac_sec || (strong && m_session->GetSecurity() <= target_ac_sec))
118  {
120  SetSentErrorMessage(true);
121  return true;
122  }
123 
124  return false;
125 }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
uint32 Realm
Definition: Realm.h:53
AccountTypes GetSecurity() const
Definition: WorldSession.h:921
Realm realm
Definition: World.cpp:3485
Definition: Language.h:399
#define sWorld
Definition: World.h:887
WorldSession * m_session
Definition: Chat.h:150
static uint32 GetSecurity(uint32 accountId)
Definition: AccountMgr.cpp:284
Battlenet::RealmHandle Id
Definition: Realm.h:86
uint32_t uint32
Definition: Define.h:150
AccountTypes
Definition: Common.h:106
Definition: World.h:118
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
bool HasPermission(uint32 permissionId)
Definition: WorldSession.cpp:1259

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual bool ChatHandler::HasPermission ( uint32  permission) const
inlinevirtual

Reimplemented in CliHandler.

100 { return m_session->HasPermission(permission); }
WorldSession * m_session
Definition: Chat.h:150
bool HasPermission(uint32 permissionId)
Definition: WorldSession.cpp:1259

+ Here is the caller graph for this function:

bool ChatHandler::HasSentErrorMessage ( ) const
inline
137 { return sentErrorMessage; }
bool sentErrorMessage
Definition: Chat.h:154

+ Here is the caller graph for this function:

bool ChatHandler::hasStringAbbr ( const char *  name,
const char *  part 
)
128 {
129  // non "" command
130  if (*name)
131  {
132  // "" part from non-"" command
133  if (!*part)
134  return false;
135 
136  while (true)
137  {
138  if (!*part)
139  return true;
140  else if (!*name)
141  return false;
142  else if (tolower(*name) != tolower(*part))
143  return false;
144  ++name; ++part;
145  }
146  }
147  // allow with any for ""
148 
149  return true;
150 }

+ Here is the caller graph for this function:

bool ChatHandler::isAvailable ( ChatCommand const cmd) const
virtual

Reimplemented in CliHandler.

73 {
74  return HasPermission(cmd.Permission);
75 }
virtual bool HasPermission(uint32 permission) const
Definition: Chat.h:100

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChatHandler::isValidChatMessage ( const char *  msg)
425 {
426 /*
427 Valid examples:
428 |cffa335ee|Hitem:812:0:0:0:0:0:0:0:70|h[Glowing Brightwood Staff]|h|r
429 |cff808080|Hquest:2278:47|h[The Platinum Discs]|h|r
430 |cffffd000|Htrade:4037:1:150:1:6AAAAAAAAAAAAAAAAAAAAAAOAADAAAAAAAAAAAAAAAAIAAAAAAAAA|h[Engineering]|h|r
431 |cff4e96f7|Htalent:2232:-1|h[Taste for Blood]|h|r
432 |cff71d5ff|Hspell:21563|h[Command]|h|r
433 |cffffd000|Henchant:3919|h[Engineering: Rough Dynamite]|h|r
434 |cffffff00|Hachievement:546:0000000000000001:0:0:0:-1:0:0:0:0|h[Safe Deposit]|h|r
435 |cff66bbff|Hglyph:21:762|h[Glyph of Bladestorm]|h|r
436 
437 | will be escaped to ||
438 */
439 
440  if (strlen(message) > 255)
441  return false;
442 
443  // more simple checks
444  if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY) < 3)
445  {
446  const char validSequence[6] = "cHhhr";
447  const char* validSequenceIterator = validSequence;
448  const std::string validCommands = "cHhr|";
449 
450  while (*message)
451  {
452  // find next pipe command
453  message = strchr(message, '|');
454 
455  if (!message)
456  return true;
457 
458  ++message;
459  char commandChar = *message;
460  if (validCommands.find(commandChar) == std::string::npos)
461  return false;
462 
463  ++message;
464  // validate sequence
465  if (sWorld->getIntConfig(CONFIG_CHAT_STRICT_LINK_CHECKING_SEVERITY) == 2)
466  {
467  if (commandChar == *validSequenceIterator)
468  {
469  if (validSequenceIterator == validSequence + 4)
470  validSequenceIterator = validSequence;
471  else
472  ++validSequenceIterator;
473  }
474  else
475  return false;
476  }
477  }
478  return true;
479  }
480 
481  return LinkExtractor(message).IsValidMessage();
482 }
#define sWorld
Definition: World.h:887
Definition: ChatLink.h:164
bool IsValidMessage()
Definition: ChatLink.cpp:591

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static char* ChatHandler::LineFromMessage ( char *&  pos)
inlinestatic
63 { char* start = strtok(pos, "\n"); pos = NULL; return start; }
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the caller graph for this function:

static bool ChatHandler::LoadCommandTable ( )
inlinestatic
139 { return load_command_table; }
static bool load_command_table
Definition: Chat.h:153

+ Here is the caller graph for this function:

bool ChatHandler::needReportToTarget ( Player chr) const
virtual

Reimplemented in CliHandler.

1057 {
1058  Player* pl = m_session->GetPlayer();
1059  return pl != chr && pl->IsVisibleGloballyFor(chr);
1060 }
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * m_session
Definition: Chat.h:150

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChatHandler::ParseCommands ( const char *  text)

chat case (.command or !command format)

ignore single . and ! in line

ignore messages staring from many dots.

skip first . or ! (in console allowed use command with . and ! and without its)

388 {
389  ASSERT(text);
390  ASSERT(*text);
391 
392  std::string fullcmd = text;
393 
395  if (m_session)
396  {
397  if (text[0] != '!' && text[0] != '.')
398  return false;
399  }
400 
402  if (strlen(text) < 2)
403  return false;
404  // original `text` can't be used. It content destroyed in command code processing.
405 
407  if ((text[0] == '.' && text[1] == '.') || (text[0] == '!' && text[1] == '!'))
408  return false;
409 
411  if (text[0] == '!' || text[0] == '.')
412  ++text;
413 
414  if (!ExecuteCommandInTable(getCommandTable(), text, fullcmd))
415  {
417  return false;
418 
420  }
421  return true;
422 }
static std::vector< ChatCommand > const & getCommandTable()
Definition: Chat.cpp:38
Definition: Language.h:39
WorldSession * m_session
Definition: Chat.h:150
bool ExecuteCommandInTable(std::vector< ChatCommand > const &table, const char *text, std::string const &fullcmd)
Definition: Chat.cpp:230
#define ASSERT
Definition: Errors.h:55
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
bool HasPermission(uint32 permissionId)
Definition: WorldSession.cpp:1259

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename... Args>
std::string ChatHandler::PGetParseString ( uint32  entry,
Args &&...  args 
) const
inline
85  {
86  return Trinity::StringFormat(GetTrinityString(entry), std::forward<Args>(args)...);
87  }
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:67

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string ChatHandler::playerLink ( std::string const name) const
inline
132 { return m_session ? "|cffffffff|Hplayer:"+name+"|h["+name+"]|h|r" : name; }
WorldSession * m_session
Definition: Chat.h:150

+ Here is the caller graph for this function:

template<typename... Args>
void ChatHandler::PSendSysMessage ( const char *  fmt,
Args &&...  args 
)
inline
73  {
74  SendSysMessage(Trinity::StringFormat(fmt, std::forward<Args>(args)...).c_str());
75  }
std::string StringFormat(Format &&fmt, Args &&...args)
Default TC string format function.
Definition: StringFormat.h:28
Definition: format.h:285
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152

+ Here is the call graph for this function:

template<typename... Args>
void ChatHandler::PSendSysMessage ( uint32  entry,
Args &&...  args 
)
inline
79  {
80  SendSysMessage(PGetParseString(entry, std::forward<Args>(args)...).c_str());
81  }
std::string PGetParseString(uint32 entry, Args &&...args) const
Definition: Chat.h:84
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
void ChatHandler::SendGlobalGMSysMessage ( const char *  str)
208 {
209  // Chat output
211 
212  // need copy to prevent corruption by strtok call in LineFromMessage original string
213  char* buf = strdup(str);
214  char* pos = buf;
215 
216  while (char* line = LineFromMessage(pos))
217  {
218  packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
219  sWorld->SendGlobalGMMessage(packet.Write());
220  }
221 
222  free(buf);
223 }
Definition: SharedDefines.h:961
static char * LineFromMessage(char *&pos)
Definition: Chat.h:63
Definition: ChatPackets.h:150
#define sWorld
Definition: World.h:887
WorldPacket const * Write() override
Definition: ChatPackets.cpp:162
void Initialize(ChatMsg chatType, Language language, WorldObject const *sender, WorldObject const *receiver, std::string message, uint32 achievementId=0, std::string channelName="", LocaleConstant locale=DEFAULT_LOCALE, std::string addonPrefix="")
Definition: ChatPackets.cpp:104
Definition: SharedDefines.h:4231

+ Here is the call graph for this function:

void ChatHandler::SendGlobalSysMessage ( const char *  str)
190 {
191  // Chat output
193 
194  // need copy to prevent corruption by strtok call in LineFromMessage original string
195  char* buf = strdup(str);
196  char* pos = buf;
197 
198  while (char* line = LineFromMessage(pos))
199  {
200  packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
201  sWorld->SendGlobalMessage(packet.Write());
202  }
203 
204  free(buf);
205 }
Definition: SharedDefines.h:961
static char * LineFromMessage(char *&pos)
Definition: Chat.h:63
Definition: ChatPackets.h:150
#define sWorld
Definition: World.h:887
WorldPacket const * Write() override
Definition: ChatPackets.cpp:162
void Initialize(ChatMsg chatType, Language language, WorldObject const *sender, WorldObject const *receiver, std::string message, uint32 achievementId=0, std::string channelName="", LocaleConstant locale=DEFAULT_LOCALE, std::string addonPrefix="")
Definition: ChatPackets.cpp:104
Definition: SharedDefines.h:4231

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ChatHandler::SendSysMessage ( char const str,
bool  escapeCharacters = false 
)
virtual

Reimplemented in CliHandler.

153 {
155 
156  // need copy to prevent corruption by strtok call in LineFromMessage original string
157  char* buf;
158  char* pos;
159 
160  if (escapeCharacters && strchr(str, '|'))
161  {
162  size_t startPos = 0;
163  std::ostringstream o;
164  while (const char* charPos = strchr(str + startPos, '|'))
165  {
166  o.write(str + startPos, charPos - str - startPos);
167  o << "||";
168  startPos = charPos - str + 1;
169  }
170  o.write(str + startPos, strlen(str) - startPos);
171  buf = strdup(o.str().c_str());
172  }
173  else
174  {
175  buf = strdup(str);
176  }
177 
178  pos = buf;
179 
180  while (char* line = LineFromMessage(pos))
181  {
182  packet.Initialize(CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
183  m_session->SendPacket(packet.Write());
184  }
185 
186  free(buf);
187 }
Definition: SharedDefines.h:961
static char * LineFromMessage(char *&pos)
Definition: Chat.h:63
Definition: ChatPackets.h:150
WorldSession * m_session
Definition: Chat.h:150
WorldPacket const * Write() override
Definition: ChatPackets.cpp:162
void Initialize(ChatMsg chatType, Language language, WorldObject const *sender, WorldObject const *receiver, std::string message, uint32 achievementId=0, std::string channelName="", LocaleConstant locale=DEFAULT_LOCALE, std::string addonPrefix="")
Definition: ChatPackets.cpp:104
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211
Definition: SharedDefines.h:4231

+ Here is the call graph for this function:

void ChatHandler::SendSysMessage ( uint32  entry)
226 {
228 }
virtual char const * GetTrinityString(uint32 entry) const
Definition: Chat.cpp:67
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152

+ Here is the call graph for this function:

bool ChatHandler::SetDataForCommandInTable ( std::vector< ChatCommand > &  table,
const char *  text,
uint32  permission,
std::string const help,
std::string const fullcommand 
)
staticprotected
333 {
334  std::string cmd = "";
335 
336  while (*text != ' ' && *text != '\0')
337  {
338  cmd += *text;
339  ++text;
340  }
341 
342  while (*text == ' ') ++text;
343 
344  for (uint32 i = 0; i < table.size(); i++)
345  {
346  // for data fill use full explicit command names
347  if (table[i].Name != cmd)
348  continue;
349 
350  // select subcommand from child commands list (including "")
351  if (!table[i].ChildCommands.empty())
352  {
353  if (SetDataForCommandInTable(table[i].ChildCommands, text, permission, help, fullcommand))
354  return true;
355  else if (*text)
356  return false;
357 
358  // fail with "" subcommands, then use normal level up command instead
359  }
360  // expected subcommand by full name DB content
361  else if (*text)
362  {
363  TC_LOG_ERROR("sql.sql", "Table `command` have unexpected subcommand '%s' in command '%s', skip.", text, fullcommand.c_str());
364  return false;
365  }
366 
367  if (table[i].Permission != permission)
368  TC_LOG_INFO("misc", "Table `command` overwrite for command '%s' default permission (%u) by %u", fullcommand.c_str(), table[i].Permission, permission);
369 
370  table[i].Permission = permission;
371  table[i].Help = help;
372  return true;
373  }
374 
375  // in case "" command let process by caller
376  if (!cmd.empty())
377  {
378  if (&table == &getCommandTable())
379  TC_LOG_ERROR("sql.sql", "Table `command` have not existed command '%s', skip.", cmd.c_str());
380  else
381  TC_LOG_ERROR("sql.sql", "Table `command` have not existed subcommand '%s' in command '%s', skip.", cmd.c_str(), fullcommand.c_str());
382  }
383 
384  return false;
385 }
static std::vector< ChatCommand > const & getCommandTable()
Definition: Chat.cpp:38
uint32_t uint32
Definition: Define.h:150
static bool SetDataForCommandInTable(std::vector< ChatCommand > &table, const char *text, uint32 permission, std::string const &help, std::string const &fullcommand)
Definition: Chat.cpp:332
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void ChatHandler::SetLoadCommandTable ( bool  val)
inlinestatic
140 { load_command_table = val; }
static bool load_command_table
Definition: Chat.h:153

+ Here is the caller graph for this function:

void ChatHandler::SetSentErrorMessage ( bool  val)
inline
138 { sentErrorMessage = val; }
bool sentErrorMessage
Definition: Chat.h:154
bool ChatHandler::ShowHelpForCommand ( std::vector< ChatCommand > const table,
const char *  cmd 
)
523 {
524  if (*cmd)
525  {
526  for (uint32 i = 0; i < table.size(); ++i)
527  {
528  // must be available (ignore handler existence for show command with possible available subcommands)
529  if (!isAvailable(table[i]))
530  continue;
531 
532  if (!hasStringAbbr(table[i].Name, cmd))
533  continue;
534 
535  // have subcommand
536  char const* subcmd = (*cmd) ? strtok(NULL, " ") : "";
537 
538  if (!table[i].ChildCommands.empty() && subcmd && *subcmd)
539  {
540  if (ShowHelpForCommand(table[i].ChildCommands, subcmd))
541  return true;
542  }
543 
544  if (!table[i].Help.empty())
545  SendSysMessage(table[i].Help.c_str());
546 
547  if (!table[i].ChildCommands.empty())
548  if (ShowHelpForSubCommands(table[i].ChildCommands, table[i].Name, subcmd ? subcmd : ""))
549  return true;
550 
551  return !table[i].Help.empty();
552  }
553  }
554  else
555  {
556  for (uint32 i = 0; i < table.size(); ++i)
557  {
558  // must be available (ignore handler existence for show command with possible available subcommands)
559  if (!isAvailable(table[i]))
560  continue;
561 
562  if (strlen(table[i].Name))
563  continue;
564 
565  if (!table[i].Help.empty())
566  SendSysMessage(table[i].Help.c_str());
567 
568  if (!table[i].ChildCommands.empty())
569  if (ShowHelpForSubCommands(table[i].ChildCommands, "", ""))
570  return true;
571 
572  return !table[i].Help.empty();
573  }
574  }
575 
576  return ShowHelpForSubCommands(table, "", cmd);
577 }
bool hasStringAbbr(const char *name, const char *part)
Definition: Chat.cpp:127
bool ShowHelpForCommand(std::vector< ChatCommand > const &table, const char *cmd)
Definition: Chat.cpp:522
virtual bool isAvailable(ChatCommand const &cmd) const
Definition: Chat.cpp:72
arena_t NULL
Definition: jemalloc_internal.h:624
bool ShowHelpForSubCommands(std::vector< ChatCommand > const &table, char const *cmd, char const *subcmd)
Definition: Chat.cpp:484
uint32_t uint32
Definition: Define.h:150
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ChatHandler::ShowHelpForSubCommands ( std::vector< ChatCommand > const table,
char const cmd,
char const subcmd 
)
protected
485 {
486  std::string list;
487  for (uint32 i = 0; i < table.size(); ++i)
488  {
489  // must be available (ignore handler existence for show command with possible available subcommands)
490  if (!isAvailable(table[i]))
491  continue;
492 
493  // for empty subcmd show all available
494  if (*subcmd && !hasStringAbbr(table[i].Name, subcmd))
495  continue;
496 
497  if (m_session)
498  list += "\n ";
499  else
500  list += "\n\r ";
501 
502  list += table[i].Name;
503 
504  if (!table[i].ChildCommands.empty())
505  list += " ...";
506  }
507 
508  if (list.empty())
509  return false;
510 
511  if (&table == &getCommandTable())
512  {
514  PSendSysMessage("%s", list.c_str());
515  }
516  else
517  PSendSysMessage(LANG_SUBCMDS_LIST, cmd, list.c_str());
518 
519  return true;
520 }
bool hasStringAbbr(const char *name, const char *part)
Definition: Chat.cpp:127
virtual bool isAvailable(ChatCommand const &cmd) const
Definition: Chat.cpp:72
Definition: Language.h:41
Definition: Language.h:42
static std::vector< ChatCommand > const & getCommandTable()
Definition: Chat.cpp:38
WorldSession * m_session
Definition: Chat.h:150
uint32_t uint32
Definition: Define.h:150
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

bool ChatHandler::load_command_table = true
staticprivate
WorldSession* ChatHandler::m_session
private
bool ChatHandler::sentErrorMessage
private

The documentation for this class was generated from the following files: