Since 0.1.30 a game on the auth server's own PC always got 127.0.0.1 from the realm list, so a VPN that was on when the server started could not break the login. With the auth server on one PC and the world server on another, that sent the game to a PC with no world server and the login failed. Now a loopback client gets 127.0.0.1 only when the realm's address or localAddress is this PC, or when something listens on 127.0.0.1 at the realm's port (the VPN case: the address is gone but the world server still listens here). Otherwise the realmlist addresses are used as before 0.1.30. The port check is kept for a minute per port.
66 lines
2.4 KiB
C++
66 lines
2.4 KiB
C++
#include "tc_catch2.h"
|
|
#include "IpAddress.h"
|
|
#include "Realm.h"
|
|
#include <boost/asio/io_context.hpp>
|
|
#include <boost/asio/ip/tcp.hpp>
|
|
|
|
namespace
|
|
{
|
|
boost::asio::ip::address Addr(char const* text)
|
|
{
|
|
boost::system::error_code error;
|
|
return Trinity::Net::make_address(text, error);
|
|
}
|
|
|
|
// a port on 127.0.0.1 that nothing listens on (taken from the system, then let go)
|
|
uint16 ClosedLoopbackPort()
|
|
{
|
|
boost::asio::io_context context;
|
|
boost::asio::ip::tcp::acceptor acceptor(context, boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::loopback(), 0));
|
|
uint16 port = acceptor.local_endpoint().port();
|
|
acceptor.close();
|
|
return port;
|
|
}
|
|
}
|
|
|
|
TEST_CASE("A game on the server PC gets 127.0.0.1 when the realm address is this PC", "[RealmLoopback]")
|
|
{
|
|
Realm realm;
|
|
realm.Addresses = { Addr("127.0.0.1") };
|
|
realm.Port = ClosedLoopbackPort();
|
|
CHECK(realm.GetAddressForClient(Addr("127.0.0.1")) == boost::asio::ip::address_v4::loopback());
|
|
}
|
|
|
|
TEST_CASE("With the world server on another PC a local game gets the realmlist address", "[RealmLoopback]")
|
|
{
|
|
// 203.0.113.5 is a documentation address: no card of this PC has it, and nothing listens on the port here
|
|
Realm realm;
|
|
realm.Addresses = { Addr("203.0.113.5") };
|
|
realm.Port = ClosedLoopbackPort();
|
|
CHECK(realm.GetAddressForClient(Addr("127.0.0.1")) == Addr("203.0.113.5"));
|
|
|
|
// with a localAddress too, the loopback client gets the localAddress, as before the 0.1.30 change
|
|
Realm lan;
|
|
lan.Addresses = { Addr("203.0.113.5"), Addr("203.0.113.6") };
|
|
lan.Port = ClosedLoopbackPort();
|
|
CHECK(lan.GetAddressForClient(Addr("127.0.0.1")) == Addr("203.0.113.6"));
|
|
}
|
|
|
|
TEST_CASE("A realm address that is gone (VPN off) still gives 127.0.0.1 while the world server listens here", "[RealmLoopback]")
|
|
{
|
|
boost::asio::io_context context;
|
|
boost::asio::ip::tcp::acceptor acceptor(context, boost::asio::ip::tcp::endpoint(boost::asio::ip::address_v4::loopback(), 0));
|
|
Realm realm;
|
|
realm.Addresses = { Addr("203.0.113.7") };
|
|
realm.Port = acceptor.local_endpoint().port();
|
|
CHECK(realm.GetAddressForClient(Addr("127.0.0.1")) == boost::asio::ip::address_v4::loopback());
|
|
}
|
|
|
|
TEST_CASE("A client from the network is not changed by the loopback rule", "[RealmLoopback]")
|
|
{
|
|
Realm realm;
|
|
realm.Addresses = { Addr("203.0.113.5") };
|
|
realm.Port = ClosedLoopbackPort();
|
|
CHECK(realm.GetAddressForClient(Addr("198.51.100.20")) == Addr("203.0.113.5"));
|
|
}
|