TrinityCore
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
void
Realm::SetName
(std::string name)
26
{
27
Name
= name;
28
NormalizedName
= std::move(name);
29
NormalizedName
.erase(std::remove_if(
NormalizedName
.begin(),
NormalizedName
.end(), ::isspace),
NormalizedName
.end());
30
}
31
32
boost::asio::ip::address
Realm::GetAddressForClient
(boost::asio::ip::address
const
& clientAddr)
const
33
{
34
if
(
auto
addressIndex =
Trinity::Net::SelectAddressForClient
(clientAddr,
Addresses
))
35
return
Addresses
[*addressIndex];
36
37
if
(clientAddr.is_loopback())
38
return
Addresses
[1];
39
40
return
Addresses
[0];
41
}
42
43
uint32
Realm::GetConfigId
()
const
44
{
45
return
ConfigIdByType
[
Type
];
46
}
47
48
uint32
const
Realm::ConfigIdByType
[
MAX_CLIENT_REALM_TYPE
] =
49
{
50
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
51
};
52
53
std::string
Battlenet::RealmHandle::GetAddressString
()
const
54
{
55
return
Trinity::StringFormat
(
"{}-{}-{}"
,
Region
,
Site
,
Realm
);
56
}
57
58
std::string
Battlenet::RealmHandle::GetSubRegionAddress
()
const
59
{
60
return
Trinity::StringFormat
(
"{}-{}-0"
, Region, Site);
61
}
uint32
uint32_t uint32
Definition:
Define.h:142
IpAddress.h
IpNetwork.h
Realm.h
MAX_CLIENT_REALM_TYPE
@ MAX_CLIENT_REALM_TYPE
Definition:
Realm.h:71
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)
Default TC string format function.
Definition:
StringFormat.h:38
Battlenet::RealmHandle::GetAddressString
std::string GetAddressString() const
Definition:
Realm.cpp:53
Battlenet::RealmHandle::Region
uint8 Region
Definition:
Realm.h:48
Battlenet::RealmHandle::GetSubRegionAddress
std::string GetSubRegionAddress() const
Definition:
Realm.cpp:58
Battlenet::RealmHandle::Site
uint8 Site
Definition:
Realm.h:49
Realm
Definition:
Realm.h:81
Realm::GetConfigId
uint32 GetConfigId() const
Definition:
Realm.cpp:43
Realm::GetAddressForClient
boost::asio::ip::address GetAddressForClient(boost::asio::ip::address const &clientAddr) const
Definition:
Realm.cpp:32
Realm::ConfigIdByType
static uint32 const ConfigIdByType[MAX_CLIENT_REALM_TYPE]
Definition:
Realm.h:99
Realm::NormalizedName
std::string NormalizedName
Definition:
Realm.h:87
Realm::Name
std::string Name
Definition:
Realm.h:86
Realm::SetName
void SetName(std::string name)
Definition:
Realm.cpp:25
Realm::Addresses
std::vector< boost::asio::ip::address > Addresses
Definition:
Realm.h:84
Realm::Type
uint8 Type
Definition:
Realm.h:88
server
shared
Realm
Realm.cpp
Generated on Thu Mar 14 2024 23:39:35 for TrinityCore by
1.9.4