// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x58(%rdi), %rax
leaq 0xc0(%rax), %rdi
cmpl $0x0, 0x750(%rax)
je 0x4169f
leaq 0x14deb(%rip), %rsi     # 0x5638a
callq 0x18c70
movq %rax, %r14
movq 0x2567a(%rip), %rax     # 0x66c28
movq (%rax), %rax
movq 0x8(%rax), %r15
cmpb $0x0, (%r15)
je 0x415ed
leaq 0x11cef(%rip), %rsi     # 0x532b1
movq %r15, %rdi
callq 0x18bc0
testl %eax, %eax
je 0x415ed
movq %r15, %rdi
movq %r14, %rsi
callq 0x18bc0
testl %eax, %eax
je 0x415ed
movq 0x2501c(%rip), %r14     # 0x66600
leaq 0x14da9(%rip), %rdx     # 0x56394
jmp 0x4165c
movq 0x24f3c(%rip), %rax     # 0x66530
movq (%rax), %rax
movss 0x20(%rax), %xmm0
movq 0x24f55(%rip), %rcx     # 0x66558
movl $0x508, %eax            # imm = 0x508
addq (%rcx), %rax
xorl %ecx, %ecx
pushq $0x1
popq %rdx
cvtsi2ss %edx, %xmm1
ucomiss %xmm1, %xmm0
jb 0x41636
cmpl $0x0, (%rax)
je 0x4162c
movq -0x8(%rax), %rsi
cmpl $0x1, 0x750(%rsi)
sbbl $-0x1, %ecx
addq $0x4a8, %rax            # imm = 0x4A8
incl %edx
jmp 0x41610
cvtsi2ss %ecx, %xmm0
movq 0x258f7(%rip), %rax     # 0x66f38
movq (%rax), %rax
ucomiss 0x20(%rax), %xmm0
jb 0x41722
movq 0x24fab(%rip), %r14     # 0x66600
leaq 0xfeae(%rip), %rdx      # 0x5150a
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq *0x10(%r14)
movq 0x58(%rbx), %rax
andl $0x0, 0x750(%rax)
pushq $0xb
popq %rdi
callq *0xc8(%r14)
leaq 0x14d2f(%rip), %rdi     # 0x563b3
callq *0xe8(%r14)
movq 0xb8(%r14), %rax
pushq $0x1
popq %rsi
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmpq *%rax
leaq 0x12853(%rip), %rsi     # 0x53ef9
callq 0x18c70
movq %rax, %r14
movq 0x251a3(%rip), %rax     # 0x66858
movq (%rax), %rax
movq 0x8(%rax), %r15
cmpb $0x0, (%r15)
je 0x41722
leaq 0x11be8(%rip), %rsi     # 0x532b1
movq %r15, %rdi
callq 0x18bc0
testl %eax, %eax
je 0x41722
movq %r15, %rdi
movq %r14, %rsi
callq 0x18bc0
testl %eax, %eax
je 0x41722
movq 0x24f15(%rip), %r14     # 0x66600
leaq 0x14cce(%rip), %rdx     # 0x563c0
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq *0x10(%r14)
movq 0x58(%rbx), %rax
movl $0x1, 0x750(%rax)
pushq $0xb
popq %rdi
callq *0xc8(%r14)
leaq 0x14cb8(%rip), %rdi     # 0x563d5
jmp 0x41684
movq 0x58(%rbx), %rax
andl $0x0, 0x744(%rax)
andl $0x0, 0xdf4(%rax)
andb $-0x2, 0xc8(%rbx)
movq %rbx, %rdi
callq 0x18ac0
movq 0x58(%rbx), %rax
xorl %ecx, %ecx
cmpl %ecx, 0x750(%rax)
je 0x41767
movq 0x25648(%rip), %rcx     # 0x66da0
movss 0x4(%rcx), %xmm0
movss %xmm0, 0xf28(%rax)
jmp 0x417d7
movq 0x24e92(%rip), %r14     # 0x66600
pushq $0x1
popq %rdi
callq *0xc8(%r14)
movq 0x24dd9(%rip), %rcx     # 0x66558
movq %rbx, %rax
subq (%rcx), %rax
movl $0x4a8, %ecx            # imm = 0x4A8
cqto
idivq %rcx
movl %eax, %edi
callq *0xd0(%r14)
pushq $0x9
popq %rdi
callq *0xc8(%r14)
leaq 0x4(%rbx), %rdi
pushq $0x2
popq %rsi
callq *0xb0(%r14)
movq 0x58(%rbx), %rdx
movw $0xe20, 0x10(%rdx)      # imm = 0xE20
cmpl $0x0, 0x750(%rdx)
movq 0x255d8(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
movss %xmm0, 0xf28(%rdx)
je 0x41838
movq %rbx, %rdi
callq 0x19790
movq 0x58(%rbx), %rdx
movl 0x1100(%rdx), %eax
movq 0x24e10(%rip), %rcx     # 0x66600
movq (%rcx), %rcx
addq $0x2c0, %rdx            # imm = 0x2C0
cmpl $-0x2, %eax
je 0x4180d
cmpl $-0x3, %eax
jne 0x4181d
leaq 0x14bd7(%rip), %rsi     # 0x563e2
jmp 0x41814
leaq 0x14bec(%rip), %rsi     # 0x56400
pushq $0x2
popq %rdi
xorl %eax, %eax
callq *%rcx
jmp 0x4186d
leaq 0x14bfb(%rip), %rsi     # 0x5641f
pushq $0x2
popq %rdi
xorl %eax, %eax
callq *%rcx
movq 0x58(%rbx), %rax
orl $-0x1, 0x1100(%rax)
jmp 0x4186d
movl 0x1100(%rdx), %eax
decl %eax
cmpl $0x2, %eax
jb 0x41857
movq %rbx, %rdi
callq 0x18d70
movq 0x58(%rbx), %rdx
movl %eax, 0x1104(%rdx)
addq $0x2c0, %rdx            # imm = 0x2C0
leaq 0x14bd9(%rip), %rsi     # 0x5643e
pushq $0x2
popq %rdi
xorl %eax, %eax
callq *(%r14)
movq 0x58(%rbx), %rax
movl 0x1104(%rax), %ecx
leal -0x1(%rcx), %edx
cmpl $0x1, %edx
ja 0x4188f
movl %ecx, 0x1100(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x198b0
movq 0x58(%rbx), %rax
andl $0x0, 0x1104(%rax)
popq %rbx
popq %r14
popq %r15
retq