TrinityCore
Loading...
Searching...
No Matches
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 "DatabaseEnv.h"
22#include "Group.h"
23#include "GroupMgr.h"
24#include "Language.h"
25#include "LFGMgr.h"
26#include "ObjectAccessor.h"
27#include "Player.h"
28#include "RBAC.h"
29
30using namespace Trinity::ChatCommands;
31
32void PrintPlayerInfo(ChatHandler* handler, Player const* player)
33{
34 if (!player)
35 return;
36
37 ObjectGuid guid = player->GetGUID();
38 lfg::LfgDungeonSet dungeons = sLFGMgr->GetSelectedDungeons(guid);
39
40 std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
41 handler->PSendSysMessage(LANG_LFG_PLAYER_INFO, player->GetName().c_str(),
42 state.c_str(), uint8(dungeons.size()), lfg::ConcatenateDungeons(dungeons).c_str(),
43 lfg::GetRolesString(sLFGMgr->GetRoles(guid)).c_str(), sLFGMgr->GetComment(guid).c_str());
44}
45
47{
48public:
49 lfg_commandscript() : CommandScript("lfg_commandscript") { }
50
52 {
53 static ChatCommandTable lfgCommandTable =
54 {
60 };
61
62 static ChatCommandTable commandTable =
63 {
64 { "lfg", lfgCommandTable },
65 };
66 return commandTable;
67 }
68
70 {
71 if (!player)
72 player = PlayerIdentifier::FromTargetOrSelf(handler);
73 if (!player)
74 return false;
75
76 if (Player* target = player->GetConnectedPlayer())
77 {
78 PrintPlayerInfo(handler, target);
79 return true;
80 }
81
82 return false;
83 }
84
86 {
87 if (!player)
88 player = PlayerIdentifier::FromTargetOrSelf(handler);
89 if (!player)
90 return false;
91
92 Group* groupTarget = nullptr;
93
94 if (Player* target = player->GetConnectedPlayer())
95 groupTarget = target->GetGroup();
96 else
97 {
99 stmt->setUInt32(0, player->GetGUID().GetCounter());
100 PreparedQueryResult resultGroup = CharacterDatabase.Query(stmt);
101 if (resultGroup)
102 groupTarget = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32());
103 }
104
105 if (!groupTarget)
106 {
107 handler->PSendSysMessage(LANG_LFG_NOT_IN_GROUP, player->GetName().c_str());
108 handler->SetSentErrorMessage(true);
109 return false;
110 }
111
112 ObjectGuid guid = groupTarget->GetGUID();
113 std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
114 handler->PSendSysMessage(LANG_LFG_GROUP_INFO, groupTarget->isLFGGroup(),
115 state.c_str(), sLFGMgr->GetDungeon(guid));
116
117 for (Group::MemberSlot const& slot : groupTarget->GetMemberSlots())
118 {
119 Player* p = ObjectAccessor::FindPlayer(slot.guid);
120 if (p)
121 PrintPlayerInfo(handler, p);
122 else
123 handler->PSendSysMessage("%s is offline.", slot.name.c_str());
124 }
125
126 return true;
127 }
128
129 static bool HandleLfgOptionsCommand(ChatHandler* handler, Optional<uint32> optionsArg)
130 {
131 if (optionsArg)
132 {
133 sLFGMgr->SetOptions(*optionsArg);
135 }
136 handler->PSendSysMessage(LANG_LFG_OPTIONS, sLFGMgr->GetOptions());
137 return true;
138 }
139
140 static bool HandleLfgQueueInfoCommand(ChatHandler* handler, Tail full)
141 {
142 handler->SendSysMessage(sLFGMgr->DumpQueueInfo(!full.empty()).c_str(), true);
143 return true;
144 }
145
146 static bool HandleLfgCleanCommand(ChatHandler* handler)
147 {
149 sLFGMgr->Clean();
150 return true;
151 }
152};
153
155{
156 new lfg_commandscript();
157}
@ CHAR_SEL_GROUP_MEMBER
std::shared_ptr< PreparedResultSet > PreparedQueryResult
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
uint8_t uint8
Definition Define.h:135
#define sGroupMgr
Definition GroupMgr.h:58
#define sLFGMgr
Definition LFGMgr.h:492
@ LANG_LFG_OPTIONS
Definition Language.h:1185
@ LANG_LFG_NOT_IN_GROUP
Definition Language.h:1183
@ LANG_LFG_GROUP_INFO
Definition Language.h:1182
@ LANG_LFG_PLAYER_INFO
Definition Language.h:1181
@ LANG_LFG_OPTIONS_CHANGED
Definition Language.h:1186
@ LANG_LFG_CLEAN
Definition Language.h:1184
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
Role Based Access Control related classes definition.
void SetSentErrorMessage(bool val)
Definition Chat.h:134
void PSendSysMessage(char const *fmt, Args &&... args)
Definition Chat.h:69
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition Chat.cpp:101
Definition Group.h:165
MemberSlotList const & GetMemberSlots() const
Definition Group.h:246
bool isLFGGroup() const
Definition Group.cpp:2443
ObjectGuid GetGUID() const
Definition Group.cpp:2473
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
void setUInt32(uint8 index, uint32 value)
std::string const & GetName() const
Definition Object.h:382
static bool HandleLfgGroupInfoCommand(ChatHandler *handler, Optional< PlayerIdentifier > player)
Definition cs_lfg.cpp:85
ChatCommandTable GetCommands() const override
Definition cs_lfg.cpp:51
static bool HandleLfgQueueInfoCommand(ChatHandler *handler, Tail full)
Definition cs_lfg.cpp:140
static bool HandleLfgOptionsCommand(ChatHandler *handler, Optional< uint32 > optionsArg)
Definition cs_lfg.cpp:129
static bool HandleLfgCleanCommand(ChatHandler *handler)
Definition cs_lfg.cpp:146
static bool HandleLfgPlayerInfoCommand(ChatHandler *handler, Optional< PlayerIdentifier > player)
Definition cs_lfg.cpp:69
void AddSC_lfg_commandscript()
Definition cs_lfg.cpp:154
void PrintPlayerInfo(ChatHandler *handler, Player const *player)
Definition cs_lfg.cpp:32
TC_GAME_API Player * FindPlayer(ObjectGuid const &)
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:50
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:102
std::string ConcatenateDungeons(LfgDungeonSet const &dungeons)
Definition LFG.cpp:26
@ RBAC_PERM_COMMAND_LFG_OPTIONS
Definition RBAC.h:305
@ RBAC_PERM_COMMAND_LFG_GROUP
Definition RBAC.h:302
@ RBAC_PERM_COMMAND_LFG_PLAYER
Definition RBAC.h:301
@ RBAC_PERM_COMMAND_LFG_QUEUE
Definition RBAC.h:303
@ RBAC_PERM_COMMAND_LFG_CLEAN
Definition RBAC.h:304
static Optional< PlayerIdentifier > FromTargetOrSelf(ChatHandler *handler)