Skip to content

Commit

Permalink
Merge pull request ddnet#8593 from Robyt3/Server-MaxClients-Fixes
Browse files Browse the repository at this point in the history
Fix crashes with `dbg_dummies` and `sv_max_clients`, ensure that `sv_max_clients` can only be set when starting server
  • Loading branch information
def- authored Jul 15, 2024
2 parents b0f0292 + 37756aa commit 804e87a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/engine/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ int main(int argc, const char **argv)
if(argc > 1)
pConsole->ParseArguments(argc - 1, &argv[1]);

pConfigManager->SetReadOnly("sv_max_clients", true);
pConfigManager->SetReadOnly("sv_test_cmds", true);
pConfigManager->SetReadOnly("sv_rescue", true);

Expand Down
5 changes: 3 additions & 2 deletions src/engine/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
}

// reserved slot
if(ClientId >= Config()->m_SvMaxClients - Config()->m_SvReservedSlots && !CheckReservedSlotAuth(ClientId, pPassword))
if(ClientId >= MaxClients() - Config()->m_SvReservedSlots && !CheckReservedSlotAuth(ClientId, pPassword))
{
m_NetServer.Drop(ClientId, "This server is full");
return;
Expand Down Expand Up @@ -2624,10 +2624,11 @@ void CServer::UpdateDebugDummies(bool ForceDisconnect)
if(m_PreviousDebugDummies == g_Config.m_DbgDummies && !ForceDisconnect)
return;

g_Config.m_DbgDummies = clamp(g_Config.m_DbgDummies, 0, MaxClients());
for(int DummyIndex = 0; DummyIndex < maximum(m_PreviousDebugDummies, g_Config.m_DbgDummies); ++DummyIndex)
{
const bool AddDummy = !ForceDisconnect && DummyIndex < g_Config.m_DbgDummies;
const int ClientId = MAX_CLIENTS - DummyIndex - 1;
const int ClientId = MaxClients() - DummyIndex - 1;
if(AddDummy && m_aClients[ClientId].m_State == CClient::STATE_EMPTY)
{
NewClientCallback(ClientId, this, false);
Expand Down
3 changes: 1 addition & 2 deletions src/game/server/gamecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ void CGameContext::SendSettings(int ClientId) const
Msg.m_SpecVote = g_Config.m_SvVoteSpectate;
Msg.m_TeamLock = 0;
Msg.m_TeamBalance = 0;
Msg.m_PlayerSlots = g_Config.m_SvMaxClients - g_Config.m_SvSpectatorSlots;
Msg.m_PlayerSlots = Server()->MaxClients() - g_Config.m_SvSpectatorSlots;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, ClientId);
}

Expand Down Expand Up @@ -3573,7 +3573,6 @@ void CGameContext::OnConsoleInit()
Console()->Chain("sv_vote_kick_min", ConchainSettingUpdate, this);
Console()->Chain("sv_vote_spectate", ConchainSettingUpdate, this);
Console()->Chain("sv_spectator_slots", ConchainSettingUpdate, this);
Console()->Chain("sv_max_clients", ConchainSettingUpdate, this);

RegisterDDRaceCommands();
RegisterChatCommands();
Expand Down

0 comments on commit 804e87a

Please sign in to comment.