summaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands/cs_player_settings.cpp
blob: 01ec08fe56b6e08c28d845193269ce7c109bbd7d (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
/*
 * 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 "Player.h"
#include "PlayerSettings.h"

using namespace Acore::ChatCommands;

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

    ChatCommandTable GetCommands() const override
    {
        static ChatCommandTable playerSettingsCommandTable =
        {
            { "announcer", HandleSettingsAnnouncerFlags, SEC_MODERATOR, Console::No },
        };
        static ChatCommandTable commandTable =
        {
            { "settings", playerSettingsCommandTable },
        };
        return commandTable;
    }

    static bool HandleSettingsAnnouncerFlags(ChatHandler* handler, std::string type, bool on)
    {
        Player* player = handler->GetPlayer();

        PlayerSetting setting;
        setting = player->GetPlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS);

        if (type == "bg")
        {
            on ? setting.RemoveFlag(ANNOUNCER_FLAG_DISABLE_BG_QUEUE) : setting.AddFlag(ANNOUNCER_FLAG_DISABLE_BG_QUEUE);
            player->UpdatePlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS, setting.value);
        }
        else if (type == "arena")
        {
            on ? setting.RemoveFlag(ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE) : setting.AddFlag(ANNOUNCER_FLAG_DISABLE_ARENA_QUEUE);
            player->UpdatePlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS, setting.value);
        }
        else if (type == "autobroadcast")
        {
            if (player->GetLevel() < sWorld->getIntConfig(CONFIG_AUTOBROADCAST_MIN_LEVEL_DISABLE))
            {
                handler->SetSentErrorMessage(true);
                handler->PSendSysMessage(LANG_CMD_AUTOBROADCAST_LVL_ERROR, sWorld->getIntConfig(CONFIG_AUTOBROADCAST_MIN_LEVEL_DISABLE));
            }

            on ? setting.RemoveFlag(ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST) : setting.AddFlag(ANNOUNCER_FLAG_DISABLE_AUTOBROADCAST);
            player->UpdatePlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS, setting.value);
        }

        handler->SetSentErrorMessage(false);
        handler->PSendSysMessage(on ? LANG_CMD_SETTINGS_ANNOUNCER_ON : LANG_CMD_SETTINGS_ANNOUNCER_OFF, type);
        return true;
    }
};

void AddSC_player_settings_commandscript()
{
    new player_settings_commandscript();
}