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 <boost/asio/ip/tcp.hpp>
22
23boost::asio::ip::tcp_endpoint Realm::GetAddressForClient(boost::asio::ip::address const& clientAddr) const
24{
25 boost::asio::ip::address realmIp;
26
27 // Attempt to send best address for client
28 if (clientAddr.is_loopback())
29 {
30 // Try guessing if realm is also connected locally
31 if (LocalAddress->is_loopback() || ExternalAddress->is_loopback())
32 realmIp = clientAddr;
33 else
34 {
35 // Assume that user connecting from the machine that bnetserver is located on
36 // has all realms available in his local network
37 realmIp = *LocalAddress;
38 }
39 }
40 else
41 {
42 if (clientAddr.is_v4() && Trinity::Net::IsInNetwork(LocalAddress->to_v4(), LocalSubnetMask->to_v4(), clientAddr.to_v4()))
43 realmIp = *LocalAddress;
44 else
45 realmIp = *ExternalAddress;
46 }
47
48 // Return external IP
49 return boost::asio::ip::tcp_endpoint(realmIp, Port);
50}
bool IsInNetwork(boost::asio::ip::address_v4 const &networkAddress, boost::asio::ip::address_v4 const &mask, boost::asio::ip::address_v4 const &clientAddress)
Definition IpNetwork.h:30
basic_endpoint< tcp > tcp_endpoint
uint16 Port
Definition Realm.h:72
boost::asio::ip::tcp_endpoint GetAddressForClient(boost::asio::ip::address const &clientAddr) const
Definition Realm.cpp:23
std::unique_ptr< boost::asio::ip::address > LocalSubnetMask
Definition Realm.h:71
std::unique_ptr< boost::asio::ip::address > LocalAddress
Definition Realm.h:70
std::unique_ptr< boost::asio::ip::address > ExternalAddress
Definition Realm.h:69