// File: /workspace/github_c_makefile_star2_O1/QwazyWabbitWOS[P]lmctf60/p_client.c
// Function: ClientConnect
qboolean ClientConnect (edict_t *ent, char *userinfo)
{
	char	*value;

	// check to see if they are on the banned IP list
	value = Info_ValueForKey (userinfo, "ip");
	if (SV_FilterPacket(value)) {
		Info_SetValueForKey(userinfo, "rejmsg", "Banned.");
		return false;
	}


	// check for a spectator
	value = Info_ValueForKey (userinfo, "spectator");
	if (deathmatch->value && *value && strcmp(value, "0")) {
		int i, numspec;

		if (*spectator_password->string && 
			strcmp(spectator_password->string, "none") && 
			strcmp(spectator_password->string, value)) {
			Info_SetValueForKey(userinfo, "rejmsg", "Spectator password required or incorrect.");
			return false;
		}

		// count spectators
		for (i = numspec = 0; i < maxclients->value; i++)
			if (g_edicts[i+1].inuse && g_edicts[i+1].client->pers.spectator)
				numspec++;

		if (numspec >= maxspectators->value) {
			Info_SetValueForKey(userinfo, "rejmsg", "Server spectator limit is full.");
			return false;
		}
	} else 
	
	{
		// check for a password
		value = Info_ValueForKey (userinfo, "password");
		if (*password->string && strcmp(password->string, "none") && 
			strcmp(password->string, value)) {
			Info_SetValueForKey(userinfo, "rejmsg", "Password required or incorrect.");
			return false;
		}
	}


	// must have name to connect
	value = Info_ValueForKey(userinfo, "name");
	if (strcmp(value, "") == 0)
	{
		Info_SetValueForKey(userinfo, "rejmsg", "You must have a name.");
		return false;
	}
	
	// they can connect
	ent->client = game.clients + (ent - g_edicts - 1);
	
	if (ent->client->p_stats_player)
	{
		ent->client->p_stats_player->dropped = true;
		ent->client->p_stats_player->info.teamnum = ent->client->ctf.teamnum;
		ent->client->p_stats_player = NULL;
	}

	// if there is already a body waiting for us (a loadgame), just
	// take it, otherwise spawn one from scratch
	if (ent->inuse == false)
	{
		// clear the respawning variables
		InitClientResp (ent->client);
		if (!game.autosaved || !ent->client->pers.weapon)
			InitClientPersistent (ent->client);
	}

	ClientUserinfoChanged (ent, userinfo);

#ifdef OLDOBSERVERCODE
	// CTF CODE -- LM_JORM
	value = Info_ValueForKey (userinfo, "autoobserve");
	if (value[0] == '1')
		ent->client->autoobserve = 1;
	else
		ent->client->autoobserve = 0;
#endif

	// Hati - copy enterframe to ctf struct and clear popup entity
	ent->client->ctf.original_enterframe = level.framenum;
	ent->client->ctf.popup_ent = NULL;
	ent->client->last_popup_frame = 0;

	// Hati - initialize spam control variables
	ent->client->spam_band_count = CTF_SPAM_BAND_MAX;
	ent->client->spam_freq_count = CTF_SPAM_FREQ_MIN;
	ent->client->spam_freq_time = level.time;
	
	// STATS-BEGIN LM_Hati
	{
		stats_player_s *p_player = NULL;
		
		if (strcmp(ent->client->pers.netname, "") != 0) //not a blank string
		{
			p_player = stats_find_dropped_player(ent->client->pers.netname);
		}
		if (p_player == NULL)
		{
			p_player = stats_new_player(ent->client->pers.netname);
		}
		ent->client->p_stats_player = p_player;
	}
	// STATS-END LM_Hati

	// END LM_JORM
	

	if (game.maxclients > 1)
		gi.dprintf ("%s connected\n", ent->client->pers.netname);

	ent->svflags = 0; // make sure we start with known default
	ent->client->pers.connected = true;
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x1380b(%rip), %rsi     # 0x59ec5
movq %r14, %rdi
callq 0x18bb0
movq %rax, %rdi
callq 0x19150
testl %eax, %eax
je 0x466f5
leaq 0x14b6c(%rip), %rsi     # 0x5b241
leaq 0x14b6c(%rip), %rdx     # 0x5b248
movq %r14, %rdi
callq 0x18560
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x149de(%rip), %rsi     # 0x5b0da
movq %r14, %rdi
callq 0x18bb0
movq %rax, %r15
movq 0x237b2(%rip), %rax     # 0x69ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x46720
jnp 0x4678b
cmpb $0x0, (%r15)
je 0x4678b
leaq 0x1564f(%rip), %rsi     # 0x5bd7c
movq %r15, %rdi
callq 0x18b20
testl %eax, %eax
je 0x4678b
movq 0x234e8(%rip), %rax     # 0x69c28
movq (%rax), %rax
movq 0x8(%rax), %r12
cmpb $0x0, (%r12)
je 0x467f3
leaq 0x11a7f(%rip), %rsi     # 0x581d8
movq %r12, %rdi
callq 0x18b20
testl %eax, %eax
je 0x467f3
movq %r12, %rdi
movq %r15, %rsi
callq 0x18b20
testl %eax, %eax
je 0x467f3
leaq 0x14ac2(%rip), %rsi     # 0x5b241
leaq 0x14aca(%rip), %rdx     # 0x5b250
jmp 0x466dc
leaq 0x12573(%rip), %rsi     # 0x58d05
movq %r14, %rdi
callq 0x18bb0
movq %rax, %r15
movq 0x230b4(%rip), %rax     # 0x69858
movq (%rax), %rax
movq 0x8(%rax), %r12
cmpb $0x0, (%r12)
je 0x46862
leaq 0x11a1b(%rip), %rsi     # 0x581d8
movq %r12, %rdi
callq 0x18b20
testl %eax, %eax
je 0x46862
movq %r12, %rdi
movq %r15, %rsi
callq 0x18b20
testl %eax, %eax
je 0x46862
leaq 0x14a5a(%rip), %rsi     # 0x5b241
leaq 0x14a8c(%rip), %rdx     # 0x5b27a
jmp 0x466dc
movq 0x22d36(%rip), %rax     # 0x69530
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x4684e
movq 0x22d47(%rip), %rcx     # 0x69558
movl $0x508, %eax            # imm = 0x508
addq (%rcx), %rax
xorl %ecx, %ecx
movl $0x1, %edx
cmpl $0x0, (%rax)
je 0x46833
movq -0x8(%rax), %rsi
cmpl $0x1, 0x750(%rsi)
sbbl $-0x1, %ecx
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
incl %edx
addq $0x4a8, %rax            # imm = 0x4A8
ucomiss %xmm1, %xmm0
ja 0x46820
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
movq 0x236e3(%rip), %rax     # 0x69f38
movq (%rax), %rax
ucomiss 0x20(%rax), %xmm1
jae 0x46a62
leaq 0x123b4(%rip), %rsi     # 0x58c1d
movq %r14, %rdi
callq 0x18bb0
cmpb $0x0, (%rax)
je 0x46a4f
movq 0x234bf(%rip), %rbp     # 0x69d40
movq 0x408(%rbp), %rax
movq 0x22cc9(%rip), %rcx     # 0x69558
movq %rbx, %rdx
subq (%rcx), %rdx
shrq $0x3, %rdx
movabsq $0x6a86036fad87bc40, %rcx # imm = 0x6A86036FAD87BC40
imulq %rdx, %rcx
leaq (%rax,%rcx), %r15
addq %rcx, %rax
addq $-0x9140, %rax          # imm = 0xFFFF6EC0
movq %rax, 0x58(%rbx)
movq 0x9138(%rax), %rax
testq %rax, %rax
je 0x468e3
movl $0x1, (%rax)
movl -0x8040(%r15), %eax
movq -0x8(%r15), %rcx
movl %eax, 0x204(%rcx)
movq $0x0, -0x8(%r15)
cmpl $0x0, 0x60(%rbx)
jne 0x46987
leaq -0x8040(%r15), %r12
leaq 0x4b6ad(%rip), %rdi     # 0x91fa8
movl $0x8038, %edx           # imm = 0x8038
movq %r12, %rsi
callq 0x18c80
leaq -0x89e8(%r15), %r13
movl $0x6b0, %edx            # imm = 0x6B0
movq %r13, %rdi
xorl %esi, %esi
callq 0x18880
movq 0x2347b(%rip), %rax     # 0x69da0
movl (%rax), %eax
movl %eax, -0x8350(%r15)
movq 0x23223(%rip), %rax     # 0x69b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
testb $0x4, %al
je 0x46950
cmpl $-0x4, (%r12)
ja 0x46950
movl $0x0, (%r12)
addq $-0x9080, %r15          # imm = 0xFFFF6F80
movl $0x698, %edx            # imm = 0x698
movq %r13, %rdi
movq %r15, %rsi
callq 0x18c80
cmpl $0x0, 0x620(%rbp)
je 0x4697e
movq 0x58(%rbx), %rax
cmpq $0x0, 0x730(%rax)
jne 0x46987
movq 0x58(%rbx), %rdi
callq 0x19920
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19aa0
movq 0x23407(%rip), %rcx     # 0x69da0
movl (%rcx), %eax
movq 0x58(%rbx), %rdi
movl %eax, 0x9128(%rdi)
xorl %eax, %eax
movq %rax, 0x9130(%rdi)
movl $0x0, 0x10fc(%rdi)
movq $0x1c2, 0x10e0(%rdi) # imm = 0x1C2
movq %rax, 0x10d8(%rdi)
movss 0x4(%rcx), %xmm0
movss %xmm0, 0x10d0(%rdi)
cmpb $0x0, 0x2c0(%rdi)
je 0x469ec
addq $0x2c0, %rdi            # imm = 0x2C0
callq 0x18fc0
testq %rax, %rax
jne 0x469ff
movl $0x2c0, %edi            # imm = 0x2C0
addq 0x58(%rbx), %rdi
callq 0x18470
movq 0x58(%rbx), %rsi
movq %rax, 0x9138(%rsi)
cmpl $0x2, 0x610(%rbp)
jl 0x46a2d
movq 0x22be6(%rip), %rcx     # 0x69600
addq $0x2c0, %rsi            # imm = 0x2C0
leaq 0x14888(%rip), %rdi     # 0x5b2b0
xorl %eax, %eax
callq *0x8(%rcx)
movl $0x0, 0xc8(%rbx)
movq 0x58(%rbx), %rax
movl $0x1, 0x304(%rax)
movl $0x1, %eax
jmp 0x466e6
leaq 0x147eb(%rip), %rsi     # 0x5b241
leaq 0x1483d(%rip), %rdx     # 0x5b29a
jmp 0x466dc
leaq 0x147d8(%rip), %rsi     # 0x5b241
leaq 0xfa9a(%rip), %rdx      # 0x5650a
jmp 0x466dc