summaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands/cs_lfg.cpp
blob: e984dbb6514b6f870f2360bd43c9ca8020d289e7 (plain)
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
/*
 * This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by the
 * Free Software Foundation; either version 3 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 Affero 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 "Chat.h"
#include "CommandScript.h"
#include "Group.h"
#include "LFGMgr.h"
#include "Language.h"
#include "Player.h"

void GetPlayerInfo(ChatHandler*  handler, Player* player)
{
    if (!player)
        return;

    ObjectGuid guid = player->GetGUID();
    lfg::LfgDungeonSet dungeons = sLFGMgr->GetSelectedDungeons(guid);

    std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
    handler->PSendSysMessage(LANG_LFG_PLAYER_INFO, player->GetName(),
                             state, uint8(dungeons.size()), lfg::ConcatenateDungeons(dungeons),
                             lfg::GetRolesString(sLFGMgr->GetRoles(guid)), sLFGMgr->GetComment(guid));
}

using namespace Acore::ChatCommands;

class lfg_commandscript : public CommandScript
{
public:
    lfg_commandscript() : CommandScript("lfg_commandscript") { }

    ChatCommandTable GetCommands() const override
    {
        static ChatCommandTable lfgCommandTable =
        {
            { "player",  HandleLfgPlayerInfoCommand, SEC_MODERATOR,     Console::No },
            { "group",   HandleLfgGroupInfoCommand,  SEC_MODERATOR,     Console::No },
            { "queue",   HandleLfgQueueInfoCommand,  SEC_MODERATOR,     Console::Yes },
            { "clean",   HandleLfgCleanCommand,      SEC_ADMINISTRATOR, Console::Yes },
            { "options", HandleLfgOptionsCommand,    SEC_GAMEMASTER,    Console::Yes },
        };

        static ChatCommandTable commandTable =
        {
            { "lfg", lfgCommandTable },
        };
        return commandTable;
    }

    static bool HandleLfgPlayerInfoCommand(ChatHandler* handler, Optional<PlayerIdentifier> player)
    {
        if (!player)
            player = PlayerIdentifier::FromTargetOrSelf(handler);
        if (!player)
            return false;

        if (Player* target = player->GetConnectedPlayer())
        {
            GetPlayerInfo(handler, target);
            return true;
        }

        return false;
    }

    static bool HandleLfgGroupInfoCommand(ChatHandler* handler, Optional<PlayerIdentifier> player)
    {
        if (!player)
            player = PlayerIdentifier::FromTargetOrSelf(handler);
        if (!player)
            return false;

        Group* groupTarget = nullptr;
        if (Player* target = player->GetConnectedPlayer())
            groupTarget = target->GetGroup();
        if (!groupTarget)
        {
            handler->PSendSysMessage(LANG_LFG_NOT_IN_GROUP, player->GetName());
            return true;
        }

        ObjectGuid guid = groupTarget->GetGUID();
        std::string const& state = lfg::GetStateString(sLFGMgr->GetState(guid));
        handler->PSendSysMessage(LANG_LFG_GROUP_INFO, groupTarget->isLFGGroup(),
                                 state, sLFGMgr->GetDungeon(guid));

        for (GroupReference* itr = groupTarget->GetFirstMember(); itr != nullptr; itr = itr->next())
            GetPlayerInfo(handler, itr->GetSource());

        return true;
    }

    static bool HandleLfgOptionsCommand(ChatHandler* handler, Optional<uint32> optionsArg)
    {
        if (optionsArg)
        {
            sLFGMgr->SetOptions(*optionsArg);
            handler->PSendSysMessage(LANG_LFG_OPTIONS_CHANGED);
        }
        handler->PSendSysMessage(LANG_LFG_OPTIONS, sLFGMgr->GetOptions());
        return true;
    }

    static bool HandleLfgQueueInfoCommand(ChatHandler* /*handler*/)
    {
        return true;
    }

    static bool HandleLfgCleanCommand(ChatHandler* handler)
    {
        handler->PSendSysMessage(LANG_LFG_CLEAN);
        sLFGMgr->Clean();
        return true;
    }
};

void AddSC_lfg_commandscript()
{
    new lfg_commandscript();
}