From 04a33c983739ed348f3d06c91ce8532f064b0a11 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 3 Feb 2019 19:35:38 +0100 Subject: [PATCH] Fix loading Coop savegames without starting server first --- src/server/sv_main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/server/sv_main.c b/src/server/sv_main.c index 4b7b1324..515de67d 100644 --- a/src/server/sv_main.c +++ b/src/server/sv_main.c @@ -645,7 +645,16 @@ SV_FinalMessage(char *message, qboolean reconnect) } /* stagger the packets to crutch operating system limited buffers */ - for (i = 0, cl = svs.clients; i < maxclients->value; i++, cl++) + /* DG: we can't just use the maxclients cvar here for the number of clients, + * because this is called by SV_Shutdown() and the shut down server might have + * a different number of clients (e.g. 1 if it's single player), when maxclients + * has already been set to a higher value for multiplayer (e.g. 4 for coop) + * Luckily, svs.num_client_entities = maxclients->value * UPDATE_BACKUP * 64; + * with the maxclients value from when the current server was started (see SV_InitGame()) + * so we can just calculate the right number of clients from that + */ + int numClients = svs.num_client_entities / ( UPDATE_BACKUP * 64 ); + for (i = 0, cl = svs.clients; i < numClients; i++, cl++) { if (cl->state >= cs_connected) { @@ -654,7 +663,7 @@ SV_FinalMessage(char *message, qboolean reconnect) } } - for (i = 0, cl = svs.clients; i < maxclients->value; i++, cl++) + for (i = 0, cl = svs.clients; i < numClients; i++, cl++) { if (cl->state >= cs_connected) {