Add clamps to 'CC_CreateFakePlayer_f'

Make sure user doesn't create bots past MAX_PLAYERS, also clamp team number as otherwise the game would crash as well.
This commit is contained in:
Kawe Mazidjatari 2023-07-16 23:49:18 +02:00
parent 4de4f92f14
commit 0e54190541

View File

@ -1406,9 +1406,26 @@ void CC_CreateFakePlayer_f(const CCommand& args)
return;
}
int numPlayers = g_pServer->GetNumClients();
// Already at max, don't create.
if (numPlayers >= g_ServerGlobalVariables->m_nMaxClients)
return;
const char* playerName = args.Arg(1);
int teamNum = atoi(args.Arg(2));
int maxTeams = int(g_pServer->GetMaxTeams()) + 1;
// Clamp team count, going above the limit will
// cause a crash. Going below 0 means that the
// engine will assign the bot to the last team.
if (teamNum > maxTeams)
teamNum = maxTeams;
g_pEngineServer->LockNetworkStringTables(true);
edict_t nHandle = g_pEngineServer->CreateFakeClient(args.Arg(1), atoi(args.Arg(2)));
edict_t nHandle = g_pEngineServer->CreateFakeClient(playerName, teamNum);
g_pServerGameClients->ClientFullyConnect(nHandle, false);
g_pEngineServer->LockNetworkStringTables(false);