Fix non random client port (NetworkConfig initialized too early)

This commit is contained in:
Benau 2020-01-30 11:30:54 +08:00
parent 964757193b
commit e1188c5532
3 changed files with 15 additions and 2 deletions

View File

@ -2031,6 +2031,8 @@ int main(int argc, char *argv[])
// ServerConfig will use stk_config for server version testing
stk_config->load(file_manager->getAsset("stk_config.xml"));
// Client port depends on user config file and stk_config
NetworkConfig::get()->initClientPort();
bool no_graphics = !CommandLine::has("--graphical-server");
#ifndef SERVER_ONLY

View File

@ -67,14 +67,23 @@ NetworkConfig::NetworkConfig()
m_done_adding_network_players = false;
m_cur_user_id = 0;
m_cur_user_token = "";
m_client_port = UserConfigParams::m_random_client_port ?
0 : stk_config->m_client_port;
m_client_port = 0;
m_joined_server_version = 0;
m_network_ai_tester = false;
m_state_frequency = 10;
m_nat64_prefix_data.fill(-1);
} // NetworkConfig
// ----------------------------------------------------------------------------
/** Separated from constructor because this needs to be run after user config
* is load.
*/
void NetworkConfig::initClientPort()
{
m_client_port = UserConfigParams::m_random_client_port ?
0 : stk_config->m_client_port;
} // initClientPort
// ----------------------------------------------------------------------------
/** Set that this is not a networked game.
*/

View File

@ -269,6 +269,8 @@ public:
// ------------------------------------------------------------------------
const std::array<uint32_t, 8>& getNAT64PrefixData() const
{ return m_nat64_prefix_data; }
// ------------------------------------------------------------------------
void initClientPort();
}; // class NetworkConfig
#endif // HEADER_NETWORK_CONFIG