TrinityCore
Loading...
Searching...
No Matches
RealmList.h
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#ifndef _REALMLIST_H
19#define _REALMLIST_H
20
21#include "ClientBuildInfo.h"
22#include "Define.h"
23#include "Duration.h"
24#include "Optional.h"
25#include "Realm.h"
26#include <array>
27#include <map>
28#include <memory>
29#include <shared_mutex>
30#include <unordered_set>
31#include <vector>
32
34{
35class ClientResponse;
36class GetAllValuesForAttributeResponse;
37}
38
39namespace JSON::RealmList
40{
41class RealmEntry;
42}
43
46{
47public:
48 typedef std::map<Battlenet::RealmHandle, std::shared_ptr<Realm>> RealmMap;
49
50 static RealmList* Instance();
51
52 RealmList(RealmList const&) = delete;
53 RealmList(RealmList&&) = delete;
54 RealmList& operator=(RealmList const&) = delete;
56
58
59 void Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInterval);
60 void Close();
61
62 std::shared_ptr<Realm const> GetRealm(Battlenet::RealmHandle const& id) const;
63 Battlenet::RealmHandle GetCurrentRealmId() const;
64 void SetCurrentRealmId(Battlenet::RealmHandle const& id);
65 std::shared_ptr<Realm const> GetCurrentRealm() const;
66
68 std::vector<uint8> GetRealmEntryJSON(Battlenet::RealmHandle const& id, uint32 build, AccountTypes accountSecurityLevel) const;
69 std::vector<uint8> GetRealmList(uint32 build, AccountTypes accountSecurityLevel, std::string const& subRegion) const;
70 uint32 JoinRealm(uint32 realmAddress, uint32 build, ClientBuild::VariantId const& buildVariant, boost::asio::ip::address const& clientAddress,
71 std::array<uint8, 32> const& clientSecret, LocaleConstant locale, std::string const& os, Minutes timezoneOffset, std::string const& accountName,
72 AccountTypes accountSecurityLevel, bgs::protocol::game_utilities::v1::ClientResponse* response) const;
73
74private:
75 RealmList();
76
77 void UpdateRealms();
78 static void UpdateRealm(Realm& realm, Battlenet::RealmHandle const& id, uint32 build, std::string const& name,
79 std::vector<boost::asio::ip::address>&& addresses,
80 uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, RealmPopulationState population);
81 void FillRealmEntry(Realm const& realm, uint32 clientBuild, AccountTypes accountSecurityLevel, JSON::RealmList::RealmEntry* realmEntry) const;
82
83 mutable std::shared_mutex _realmsMutex;
85 std::map<Battlenet::RealmHandle, std::string> _removedRealms;
86 std::unordered_set<std::string> _subRegions;
88 std::unique_ptr<Trinity::Asio::DeadlineTimer> _updateTimer;
89 std::unique_ptr<Trinity::Net::Resolver> _resolver;
91};
92
93#define sRealmList RealmList::Instance()
94
95#endif
LocaleConstant
Definition Common.h:51
AccountTypes
Definition Common.h:42
uint8_t uint8
Definition Define.h:156
#define TC_SHARED_API
Definition Define.h:123
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
std::chrono::minutes Minutes
Minutes shorthand typedef.
Definition Duration.h:32
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
RealmFlags
Definition Realm.h:28
RealmPopulationState
Definition Realm.h:43
Storage object for the list of realms on the server.
Definition RealmList.h:46
RealmList(RealmList const &)=delete
std::map< Battlenet::RealmHandle, std::shared_ptr< Realm > > RealmMap
Definition RealmList.h:48
std::map< Battlenet::RealmHandle, std::string > _removedRealms
Definition RealmList.h:85
RealmMap _realms
Definition RealmList.h:84
RealmList(RealmList &&)=delete
RealmList & operator=(RealmList const &)=delete
RealmList & operator=(RealmList &&)=delete
std::unordered_set< std::string > _subRegions
Definition RealmList.h:86
uint32 _updateInterval
Definition RealmList.h:87
Optional< Battlenet::RealmHandle > _currentRealmId
Definition RealmList.h:90
std::shared_mutex _realmsMutex
Definition RealmList.h:83
std::unique_ptr< Trinity::Net::Resolver > _resolver
Definition RealmList.h:89
std::unique_ptr< Trinity::Asio::DeadlineTimer > _updateTimer
Definition RealmList.h:88
Definition Realm.h:139