// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x0, 0x750(%rax)
je 0x5a64d
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
addq $0xc0, %rdi
leaq 0x1cc05(%rip), %rsi     # 0x7706c
callq 0x18cb0
movq %rax, -0x18(%rbp)
movq 0x287b1(%rip), %rax     # 0x82c28
movq (%rax), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x5a53e
movq 0x28797(%rip), %rax     # 0x82c28
movq (%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x19cc1(%rip), %rsi     # 0x74160
callq 0x18bf0
cmpl $0x0, %eax
je 0x5a53e
movq 0x28774(%rip), %rax     # 0x82c28
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x18bf0
cmpl $0x0, %eax
je 0x5a53e
movq 0x28130(%rip), %rax     # 0x82600
movq 0x10(%rax), %rcx
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq 0x1cb92(%rip), %rdx     # 0x77076
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0x750(%rax)
movl $0xb, %edi
movq 0x280fa(%rip), %rax     # 0x82600
callq *0xc8(%rax)
leaq 0x1cb82(%rip), %rdi     # 0x77095
movq 0x280e6(%rip), %rax     # 0x82600
callq *0xe8(%rax)
movq 0x280d9(%rip), %rax     # 0x82600
movq 0xb8(%rax), %rax
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0x5aa0c
movl $0x1, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
cvtsi2ssl -0xc(%rbp), %xmm1
movq 0x27fd8(%rip), %rax     # 0x82530
movq (%rax), %rax
movss 0x20(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x5a5be
movq 0x27fec(%rip), %rax     # 0x82558
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0x4a8, %rcx, %rcx      # imm = 0x4A8
addq %rcx, %rax
cmpl $0x0, 0x60(%rax)
je 0x5a5b1
movq 0x27fce(%rip), %rax     # 0x82558
movq (%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0x4a8, %rcx, %rcx      # imm = 0x4A8
addq %rcx, %rax
movq 0x58(%rax), %rax
cmpl $0x0, 0x750(%rax)
je 0x5a5b1
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5a5b3
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x5a54c
cvtsi2ssl -0x10(%rbp), %xmm0
movq 0x2896e(%rip), %rax     # 0x82f38
movq (%rax), %rax
ucomiss 0x20(%rax), %xmm0
jb 0x5a648
movq 0x28026(%rip), %rax     # 0x82600
movq 0x10(%rax), %rcx
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq 0x17ed8(%rip), %rdx     # 0x724c6
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0x750(%rax)
movl $0xb, %edi
movq 0x27ff0(%rip), %rax     # 0x82600
callq *0xc8(%rax)
leaq 0x1ca78(%rip), %rdi     # 0x77095
movq 0x27fdc(%rip), %rax     # 0x82600
callq *0xe8(%rax)
movq 0x27fcf(%rip), %rax     # 0x82600
movq 0xb8(%rax), %rax
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0x5aa0c
jmp 0x5a73c
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdi
addq $0xc0, %rdi
leaq 0x1a59e(%rip), %rsi     # 0x74c01
callq 0x18cb0
movq %rax, -0x20(%rbp)
movq 0x281e5(%rip), %rax     # 0x82858
movq (%rax), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x5a73a
movq 0x281cb(%rip), %rax     # 0x82858
movq (%rax), %rax
movq 0x8(%rax), %rdi
leaq 0x19ac5(%rip), %rsi     # 0x74160
callq 0x18bf0
cmpl $0x0, %eax
je 0x5a73a
movq 0x281a8(%rip), %rax     # 0x82858
movq (%rax), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x18bf0
cmpl $0x0, %eax
je 0x5a73a
movq 0x27f34(%rip), %rax     # 0x82600
movq 0x10(%rax), %rcx
movq -0x8(%rbp), %rdi
movl $0x2, %esi
leaq 0x1c9c2(%rip), %rdx     # 0x770a2
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x1, 0x750(%rax)
movl $0xb, %edi
movq 0x27efe(%rip), %rax     # 0x82600
callq *0xc8(%rax)
leaq 0x1c9a8(%rip), %rdi     # 0x770b7
movq 0x27eea(%rip), %rax     # 0x82600
callq *0xe8(%rax)
movq 0x27edd(%rip), %rax     # 0x82600
movq 0xb8(%rax), %rax
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq *%rax
jmp 0x5aa0c
jmp 0x5a73c
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0x744(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0xdf4(%rax)
movq -0x8(%rbp), %rax
movl 0xc8(%rax), %ecx
andl $-0x2, %ecx
movl %ecx, 0xc8(%rax)
movq -0x8(%rbp), %rdi
callq 0x18af0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x0, 0x750(%rax)
jne 0x5a822
movl $0x1, %edi
movq 0x27e63(%rip), %rax     # 0x82600
callq *0xc8(%rax)
movq 0x27e56(%rip), %rax     # 0x82600
movq 0xd0(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x27d98(%rip), %rcx     # 0x82558
movq (%rcx), %rcx
subq %rcx, %rax
movl $0x4a8, %ecx            # imm = 0x4A8
cqto
idivq %rcx
movq %rax, %rcx
movq -0x28(%rbp), %rax
movl %ecx, %edi
callq *%rax
movl $0x9, %edi
movq 0x27e19(%rip), %rax     # 0x82600
callq *0xc8(%rax)
movq 0x27e0c(%rip), %rax     # 0x82600
movq 0xb0(%rax), %rax
movq -0x8(%rbp), %rdi
addq $0x4, %rdi
movl $0x2, %esi
callq *%rax
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movb $0x20, 0x10(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movb $0xe, 0x11(%rax)
movq 0x28577(%rip), %rax     # 0x82da0
movss 0x4(%rax), %xmm0
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movss %xmm0, 0xf28(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x0, 0x750(%rax)
je 0x5a92b
movq -0x8(%rbp), %rdi
callq 0x19810
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $-0x3, 0x1100(%rax)
jne 0x5a8a2
movq 0x27d8c(%rip), %rax     # 0x82600
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
movl $0x2, %edi
leaq 0x1c82b(%rip), %rsi     # 0x770c4
movb $0x0, %al
callq *%rcx
jmp 0x5a929
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $-0x2, 0x1100(%rax)
jne 0x5a8e5
movq 0x27d46(%rip), %rax     # 0x82600
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
movl $0x2, %edi
leaq 0x1c803(%rip), %rsi     # 0x770e2
movb $0x0, %al
callq *%rcx
jmp 0x5a927
movq 0x27d14(%rip), %rax     # 0x82600
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
movl $0x2, %edi
leaq 0x1c7f0(%rip), %rsi     # 0x77101
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0xffffffff, 0x1100(%rax) # imm = 0xFFFFFFFF
jmp 0x5a929
jmp 0x5a996
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x1, 0x1100(%rax)
je 0x5a966
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x2, 0x1100(%rax)
je 0x5a966
movq -0x8(%rbp), %rdi
callq 0x18dd0
movl %eax, %ecx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl %ecx, 0x1104(%rax)
movq 0x27c93(%rip), %rax     # 0x82600
movq (%rax), %rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rdx
addq $0xc0, %rdx
addq $0x200, %rdx            # imm = 0x200
movl $0x2, %edi
leaq 0x1c78e(%rip), %rsi     # 0x77120
movb $0x0, %al
callq *%rcx
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x1, 0x1104(%rax)
jne 0x5a9c8
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x1, 0x1100(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x19930
jmp 0x5a9fa
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
cmpl $0x2, 0x1104(%rax)
jne 0x5a9f8
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x2, 0x1100(%rax)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x19930
jmp 0x5a9fa
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x0, 0x1104(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)