TrinityCore
Loading...
Searching...
No Matches
Realm.cpp
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
#include "
Realm.h
"
19
#include "
IpAddress.h
"
20
#include "
IpNetwork.h
"
21
#include "
StringFormat.h
"
22
#include <algorithm>
23
#include <cctype>
24
25
Realm::Realm
() =
default
;
26
Realm::Realm
(
Realm
const
& other) =
default
;
27
Realm::Realm
(
Realm
&& other)
noexcept
=
default
;
28
Realm
&
Realm::operator=
(
Realm
const
& other) =
default
;
29
Realm
&
Realm::operator=
(
Realm
&& other)
noexcept
=
default
;
30
Realm::~Realm
() =
default
;
31
32
void
Realm::SetName
(std::string name)
33
{
34
Name
= name;
35
NormalizedName
= std::move(name);
36
std::erase_if(
NormalizedName
, [](
char
c) {
return
std::isspace(
static_cast<
unsigned
char
>
(c)); });
37
}
38
39
boost::asio::ip::address
Realm::GetAddressForClient
(boost::asio::ip::address
const
& clientAddr)
const
40
{
41
if
(
auto
addressIndex =
Trinity::Net::SelectAddressForClient
(clientAddr,
Addresses
))
42
return
Addresses
[*addressIndex];
43
44
if
(
Addresses
.size() > 1 && clientAddr.is_loopback())
45
return
Addresses
[1];
46
47
return
Addresses
[0];
48
}
49
50
uint32
Realm::GetConfigId
()
const
51
{
52
return
ConfigIdByType
[
Type
];
53
}
54
55
uint32
const
Realm::ConfigIdByType
[
MAX_CLIENT_REALM_TYPE
] =
56
{
57
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
58
};
59
60
std::string
Battlenet::RealmHandle::GetAddressString
()
const
61
{
62
return
Trinity::StringFormat
(
"{}-{}-{}"
,
Region
,
Site
,
Realm
);
63
}
64
65
std::string
Battlenet::RealmHandle::GetSubRegionAddress
()
const
66
{
67
return
Trinity::StringFormat
(
"{}-{}-0"
, Region, Site);
68
}
uint32
uint32_t uint32
Definition
Define.h:154
IpAddress.h
IpNetwork.h
Realm.h
MAX_CLIENT_REALM_TYPE
@ MAX_CLIENT_REALM_TYPE
Definition
Realm.h:129
StringFormat.h
Trinity::Net::SelectAddressForClient
Optional< std::size_t > SelectAddressForClient(boost::asio::ip::address const &clientAddress, std::span< boost::asio::ip::address const > const &addresses)
Definition
IpNetwork.cpp:71
Trinity::StringFormat
std::string StringFormat(FormatString< Args... > fmt, Args &&... args) noexcept
Default TC string format function.
Definition
StringFormat.h:57
Battlenet::RealmHandle::GetAddressString
std::string GetAddressString() const
Definition
Realm.cpp:60
Battlenet::RealmHandle::Region
uint8 Region
Definition
Realm.h:106
Battlenet::RealmHandle::GetSubRegionAddress
std::string GetSubRegionAddress() const
Definition
Realm.cpp:65
Battlenet::RealmHandle::Site
uint8 Site
Definition
Realm.h:107
Realm
Definition
Realm.h:139
Realm::GetConfigId
uint32 GetConfigId() const
Definition
Realm.cpp:50
Realm::GetAddressForClient
boost::asio::ip::address GetAddressForClient(boost::asio::ip::address const &clientAddr) const
Definition
Realm.cpp:39
Realm::ConfigIdByType
static uint32 const ConfigIdByType[MAX_CLIENT_REALM_TYPE]
Definition
Realm.h:55
Realm::NormalizedName
std::string NormalizedName
Definition
Realm.h:152
Realm::Name
std::string Name
Definition
Realm.h:151
Realm::operator=
Realm & operator=(Realm const &other)
Realm::Realm
Realm()
Realm::SetName
void SetName(std::string name)
Definition
Realm.cpp:32
Realm::~Realm
~Realm()
Realm::Addresses
std::vector< boost::asio::ip::address > Addresses
Definition
Realm.h:149
Realm::Type
uint8 Type
Definition
Realm.h:153
server
shared
Realm
Realm.cpp
Generated by
1.9.8