From f7eda384ea46c4b1de3f13fcde9d4f0fd624b2db Mon Sep 17 00:00:00 2001 From: MikiGamer <35080830+MikiGamer@users.noreply.github.com> Date: Thu, 9 Jul 2020 14:15:21 +0200 Subject: [PATCH] changes for auto port --- autoexec_server.cfg | 5 +---- src/engine/server/server.cpp | 25 ++++++++++--------------- src/engine/shared/config_variables.h | 2 -- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/autoexec_server.cfg b/autoexec_server.cfg index f3deffe25..d0b04bf1f 100644 --- a/autoexec_server.cfg +++ b/autoexec_server.cfg @@ -14,10 +14,7 @@ # Server port (only port range 8303-8310 show up in LAN tab) # - "Automatically selecting free port from range 8303-8310" for 0 -sv_port 8303 - -# Find free port automatically (range from 8303-8310) -sv_find_free_port 1 +sv_port 0 # Server name sv_name "My DDNet server" diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index fc2e7fba5..e3c2d6537 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -2308,7 +2308,7 @@ int CServer::Run() m_PrintCBIndex = Console()->RegisterPrintCallback(g_Config.m_ConsoleOutputLevel, SendRconLineAuthed, this); // load map - if (!LoadMap(g_Config.m_SvMap)) + if(!LoadMap(g_Config.m_SvMap)) { dbg_msg("server", "failed to load map. mapname='%s'", g_Config.m_SvMap); return -1; @@ -2317,27 +2317,28 @@ int CServer::Run() // start server NETADDR BindAddr; int NetType = g_Config.m_SvIpv4Only ? NETTYPE_IPV4 : NETTYPE_ALL; + int Port = (g_Config.m_SvPort == 0) ? 8303 : g_Config.m_SvPort; - if (g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NetType) == 0) + if(g_Config.m_Bindaddr[0] && net_host_lookup(g_Config.m_Bindaddr, &BindAddr, NetType) == 0) { // sweet! BindAddr.type = NetType; - BindAddr.port = g_Config.m_SvPort == 0 ? 8303 : g_Config.m_SvPort; + BindAddr.port = Port; } else { mem_zero(&BindAddr, sizeof(BindAddr)); BindAddr.type = NetType; - BindAddr.port = g_Config.m_SvPort == 0 ? 8303 : g_Config.m_SvPort; + BindAddr.port = Port; } #if defined(CONF_UPNP) m_UPnP.Open(BindAddr); #endif - if(!g_Config.m_SvFindFreePort && (g_Config.m_SvPort != 0)) + if(g_Config.m_SvPort != 0) { - if (!m_NetServer.Open(BindAddr, &m_ServerBan, g_Config.m_SvMaxClients, g_Config.m_SvMaxClientsPerIP, 0)) + if(!m_NetServer.Open(BindAddr, &m_ServerBan, g_Config.m_SvMaxClients, g_Config.m_SvMaxClientsPerIP, 0)) { dbg_msg("server", "couldn't open socket. port %d might already be in use", g_Config.m_SvPort); return -1; @@ -2345,24 +2346,18 @@ int CServer::Run() } else { - while (!m_NetServer.Open(BindAddr, &m_ServerBan, g_Config.m_SvMaxClients, g_Config.m_SvMaxClientsPerIP, 0)) + while(!m_NetServer.Open(BindAddr, &m_ServerBan, g_Config.m_SvMaxClients, g_Config.m_SvMaxClientsPerIP, 0)) { - if (((int)(BindAddr.port - 8303)) < 7) //ugly af + if(BindAddr.port < 8310) { dbg_msg("server", "couldn't open socket. port %d might already be in use. checking for next port.", BindAddr.port); BindAddr.port++; } - else if (g_Config.m_SvFindFreePortM) + else { dbg_msg("server", "couldn't open socket. port %d might already be in use", BindAddr.port); return -1; } - else - { - //Do one more cycle to be sure all ports used - g_Config.m_SvFindFreePortM = 1; - BindAddr.port = 8303; - } } } diff --git a/src/engine/shared/config_variables.h b/src/engine/shared/config_variables.h index dcdf80557..aba069d9e 100644 --- a/src/engine/shared/config_variables.h +++ b/src/engine/shared/config_variables.h @@ -140,8 +140,6 @@ MACRO_CONFIG_STR(SvDnsblKey, sv_dnsbl_key, 128, "", CFGFLAG_SERVER|CFGFLAG_NONTE MACRO_CONFIG_INT(SvDnsblVote, sv_dnsbl_vote, 0, 0, 1, CFGFLAG_SERVER, "Block votes by blacklisted addresses") MACRO_CONFIG_INT(SvDnsblBan, sv_dnsbl_ban, 0, 0, 1, CFGFLAG_SERVER, "Automatically ban blacklisted addresses") MACRO_CONFIG_INT(SvRconVote, sv_rcon_vote, 0, 0, 1, CFGFLAG_SERVER, "Only allow authed clients to call votes") -MACRO_CONFIG_INT(SvFindFreePort, sv_find_free_port, 1, 0, 1, CFGFLAG_SERVER, "Enables automatically searching for next available port (8303-8310)") -MACRO_CONFIG_INT(SvFindFreePortM, sv_find_free_port_m, 0, 0, 1, CFGFLAG_SERVER, "") MACRO_CONFIG_INT(SvPlayerDemoRecord, sv_player_demo_record, 0, 0, 1, CFGFLAG_SERVER, "Automatically record demos for each player") MACRO_CONFIG_INT(SvDemoChat, sv_demo_chat, 0, 0, 1, CFGFLAG_SERVER, "Record chat for demos")