TrinityCore
cs_lfg.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ScriptMgr.h"
19#include "CharacterCache.h"
20#include "Chat.h"
21#include "ChatCommand.h"
22#include "DatabaseEnv.h"
23#include "Group.h"
24#include "GroupMgr.h"
25#include "Language.h"
26#include "LFGMgr.h"
27#include "ObjectAccessor.h"
28#include "Player.h"
29#include "RBAC.h"
30
31using namespace Trinity::ChatCommands;
32
33void PrintPlayerInfo(ChatHandler* handler, Player const* player)
34{
35 if (!player)
36 return;
37
38 ObjectGuid guid = player->GetGUID();
39 lfg::LfgDungeonSet dungeons = sLFGMgr->GetSelectedDungeons(guid);
40
41 std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
42 handler->PSendSysMessage(LANG_LFG_PLAYER_INFO, player->GetName().c_str(),
43 state.c_str(), uint8(dungeons.size()), lfg::ConcatenateDungeons(dungeons).c_str(),
44 lfg::GetRolesString(sLFGMgr->GetRoles(guid)).c_str());
45}
46
48{
49public:
50 lfg_commandscript() : CommandScript("lfg_commandscript") { }
51
53 {
54 static ChatCommandTable lfgCommandTable =
55 {
61 };
62
63 static ChatCommandTable commandTable =
64 {
65 { "lfg", lfgCommandTable },
66 };
67 return commandTable;
68 }
69
71 {
72 if (!player)
73 player = PlayerIdentifier::FromTargetOrSelf(handler);
74 if (!player)
75 return false;
76
77 if (Player* target = player->GetConnectedPlayer())
78 {
79 PrintPlayerInfo(handler, target);
80 return true;
81 }
82
83 return false;
84 }
85
87 {
88 if (!player)
89 player = PlayerIdentifier::FromTargetOrSelf(handler);
90 if (!player)
91 return false;
92
93 Group* groupTarget = nullptr;
94
95 if (Player* target = player->GetConnectedPlayer())
96 groupTarget = target->GetGroup();
97 else
98 {
100 stmt->setUInt64(0, player->GetGUID().GetCounter());
101 PreparedQueryResult resultGroup = CharacterDatabase.Query(stmt);
102 if (resultGroup)
103 groupTarget = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32());
104 }
105
106 if (!groupTarget)
107 {
108 handler->PSendSysMessage(LANG_LFG_NOT_IN_GROUP, player->GetName().c_str());
109 handler->SetSentErrorMessage(true);
110 return false;
111 }
112
113 ObjectGuid guid = groupTarget->GetGUID();
114 std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
115 handler->PSendSysMessage(LANG_LFG_GROUP_INFO, groupTarget->isLFGGroup(),
116 state.c_str(), sLFGMgr->GetDungeon(guid));
117
118 for (Group::MemberSlot const& slot : groupTarget->GetMemberSlots())
119 {
120 Player* p = ObjectAccessor::FindPlayer(slot.guid);
121 if (p)
122 PrintPlayerInfo(handler, p);
123 else
124 handler->PSendSysMessage("%s is offline.", slot.name.c_str());
125 }
126
127 return true;
128 }
129
130 static bool HandleLfgOptionsCommand(ChatHandler* handler, Optional<uint32> optionsArg)
131 {
132 if (optionsArg)
133 {
134 sLFGMgr->SetOptions(*optionsArg);
136 }
137 handler->PSendSysMessage(LANG_LFG_OPTIONS, sLFGMgr->GetOptions());
138 return true;
139 }
140
141 static bool HandleLfgQueueInfoCommand(ChatHandler* handler, Tail full)
142 {
143 handler->SendSysMessage(sLFGMgr->DumpQueueInfo(!full.empty()).c_str(), true);
144 return true;
145 }
146
147 static bool HandleLfgCleanCommand(ChatHandler* handler)
148 {
150 sLFGMgr->Clean();
151 return true;
152 }
153};
154
156{
157 new lfg_commandscript();
158}
@ CHAR_SEL_GROUP_MEMBER
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
uint8_t uint8
Definition: Define.h:144
#define sGroupMgr
Definition: GroupMgr.h:61
#define sLFGMgr
Definition: LFGMgr.h:507
@ LANG_LFG_OPTIONS
Definition: Language.h:1182
@ LANG_LFG_NOT_IN_GROUP
Definition: Language.h:1180
@ LANG_LFG_GROUP_INFO
Definition: Language.h:1179
@ LANG_LFG_PLAYER_INFO
Definition: Language.h:1178
@ LANG_LFG_OPTIONS_CHANGED
Definition: Language.h:1183
@ LANG_LFG_CLEAN
Definition: Language.h:1181
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
Role Based Access Control related classes definition.
void PSendSysMessage(const char *fmt, Args &&... args)
Definition: Chat.h:57
void SetSentErrorMessage(bool val)
Definition: Chat.h:114
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:113
Definition: Group.h:197
MemberSlotList const & GetMemberSlots() const
Definition: Group.h:324
bool isLFGGroup() const
Definition: Group.cpp:1633
ObjectGuid GetGUID() const
Definition: Group.cpp:1663
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
void setUInt64(const uint8 index, const uint64 value)
std::string const & GetName() const
Definition: Object.h:555
static bool HandleLfgGroupInfoCommand(ChatHandler *handler, Optional< PlayerIdentifier > player)
Definition: cs_lfg.cpp:86
ChatCommandTable GetCommands() const override
Definition: cs_lfg.cpp:52
static bool HandleLfgQueueInfoCommand(ChatHandler *handler, Tail full)
Definition: cs_lfg.cpp:141
static bool HandleLfgOptionsCommand(ChatHandler *handler, Optional< uint32 > optionsArg)
Definition: cs_lfg.cpp:130
static bool HandleLfgCleanCommand(ChatHandler *handler)
Definition: cs_lfg.cpp:147
static bool HandleLfgPlayerInfoCommand(ChatHandler *handler, Optional< PlayerIdentifier > player)
Definition: cs_lfg.cpp:70
void AddSC_lfg_commandscript()
Definition: cs_lfg.cpp:155
void PrintPlayerInfo(ChatHandler *handler, Player const *player)
Definition: cs_lfg.cpp:33
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:49
std::string GetStateString(LfgState state)
Definition: LFG.cpp:75
std::string GetRolesString(uint8 roles)
Definition: LFG.cpp:41
std::set< uint32 > LfgDungeonSet
Definition: LFG.h:132
std::string ConcatenateDungeons(LfgDungeonSet const &dungeons)
Definition: LFG.cpp:26
@ RBAC_PERM_COMMAND_LFG_OPTIONS
Definition: RBAC.h:307
@ RBAC_PERM_COMMAND_LFG_GROUP
Definition: RBAC.h:304
@ RBAC_PERM_COMMAND_LFG_PLAYER
Definition: RBAC.h:303
@ RBAC_PERM_COMMAND_LFG_QUEUE
Definition: RBAC.h:305
@ RBAC_PERM_COMMAND_LFG_CLEAN
Definition: RBAC.h:306