Files
TCPlayerbotCore/src/server/scripts/Commands/cs_lfg.cpp
T

159 lines
5.3 KiB
C++
Raw Normal View History

2012-10-23 11:44:02 +02:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2012-10-23 11:44:02 +02:00
*
* 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/>.
*/
2017-05-20 00:09:37 +02:00
#include "ScriptMgr.h"
#include "CharacterCache.h"
2012-10-23 11:44:02 +02:00
#include "Chat.h"
#include "ChatCommand.h"
2017-05-18 23:52:58 +02:00
#include "DatabaseEnv.h"
#include "Group.h"
#include "GroupMgr.h"
#include "Language.h"
2012-10-23 11:44:02 +02:00
#include "LFGMgr.h"
2017-06-04 01:00:45 +02:00
#include "ObjectAccessor.h"
#include "Player.h"
2017-05-20 00:09:37 +02:00
#include "RBAC.h"
2012-10-23 11:44:02 +02:00
using namespace Trinity::ChatCommands;
void PrintPlayerInfo(ChatHandler* handler, Player const* player)
2012-10-23 11:44:02 +02:00
{
if (!player)
return;
ObjectGuid guid = player->GetGUID();
lfg::LfgDungeonSet dungeons = sLFGMgr->GetSelectedDungeons(guid);
2012-10-23 11:44:02 +02:00
std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
handler->PSendSysMessage(LANG_LFG_PLAYER_INFO, player->GetName().c_str(),
state.c_str(), uint8(dungeons.size()), lfg::ConcatenateDungeons(dungeons).c_str(),
lfg::GetRolesString(sLFGMgr->GetRoles(guid)).c_str());
2012-10-23 11:44:02 +02:00
}
class lfg_commandscript : public CommandScript
{
public:
lfg_commandscript() : CommandScript("lfg_commandscript") { }
ChatCommandTable GetCommands() const override
2012-10-23 11:44:02 +02:00
{
static ChatCommandTable lfgCommandTable =
2012-10-23 11:44:02 +02:00
{
{ "player", HandleLfgPlayerInfoCommand, rbac::RBAC_PERM_COMMAND_LFG_PLAYER, Console::No },
{ "group", HandleLfgGroupInfoCommand, rbac::RBAC_PERM_COMMAND_LFG_GROUP, Console::No },
{ "queue", HandleLfgQueueInfoCommand, rbac::RBAC_PERM_COMMAND_LFG_QUEUE, Console::Yes },
{ "clean", HandleLfgCleanCommand, rbac::RBAC_PERM_COMMAND_LFG_CLEAN, Console::Yes },
{ "options", HandleLfgOptionsCommand, rbac::RBAC_PERM_COMMAND_LFG_OPTIONS, Console::Yes },
2012-10-23 11:44:02 +02:00
};
static ChatCommandTable commandTable =
2012-10-23 11:44:02 +02:00
{
{ "lfg", lfgCommandTable },
2012-10-23 11:44:02 +02:00
};
return commandTable;
}
static bool HandleLfgPlayerInfoCommand(ChatHandler* handler, Optional<PlayerIdentifier> player)
2012-10-23 11:44:02 +02:00
{
if (!player)
player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player)
2012-10-23 11:44:02 +02:00
return false;
if (Player* target = player->GetConnectedPlayer())
{
PrintPlayerInfo(handler, target);
return true;
}
return false;
2012-10-23 11:44:02 +02:00
}
static bool HandleLfgGroupInfoCommand(ChatHandler* handler, Optional<PlayerIdentifier> player)
2012-10-23 11:44:02 +02:00
{
if (!player)
player = PlayerIdentifier::FromTargetOrSelf(handler);
if (!player)
2012-10-23 11:44:02 +02:00
return false;
2020-08-14 17:06:03 +02:00
Group* groupTarget = nullptr;
if (Player* target = player->GetConnectedPlayer())
groupTarget = target->GetGroup();
else
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GROUP_MEMBER);
stmt->setUInt64(0, player->GetGUID().GetCounter());
PreparedQueryResult resultGroup = CharacterDatabase.Query(stmt);
if (resultGroup)
groupTarget = sGroupMgr->GetGroupByDbStoreId((*resultGroup)[0].GetUInt32());
}
if (!groupTarget)
2012-10-23 11:44:02 +02:00
{
handler->PSendSysMessage(LANG_LFG_NOT_IN_GROUP, player->GetName().c_str());
handler->SetSentErrorMessage(true);
return false;
2012-10-23 11:44:02 +02:00
}
ObjectGuid guid = groupTarget->GetGUID();
std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
handler->PSendSysMessage(LANG_LFG_GROUP_INFO, groupTarget->isLFGGroup(),
state.c_str(), sLFGMgr->GetDungeon(guid));
2012-10-23 11:44:02 +02:00
for (Group::MemberSlot const& slot : groupTarget->GetMemberSlots())
{
Player* p = ObjectAccessor::FindPlayer(slot.guid);
if (p)
PrintPlayerInfo(handler, p);
else
handler->PSendSysMessage("%s is offline.", slot.name.c_str());
}
2012-10-23 11:44:02 +02:00
return true;
}
static bool HandleLfgOptionsCommand(ChatHandler* handler, Optional<uint32> optionsArg)
2012-10-23 11:44:02 +02:00
{
if (optionsArg)
2012-10-23 11:44:02 +02:00
{
sLFGMgr->SetOptions(*optionsArg);
2012-10-23 11:44:02 +02:00
handler->PSendSysMessage(LANG_LFG_OPTIONS_CHANGED);
}
handler->PSendSysMessage(LANG_LFG_OPTIONS, sLFGMgr->GetOptions());
return true;
}
static bool HandleLfgQueueInfoCommand(ChatHandler* handler, Tail full)
2012-10-23 11:44:02 +02:00
{
handler->SendSysMessage(sLFGMgr->DumpQueueInfo(!full.empty()).c_str(), true);
2012-10-23 11:44:02 +02:00
return true;
}
static bool HandleLfgCleanCommand(ChatHandler* handler)
2012-10-23 11:44:02 +02:00
{
handler->PSendSysMessage(LANG_LFG_CLEAN);
sLFGMgr->Clean();
return true;
}
};
void AddSC_lfg_commandscript()
{
new lfg_commandscript();
}