From 70c3650ee145d5f173869596b784067876435f25 Mon Sep 17 00:00:00 2001 From: dongresource Date: Thu, 21 Oct 2021 20:58:41 +0200 Subject: [PATCH] Add config option to disable the localhost workaround There are some network configurations in which it's undesirable; such as reverse tunneling through ssh. These are obscure enough to allow leaving the option undocumented (in the example config file). --- src/servers/CNLoginServer.cpp | 2 +- src/settings.cpp | 4 +++- src/settings.hpp | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/servers/CNLoginServer.cpp b/src/servers/CNLoginServer.cpp index fbfaf04..999fb1c 100644 --- a/src/servers/CNLoginServer.cpp +++ b/src/servers/CNLoginServer.cpp @@ -445,7 +445,7 @@ void CNLoginServer::characterSelect(CNSocket* sock, CNPacketData* data) { * the shard IP has been configured to an address the local machine can't * reach itself from. */ - if (sock->sockaddr.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) + if (settings::LOCALHOSTWORKAROUND && sock->sockaddr.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) shard_ip = "127.0.0.1"; memcpy(resp.g_FE_ServerIP, shard_ip, strlen(shard_ip)); diff --git a/src/settings.cpp b/src/settings.cpp index 8054e65..79b999d 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -14,6 +14,7 @@ int settings::DBSAVEINTERVAL = 240; int settings::SHARDPORT = 23001; std::string settings::SHARDSERVERIP = "127.0.0.1"; +bool settings::LOCALHOSTWORKAROUND = true; time_t settings::TIMEOUT = 60000; int settings::VIEWDISTANCE = 25600; bool settings::SIMULATEMOBS = true; @@ -79,7 +80,8 @@ void settings::init() { LOGINPORT = reader.GetInteger("login", "port", LOGINPORT); SHARDPORT = reader.GetInteger("shard", "port", SHARDPORT); DBSAVEINTERVAL = reader.GetInteger("login", "dbsaveinterval", DBSAVEINTERVAL); - SHARDSERVERIP = reader.Get("shard", "ip", "127.0.0.1"); + SHARDSERVERIP = reader.Get("shard", "ip", SHARDSERVERIP); + LOCALHOSTWORKAROUND = reader.GetBoolean("shard", "localhostworkaround", LOCALHOSTWORKAROUND); TIMEOUT = reader.GetInteger("shard", "timeout", TIMEOUT); VIEWDISTANCE = reader.GetInteger("shard", "viewdistance", VIEWDISTANCE); SIMULATEMOBS = reader.GetBoolean("shard", "simulatemobs", SIMULATEMOBS); diff --git a/src/settings.hpp b/src/settings.hpp index d925fd4..39de71e 100644 --- a/src/settings.hpp +++ b/src/settings.hpp @@ -7,6 +7,7 @@ namespace settings { extern int DBSAVEINTERVAL; extern int SHARDPORT; extern std::string SHARDSERVERIP; + extern bool LOCALHOSTWORKAROUND; extern time_t TIMEOUT; extern int VIEWDISTANCE; extern bool SIMULATEMOBS;