]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
rcon: support variable expansion in received commands
[xonotic/darkplaces.git] / cl_main.c
index 64e711c79ab349f52b6d6b7c4c0b0e93e352fd17..7dffe2c8a46db87ae24e7d4065b397a45ec277a3 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -439,6 +439,8 @@ void CL_DisconnectEx(qbool kicked, const char *fmt, ... )
                                MSG_WriteByte(&buf, clc_disconnect);
                                if(cls.protocol == PROTOCOL_DARKPLACES8)
                                        MSG_WriteString(&buf, reason);
+                               // DP8 TODO: write a simpler func that Sys_HandleCrash() calls
+                               // to send a disconnect message indicating we crashed
                        }
                        NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
                        NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
@@ -447,10 +449,14 @@ void CL_DisconnectEx(qbool kicked, const char *fmt, ... )
 
                NetConn_Close(cls.netcon);
                cls.netcon = NULL;
-               if(fmt)
-                       Con_Printf("Disconnect: %s\n", reason);
+
+               // It's possible for a server to disconnect a player with an empty reason
+               // which is checked here rather than above so we don't print "Disconnect by user".
+               if(fmt && reason[0] != '\0')
+                       dpsnprintf(cl_connect_status, sizeof(cl_connect_status), "Disconnect: %s", reason);
                else
-                       Con_Printf("Disconnected\n");
+                       strlcpy(cl_connect_status, "Disconnected", sizeof(cl_connect_status));
+               Con_Printf("%s\n", cl_connect_status);
        }
        cls.state = ca_disconnected;
        cl.islocalgame = false;
@@ -492,7 +498,7 @@ static void CL_Reconnect_f(cmd_state_t *cmd)
                if (temp[0])
                        CL_EstablishConnection(temp, -1);
                else
-                       Con_Printf("Reconnect to what server?  (you have not connected to a server yet)\n");
+                       Con_Printf(CON_WARN "Reconnect to what server?  (you have not connected to a server yet)\n");
                return;
        }
        // if connected, do something based on protocol
@@ -572,18 +578,13 @@ void CL_EstablishConnection(const char *address, int firstarg)
        if (Sys_CheckParm("-benchmark"))
                return;
 
-       // clear menu's connect error message
-#ifdef CONFIG_MENU
-       M_Update_Return_Reason("");
-#endif
-
        // make sure the client ports are open before attempting to connect
        NetConn_UpdateSockets();
 
        if (LHNETADDRESS_FromString(&cls.connect_address, address, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
        {
                cls.connect_trying = true;
-               cls.connect_remainingtries = 3;
+               cls.connect_remainingtries = 10;
                cls.connect_nextsendtime = 0;
 
                // only NOW, set connect_userinfo
@@ -601,17 +602,13 @@ void CL_EstablishConnection(const char *address, int firstarg)
                        *cls.connect_userinfo = 0;
                }
 
-#ifdef CONFIG_MENU
-               M_Update_Return_Reason("Trying to connect...");
-#endif
+               strlcpy(cl_connect_status, "Connect: pending...", sizeof(cl_connect_status));
                SCR_BeginLoadingPlaque(false);
        }
        else
        {
-               Con_Print("Unable to find a suitable network socket to connect to server.\n");
-#ifdef CONFIG_MENU
-               M_Update_Return_Reason("No network");
-#endif
+               Con_Printf(CON_ERROR "Connect: failed, unable to find a network socket suitable to reach %s\n", address);
+               strlcpy(cl_connect_status, "Connect: failed, no network", sizeof(cl_connect_status));
        }
 }
 
@@ -2858,7 +2855,7 @@ double CL_Frame (double time)
 
                        // on some legacy systems, we need to sleep to keep input responsive
                        if (cl_maxfps_alwayssleep.value > 0 && !cls.timedemo)
-                               Sys_Sleep((int)bound(1, cl_maxfps_alwayssleep.value * 1000, 50000));
+                               Sys_Sleep(min(cl_maxfps_alwayssleep.value / 1000, 0.05));
                }
 
                // apply slowmo scaling