Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
cs_titles.cpp
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
/* ScriptData
7
Name: titles_commandscript
8
%Complete: 100
9
Comment: All titles related commands
10
Category: commandscripts
11
EndScriptData */
12
13
#include "
Chat.h
"
14
#include "
Language.h
"
15
#include "
ObjectMgr.h
"
16
#include "
Player.h
"
17
#include "
ScriptMgr.h
"
18
19
class
titles_commandscript
:
public
CommandScript
20
{
21
public
:
22
titles_commandscript
() :
CommandScript
(
"titles_commandscript"
) { }
23
24
std::vector<ChatCommand>
GetCommands
() const
OVERRIDE
25
{
26
static
std::vector<ChatCommand> titlesSetCommandTable =
27
{
28
{
"mask"
,
rbac::RBAC_PERM_COMMAND_TITLES_SET_MASK
,
false
, &
HandleTitlesSetMaskCommand
,
""
, },
29
};
30
static
std::vector<ChatCommand> titlesCommandTable =
31
{
32
{
"add"
,
rbac::RBAC_PERM_COMMAND_TITLES_ADD
,
false
, &
HandleTitlesAddCommand
,
""
, },
33
{
"current"
,
rbac::RBAC_PERM_COMMAND_TITLES_CURRENT
,
false
, &
HandleTitlesCurrentCommand
,
""
, },
34
{
"remove"
,
rbac::RBAC_PERM_COMMAND_TITLES_REMOVE
,
false
, &
HandleTitlesRemoveCommand
,
""
, },
35
{
"set"
,
rbac::RBAC_PERM_COMMAND_TITLES_SET
,
false
, NULL,
""
, titlesSetCommandTable },
36
};
37
static
std::vector<ChatCommand> commandTable =
38
{
39
{
"titles"
,
rbac::RBAC_PERM_COMMAND_TITLES
,
false
, NULL,
""
, titlesCommandTable },
40
};
41
return
commandTable;
42
}
43
44
static
bool
HandleTitlesCurrentCommand
(
ChatHandler
* handler,
char
const
* args)
45
{
46
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
47
char
* id_p = handler->
extractKeyFromLink
((
char
*)args,
"Htitle"
);
48
if
(!id_p)
49
return
false
;
50
51
int32
id
= atoi(id_p);
52
if
(
id
<= 0)
53
{
54
handler->
PSendSysMessage
(
LANG_INVALID_TITLE_ID
,
id
);
55
handler->
SetSentErrorMessage
(
true
);
56
return
false
;
57
}
58
59
Player
* target = handler->
getSelectedPlayer
();
60
if
(!target)
61
{
62
handler->
SendSysMessage
(
LANG_NO_CHAR_SELECTED
);
63
handler->
SetSentErrorMessage
(
true
);
64
return
false
;
65
}
66
67
// check online security
68
if
(handler->
HasLowerSecurity
(target, 0))
69
return
false
;
70
71
CharTitlesEntry
const
* titleInfo =
sCharTitlesStore
.LookupEntry(
id
);
72
if
(!titleInfo)
73
{
74
handler->
PSendSysMessage
(
LANG_INVALID_TITLE_ID
,
id
);
75
handler->
SetSentErrorMessage
(
true
);
76
return
false
;
77
}
78
79
std::string tNameLink = handler->
GetNameLink
(target);
80
81
target->
SetTitle
(titleInfo);
// to be sure that title now known
82
target->
SetUInt32Value
(
PLAYER_FIELD_PLAYER_TITLE
, titleInfo->
bit_index
);
83
84
handler->
PSendSysMessage
(
LANG_TITLE_CURRENT_RES
,
id
, titleInfo->
name
, tNameLink.c_str());
85
86
return
true
;
87
}
88
89
static
bool
HandleTitlesAddCommand
(
ChatHandler
* handler,
char
const
* args)
90
{
91
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
92
char
* id_p = handler->
extractKeyFromLink
((
char
*)args,
"Htitle"
);
93
if
(!id_p)
94
return
false
;
95
96
int32
id
= atoi(id_p);
97
if
(
id
<= 0)
98
{
99
handler->
PSendSysMessage
(
LANG_INVALID_TITLE_ID
,
id
);
100
handler->
SetSentErrorMessage
(
true
);
101
return
false
;
102
}
103
104
Player
* target = handler->
getSelectedPlayer
();
105
if
(!target)
106
{
107
handler->
SendSysMessage
(
LANG_NO_CHAR_SELECTED
);
108
handler->
SetSentErrorMessage
(
true
);
109
return
false
;
110
}
111
112
// check online security
113
if
(handler->
HasLowerSecurity
(target, 0))
114
return
false
;
115
116
CharTitlesEntry
const
* titleInfo =
sCharTitlesStore
.LookupEntry(
id
);
117
if
(!titleInfo)
118
{
119
handler->
PSendSysMessage
(
LANG_INVALID_TITLE_ID
,
id
);
120
handler->
SetSentErrorMessage
(
true
);
121
return
false
;
122
}
123
124
std::string tNameLink = handler->
GetNameLink
(target);
125
126
char
titleNameStr[80];
127
snprintf(titleNameStr, 80, titleInfo->
name
, target->
GetName
().c_str());
128
129
target->
SetTitle
(titleInfo);
130
handler->
PSendSysMessage
(
LANG_TITLE_ADD_RES
,
id
, titleNameStr, tNameLink.c_str());
131
132
return
true
;
133
}
134
135
static
bool
HandleTitlesRemoveCommand
(
ChatHandler
* handler,
char
const
* args)
136
{
137
// number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
138
char
* id_p = handler->
extractKeyFromLink
((
char
*)args,
"Htitle"
);
139
if
(!id_p)
140
return
false
;
141
142
int32
id
= atoi(id_p);
143
if
(
id
<= 0)
144
{
145
handler->
PSendSysMessage
(
LANG_INVALID_TITLE_ID
,
id
);
146
handler->
SetSentErrorMessage
(
true
);
147
return
false
;
148
}
149
150
Player
* target = handler->
getSelectedPlayer
();
151
if
(!target)
152
{
153
handler->
SendSysMessage
(
LANG_NO_CHAR_SELECTED
);
154
handler->
SetSentErrorMessage
(
true
);
155
return
false
;
156
}
157
158
// check online security
159
if
(handler->
HasLowerSecurity
(target, 0))
160
return
false
;
161
162
CharTitlesEntry
const
* titleInfo =
sCharTitlesStore
.LookupEntry(
id
);
163
if
(!titleInfo)
164
{
165
handler->
PSendSysMessage
(
LANG_INVALID_TITLE_ID
,
id
);
166
handler->
SetSentErrorMessage
(
true
);
167
return
false
;
168
}
169
170
target->
SetTitle
(titleInfo,
true
);
171
172
std::string tNameLink = handler->
GetNameLink
(target);
173
174
char
titleNameStr[80];
175
snprintf(titleNameStr, 80, titleInfo->
name
, target->
GetName
().c_str());
176
177
handler->
PSendSysMessage
(
LANG_TITLE_REMOVE_RES
,
id
, titleNameStr, tNameLink.c_str());
178
179
if
(!target->
HasTitle
(target->
GetInt32Value
(
PLAYER_FIELD_PLAYER_TITLE
)))
180
{
181
target->
SetUInt32Value
(
PLAYER_FIELD_PLAYER_TITLE
, 0);
182
handler->
PSendSysMessage
(
LANG_CURRENT_TITLE_RESET
, tNameLink.c_str());
183
}
184
185
return
true
;
186
}
187
188
//Edit Player KnownTitles
189
static
bool
HandleTitlesSetMaskCommand
(
ChatHandler
* handler,
char
const
* args)
190
{
191
if
(!*args)
192
return
false
;
193
194
uint64
titles = 0;
195
196
sscanf((
char
*)args,
UI64FMTD
, &titles);
197
198
Player
* target = handler->
getSelectedPlayer
();
199
if
(!target)
200
{
201
handler->
SendSysMessage
(
LANG_NO_CHAR_SELECTED
);
202
handler->
SetSentErrorMessage
(
true
);
203
return
false
;
204
}
205
206
// check online security
207
if
(handler->
HasLowerSecurity
(target, 0))
208
return
false
;
209
210
uint64
titles2 = titles;
211
212
for
(
uint32
i = 1; i <
sCharTitlesStore
.GetNumRows(); ++i)
213
if
(
CharTitlesEntry
const
* tEntry =
sCharTitlesStore
.LookupEntry(i))
214
titles2 &= ~(
uint64
(1) << tEntry->bit_index);
215
216
titles &= ~titles2;
// remove not existed titles
217
218
target->
SetUInt64Value
(
PLAYER_FIELD_KNOWN_TITLES
, titles);
219
handler->
SendSysMessage
(
LANG_DONE
);
220
221
if
(!target->
HasTitle
(target->
GetInt32Value
(
PLAYER_FIELD_PLAYER_TITLE
)))
222
{
223
target->
SetUInt32Value
(
PLAYER_FIELD_PLAYER_TITLE
, 0);
224
handler->
PSendSysMessage
(
LANG_CURRENT_TITLE_RESET
, handler->
GetNameLink
(target).c_str());
225
}
226
227
return
true
;
228
}
229
};
230
231
void
AddSC_titles_commandscript
()
232
{
233
new
titles_commandscript
();
234
}
Chat.h
sCharTitlesStore
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
int32
std::int32_t int32
Definition
Define.h:73
UI64FMTD
#define UI64FMTD
Definition
Define.h:64
uint32
std::uint32_t uint32
Definition
Define.h:77
OVERRIDE
#define OVERRIDE
Definition
Define.h:60
uint64
std::uint64_t uint64
Definition
Define.h:76
Language.h
LANG_TITLE_CURRENT_RES
@ LANG_TITLE_CURRENT_RES
Definition
Language.h:362
LANG_TITLE_REMOVE_RES
@ LANG_TITLE_REMOVE_RES
Definition
Language.h:361
LANG_TITLE_ADD_RES
@ LANG_TITLE_ADD_RES
Definition
Language.h:360
LANG_CURRENT_TITLE_RESET
@ LANG_CURRENT_TITLE_RESET
Definition
Language.h:363
LANG_INVALID_TITLE_ID
@ LANG_INVALID_TITLE_ID
Definition
Language.h:359
LANG_NO_CHAR_SELECTED
@ LANG_NO_CHAR_SELECTED
Definition
Language.h:118
LANG_DONE
@ LANG_DONE
Definition
Language.h:56
ObjectMgr.h
Player.h
ScriptMgr.h
PLAYER_FIELD_KNOWN_TITLES
@ PLAYER_FIELD_KNOWN_TITLES
Definition
UpdateFields.h:166
PLAYER_FIELD_PLAYER_TITLE
@ PLAYER_FIELD_PLAYER_TITLE
Definition
UpdateFields.h:154
ChatHandler
Definition
Chat.h:41
ChatHandler::GetNameLink
virtual std::string GetNameLink() const
Definition
Chat.h:79
ChatHandler::HasLowerSecurity
bool HasLowerSecurity(Player *target, uint64 guid, bool strong=false)
Definition
Chat.cpp:78
ChatHandler::getSelectedPlayer
Player * getSelectedPlayer()
Definition
Chat.cpp:829
ChatHandler::extractKeyFromLink
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition
Chat.cpp:873
ChatHandler::PSendSysMessage
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition
Chat.cpp:221
ChatHandler::SetSentErrorMessage
void SetSentErrorMessage(bool val)
Definition
Chat.h:114
ChatHandler::SendSysMessage
virtual void SendSysMessage(const char *str)
Definition
Chat.cpp:153
CommandScript::CommandScript
CommandScript(const char *name)
Definition
ScriptMgr.cpp:1466
Object::GetInt32Value
int32 GetInt32Value(uint16 index) const
Definition
Object.cpp:319
Object::SetUInt32Value
void SetUInt32Value(uint16 index, uint32 value)
Definition
Object.cpp:1038
Object::SetUInt64Value
void SetUInt64Value(uint16 index, uint64 value)
Definition
Object.cpp:1079
Player
Definition
Player.h:1289
Player::HasTitle
bool HasTitle(uint32 bitIndex)
Definition
Player.cpp:20424
Player::SetTitle
void SetTitle(CharTitlesEntry const *title, bool lost=false)
Definition
Player.cpp:20434
WorldObject::GetName
std::string const & GetName() const
Definition
Object.h:664
titles_commandscript
Definition
cs_titles.cpp:20
titles_commandscript::GetCommands
std::vector< ChatCommand > GetCommands() const OVERRIDE
Definition
cs_titles.cpp:24
titles_commandscript::HandleTitlesRemoveCommand
static bool HandleTitlesRemoveCommand(ChatHandler *handler, char const *args)
Definition
cs_titles.cpp:135
titles_commandscript::HandleTitlesAddCommand
static bool HandleTitlesAddCommand(ChatHandler *handler, char const *args)
Definition
cs_titles.cpp:89
titles_commandscript::HandleTitlesCurrentCommand
static bool HandleTitlesCurrentCommand(ChatHandler *handler, char const *args)
Definition
cs_titles.cpp:44
titles_commandscript::HandleTitlesSetMaskCommand
static bool HandleTitlesSetMaskCommand(ChatHandler *handler, char const *args)
Definition
cs_titles.cpp:189
titles_commandscript::titles_commandscript
titles_commandscript()
Definition
cs_titles.cpp:22
AddSC_titles_commandscript
void AddSC_titles_commandscript()
Definition
cs_titles.cpp:231
rbac::RBAC_PERM_COMMAND_TITLES_CURRENT
@ RBAC_PERM_COMMAND_TITLES_CURRENT
Definition
RBAC.h:651
rbac::RBAC_PERM_COMMAND_TITLES_ADD
@ RBAC_PERM_COMMAND_TITLES_ADD
Definition
RBAC.h:650
rbac::RBAC_PERM_COMMAND_TITLES_SET_MASK
@ RBAC_PERM_COMMAND_TITLES_SET_MASK
Definition
RBAC.h:654
rbac::RBAC_PERM_COMMAND_TITLES_REMOVE
@ RBAC_PERM_COMMAND_TITLES_REMOVE
Definition
RBAC.h:652
rbac::RBAC_PERM_COMMAND_TITLES
@ RBAC_PERM_COMMAND_TITLES
Definition
RBAC.h:649
rbac::RBAC_PERM_COMMAND_TITLES_SET
@ RBAC_PERM_COMMAND_TITLES_SET
Definition
RBAC.h:653
CharTitlesEntry
Definition
DBCStructure.h:813
CharTitlesEntry::bit_index
uint32 bit_index
Definition
DBCStructure.h:818
CharTitlesEntry::name
char * name
Definition
DBCStructure.h:816
src
server
scripts
Commands
cs_titles.cpp
Generated on
for Project SkyFire Core by
1.17.0