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
33namespace JSON::RealmList
34{
35class RealmEntry;
36}
37
39{
41 std::vector<uint8> JoinTicket;
42 std::vector<uint8> ServerAddresses;
43 std::vector<uint8> JoinSecret;
44};
45
48{
49public:
50 typedef std::map<Battlenet::RealmHandle, std::shared_ptr<Realm>> RealmMap;
51
52 static RealmList* Instance();
53
54 RealmList(RealmList const&) = delete;
55 RealmList(RealmList&&) = delete;
56 RealmList& operator=(RealmList const&) = delete;
58
60
61 void Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInterval);
62 void Close();
63
64 std::shared_ptr<Realm const> GetRealm(Battlenet::RealmHandle const& id) const;
65 Battlenet::RealmHandle GetCurrentRealmId() const;
66 void SetCurrentRealmId(Battlenet::RealmHandle const& id);
67 std::shared_ptr<Realm const> GetCurrentRealm() const;
68
69 std::vector<std::string> GetSubRegions() const;
70 std::string GetRealmEntryJSON(Battlenet::RealmHandle const& id, uint32 build, AccountTypes accountSecurityLevel) const;
71 std::vector<uint8> GetRealmList(uint32 build, AccountTypes accountSecurityLevel, std::string const& subRegion) const;
72 RealmJoinResult JoinRealm(uint32 realmAddress, uint32 build, ClientBuild::VariantId const& buildVariant, boost::asio::ip::address const& clientAddress,
73 std::array<uint8, 32> const& clientSecret, LocaleConstant locale, std::string const& os, Minutes timezoneOffset, std::string const& accountName,
74 AccountTypes accountSecurityLevel) const;
75
76private:
77 RealmList();
78
79 void UpdateRealms();
80 static void UpdateRealm(Realm& realm, Battlenet::RealmHandle const& id, uint32 build, std::string const& name,
81 std::vector<boost::asio::ip::address>&& addresses,
82 uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, RealmPopulationState population);
83 void FillRealmEntry(Realm const& realm, uint32 clientBuild, AccountTypes accountSecurityLevel, JSON::RealmList::RealmEntry* realmEntry) const;
84
85 mutable std::shared_mutex _realmsMutex;
87 std::map<Battlenet::RealmHandle, std::string> _removedRealms;
88 std::unordered_set<std::string> _subRegions;
90 std::unique_ptr<Trinity::Asio::DeadlineTimer> _updateTimer;
91 std::unique_ptr<Trinity::Net::Resolver> _resolver;
93};
94
95#define sRealmList RealmList::Instance()
96
97#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:48
RealmList(RealmList const &)=delete
std::map< Battlenet::RealmHandle, std::shared_ptr< Realm > > RealmMap
Definition RealmList.h:50
std::map< Battlenet::RealmHandle, std::string > _removedRealms
Definition RealmList.h:87
RealmMap _realms
Definition RealmList.h:86
RealmList(RealmList &&)=delete
RealmList & operator=(RealmList const &)=delete
RealmList & operator=(RealmList &&)=delete
std::unordered_set< std::string > _subRegions
Definition RealmList.h:88
uint32 _updateInterval
Definition RealmList.h:89
Optional< Battlenet::RealmHandle > _currentRealmId
Definition RealmList.h:92
std::shared_mutex _realmsMutex
Definition RealmList.h:85
std::unique_ptr< Trinity::Net::Resolver > _resolver
Definition RealmList.h:91
std::unique_ptr< Trinity::Asio::DeadlineTimer > _updateTimer
Definition RealmList.h:90
std::vector< uint8 > JoinSecret
Definition RealmList.h:43
std::vector< uint8 > JoinTicket
Definition RealmList.h:41
std::vector< uint8 > ServerAddresses
Definition RealmList.h:42
Definition Realm.h:139