From 3d64a9c0b20d1d0fca84aab0369cafcb240654f1 Mon Sep 17 00:00:00 2001 From: divverent Date: Sat, 7 Mar 2009 13:41:21 +0000 Subject: [PATCH] allow maxplayers to be changed in game (it'll then be latched and the change will be applied on the next "map" (not "changelevel") command) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8778 d7cf8633-e32d-0410-b094-e92efae38249 --- host.c | 2 +- host_cmd.c | 15 ++++++++++----- server.h | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/host.c b/host.c index dbad918f..b8209a67 100644 --- a/host.c +++ b/host.c @@ -188,7 +188,7 @@ void Host_ServerOptions (void) } } - svs.maxclients = bound(1, svs.maxclients, MAX_SCOREBOARD); + svs.maxclients = svs.maxclients_next = bound(1, svs.maxclients, MAX_SCOREBOARD); svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients); diff --git a/host_cmd.c b/host_cmd.c index 0437bbde..b5a9c452 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -363,6 +363,14 @@ void Host_Map_f (void) CL_Disconnect (); Host_ShutdownServer(); + if(svs.maxclients != svs.maxclients_next) + { + svs.maxclients = svs.maxclients_next; + if (svs.clients) + Mem_Free(svs.clients); + svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients); + } + // remove menu key_dest = key_game; @@ -2308,17 +2316,14 @@ static void MaxPlayers_f(void) if (sv.active) { Con_Print("maxplayers can not be changed while a server is running.\n"); - return; + Con_Print("It will be changed on next server startup (\"map\" command).\n"); } n = atoi(Cmd_Argv(1)); n = bound(1, n, MAX_SCOREBOARD); Con_Printf("\"maxplayers\" set to \"%u\"\n", n); - if (svs.clients) - Mem_Free(svs.clients); - svs.maxclients = n; - svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients); + svs.maxclients_next = n; if (n == 1) Cvar_Set ("deathmatch", "0"); else diff --git a/server.h b/server.h index 99c5296d..0d7b239f 100644 --- a/server.h +++ b/server.h @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. typedef struct server_static_s { // number of svs.clients slots (updated by maxplayers command) - int maxclients; + int maxclients, maxclients_next; // client slots struct client_s *clients; // episode completion information -- 2.39.2