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
25Realm::Realm() = default;
26Realm::Realm(Realm const& other) = default;
27Realm::Realm(Realm&& other) noexcept = default;
28Realm& Realm::operator=(Realm const& other) = default;
29Realm& Realm::operator=(Realm&& other) noexcept = default;
30Realm::~Realm() = default;
31
32void 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
39boost::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
51{
52 return ConfigIdByType[Type];
53}
54
56{
57 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
58};
59
61{
62 return Trinity::StringFormat("{}-{}-{}", Region, Site, Realm);
63}
64
66{
67 return Trinity::StringFormat("{}-{}-0", Region, Site);
68}
uint32_t uint32
Definition Define.h:154
@ MAX_CLIENT_REALM_TYPE
Definition Realm.h:129
Optional< std::size_t > SelectAddressForClient(boost::asio::ip::address const &clientAddress, std::span< boost::asio::ip::address const > const &addresses)
Definition IpNetwork.cpp:71
std::string StringFormat(FormatString< Args... > fmt, Args &&... args) noexcept
Default TC string format function.
std::string GetAddressString() const
Definition Realm.cpp:60
std::string GetSubRegionAddress() const
Definition Realm.cpp:65
Definition Realm.h:139
uint32 GetConfigId() const
Definition Realm.cpp:50
boost::asio::ip::address GetAddressForClient(boost::asio::ip::address const &clientAddr) const
Definition Realm.cpp:39
static uint32 const ConfigIdByType[MAX_CLIENT_REALM_TYPE]
Definition Realm.h:55
std::string NormalizedName
Definition Realm.h:152
std::string Name
Definition Realm.h:151
Realm & operator=(Realm const &other)
void SetName(std::string name)
Definition Realm.cpp:32
std::vector< boost::asio::ip::address > Addresses
Definition Realm.h:149
uint8 Type
Definition Realm.h:153