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

Public Member Functions

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

Static Public Member Functions

static bool HandleGroupSummonCommand (ChatHandler *handler, char const *args)
 
static bool HandleGroupLeaderCommand (ChatHandler *handler, char const *args)
 
static bool HandleGroupDisbandCommand (ChatHandler *handler, char const *args)
 
static bool HandleGroupRemoveCommand (ChatHandler *handler, char const *args)
 
static bool HandleGroupJoinCommand (ChatHandler *handler, char const *args)
 
static bool HandleGroupListCommand (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

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

Member Function Documentation

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

Implements CommandScript.

32  {
33  static std::vector<ChatCommand> groupCommandTable =
34  {
41  };
42 
43  static std::vector<ChatCommand> commandTable =
44  {
45  { "group", rbac::RBAC_PERM_COMMAND_GROUP, false, NULL, "", groupCommandTable },
46  };
47  return commandTable;
48  }
Definition: RBAC.h:379
static bool HandleGroupLeaderCommand(ChatHandler *handler, char const *args)
Definition: cs_group.cpp:144
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleGroupRemoveCommand(ChatHandler *handler, char const *args)
Definition: cs_group.cpp:191
static bool HandleGroupDisbandCommand(ChatHandler *handler, char const *args)
Definition: cs_group.cpp:170
static bool HandleGroupJoinCommand(ChatHandler *handler, char const *args)
Definition: cs_group.cpp:212
static bool HandleGroupSummonCommand(ChatHandler *handler, char const *args)
Definition: cs_group.cpp:51
static bool HandleGroupListCommand(ChatHandler *handler, char const *args)
Definition: cs_group.cpp:259

+ Here is the call graph for this function:

static bool group_commandscript::HandleGroupDisbandCommand ( ChatHandler handler,
char const args 
)
inlinestatic
171  {
172  Player* player = NULL;
173  Group* group = NULL;
174  ObjectGuid guid;
175  char* nameStr = strtok((char*)args, " ");
176 
177  if (!handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid))
178  return false;
179 
180  if (!group)
181  {
182  handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, player->GetName().c_str());
183  handler->SetSentErrorMessage(true);
184  return false;
185  }
186 
187  group->Disband();
188  return true;
189  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:950
bool GetPlayerGroupAndGUIDByName(const char *cname, Player *&player, Group *&group, ObjectGuid &guid, bool offline=false)
Definition: Chat.cpp:1104
void Disband(bool hideDestroy=false)
Definition: Group.cpp:757
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: ObjectGuid.h:189
Definition: Group.h:191

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool group_commandscript::HandleGroupJoinCommand ( ChatHandler handler,
char const args 
)
inlinestatic
213  {
214  if (!*args)
215  return false;
216 
217  Player* playerSource = NULL;
218  Player* playerTarget = NULL;
219  Group* groupSource = NULL;
220  Group* groupTarget = NULL;
221  ObjectGuid guidSource;
222  ObjectGuid guidTarget;
223  char* nameplgrStr = strtok((char*)args, " ");
224  char* nameplStr = strtok(NULL, " ");
225 
226  if (!handler->GetPlayerGroupAndGUIDByName(nameplgrStr, playerSource, groupSource, guidSource, true))
227  return false;
228 
229  if (!groupSource)
230  {
231  handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, playerSource->GetName().c_str());
232  handler->SetSentErrorMessage(true);
233  return false;
234  }
235 
236  if (!handler->GetPlayerGroupAndGUIDByName(nameplStr, playerTarget, groupTarget, guidTarget, true))
237  return false;
238 
239  if (groupTarget || playerTarget->GetGroup() == groupSource)
240  {
241  handler->PSendSysMessage(LANG_GROUP_ALREADY_IN_GROUP, playerTarget->GetName().c_str());
242  handler->SetSentErrorMessage(true);
243  return false;
244  }
245 
246  if (groupSource->IsFull())
247  {
249  handler->SetSentErrorMessage(true);
250  return false;
251  }
252 
253  groupSource->AddMember(playerTarget);
254  groupSource->BroadcastGroupUpdate();
255  handler->PSendSysMessage(LANG_GROUP_PLAYER_JOINED, playerTarget->GetName().c_str(), playerSource->GetName().c_str());
256  return true;
257  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
void BroadcastGroupUpdate(void)
Definition: Group.cpp:2283
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:950
bool AddMember(Player *player)
Definition: Group.cpp:368
bool IsFull() const
Definition: Group.cpp:2499
bool GetPlayerGroupAndGUIDByName(const char *cname, Player *&player, Group *&group, ObjectGuid &guid, bool offline=false)
Definition: Chat.cpp:1104
Definition: Language.h:951
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:948
Definition: ObjectGuid.h:189
Definition: Language.h:949
Definition: Group.h:191

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool group_commandscript::HandleGroupLeaderCommand ( ChatHandler handler,
char const args 
)
inlinestatic
145  {
146  Player* player = NULL;
147  Group* group = NULL;
148  ObjectGuid guid;
149  char* nameStr = strtok((char*)args, " ");
150 
151  if (!handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid))
152  return false;
153 
154  if (!group)
155  {
156  handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, player->GetName().c_str());
157  handler->SetSentErrorMessage(true);
158  return false;
159  }
160 
161  if (group->GetLeaderGUID() != guid)
162  {
163  group->ChangeLeader(guid);
164  group->SendUpdate();
165  }
166 
167  return true;
168  }
ObjectGuid GetLeaderGUID() const
Definition: Group.cpp:2529
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:950
bool GetPlayerGroupAndGUIDByName(const char *cname, Player *&player, Group *&group, ObjectGuid &guid, bool offline=false)
Definition: Chat.cpp:1104
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: ObjectGuid.h:189
void SendUpdate()
Definition: Group.cpp:1567
Definition: Group.h:191
void ChangeLeader(ObjectGuid guid, int8 partyIndex=0)
Definition: Group.cpp:651

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool group_commandscript::HandleGroupListCommand ( ChatHandler handler,
char const args 
)
inlinestatic
260  {
261  // Get ALL the variables!
262  Player* playerTarget;
263  uint32 phase = 0;
264  ObjectGuid guidTarget;
265  std::string nameTarget;
266  std::string zoneName;
267  const char* onlineState = "";
268 
269  // Parse the guid to uint32...
270  ObjectGuid parseGUID = ObjectGuid::Create<HighGuid::Player>(strtoull(args, nullptr, 10));
271 
272  // ... and try to extract a player out of it.
273  if (ObjectMgr::GetPlayerNameByGUID(parseGUID, nameTarget))
274  {
275  playerTarget = ObjectAccessor::FindPlayer(parseGUID);
276  guidTarget = parseGUID;
277  }
278  // If not, we return false and end right away.
279  else if (!handler->extractPlayerTarget((char*)args, &playerTarget, &guidTarget, &nameTarget))
280  return false;
281 
282  // Next, we need a group. So we define a group variable.
283  Group* groupTarget = NULL;
284 
285  // We try to extract a group from an online player.
286  if (playerTarget)
287  groupTarget = playerTarget->GetGroup();
288 
289  // If not, we extract it from the SQL.
290  if (!groupTarget)
291  {
293  stmt->setUInt64(0, guidTarget.GetCounter());
294  PreparedQueryResult resultGroup = CharacterDatabase.Query(stmt);
295  if (resultGroup)
296  groupTarget = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32());
297  }
298 
299  // If both fails, players simply has no party. Return false.
300  if (!groupTarget)
301  {
302  handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, nameTarget.c_str());
303  handler->SetSentErrorMessage(true);
304  return false;
305  }
306 
307  // We get the group members after successfully detecting a group.
308  Group::MemberSlotList const& members = groupTarget->GetMemberSlots();
309 
310  // To avoid a cluster fuck, namely trying multiple queries to simply get a group member count...
311  handler->PSendSysMessage(LANG_GROUP_TYPE, (groupTarget->isRaidGroup() ? "raid" : "party"), members.size());
312  // ... we simply move the group type and member count print after retrieving the slots and simply output it's size.
313 
314  // While rather dirty codestyle-wise, it saves space (if only a little). For each member, we look several informations up.
315  for (Group::MemberSlotList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
316  {
317  // Define temporary variable slot to iterator.
318  Group::MemberSlot const& slot = *itr;
319 
320  // Check for given flag and assign it to that iterator
321  std::string flags;
322  if (slot.flags & MEMBER_FLAG_ASSISTANT)
323  flags = "Assistant";
324 
325  if (slot.flags & MEMBER_FLAG_MAINTANK)
326  {
327  if (!flags.empty())
328  flags.append(", ");
329  flags.append("MainTank");
330  }
331 
332  if (slot.flags & MEMBER_FLAG_MAINASSIST)
333  {
334  if (!flags.empty())
335  flags.append(", ");
336  flags.append("MainAssist");
337  }
338 
339  if (flags.empty())
340  flags = "None";
341 
342  // Check if iterator is online. If is...
343  Player* p = ObjectAccessor::FindPlayer((*itr).guid);
344  if (p)
345  {
346  // ... than, it prints information like "is online", where he is, etc...
347  onlineState = "online";
348  phase = (!p->IsGameMaster() ? p->GetPhaseMask() : -1);
349 
350  AreaTableEntry const* area = sAreaTableStore.LookupEntry(p->GetAreaId());
351  if (area)
352  {
353  AreaTableEntry const* zone = sAreaTableStore.LookupEntry(area->ParentAreaID);
354  if (zone)
355  zoneName = zone->AreaName_lang;
356  }
357  }
358  else
359  {
360  // ... else, everything is set to offline or neutral values.
361  zoneName = "<ERROR>";
362  onlineState = "Offline";
363  phase = 0;
364  }
365 
366  // Now we can print those informations for every single member of each group!
367  handler->PSendSysMessage(LANG_GROUP_PLAYER_NAME_GUID, slot.name.c_str(), onlineState,
368  zoneName.c_str(), phase, slot.guid.ToString().c_str(), flags.c_str(),
369  lfg::GetRolesString(slot.roles).c_str());
370  }
371 
372  // And finish after every iterator is done.
373  return true;
374  }
uint8 roles
Definition: Group.h:201
Definition: DBCStructure.h:37
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
Definition: Group.h:76
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
bool isRaidGroup() const
Definition: Group.cpp:2509
std::list< MemberSlot > MemberSlotList
Definition: Group.h:204
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:950
ObjectGuid guid
Definition: Group.h:196
bool extractPlayerTarget(char *args, Player **player, ObjectGuid *player_guid=NULL, std::string *player_name=NULL)
Definition: Chat.cpp:945
Definition: PreparedStatement.h:74
Definition: Language.h:953
DBCStorage< AreaTableEntry > sAreaTableStore(AreaTablefmt)
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
Definition: ObjectAccessor.cpp:209
Definition: Language.h:952
Definition: Group.h:194
Definition: Group.h:77
std::string GetRolesString(uint8 roles)
Definition: LFG.cpp:40
uint32_t uint32
Definition: Define.h:150
#define sGroupMgr
Definition: GroupMgr.h:59
uint8 flags
Definition: Group.h:200
char * AreaName_lang
Definition: DBCStructure.h:51
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
std::string name
Definition: Group.h:197
uint32 ParentAreaID
Definition: DBCStructure.h:41
MemberSlotList const & GetMemberSlots() const
Definition: Group.h:294
Definition: CharacterDatabase.h:69
static bool GetPlayerNameByGUID(ObjectGuid const &guid, std::string &name)
Definition: ObjectMgr.cpp:2258
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
Definition: Group.h:78
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: ObjectGuid.h:189
uint8 flags
Definition: DisableMgr.cpp:44
std::string ToString() const
Definition: ObjectGuid.cpp:99
Definition: Group.h:191
LowType GetCounter() const
Definition: ObjectGuid.h:221

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool group_commandscript::HandleGroupRemoveCommand ( ChatHandler handler,
char const args 
)
inlinestatic
192  {
193  Player* player = NULL;
194  Group* group = NULL;
195  ObjectGuid guid;
196  char* nameStr = strtok((char*)args, " ");
197 
198  if (!handler->GetPlayerGroupAndGUIDByName(nameStr, player, group, guid))
199  return false;
200 
201  if (!group)
202  {
203  handler->PSendSysMessage(LANG_GROUP_NOT_IN_GROUP, player->GetName().c_str());
204  handler->SetSentErrorMessage(true);
205  return false;
206  }
207 
208  group->RemoveMember(guid);
209  return true;
210  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:950
bool GetPlayerGroupAndGUIDByName(const char *cname, Player *&player, Group *&group, ObjectGuid &guid, bool offline=false)
Definition: Chat.cpp:1104
bool RemoveMember(ObjectGuid guid, const RemoveMethod &method=GROUP_REMOVEMETHOD_DEFAULT, ObjectGuid kicker=ObjectGuid::Empty, const char *reason=NULL)
Definition: Group.cpp:526
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: ObjectGuid.h:189
Definition: Group.h:191

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool group_commandscript::HandleGroupSummonCommand ( ChatHandler handler,
char const args 
)
inlinestatic
52  {
53  Player* target;
54  if (!handler->extractPlayerTarget((char*)args, &target))
55  return false;
56 
57  // check online security
58  if (handler->HasLowerSecurity(target, ObjectGuid::Empty))
59  return false;
60 
61  Group* group = target->GetGroup();
62 
63  std::string nameLink = handler->GetNameLink(target);
64 
65  if (!group)
66  {
67  handler->PSendSysMessage(LANG_NOT_IN_GROUP, nameLink.c_str());
68  handler->SetSentErrorMessage(true);
69  return false;
70  }
71 
72  Player* gmPlayer = handler->GetSession()->GetPlayer();
73  Group* gmGroup = gmPlayer->GetGroup();
74  Map* gmMap = gmPlayer->GetMap();
75  bool toInstance = gmMap->Instanceable();
76 
77  // we are in instance, and can summon only player in our group with us as lead
78  if (toInstance && (
79  !gmGroup || group->GetLeaderGUID() != gmPlayer->GetGUID() ||
80  gmGroup->GetLeaderGUID() != gmPlayer->GetGUID()))
81  // the last check is a bit excessive, but let it be, just in case
82  {
84  handler->SetSentErrorMessage(true);
85  return false;
86  }
87 
88  for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
89  {
90  Player* player = itr->GetSource();
91 
92  if (!player || player == gmPlayer || !player->GetSession())
93  continue;
94 
95  // check online security
96  if (handler->HasLowerSecurity(player, ObjectGuid::Empty))
97  return false;
98 
99  std::string plNameLink = handler->GetNameLink(player);
100 
101  if (player->IsBeingTeleported())
102  {
103  handler->PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
104  handler->SetSentErrorMessage(true);
105  return false;
106  }
107 
108  if (toInstance)
109  {
110  Map* playerMap = player->GetMap();
111 
112  if (playerMap->Instanceable() && playerMap->GetInstanceId() != gmMap->GetInstanceId())
113  {
114  // cannot summon from instance to instance
115  handler->PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST, plNameLink.c_str());
116  handler->SetSentErrorMessage(true);
117  return false;
118  }
119  }
120 
121  handler->PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(), "");
122  if (handler->needReportToTarget(player))
123  ChatHandler(player->GetSession()).PSendSysMessage(LANG_SUMMONED_BY, handler->GetNameLink().c_str());
124 
125  // stop flight if need
126  if (player->IsInFlight())
127  {
128  player->GetMotionMaster()->MovementExpired();
129  player->CleanupAfterTaxiFlight();
130  }
131  // save only in non-flight case
132  else
133  player->SaveRecallPosition();
134 
135  // before GM
136  float x, y, z;
137  gmPlayer->GetClosePoint(x, y, z, player->GetObjectSize());
138  player->TeleportTo(gmPlayer->GetMapId(), x, y, z, player->GetOrientation());
139  }
140 
141  return true;
142  }
Definition: Language.h:141
ObjectGuid GetLeaderGUID() const
Definition: Group.cpp:2529
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
static ObjectGuid const Empty
Definition: ObjectGuid.h:196
Definition: Language.h:133
arena_t NULL
Definition: jemalloc_internal.h:624
Player * GetPlayer() const
Definition: WorldSession.h:927
Definition: Language.h:132
bool extractPlayerTarget(char *args, Player **player, ObjectGuid *player_guid=NULL, std::string *player_name=NULL)
Definition: Chat.cpp:945
bool HasLowerSecurity(Player *target, ObjectGuid guid, bool strong=false)
Definition: Chat.cpp:77
virtual std::string GetNameLink() const
Definition: Chat.h:101
G3D::int16 z
Definition: Vector3int16.h:46
G3D::int16 y
Definition: Vector2int16.h:38
GroupReference * GetFirstMember()
Definition: Group.h:295
Definition: Map.h:259
Definition: Chat.h:56
WorldSession * GetSession()
Definition: Chat.h:59
bool Instanceable() const
Definition: Map.h:394
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:126
Definition: Language.h:127
G3D::int16 x
Definition: Vector2int16.h:37
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
virtual bool needReportToTarget(Player *chr) const
Definition: Chat.cpp:1056
uint32 GetInstanceId() const
Definition: Map.h:368
Definition: Group.h:191
Definition: GroupReference.h:27

+ 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: