summaryrefslogtreecommitdiff
path: root/src/server/shared/Realms/RealmList.h
blob: cb85b32922ec42f6b5b360ff2e20e0e54a7c090f (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
/*
 * 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 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/>.
 */

#ifndef _REALMLIST_H
#define _REALMLIST_H

#include "Define.h"
#include "Realm.h"
#include <boost/asio/steady_timer.hpp>
#include <array>
#include <map>
#include <memory> // NOTE: this import is NEEDED (even though some IDEs report it as unused)
#include <vector>

namespace Acore::Asio
{
    class IoContext;
}

namespace boost::system
{
    class error_code;
}

struct RealmBuildInfo
{
    uint32 Build;
    uint32 MajorVersion;
    uint32 MinorVersion;
    uint32 BugfixVersion;
    std::array<char, 4> HotfixVersion;
    std::array<uint8, 20> WindowsHash;
    std::array<uint8, 20> MacHash;
};

/// Storage object for the list of realms on the server
class AC_SHARED_API RealmList
{
public:
    typedef std::map<RealmHandle, Realm> RealmMap;

    static RealmList* Instance();

    void Initialize(Acore::Asio::IoContext& ioContext, uint32 updateInterval);
    void Close();

    [[nodiscard]] RealmMap const& GetRealms() const { return _realms; }
    [[nodiscard]] Realm const* GetRealm(RealmHandle const& id) const;

    [[nodiscard]] RealmBuildInfo const* GetBuildInfo(uint32 build) const;

private:
    RealmList();
    ~RealmList() = default;

    void LoadBuildInfo();
    void UpdateRealms(boost::system::error_code const& error);
    void UpdateRealm(RealmHandle const& id, uint32 build, std::string const& name,
        boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr, boost::asio::ip::address&& localSubmask,
        uint16 port, uint8 icon, RealmFlags flag, uint8 realmTimezone, AccountTypes allowedSecurityLevel, float population);

    std::vector<RealmBuildInfo> _builds;
    RealmMap _realms;
    uint32 _updateInterval{0};
    std::unique_ptr<boost::asio::steady_timer> _updateTimer;
    std::unique_ptr<Acore::Asio::Resolver> _resolver;
};

#define sRealmList RealmList::Instance()

#endif