// File: /workspace/github_c_makefile_star2_O3/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 0x135ce(%rip), %rsi     # 0x590d9
movq %r14, %rdi
callq 0x18bb0
movq %rax, %rdi
callq 0x19150
testl %eax, %eax
je 0x45b46
leaq 0x149db(%rip), %rsi     # 0x5a501
leaq 0x149db(%rip), %rdx     # 0x5a508
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 0x1484d(%rip), %rsi     # 0x5a39a
movq %r14, %rdi
callq 0x18bb0
movq %rax, %r15
movq 0x23361(%rip), %rax     # 0x68ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x45b71
jnp 0x45bd7
movzbl (%r15), %eax
testl %eax, %eax
je 0x45bd7
cmpl $0x30, %eax
jne 0x45b85
cmpb $0x0, 0x1(%r15)
je 0x45bd7
movq 0x2309c(%rip), %rax     # 0x68c28
movq (%rax), %rax
movq 0x8(%rax), %r12
cmpb $0x0, (%r12)
je 0x45c3f
leaq 0x1172c(%rip), %rsi     # 0x572d1
movq %r12, %rdi
callq 0x18b20
testl %eax, %eax
je 0x45c3f
movq %r12, %rdi
movq %r15, %rsi
callq 0x18b20
testl %eax, %eax
je 0x45c3f
leaq 0x14936(%rip), %rsi     # 0x5a501
leaq 0x1493e(%rip), %rdx     # 0x5a510
jmp 0x45b2d
leaq 0x1233b(%rip), %rsi     # 0x57f19
movq %r14, %rdi
callq 0x18bb0
movq %rax, %r15
movq 0x22c68(%rip), %rax     # 0x68858
movq (%rax), %rax
movq 0x8(%rax), %r12
cmpb $0x0, (%r12)
je 0x45cae
leaq 0x116c8(%rip), %rsi     # 0x572d1
movq %r12, %rdi
callq 0x18b20
testl %eax, %eax
je 0x45cae
movq %r12, %rdi
movq %r15, %rsi
callq 0x18b20
testl %eax, %eax
je 0x45cae
leaq 0x148ce(%rip), %rsi     # 0x5a501
leaq 0x14900(%rip), %rdx     # 0x5a53a
jmp 0x45b2d
movq 0x228ea(%rip), %rax     # 0x68530
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x45c9a
movq 0x228fb(%rip), %rcx     # 0x68558
movl $0x508, %eax            # imm = 0x508
addq (%rcx), %rax
xorl %ecx, %ecx
movl $0x1, %edx
cmpl $0x0, (%rax)
je 0x45c7f
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 0x45c6c
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
movq 0x23297(%rip), %rax     # 0x68f38
movq (%rax), %rax
ucomiss 0x20(%rax), %xmm1
jae 0x45ea8
leaq 0x1217c(%rip), %rsi     # 0x57e31
movq %r14, %rdi
callq 0x18bb0
cmpb $0x0, (%rax)
je 0x45e95
movq 0x23073(%rip), %rbp     # 0x68d40
movq 0x408(%rbp), %rax
movq 0x2287d(%rip), %rcx     # 0x68558
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 0x45d2b
movl $0x1, (%rax)
movl -0x8040(%r15), %ecx
movl %ecx, 0x204(%rax)
movq $0x0, -0x8(%r15)
cmpl $0x0, 0x60(%rbx)
jne 0x45dcb
leaq -0x8040(%r15), %r12
leaq 0x4b265(%rip), %rdi     # 0x90fa8
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 0x23033(%rip), %rax     # 0x68da0
movl (%rax), %eax
movl %eax, -0x8350(%r15)
movq 0x22ddb(%rip), %rax     # 0x68b58
movq (%rax), %rax
cvttss2si 0x20(%rax), %eax
testb $0x4, %al
je 0x45d98
cmpl $-0x4, (%r12)
ja 0x45d98
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)
movq 0x58(%rbx), %rdi
je 0x45dc6
cmpq $0x0, 0x730(%rdi)
jne 0x45dcb
callq 0x19910
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19a90
movq 0x22fc3(%rip), %rax     # 0x68da0
movl (%rax), %ecx
movq 0x58(%rbx), %rdi
movl %ecx, 0x9128(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x9130(%rdi)
movl $0x0, 0x10fc(%rdi)
movq $0x1c2, 0x10e0(%rdi) # imm = 0x1C2
movq %rcx, 0x10d8(%rdi)
movss 0x4(%rax), %xmm0
movss %xmm0, 0x10d0(%rdi)
cmpb $0x0, 0x2c0(%rdi)
je 0x45e39
addq $0x2c0, %rdi            # imm = 0x2C0
callq 0x18fc0
testq %rax, %rax
jne 0x45e45
movq 0x58(%rbx), %rdi
addq $0x2c0, %rdi            # imm = 0x2C0
callq 0x18470
movq 0x58(%rbx), %rsi
movq %rax, 0x9138(%rsi)
cmpl $0x2, 0x610(%rbp)
jl 0x45e77
movq 0x227a0(%rip), %rcx     # 0x68600
addq $0x2c0, %rsi            # imm = 0x2C0
leaq 0x14702(%rip), %rdi     # 0x5a570
xorl %eax, %eax
callq *0x8(%rcx)
movq 0x58(%rbx), %rsi
movl $0x0, 0xc8(%rbx)
movl $0x1, 0x304(%rsi)
movl $0x1, %eax
jmp 0x45b37
leaq 0x14665(%rip), %rsi     # 0x5a501
leaq 0x146b7(%rip), %rdx     # 0x5a55a
jmp 0x45b2d
leaq 0x14652(%rip), %rsi     # 0x5a501
leaq 0xf674(%rip), %rdx      # 0x5552a
jmp 0x45b2d