Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
Chat.h
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#ifndef SKYFIRESERVER_CHAT_H
7#define SKYFIRESERVER_CHAT_H
8
9#include "RBAC.h"
10#include "SharedDefines.h"
11#include "WorldSession.h"
12
13#include <vector>
14
15class ChatHandler;
16class Creature;
17class Group;
18class Player;
19class Unit;
20class WorldSession;
21class WorldObject;
22
23struct GameTele;
24
26{
27 typedef bool(*pHandler)(ChatHandler*, char const*);
28
29public:
30 ChatCommand(char const* name, uint32 permission, bool allowConsole, pHandler handler, std::string help, std::vector<ChatCommand> childCommands = std::vector<ChatCommand>())
31 : Name(name), Permission(permission), AllowConsole(allowConsole), Handler(handler), Help(std::move(help)), ChildCommands(std::move(childCommands)) { }
32 const char* Name;
33 uint32 Permission; // function pointer required correct align (use uint32)
36 std::string Help;
37 std::vector<ChatCommand> ChildCommands;
38};
39
41{
42public:
44 explicit ChatHandler(WorldSession* session) : m_session(session), sentErrorMessage(false) { }
45 virtual ~ChatHandler() { }
46
47 // Builds chat packet and returns receiver guid position in the packet to substitute in whisper builders
48 static size_t BuildChatPacket(WorldPacket& data, ChatMsg chatType, Language language, ObjectGuid senderGUID, ObjectGuid receiverGUID, std::string const& message, uint8 chatTag,
49 std::string const& senderName = "", std::string const& receiverName = "",
50 uint32 achievementId = 0, bool gmMessage = false, std::string const& channelName = "", std::string const& addonPrefix = "");
51
52 // Builds chat packet and returns receiver guid position in the packet to substitute in whisper builders
53 static size_t BuildChatPacket(WorldPacket& data, ChatMsg chatType, Language language, WorldObject const* sender, WorldObject const* receiver, std::string const& message, uint32 achievementId = 0, std::string const& channelName = "", LocaleConstant locale = DEFAULT_LOCALE, std::string const& addonPrefix = "");
54
55
56 static char* LineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = NULL; return start; }
57
58 // function with different implementation for chat/console
59 virtual const char* GetSkyFireString(int32 entry) const;
60 virtual void SendSysMessage(const char* str);
61
62 void SendSysMessage(int32 entry);
63 void PSendSysMessage(const char* format, ...) ATTR_PRINTF(2, 3);
64 void PSendSysMessage(int32 entry, ...);
65 std::string PGetParseString(int32 entry, ...) const;
66
67 bool ParseCommands(const char* text);
68
69 static std::vector<ChatCommand> const& getCommandTable();
70
71 bool isValidChatMessage(const char* msg);
72 void SendGlobalSysMessage(const char* str);
73
74 bool hasStringAbbr(const char* name, const char* part);
75
76 // function with different implementation for chat/console
77 virtual bool isAvailable(ChatCommand const& cmd) const;
78 virtual bool HasPermission(uint32 permission) const { return m_session->HasPermission(permission); }
79 virtual std::string GetNameLink() const { return GetNameLink(m_session->GetPlayer()); }
80 virtual bool needReportToTarget(Player* chr) const;
81 virtual LocaleConstant GetSessionDbcLocale() const;
82 virtual int GetSessionDbLocaleIndex() const;
83
84 bool HasLowerSecurity(Player* target, uint64 guid, bool strong = false);
85 bool HasLowerSecurityAccount(WorldSession* target, uint32 account, bool strong = false);
86
87 void SendGlobalGMSysMessage(const char* str);
92
93 char* extractKeyFromLink(char* text, char const* linkType, char** something1 = NULL);
94 char* extractKeyFromLink(char* text, char const* const* linkTypes, int* found_idx, char** something1 = NULL);
95
96 // if args have single value then it return in arg2 and arg1 == NULL
97 void extractOptFirstArg(char* args, char** arg1, char** arg2);
98 char* extractQuotedArg(char* args);
99
100 uint32 extractSpellIdFromLink(char* text);
101 uint64 extractGuidFromLink(char* text);
102 GameTele const* extractGameTeleFromLink(char* text);
103 bool GetPlayerGroupAndGUIDByName(const char* cname, Player*& player, Group*& group, uint64& guid, bool offline = false);
104 std::string extractPlayerNameFromLink(char* text);
105 // select by arg (name/link) or in-game selection online/offline player
106 bool extractPlayerTarget(char* args, Player** player, uint64* player_guid = NULL, std::string* player_name = NULL);
107
108 std::string playerLink(std::string const& name) const { return m_session ? "|cffffffff|Hplayer:" + name + "|h[" + name + "]|h|r" : name; }
109 std::string GetNameLink(Player* chr) const;
110
113 bool HasSentErrorMessage() const { return sentErrorMessage; }
114 void SetSentErrorMessage(bool val) { sentErrorMessage = val; }
115 static bool LoadCommandTable() { return load_command_table; }
116 static void SetLoadCommandTable(bool val) { load_command_table = val; }
117
118 bool ShowHelpForCommand(std::vector<ChatCommand> const& table, const char* cmd);
119protected:
120 explicit ChatHandler() : m_session(NULL), sentErrorMessage(false) { } // for CLI subclass
121 static bool SetDataForCommandInTable(std::vector<ChatCommand>& table, const char* text, uint32 permission, std::string const& help, std::string const& fullcommand);
122 bool ExecuteCommandInTable(std::vector<ChatCommand> const& table, const char* text, std::string const& fullcmd);
123 bool ShowHelpForSubCommands(std::vector<ChatCommand> const& table, char const* cmd, char const* subcmd);
124
125private:
126 WorldSession* m_session; // != NULL for chat command call and NULL for CLI command
127
128 // common global flag
131};
132
134{
135public:
136 typedef void Print(void*, char const*);
137 explicit CliHandler(void* callbackArg, Print* zprint) : m_callbackArg(callbackArg), m_print(zprint) { }
138
139 // overwrite functions
140 const char* GetSkyFireString(int32 entry) const;
141 bool isAvailable(ChatCommand const& cmd) const;
142 bool HasPermission(uint32 /*permission*/) const { return true; }
143 void SendSysMessage(const char* str);
144 std::string GetNameLink() const;
145 bool needReportToTarget(Player* chr) const;
147 int GetSessionDbLocaleIndex() const;
148
149private:
152};
153
154#endif
const AuthHandler table[]
LocaleConstant
Definition Common.h:138
#define DEFAULT_LOCALE
Definition Common.h:154
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
#define ATTR_PRINTF(F, V)
Definition Define.h:55
std::uint64_t uint64
Definition Define.h:76
Role Based Access Control related classes definition.
ChatMsg
Language
pHandler Handler
Definition Chat.h:35
std::string Help
Definition Chat.h:36
bool(* pHandler)(ChatHandler *, char const *)
Definition Chat.h:27
std::vector< ChatCommand > ChildCommands
Definition Chat.h:37
uint32 Permission
Definition Chat.h:33
ChatCommand(char const *name, uint32 permission, bool allowConsole, pHandler handler, std::string help, std::vector< ChatCommand > childCommands=std::vector< ChatCommand >())
Definition Chat.h:30
const char * Name
Definition Chat.h:32
bool AllowConsole
Definition Chat.h:34
static bool LoadCommandTable()
Definition Chat.h:115
virtual std::string GetNameLink() const
Definition Chat.h:79
GameTele const * extractGameTeleFromLink(char *text)
Definition Chat.cpp:1089
bool HasLowerSecurity(Player *target, uint64 guid, bool strong=false)
Definition Chat.cpp:78
static void SetLoadCommandTable(bool val)
Definition Chat.h:116
bool ParseCommands(const char *text)
Definition Chat.cpp:388
virtual bool isAvailable(ChatCommand const &cmd) const
Definition Chat.cpp:73
std::string PGetParseString(int32 entry,...) const
Definition Chat.cpp:57
void extractOptFirstArg(char *args, char **arg1, char **arg2)
Definition Chat.cpp:1237
static bool SetDataForCommandInTable(std::vector< ChatCommand > &table, const char *text, uint32 permission, std::string const &help, std::string const &fullcommand)
Definition Chat.cpp:333
GameObject * GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid, uint32 entry)
Definition Chat.cpp:998
std::string playerLink(std::string const &name) const
Definition Chat.h:108
static bool load_command_table
Definition Chat.h:129
char * extractQuotedArg(char *args)
Definition Chat.cpp:1255
Unit * getSelectedUnit()
Definition Chat.cpp:841
void SendGlobalGMSysMessage(const char *str)
Definition Chat.cpp:188
bool ExecuteCommandInTable(std::vector< ChatCommand > const &table, const char *text, std::string const &fullcmd)
Definition Chat.cpp:231
Player * getSelectedPlayer()
Definition Chat.cpp:829
WorldSession * GetSession()
Definition Chat.h:43
void SendGlobalSysMessage(const char *str)
Definition Chat.cpp:170
bool HasSentErrorMessage() const
Definition Chat.h:113
virtual LocaleConstant GetSessionDbcLocale() const
Definition Chat.cpp:1277
bool isValidChatMessage(const char *msg)
Definition Chat.cpp:425
virtual bool HasPermission(uint32 permission) const
Definition Chat.h:78
ChatHandler(WorldSession *session)
Definition Chat.h:44
WorldSession * m_session
Definition Chat.h:126
virtual int GetSessionDbLocaleIndex() const
Definition Chat.cpp:1282
virtual ~ChatHandler()
Definition Chat.h:45
bool hasStringAbbr(const char *name, const char *part)
Definition Chat.cpp:128
Creature * getSelectedCreature()
Definition Chat.cpp:865
uint32 extractSpellIdFromLink(char *text)
Definition Chat.cpp:1042
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition Chat.cpp:873
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition Chat.cpp:221
static size_t BuildChatPacket(WorldPacket &data, ChatMsg chatType, Language language, ObjectGuid senderGUID, ObjectGuid receiverGUID, std::string const &message, uint8 chatTag, std::string const &senderName="", std::string const &receiverName="", uint32 achievementId=0, bool gmMessage=false, std::string const &channelName="", std::string const &addonPrefix="")
Definition Chat.cpp:580
void SetSentErrorMessage(bool val)
Definition Chat.h:114
ChatHandler()
Definition Chat.h:120
WorldObject * getSelectedObject()
Definition Chat.cpp:852
uint64 extractGuidFromLink(char *text)
Definition Chat.cpp:1119
static char * LineFromMessage(char *&pos)
Definition Chat.h:56
bool ShowHelpForSubCommands(std::vector< ChatCommand > const &table, char const *cmd, char const *subcmd)
Definition Chat.cpp:485
bool sentErrorMessage
Definition Chat.h:130
bool extractPlayerTarget(char *args, Player **player, uint64 *player_guid=NULL, std::string *player_name=NULL)
Definition Chat.cpp:1184
virtual bool needReportToTarget(Player *chr) const
Definition Chat.cpp:1271
virtual void SendSysMessage(const char *str)
Definition Chat.cpp:153
virtual const char * GetSkyFireString(int32 entry) const
Definition Chat.cpp:68
bool GetPlayerGroupAndGUIDByName(const char *cname, Player *&player, Group *&group, uint64 &guid, bool offline=false)
Definition Chat.cpp:1319
std::string extractPlayerNameFromLink(char *text)
Definition Chat.cpp:1170
bool ShowHelpForCommand(std::vector< ChatCommand > const &table, const char *cmd)
Definition Chat.cpp:523
GameObject * GetNearbyGameObject()
Definition Chat.cpp:985
bool HasLowerSecurityAccount(WorldSession *target, uint32 account, bool strong=false)
Definition Chat.cpp:98
static std::vector< ChatCommand > const & getCommandTable()
Definition Chat.cpp:29
bool HasPermission(uint32) const
Definition Chat.h:142
void SendSysMessage(const char *str)
Definition Chat.cpp:1303
void Print(void *, char const *)
Definition Chat.h:136
bool needReportToTarget(Player *chr) const
Definition Chat.cpp:1314
const char * GetSkyFireString(int32 entry) const
Definition Chat.cpp:1292
LocaleConstant GetSessionDbcLocale() const
Definition Chat.cpp:1363
CliHandler(void *callbackArg, Print *zprint)
Definition Chat.h:137
int GetSessionDbLocaleIndex() const
Definition Chat.cpp:1368
void * m_callbackArg
Definition Chat.h:150
Print * m_print
Definition Chat.h:151
std::string GetNameLink() const
Definition Chat.cpp:1309
bool isAvailable(ChatCommand const &cmd) const
Definition Chat.cpp:1297
Definition Group.h:147
Definition Unit.h:1367
Player session in the World.