// File: /workspace/github_c_makefile_star2_O1/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 0x45bfa
leaq 0x15603(%rip), %rsi     # 0x5b0da
callq 0x18bb0
movq %rax, %r14
movq 0x24142(%rip), %rax     # 0x69c28
movq (%rax), %rax
movq 0x8(%rax), %r15
cmpb $0x0, (%r15)
je 0x45b28
leaq 0x126de(%rip), %rsi     # 0x581d8
movq %r15, %rdi
callq 0x18b20
testl %eax, %eax
je 0x45b28
movq %r15, %rdi
movq %r14, %rsi
callq 0x18b20
testl %eax, %eax
je 0x45b28
movq 0x23ae4(%rip), %r14     # 0x69600
leaq 0x155c1(%rip), %rdx     # 0x5b0e4
jmp 0x45ba9
movq 0x23a01(%rip), %rax     # 0x69530
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss 0xe3e7(%rip), %xmm0     # 0x53f28
jb 0x45b87
movq 0x23a0e(%rip), %rcx     # 0x69558
movl $0x508, %eax            # imm = 0x508
addq (%rcx), %rax
xorl %ecx, %ecx
movl $0x2, %edx
cmpl $0x0, (%rax)
je 0x45b6c
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 0x45b59
xorps %xmm1, %xmm1
cvtsi2ss %ecx, %xmm1
movq 0x243aa(%rip), %rax     # 0x69f38
movq (%rax), %rax
ucomiss 0x20(%rax), %xmm1
jb 0x45c81
movq 0x23a5e(%rip), %r14     # 0x69600
leaq 0x10961(%rip), %rdx     # 0x5650a
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 0x1552b(%rip), %rdi     # 0x5b103
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 0x13104(%rip), %rsi     # 0x58d05
callq 0x18bb0
movq %rax, %r14
movq 0x23c48(%rip), %rax     # 0x69858
movq (%rax), %rax
movq 0x8(%rax), %r15
cmpb $0x0, (%r15)
je 0x45c81
leaq 0x125b4(%rip), %rsi     # 0x581d8
movq %r15, %rdi
callq 0x18b20
testl %eax, %eax
je 0x45c81
movq %r15, %rdi
movq %r14, %rsi
callq 0x18b20
testl %eax, %eax
je 0x45c81
movq 0x239ba(%rip), %r14     # 0x69600
leaq 0x154c3(%rip), %rdx     # 0x5b110
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 0x154a9(%rip), %rdi     # 0x5b125
jmp 0x45bd8
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)
jne 0x45d05
movq 0x2394b(%rip), %r14     # 0x69600
movl $0x1, %edi
callq *0xc8(%r14)
movq 0x23890(%rip), %rax     # 0x69558
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), %rax
movw $0xe20, 0x10(%rax)      # imm = 0xE20
movq 0x24094(%rip), %rax     # 0x69da0
movss 0x4(%rax), %xmm0
movq 0x58(%rbx), %rax
movss %xmm0, 0xf28(%rax)
cmpl $0x0, 0x750(%rax)
je 0x45d5c
movq %rbx, %rdi
callq 0x195d0
movq 0x58(%rbx), %rdx
movl 0x1100(%rdx), %eax
movq 0x238c1(%rip), %rcx     # 0x69600
movq (%rcx), %rcx
addq $0x2c0, %rdx            # imm = 0x2C0
cmpl $-0x2, %eax
je 0x45d9d
cmpl $-0x3, %eax
jne 0x45daf
leaq 0x153d8(%rip), %rsi     # 0x5b132
jmp 0x45da4
movl 0x1100(%rax), %eax
decl %eax
cmpl $0x2, %eax
jb 0x45d7b
movq %rbx, %rdi
callq 0x18c90
movq 0x58(%rbx), %rcx
movl %eax, 0x1104(%rcx)
movq 0x2387e(%rip), %rcx     # 0x69600
movl $0x2c0, %edx            # imm = 0x2C0
addq 0x58(%rbx), %rdx
leaq 0x153fc(%rip), %rsi     # 0x5b18e
movl $0x2, %edi
xorl %eax, %eax
callq *(%rcx)
jmp 0x45dcd
leaq 0x153ac(%rip), %rsi     # 0x5b150
movl $0x2, %edi
xorl %eax, %eax
callq *%rcx
jmp 0x45dcd
leaq 0x153b9(%rip), %rsi     # 0x5b16f
movl $0x2, %edi
xorl %eax, %eax
callq *%rcx
movq 0x58(%rbx), %rax
movl $0xffffffff, 0x1100(%rax) # imm = 0xFFFFFFFF
movq 0x58(%rbx), %rax
movl 0x1104(%rax), %ecx
leal -0x1(%rcx), %edx
cmpl $0x1, %edx
ja 0x45def
movl %ecx, 0x1100(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x196f0
movq 0x58(%rbx), %rax
movl $0x0, 0x1104(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq