]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Combine NetConn_UpdateSockets_Client() and NetConn_cl_netport_Callback()
authorbones_was_here <bones_was_here@xonotic.au>
Tue, 24 Jan 2023 01:45:32 +0000 (11:45 +1000)
committerbones_was_here <bones_was_here@xonotic.au>
Tue, 24 Jan 2023 01:45:32 +0000 (11:45 +1000)
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 <bones_was_here@xonotic.au>
netconn.c
netconn.h

index 91c800b66d56d4e49d0d5359fa18031b4599b3cb..631d89b7881e79fd7ea6ae32c24f981f8adb275d 100755 (executable)
--- 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);
index f8e9f7a459031b78188819a900b41801144c9474..9249af10336994c20e1941d712e2352c8010d111 100755 (executable)
--- 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);