diff --git a/data/stk_config.xml b/data/stk_config.xml index 9d60c3835..9fd6c6be4 100644 --- a/data/stk_config.xml +++ b/data/stk_config.xml @@ -487,4 +487,11 @@ --> + + + diff --git a/src/config/stk_config.cpp b/src/config/stk_config.cpp index 6ceed8378..2f257ebc1 100644 --- a/src/config/stk_config.cpp +++ b/src/config/stk_config.cpp @@ -126,6 +126,12 @@ void STKConfig::load(const std::string &filename) Log::fatal("StkConfig", "No rotationalsmoothing defined in stk_config."); } + if (m_client_port == 0 || m_server_port == 0 || m_server_discovery_port == 0 || + m_client_port == m_server_port || m_client_port == m_server_discovery_port || + m_server_port == m_server_discovery_port) + { + Log::fatal("StkConfig", "Invalid default port values."); + } CHECK_NEG(m_max_karts, "get("quality", &m_tc_quality); } + if (const XMLNode *tc = root->getNode("network")) + { + unsigned server_discovery_port = 0; + unsigned client_port = 0; + unsigned server_port = 0; + tc->get("server-discovery-port", &server_discovery_port); + tc->get("client-port", &client_port); + tc->get("server-port", &server_port); + m_server_discovery_port = (uint16_t)server_discovery_port; + m_client_port = (uint16_t)client_port; + m_server_port = (uint16_t)server_port; + } + // Get the default KartProperties // ------------------------------ const XMLNode *node = root -> getNode("general-kart-defaults"); diff --git a/src/config/stk_config.hpp b/src/config/stk_config.hpp index 2c7cd1154..7aa593696 100644 --- a/src/config/stk_config.hpp +++ b/src/config/stk_config.hpp @@ -171,6 +171,11 @@ public: unsigned m_tc_quality; + /** Client and server port use random ports if enabled in user config. */ + uint16_t m_server_discovery_port; + uint16_t m_client_port; + uint16_t m_server_port; + /** Lists of TTF files used in STK. */ std::vector m_normal_ttf; std::vector m_digit_ttf; diff --git a/src/config/user_config.hpp b/src/config/user_config.hpp index cb51eadcf..541d2fb10 100644 --- a/src/config/user_config.hpp +++ b/src/config/user_config.hpp @@ -739,9 +739,15 @@ namespace UserConfigParams std::make_pair(1100, 4) )); + // ---- Network + PARAM_PREFIX GroupUserConfigParam m_network_group + PARAM_DEFAULT(GroupUserConfigParam("Network", "Network Settings")); PARAM_PREFIX BoolUserConfigParam m_log_packets - PARAM_DEFAULT( BoolUserConfigParam(false, "log-network-packets", - "If all network packets should be logged") ); + PARAM_DEFAULT(BoolUserConfigParam(false, "log-network-packets", + &m_network_group, "If all network packets should be logged")); + PARAM_PREFIX BoolUserConfigParam m_random_ports + PARAM_DEFAULT(BoolUserConfigParam(true, "randrom-ports", + &m_network_group, "Use random ports for client and server connection")); // ---- Graphic Quality PARAM_PREFIX GroupUserConfigParam m_graphics_quality diff --git a/src/network/network_config.cpp b/src/network/network_config.cpp index 9f04f0a83..09134bd16 100644 --- a/src/network/network_config.cpp +++ b/src/network/network_config.cpp @@ -17,6 +17,8 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "network/network_config.hpp" +#include "config/stk_config.hpp" +#include "config/user_config.hpp" #include "online/xml_request.hpp" NetworkConfig *NetworkConfig::m_network_config = NULL; @@ -46,9 +48,17 @@ NetworkConfig::NetworkConfig() m_cur_user_token = ""; m_server_name = ""; m_password = ""; - m_server_discovery_port = 2757; - m_server_port = 2758; - m_client_port = 2759; + m_server_discovery_port = stk_config->m_server_discovery_port; + if (UserConfigParams::m_random_ports) + { + m_client_port = 0; + m_server_port = 0; + } + else + { + m_client_port = stk_config->m_client_port; + m_server_port = stk_config->m_server_port; + } } // NetworkConfig // ----------------------------------------------------------------------------