forked from TrinityCore/TrinityCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcs_group.cpp
More file actions
387 lines (325 loc) · 13.5 KB
/
cs_group.cpp
File metadata and controls
387 lines (325 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/*
* Copyright (C) 2008-2019 TrinityCore <https://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "DB2Stores.h"
#include "GroupMgr.h"
#include "Language.h"
#include "LFG.h"
#include "Map.h"
#include "MotionMaster.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "PhasingHandler.h"
#include "Player.h"
#include "RBAC.h"
#include "WorldSession.h"
class group_commandscript : public CommandScript
{
public:
group_commandscript() : CommandScript("group_commandscript") { }
std::vector<ChatCommand> GetCommands() const override
{
static std::vector<ChatCommand> groupCommandTable =
{
{ "leader", rbac::RBAC_PERM_COMMAND_GROUP_LEADER, false, &HandleGroupLeaderCommand, "" },
{ "disband", rbac::RBAC_PERM_COMMAND_GROUP_DISBAND, false, &HandleGroupDisbandCommand, "" },
{ "remove", rbac::RBAC_PERM_COMMAND_GROUP_REMOVE, false, &HandleGroupRemoveCommand, "" },
{ "join", rbac::RBAC_PERM_COMMAND_GROUP_JOIN, false, &HandleGroupJoinCommand, "" },
{ "list", rbac::RBAC_PERM_COMMAND_GROUP_LIST, false, &HandleGroupListCommand, "" },
{ "summon", rbac::RBAC_PERM_COMMAND_GROUP_SUMMON, false, &HandleGroupSummonCommand, "" },
};
static std::vector<ChatCommand> commandTable =
{
{ "group", rbac::RBAC_PERM_COMMAND_GROUP, false, NULL, "", groupCommandTable },
};
return commandTable;
}
// Summon group of player
static bool HandleGroupSummonCommand(ChatHandler* handler, char const* args)
{
Player* target;
if (!handler->extractPlayerTarget((char*)args, &target))
return false;
// check online security
if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
return false;
Group* group = target->GetGroup();
std::string nameLink = handler->GetNameLink(target);
if (!group)
{
handler->PSendSysMessage(LANG_NOT_IN_GROUP, nameLink.c_str());
handler->SetSentErrorMessage(true);
return false;
}
Player* gmPlayer = handler->GetSession()->GetPlayer();
Group* gmGroup = gmPlayer->GetGroup();
Map* gmMap = gmPlayer->GetMap();
bool toInstance = gmMap->Instanceable();
// we are in instance, and can summon only player in our group with us as lead
if (toInstance && (
!gmGroup || group->GetLeaderGUID() != gmPlayer->GetGUID() ||
gmGroup->GetLeaderGUID() != gmPlayer->GetGUID()))
// the last check is a bit excessive, but let it be, just in case
{
handler->SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
handler->SetSentErrorMessage(true);
return false;
}
for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
{
Player* player = itr->GetSource();
if (!player || player == gmPlayer || !player->GetSession())
continue;
// check online security
if (handler->HasLowerSecurity(player, ObjectGuid::Empty))
return false;
std::string plNameLink = handler->GetNameLink(player);
if (player->IsBeingTeleported())
{
handler->PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
handler->SetSentErrorMessage(true);
return false;
}
if (toInstance)
{
Map* playerMap = player->GetMap();
if (playerMap->Instanceable() && playerMap->GetInstanceId() != gmMap->GetInstanceId())
{
// cannot summon from instance to instance
handler->PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST, plNameLink.c_str());
handler->SetSentErrorMessage(true);
return false;
}
}
handler->PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(), "");
if (handler->needReportToTarget(player))
ChatHandler(player->GetSession()).PSendSysMessage(LANG_SUMMONED_BY, handler->GetNameLink().c_str());
// stop flight if need
if (player->IsInFlight())
{
player->GetMotionMaster()->MovementExpired();
player->CleanupAfterTaxiFlight();
}
// save only in non-flight case
else
player->SaveRecallPosition();
// before GM
float x, y, z;
gmPlayer->GetClosePoint(x, y, z, player->GetObjectSize());
player->TeleportTo(gmPlayer->GetMapId(), x, y, z, player->GetOrientation());
}
return true;
}
static bool HandleGroupLeaderCommand(ChatHandler* handler, char const* args)
{
Player* player = NULL;
Group* group = NULL;
ObjectGuid guid;
char* nameStr = strtok((char*)args, " ");
if (!handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid))
return false;
if (!group)
{
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, player->GetName().c_str());
handler->SetSentErrorMessage(true);
return false;
}
if (group->GetLeaderGUID() != guid)
{
group->ChangeLeader(guid);
group->SendUpdate();
}
return true;
}
static bool HandleGroupDisbandCommand(ChatHandler* handler, char const* args)
{
Player* player = NULL;
Group* group = NULL;
ObjectGuid guid;
char* nameStr = strtok((char*)args, " ");
if (!handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid))
return false;
if (!group)
{
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, player->GetName().c_str());
handler->SetSentErrorMessage(true);
return false;
}
group->Disband();
return true;
}
static bool HandleGroupRemoveCommand(ChatHandler* handler, char const* args)
{
Player* player = NULL;
Group* group = NULL;
ObjectGuid guid;
char* nameStr = strtok((char*)args, " ");
if (!handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid))
return false;
if (!group)
{
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, player->GetName().c_str());
handler->SetSentErrorMessage(true);
return false;
}
group->RemoveMember(guid);
return true;
}
static bool HandleGroupJoinCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
Player* playerSource = NULL;
Player* playerTarget = NULL;
Group* groupSource = NULL;
Group* groupTarget = NULL;
ObjectGuid guidSource;
ObjectGuid guidTarget;
char* nameplgrStr = strtok((char*)args, " ");
char* nameplStr = strtok(NULL, " ");
if (!handler->GetPlayerGroupAndGUIDByName(nameplgrStr, playerSource, groupSource, guidSource, true))
return false;
if (!groupSource)
{
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, playerSource->GetName().c_str());
handler->SetSentErrorMessage(true);
return false;
}
if (!handler->GetPlayerGroupAndGUIDByName(nameplStr, playerTarget, groupTarget, guidTarget, true))
return false;
if (groupTarget || playerTarget->GetGroup() == groupSource)
{
handler->PSendSysMessage(LANG_GROUP_ALREADY_IN_GROUP, playerTarget->GetName().c_str());
handler->SetSentErrorMessage(true);
return false;
}
if (groupSource->IsFull())
{
handler->PSendSysMessage(LANG_GROUP_FULL);
handler->SetSentErrorMessage(true);
return false;
}
groupSource->AddMember(playerTarget);
groupSource->BroadcastGroupUpdate();
handler->PSendSysMessage(LANG_GROUP_PLAYER_JOINED, playerTarget->GetName().c_str(), playerSource->GetName().c_str());
return true;
}
static bool HandleGroupListCommand(ChatHandler* handler, char const* args)
{
// Get ALL the variables!
Player* playerTarget;
ObjectGuid guidTarget;
std::string nameTarget;
std::string zoneName;
const char* onlineState = "";
// Parse the guid to uint32...
ObjectGuid parseGUID = ObjectGuid::Create<HighGuid::Player>(strtoull(args, nullptr, 10));
// ... and try to extract a player out of it.
if (ObjectMgr::GetPlayerNameByGUID(parseGUID, nameTarget))
{
playerTarget = ObjectAccessor::FindPlayer(parseGUID);
guidTarget = parseGUID;
}
// If not, we return false and end right away.
else if (!handler->extractPlayerTarget((char*)args, &playerTarget, &guidTarget, &nameTarget))
return false;
// Next, we need a group. So we define a group variable.
Group* groupTarget = NULL;
// We try to extract a group from an online player.
if (playerTarget)
groupTarget = playerTarget->GetGroup();
// If not, we extract it from the SQL.
if (!groupTarget)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GROUP_MEMBER);
stmt->setUInt64(0, guidTarget.GetCounter());
PreparedQueryResult resultGroup = CharacterDatabase.Query(stmt);
if (resultGroup)
groupTarget = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32());
}
// If both fails, players simply has no party. Return false.
if (!groupTarget)
{
handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, nameTarget.c_str());
handler->SetSentErrorMessage(true);
return false;
}
// We get the group members after successfully detecting a group.
Group::MemberSlotList const& members = groupTarget->GetMemberSlots();
// To avoid a cluster fuck, namely trying multiple queries to simply get a group member count...
handler->PSendSysMessage(LANG_GROUP_TYPE, (groupTarget->isRaidGroup() ? "raid" : "party"), std::to_string(members.size()).c_str());
// ... we simply move the group type and member count print after retrieving the slots and simply output it's size.
// While rather dirty codestyle-wise, it saves space (if only a little). For each member, we look several informations up.
for (Group::MemberSlotList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
// Define temporary variable slot to iterator.
Group::MemberSlot const& slot = *itr;
// Check for given flag and assign it to that iterator
std::string flags;
if (slot.flags & MEMBER_FLAG_ASSISTANT)
flags = "Assistant";
if (slot.flags & MEMBER_FLAG_MAINTANK)
{
if (!flags.empty())
flags.append(", ");
flags.append("MainTank");
}
if (slot.flags & MEMBER_FLAG_MAINASSIST)
{
if (!flags.empty())
flags.append(", ");
flags.append("MainAssist");
}
if (flags.empty())
flags = "None";
// Check if iterator is online. If is...
Player* p = ObjectAccessor::FindPlayer((*itr).guid);
std::string phases;
if (p)
{
// ... than, it prints information like "is online", where he is, etc...
onlineState = "online";
phases = PhasingHandler::FormatPhases(p->GetPhaseShift());
AreaTableEntry const* area = sAreaTableStore.LookupEntry(p->GetAreaId());
if (area)
{
AreaTableEntry const* zone = sAreaTableStore.LookupEntry(area->ParentAreaID);
if (zone)
zoneName = zone->AreaName->Str[handler->GetSessionDbcLocale()];
}
}
else
{
// ... else, everything is set to offline or neutral values.
zoneName = "<ERROR>";
onlineState = "Offline";
}
// Now we can print those informations for every single member of each group!
handler->PSendSysMessage(LANG_GROUP_PLAYER_NAME_GUID, slot.name.c_str(), onlineState,
zoneName.c_str(), phases.c_str(), slot.guid.ToString().c_str(), flags.c_str(),
lfg::GetRolesString(slot.roles).c_str());
}
// And finish after every iterator is done.
return true;
}
};
void AddSC_group_commandscript()
{
new group_commandscript();
}