<commit_before>/*
===========================================================================

Daemon GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.

This file is part of the Daemon GPL Source Code (Daemon Source Code).

Daemon Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Daemon Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Daemon Source Code.  If not, see <http://www.gnu.org/licenses/>.

In addition, the Daemon Source Code is also subject to certain additional terms.
You should have received a copy of these additional terms immediately following the
terms and conditions of the GNU General Public License which accompanied the Daemon
Source Code.  If not, please request a copy in writing from id Software at the address
below.

If you have questions concerning this license or the applicable additional terms, you
may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville,
Maryland 20850 USA.

===========================================================================
*/

// sv_bot.c

#include "server.h"

int                    bot_enable;

/*
==================
SV_BotAllocateClient
==================
*/
int SV_BotAllocateClient( int clientNum )
{
	int      i;
	client_t *cl;

	// Arnout: added possibility to request a clientnum
	if ( clientNum > 0 )
	{
		if ( clientNum >= sv_maxclients->integer )
		{
			return -1;
		}

		cl = &svs.clients[ clientNum ];

		if ( cl->state != CS_FREE )
		{
			return -1;
		}
		else
		{
			i = clientNum;
		}
	}
	else
	{
		// find a client slot
		for ( i = 0, cl = svs.clients; i < sv_maxclients->integer; i++, cl++ )
		{
			// Wolfenstein, never use the first slot, otherwise if a bot connects before the first client on a listen server, game won't start
			if ( i < 1 )
			{
				continue;
			}

			// done.
			if ( cl->state == CS_FREE )
			{
				break;
			}
		}
	}

	if ( i == sv_maxclients->integer )
	{
		return -1;
	}

	cl->gentity = SV_GentityNum( i );
	cl->gentity->s.number = i;
	cl->state = CS_ACTIVE;
	cl->lastPacketTime = svs.time;
	cl->netchan.remoteAddress.type = NA_BOT;<commit_msg>Never use reserved slots for bots.<commit_after>/*
===========================================================================

Daemon GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.

This file is part of the Daemon GPL Source Code (Daemon Source Code).

Daemon Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Daemon Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Daemon Source Code.  If not, see <http://www.gnu.org/licenses/>.

In addition, the Daemon Source Code is also subject to certain additional terms.
You should have received a copy of these additional terms immediately following the
terms and conditions of the GNU General Public License which accompanied the Daemon
Source Code.  If not, please request a copy in writing from id Software at the address
below.

If you have questions concerning this license or the applicable additional terms, you
may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville,
Maryland 20850 USA.

===========================================================================
*/

// sv_bot.c

#include "server.h"

int                    bot_enable;

/*
==================
SV_BotAllocateClient
==================
*/
int SV_BotAllocateClient( int clientNum )
{
	int      i;
	int      firstSlot = MAX( 1, sv_privateClients->integer );
	client_t *cl;

	// Arnout: added possibility to request a clientnum
	if ( clientNum > 0 )
	{
		if ( clientNum >= sv_maxclients->integer )
		{
			return -1;
		}

		cl = &svs.clients[ clientNum ];

		if ( cl->state != CS_FREE )
		{
			return -1;
		}
		else
		{
			i = clientNum;
		}
	}
	else
	{
		// find a client slot
		for ( i = 0, cl = svs.clients; i < sv_maxclients->integer; i++, cl++ )
		{
			// Wolfenstein, never use the first slot, otherwise if a bot connects before the first client on a listen server, game won't start
			// Also, never use reserved slots since that messes up the reported player count
			if ( i < firstSlot )
			{
				continue;
			}

			// done.
			if ( cl->state == CS_FREE )
			{
				break;
			}
		}
	}

	if ( i == sv_maxclients->integer )
	{
		return -1;
	}

	cl->gentity = SV_GentityNum( i );
	cl->gentity->s.number = i;
	cl->state = CS_ACTIVE;
	cl->lastPacketTime = svs.time;
	cl->netchan.remoteAddress.type = NA_BOT;
{'fraction_non_alphanumeric': 0.14420358152686144, 'fraction_numerical': 0.008671065032987747, 'mean_word_length': 3.489001692047377, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7218475', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1497, 'n_words': 656}