From 7d3156325e15df8e3d74b629b885dbd67f91f343 Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Tue, 24 Jan 2023 11:45:32 +1000 Subject: [PATCH] Combine NetConn_UpdateSockets_Client() and NetConn_cl_netport_Callback() These blocks must run together to avoid bug https://gitlab.com/xonotic/darkplaces/-/issues/376 Also, after a057e4757b55a90cbcdc287b3fdf54ccc2682315 the only NetConn_UpdateSockets_Client() call site was in NetConn_cl_netport_Callback(). Signed-off-by: bones_was_here --- netconn.c | 32 ++++++++++++++------------------ netconn.h | 1 - 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/netconn.c b/netconn.c index 91c800b6..631d89b7 100755 --- a/netconn.c +++ b/netconn.c @@ -1146,22 +1146,9 @@ void NetConn_Close(netconn_t *conn) static int clientport = -1; static int clientport2 = -1; -static int hostport = -1; - -// Call on disconnect, during startup, or if cl_netport is changed -void NetConn_UpdateSockets_Client(void) -{ - if (cls.state == ca_disconnected && clientport != clientport2) - { - clientport = clientport2; - NetConn_CloseClientPorts(); - } - if (cl_numsockets == 0) - NetConn_OpenClientPorts(); -} -// Call when cl_port is changed -static void NetConn_cl_netport_Callback(cvar_t *var) +// Call on disconnect, during startup, or if cl_port/cl_netport is changed +static void NetConn_CL_UpdateSockets_Callback(cvar_t *var) { if(cls.state != ca_dedicated) { @@ -1171,11 +1158,20 @@ static void NetConn_cl_netport_Callback(cvar_t *var) if (cls.state == ca_connected) Con_Print("Changing \"cl_port\" will not take effect until you reconnect.\n"); } - NetConn_UpdateSockets_Client(); + + if (cls.state == ca_disconnected && clientport != clientport2) + { + clientport = clientport2; + NetConn_CloseClientPorts(); + } + if (cl_numsockets == 0) + NetConn_OpenClientPorts(); } } -// Call when port is changed +static int hostport = -1; + +// Call when port/sv_netport is changed static void NetConn_sv_netport_Callback(cvar_t *var) { if (hostport != var->integer) @@ -3907,7 +3903,7 @@ void NetConn_Init(void) Cvar_RegisterVariable(&hostname); Cvar_RegisterVariable(&developer_networking); Cvar_RegisterVariable(&cl_netport); - Cvar_RegisterCallback(&cl_netport, NetConn_cl_netport_Callback); + Cvar_RegisterCallback(&cl_netport, NetConn_CL_UpdateSockets_Callback); Cvar_RegisterVariable(&sv_netport); Cvar_RegisterCallback(&sv_netport, NetConn_sv_netport_Callback); Cvar_RegisterVariable(&net_address); diff --git a/netconn.h b/netconn.h index f8e9f7a4..9249af10 100755 --- a/netconn.h +++ b/netconn.h @@ -443,7 +443,6 @@ void NetConn_CloseClientPorts(void); void NetConn_OpenClientPorts(void); void NetConn_CloseServerPorts(void); void NetConn_OpenServerPorts(int opennetports); -void NetConn_UpdateSockets_Client(void); void NetConn_UpdateSockets(void); lhnetsocket_t *NetConn_ChooseClientSocketForAddress(lhnetaddress_t *address); lhnetsocket_t *NetConn_ChooseServerSocketForAddress(lhnetaddress_t *address); -- 2.39.2