Fix legacy serverinfo with reserved slots and num_players > 15 (fixes #3678)

This commit is contained in:
def 2021-03-07 11:11:52 +01:00
parent d0d06d9325
commit b1ed91b835

View file

@ -1855,6 +1855,9 @@ void CServer::CacheServerInfo(CCache *pCache, int Type, bool SendClients)
ADD_INT(p, g_Config.m_Password[0] ? SERVER_FLAG_PASSWORD : 0);
int MaxClients = m_NetServer.MaxClients();
// How many clients the used serverinfo protocol supports, has to be tracked
// separately to make sure we don't subtract the reserved slots from it
int MaxClientsProtocol = MAX_CLIENTS;
if(Type == SERVERINFO_VANILLA || Type == SERVERINFO_INGAME)
{
if(ClientCount >= VANILLA_MAX_CLIENTS)
@ -1864,16 +1867,15 @@ void CServer::CacheServerInfo(CCache *pCache, int Type, bool SendClients)
else
ClientCount = VANILLA_MAX_CLIENTS;
}
if(MaxClients > VANILLA_MAX_CLIENTS)
MaxClients = VANILLA_MAX_CLIENTS;
MaxClientsProtocol = VANILLA_MAX_CLIENTS;
if(PlayerCount > ClientCount)
PlayerCount = ClientCount;
}
ADD_INT(p, PlayerCount); // num players
ADD_INT(p, maximum(MaxClients - maximum(g_Config.m_SvSpectatorSlots, g_Config.m_SvReservedSlots), PlayerCount)); // max players
ADD_INT(p, minimum(MaxClientsProtocol, maximum(MaxClients - maximum(g_Config.m_SvSpectatorSlots, g_Config.m_SvReservedSlots), PlayerCount))); // max players
ADD_INT(p, ClientCount); // num clients
ADD_INT(p, maximum(MaxClients - g_Config.m_SvReservedSlots, ClientCount)); // max clients
ADD_INT(p, minimum(MaxClientsProtocol, maximum(MaxClients - g_Config.m_SvReservedSlots, ClientCount))); // max clients
if(Type == SERVERINFO_EXTENDED)
p.AddString("", 0); // extra info, reserved