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
25void 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
32boost::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
44{
45 return ConfigIdByType[Type];
46}
47
49{
50 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
51};
52
54{
55 return Trinity::StringFormat("{}-{}-{}", Region, Site, Realm);
56}
57
59{
60 return Trinity::StringFormat("{}-{}-0", Region, Site);
61}
uint32_t uint32
Definition: Define.h:142
@ MAX_CLIENT_REALM_TYPE
Definition: Realm.h:71
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)
Default TC string format function.
Definition: StringFormat.h:38
std::string GetAddressString() const
Definition: Realm.cpp:53
std::string GetSubRegionAddress() const
Definition: Realm.cpp:58
Definition: Realm.h:81
uint32 GetConfigId() const
Definition: Realm.cpp:43
boost::asio::ip::address GetAddressForClient(boost::asio::ip::address const &clientAddr) const
Definition: Realm.cpp:32
static uint32 const ConfigIdByType[MAX_CLIENT_REALM_TYPE]
Definition: Realm.h:99
std::string NormalizedName
Definition: Realm.h:87
std::string Name
Definition: Realm.h:86
void SetName(std::string name)
Definition: Realm.cpp:25
std::vector< boost::asio::ip::address > Addresses
Definition: Realm.h:84
uint8 Type
Definition: Realm.h:88