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

Public Member Functions

 titles_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleTitlesCurrentCommand (ChatHandler *handler, char const *args)
 
static bool HandleTitlesAddCommand (ChatHandler *handler, char const *args)
 
static bool HandleTitlesRemoveCommand (ChatHandler *handler, char const *args)
 
static bool HandleTitlesSetMaskCommand (ChatHandler *handler, char const *args)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()
 

Constructor & Destructor Documentation

titles_commandscript::titles_commandscript ( )
inline
34 : CommandScript("titles_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> titles_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

37  {
38  static std::vector<ChatCommand> titlesSetCommandTable =
39  {
41  };
42  static std::vector<ChatCommand> titlesCommandTable =
43  {
47  { "set", rbac::RBAC_PERM_COMMAND_TITLES_SET, false, NULL, "", titlesSetCommandTable },
48  };
49  static std::vector<ChatCommand> commandTable =
50  {
51  { "titles", rbac::RBAC_PERM_COMMAND_TITLES, false, NULL, "", titlesCommandTable },
52  };
53  return commandTable;
54  }
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleTitlesAddCommand(ChatHandler *handler, char const *args)
Definition: cs_titles.cpp:100
static bool HandleTitlesSetMaskCommand(ChatHandler *handler, char const *args)
Definition: cs_titles.cpp:200
static bool HandleTitlesCurrentCommand(ChatHandler *handler, char const *args)
Definition: cs_titles.cpp:56
static bool HandleTitlesRemoveCommand(ChatHandler *handler, char const *args)
Definition: cs_titles.cpp:146
Definition: RBAC.h:655

+ Here is the call graph for this function:

static bool titles_commandscript::HandleTitlesAddCommand ( ChatHandler handler,
char const args 
)
inlinestatic
101  {
102  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
103  char* id_p = handler->extractKeyFromLink((char*)args, "Htitle");
104  if (!id_p)
105  return false;
106 
107  int32 id = atoi(id_p);
108  if (id <= 0)
109  {
111  handler->SetSentErrorMessage(true);
112  return false;
113  }
114 
115  Player* target = handler->getSelectedPlayer();
116  if (!target)
117  {
119  handler->SetSentErrorMessage(true);
120  return false;
121  }
122 
123  // check online security
124  if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
125  return false;
126 
127  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
128  if (!titleInfo)
129  {
131  handler->SetSentErrorMessage(true);
132  return false;
133  }
134 
135  std::string tNameLink = handler->GetNameLink(target);
136 
137  char titleNameStr[80];
138  snprintf(titleNameStr, 80, target->getGender() == GENDER_MALE ? titleInfo->NameMale_lang : titleInfo->NameFemale_lang, target->GetName().c_str());
139 
140  target->SetTitle(titleInfo);
141  handler->PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
142 
143  return true;
144  }
Definition: Language.h:380
Definition: Language.h:381
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: DBCStructure.h:162
#define snprintf
Definition: Common.h:76
Definition: Language.h:140
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesfmt)
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition: Chat.cpp:77
Definition: SharedDefines.h:93
virtual std::string GetNameLink() const
Definition: Chat.h:101
int32_t int32
Definition: Define.h:146
char * NameMale_lang
Definition: DBCStructure.h:166
Player * getSelectedPlayer()
Definition: Chat.cpp:579
char * NameFemale_lang
Definition: DBCStructure.h:167
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
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:

static bool titles_commandscript::HandleTitlesCurrentCommand ( ChatHandler handler,
char const args 
)
inlinestatic
57  {
58  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
59  char* id_p = handler->extractKeyFromLink((char*)args, "Htitle");
60  if (!id_p)
61  return false;
62 
63  int32 id = atoi(id_p);
64  if (id <= 0)
65  {
67  handler->SetSentErrorMessage(true);
68  return false;
69  }
70 
71  Player* target = handler->getSelectedPlayer();
72  if (!target)
73  {
75  handler->SetSentErrorMessage(true);
76  return false;
77  }
78 
79  // check online security
80  if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
81  return false;
82 
83  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
84  if (!titleInfo)
85  {
87  handler->SetSentErrorMessage(true);
88  return false;
89  }
90 
91  std::string tNameLink = handler->GetNameLink(target);
92 
93  target->SetTitle(titleInfo); // to be sure that title now known
94  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->MaskID);
95 
96  handler->PSendSysMessage(LANG_TITLE_CURRENT_RES, id, target->getGender() == GENDER_MALE ? titleInfo->NameMale_lang : titleInfo->NameFemale_lang, tNameLink.c_str());
97  return true;
98  }
Definition: Language.h:380
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: DBCStructure.h:162
Definition: Language.h:383
Definition: Language.h:140
uint32 MaskID
Definition: DBCStructure.h:168
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesfmt)
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition: Chat.cpp:77
Definition: SharedDefines.h:93
virtual std::string GetNameLink() const
Definition: Chat.h:101
int32_t int32
Definition: Define.h:146
char * NameMale_lang
Definition: DBCStructure.h:166
Player * getSelectedPlayer()
Definition: Chat.cpp:579
char * NameFemale_lang
Definition: DBCStructure.h:167
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: UpdateFields.h:203
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
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:

static bool titles_commandscript::HandleTitlesRemoveCommand ( ChatHandler handler,
char const args 
)
inlinestatic
147  {
148  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
149  char* id_p = handler->extractKeyFromLink((char*)args, "Htitle");
150  if (!id_p)
151  return false;
152 
153  int32 id = atoi(id_p);
154  if (id <= 0)
155  {
157  handler->SetSentErrorMessage(true);
158  return false;
159  }
160 
161  Player* target = handler->getSelectedPlayer();
162  if (!target)
163  {
165  handler->SetSentErrorMessage(true);
166  return false;
167  }
168 
169  // check online security
170  if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
171  return false;
172 
173  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
174  if (!titleInfo)
175  {
177  handler->SetSentErrorMessage(true);
178  return false;
179  }
180 
181  target->SetTitle(titleInfo, true);
182 
183  std::string tNameLink = handler->GetNameLink(target);
184 
185  char titleNameStr[80];
186  snprintf(titleNameStr, 80, target->getGender() == GENDER_MALE ? titleInfo->NameMale_lang : titleInfo->NameFemale_lang, target->GetName().c_str());
187 
188  handler->PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, tNameLink.c_str());
189 
190  if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
191  {
192  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
193  handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, tNameLink.c_str());
194  }
195 
196  return true;
197  }
Definition: Language.h:380
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: Language.h:382
Definition: DBCStructure.h:162
#define snprintf
Definition: Common.h:76
Definition: Language.h:384
Definition: Language.h:140
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesfmt)
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition: Chat.cpp:77
Definition: SharedDefines.h:93
virtual std::string GetNameLink() const
Definition: Chat.h:101
int32_t int32
Definition: Define.h:146
char * NameMale_lang
Definition: DBCStructure.h:166
Player * getSelectedPlayer()
Definition: Chat.cpp:579
char * NameFemale_lang
Definition: DBCStructure.h:167
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: UpdateFields.h:203
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
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:

static bool titles_commandscript::HandleTitlesSetMaskCommand ( ChatHandler handler,
char const args 
)
inlinestatic
201  {
202  if (!*args)
203  return false;
204 
205  uint64 titles = 0;
206 
207  sscanf((char*)args, UI64FMTD, &titles);
208 
209  Player* target = handler->getSelectedPlayer();
210  if (!target)
211  {
213  handler->SetSentErrorMessage(true);
214  return false;
215  }
216 
217  // check online security
218  if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
219  return false;
220 
221  uint64 titles2 = titles;
222 
223  for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
224  if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
225  titles2 &= ~(uint64(1) << tEntry->MaskID);
226 
227  titles &= ~titles2; // remove not existed titles
228 
229  target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
230  handler->SendSysMessage(LANG_DONE);
231 
232  if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
233  {
234  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
235  handler->PSendSysMessage(LANG_CURRENT_TITLE_RESET, handler->GetNameLink(target).c_str());
236  }
237 
238  return true;
239  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: DBCStructure.h:162
Definition: Language.h:384
uint64_t uint64
Definition: g3dmath.h:170
Definition: Language.h:140
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesfmt)
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition: Chat.cpp:77
virtual std::string GetNameLink() const
Definition: Chat.h:101
#define UI64FMTD
Definition: Define.h:137
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
Player * getSelectedPlayer()
Definition: Chat.cpp:579
Definition: UpdateFields.h:213
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: UpdateFields.h:203
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


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