// File: /workspace/github_c_makefile_star2_O3/QwazyWabbitWOS[P]lmctf60/p_client.c
// Function: spectator_respawn
void spectator_respawn (edict_t *ent)
{
int i, numspec;
//int New_Team;

	// if the user wants to become a spectator, make sure he doesn't
	// exceed max_spectators

	//sprintf(DBuffer, "sr0 t %d p %d r %d", ent->client->ctf.teamnum,
	//	ent->client->pers.spectator, ent->client->resp.spectator);
	//Debug_Show(DBuffer);


	if (ent->client->pers.spectator) 
	{
		char *value = Info_ValueForKey (ent->client->pers.userinfo, "spectator");
		if (*spectator_password->string && 
			strcmp(spectator_password->string, "none") && 
			strcmp(spectator_password->string, value)) {
			gi.cprintf(ent, PRINT_HIGH, "Spectator password incorrect.\n");
			ent->client->pers.spectator = false;
			gi.WriteByte (svc_stufftext);
			gi.WriteString ("spectator 0\n");
			gi.unicast(ent, true);
			return;
		}

		//This section here really should not need to be in because I am checking previous
		//to this, but I am leaving it in as a precaution
		//-bat

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

		if (numspec >= maxspectators->value) {
			gi.cprintf(ent, PRINT_HIGH, "Server spectator limit is full.");
			ent->client->pers.spectator = false;
			// reset his spectator var
			gi.WriteByte (svc_stufftext);
			gi.WriteString ("spectator 0\n");
			gi.unicast(ent, true);
			return;
		}
	} 
	else 
	{
		// he was a spectator and wants to join the game
		// he must have the right password
		char *value = Info_ValueForKey (ent->client->pers.userinfo, "password");
		if (*password->string && strcmp(password->string, "none") && 
			strcmp(password->string, value)) {
			gi.cprintf(ent, PRINT_HIGH, "Password incorrect.\n");
			ent->client->pers.spectator = true;
			gi.WriteByte (svc_stufftext);
			gi.WriteString ("spectator 1\n");
			gi.unicast(ent, true);
			return;
		}

	}

	// clear client on respawn
	ent->client->resp.score = ent->client->pers.score = 0;

	ent->svflags &= ~SVF_NOCLIENT;
	
	PutClientInServer (ent);

	// add a teleportation effect
	if (!ent->client->pers.spectator)  {
		// send effect
		gi.WriteByte (svc_muzzleflash);
		gi.WriteShort (ent-g_edicts);
		gi.WriteByte (MZ_LOGIN);
		gi.multicast (ent->s.origin, MULTICAST_PVS);

		// hold in place briefly
		ent->client->ps.pmove.pm_flags = PMF_TIME_TELEPORT;
		ent->client->ps.pmove.pm_time = 14;
	}

	ent->client->respawn_time = level.time;

	if (ent->client->pers.spectator) 
	{
		//I added this -bat
		Drop_All(ent);
		if(ent->client->ctf.teamnum == CTF_TEAM_OBSERVER_RED)
			gi.bprintf(PRINT_HIGH, "%s is observing the red team\n", ent->client->pers.netname);
		else if(ent->client->ctf.teamnum == CTF_TEAM_OBSERVER_BLUE)
			gi.bprintf(PRINT_HIGH, "%s is observing the blue team\n", ent->client->pers.netname);
		else
		{
			gi.bprintf (PRINT_HIGH, "%s has moved to the sidelines\n", ent->client->pers.netname);
			ent->client->ctf.teamnum = CTF_TEAM_OBSERVER;
		}
	}
	else
	{
		//I only want to do this if they have typed the spectator command!
		if(ent->client->ctf.teamnum != CTF_TEAM_RED &&
			ent->client->ctf.teamnum != CTF_TEAM_BLUE)
	 		ent->client->ctf.New_Team = Team_To_Join(ent);

		gi.bprintf (PRINT_HIGH, "%s joined the game\n", ent->client->pers.netname);
	}
	
	if(ent->client->ctf.New_Team == CTF_TEAM_RED)
	{
		ent->client->ctf.teamnum = CTF_TEAM_RED;
		ClientSetSkin(ent, NULL);
	}
	else if(ent->client->ctf.New_Team == CTF_TEAM_BLUE)
	{
		ent->client->ctf.teamnum = CTF_TEAM_BLUE;
		ClientSetSkin(ent, NULL);
	}


	ent->client->ctf.New_Team = CTF_TEAM_UNDEFINED;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x58(%rdi), %rax
leaq 0xc0(%rax), %rdi
cmpl $0x0, 0x750(%rax)
je 0x45052
leaq 0x1546b(%rip), %rsi     # 0x5a39a
callq 0x18bb0
movq %rax, %r14
movq 0x23cea(%rip), %rax     # 0x68c28
movq (%rax), %rax
movq 0x8(%rax), %r15
cmpb $0x0, (%r15)
je 0x44f80
leaq 0x1237f(%rip), %rsi     # 0x572d1
movq %r15, %rdi
callq 0x18b20
testl %eax, %eax
je 0x44f80
movq %r15, %rdi
movq %r14, %rsi
callq 0x18b20
testl %eax, %eax
je 0x44f80
movq 0x2368c(%rip), %r14     # 0x68600
leaq 0x15429(%rip), %rdx     # 0x5a3a4
jmp 0x45001
movq 0x235a9(%rip), %rax     # 0x68530
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss 0xdf8f(%rip), %xmm0     # 0x52f28
jb 0x44fdf
movq 0x235b6(%rip), %rcx     # 0x68558
movl $0x508, %eax            # imm = 0x508
addq (%rcx), %rax
xorl %ecx, %ecx
movl $0x2, %edx
cmpl $0x0, (%rax)
je 0x44fc4
movq -0x8(%rax), %rsi
cmpl $0x1, 0x750(%rsi)
sbbl $-0x1, %ecx
xorps %xmm1, %xmm1
cvtsi2ss %edx, %xmm1
addq $0x4a8, %rax            # imm = 0x4A8
incl %edx
ucomiss %xmm1, %xmm0
jae 0x44fb1
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
movq 0x23f52(%rip), %rax     # 0x68f38
movq (%rax), %rax
ucomiss 0x20(%rax), %xmm1
jb 0x450d9
movq 0x23606(%rip), %r14     # 0x68600
leaq 0x10529(%rip), %rdx     # 0x5552a
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq *0x10(%r14)
movq 0x58(%rbx), %rax
movl $0x0, 0x750(%rax)
movl $0xb, %edi
callq *0xc8(%r14)
leaq 0x15393(%rip), %rdi     # 0x5a3c3
callq *0xe8(%r14)
movq 0xb8(%r14), %rax
movq %rbx, %rdi
movl $0x1, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmpq *%rax
leaq 0x12ec0(%rip), %rsi     # 0x57f19
callq 0x18bb0
movq %rax, %r14
movq 0x237f0(%rip), %rax     # 0x68858
movq (%rax), %rax
movq 0x8(%rax), %r15
cmpb $0x0, (%r15)
je 0x450d9
leaq 0x12255(%rip), %rsi     # 0x572d1
movq %r15, %rdi
callq 0x18b20
testl %eax, %eax
je 0x450d9
movq %r15, %rdi
movq %r14, %rsi
callq 0x18b20
testl %eax, %eax
je 0x450d9
movq 0x23562(%rip), %r14     # 0x68600
leaq 0x1532b(%rip), %rdx     # 0x5a3d0
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq *0x10(%r14)
movq 0x58(%rbx), %rax
movl $0x1, 0x750(%rax)
movl $0xb, %edi
callq *0xc8(%r14)
leaq 0x15311(%rip), %rdi     # 0x5a3e5
jmp 0x45030
movq 0x58(%rbx), %rax
xorl %ebp, %ebp
movl %ebp, 0x744(%rax)
movl %ebp, 0xdf4(%rax)
andb $-0x2, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x18a20
movq 0x58(%rbx), %rax
cmpl %ebp, 0x750(%rax)
je 0x4511c
movq 0x23c93(%rip), %rcx     # 0x68da0
movss 0x4(%rcx), %xmm0
movss %xmm0, 0xf28(%rax)
jmp 0x45190
movq 0x234dd(%rip), %r14     # 0x68600
movl $0x1, %edi
callq *0xc8(%r14)
movq 0x23422(%rip), %rax     # 0x68558
movq %rbx, %rcx
subq (%rax), %rcx
shrq $0x3, %rcx
imull $0x8ce2cabd, %ecx, %edi # imm = 0x8CE2CABD
callq *0xd0(%r14)
movl $0x9, %edi
callq *0xc8(%r14)
leaq 0x4(%rbx), %rdi
movl $0x2, %esi
callq *0xb0(%r14)
movq 0x58(%rbx), %rdx
movw $0xe20, 0x10(%rdx)      # imm = 0xE20
cmpl $0x0, 0x750(%rdx)
movq 0x23c1f(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
movss %xmm0, 0xf28(%rdx)
je 0x451f8
movq %rbx, %rdi
callq 0x195d0
movq 0x58(%rbx), %rdx
movl 0x1100(%rdx), %eax
movq 0x23457(%rip), %rcx     # 0x68600
movq (%rcx), %rcx
addq $0x2c0, %rdx            # imm = 0x2C0
cmpl $-0x2, %eax
je 0x451c6
cmpl $-0x3, %eax
jne 0x451d8
leaq 0x1522e(%rip), %rsi     # 0x5a3f2
jmp 0x451cd
leaq 0x15243(%rip), %rsi     # 0x5a410
movl $0x2, %edi
xorl %eax, %eax
callq *%rcx
jmp 0x4522f
leaq 0x15250(%rip), %rsi     # 0x5a42f
movl $0x2, %edi
xorl %eax, %eax
callq *%rcx
movq 0x58(%rbx), %rax
movl $0xffffffff, 0x1100(%rax) # imm = 0xFFFFFFFF
jmp 0x4522f
movl 0x1100(%rdx), %eax
decl %eax
cmpl $0x2, %eax
jb 0x45217
movq %rbx, %rdi
callq 0x18c90
movq 0x58(%rbx), %rdx
movl %eax, 0x1104(%rdx)
addq $0x2c0, %rdx            # imm = 0x2C0
leaq 0x15229(%rip), %rsi     # 0x5a44e
movl $0x2, %edi
xorl %eax, %eax
callq *(%r14)
movq 0x58(%rbx), %rax
movl 0x1104(%rax), %ecx
leal -0x1(%rcx), %edx
cmpl $0x1, %edx
ja 0x45251
movl %ecx, 0x1100(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x196e0
movq 0x58(%rbx), %rax
movl $0x0, 0x1104(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq