]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
SVVM: fully shut down when stopping a server to avoid segfaulting later
[xonotic/darkplaces.git] / cl_main.c
index 218f7b2451ca7cfca81b05c471d265d0ce52975d..cba1b7560298eed2df02b2cdc9815b64dd3de0c8 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -302,7 +302,7 @@ void CL_ExpandEntities(int num)
        if (num >= cl.max_entities)
        {
                if (!cl.entities)
-                       Sys_Error("CL_ExpandEntities: cl.entities not initialized");
+                       Sys_Abort("CL_ExpandEntities: cl.entities not initialized");
                if (num >= MAX_EDICTS)
                        Host_Error("CL_ExpandEntities: num %i >= %i", num, MAX_EDICTS);
                oldmaxentities = cl.max_entities;
@@ -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");
+                       dp_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
+               dp_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);
+               dp_strlcpy(cl_connect_status, "Connect: failed, no network", sizeof(cl_connect_status));
        }
 }
 
@@ -893,7 +890,7 @@ void CL_AllocLightFlash(entity_render_t *ent, matrix4x4_t *matrix, float radius,
                dl->die = 0;
        dl->cubemapname[0] = 0;
        if (cubemapname && cubemapname[0])
-               strlcpy(dl->cubemapname, cubemapname, sizeof(dl->cubemapname));
+               dp_strlcpy(dl->cubemapname, cubemapname, sizeof(dl->cubemapname));
        dl->style = style;
        dl->shadow = shadowenable;
        dl->corona = corona;
@@ -2163,7 +2160,7 @@ static void CL_Fog_HeightTexture_f(cmd_state_t *cmd)
        r_refdef.fog_end = atof(Cmd_Argv(cmd, 7));
        r_refdef.fog_height = atof(Cmd_Argv(cmd, 8));
        r_refdef.fog_fadedepth = atof(Cmd_Argv(cmd, 9));
-       strlcpy(r_refdef.fog_height_texturename, Cmd_Argv(cmd, 10), sizeof(r_refdef.fog_height_texturename));
+       dp_strlcpy(r_refdef.fog_height_texturename, Cmd_Argv(cmd, 10), sizeof(r_refdef.fog_height_texturename));
 }
 
 
@@ -2228,7 +2225,7 @@ void CL_Locs_FindLocationName(char *buffer, size_t buffersize, vec3_t point)
        cl_locnode_t *loc;
        loc = CL_Locs_FindNearest(point);
        if (loc)
-               strlcpy(buffer, loc->name, buffersize);
+               dp_strlcpy(buffer, loc->name, buffersize);
        else
                dpsnprintf(buffer, buffersize, "LOC=%.0f:%.0f:%.0f", point[0], point[1], point[2]);
 }