// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/p_client.c
// Function: ClientDisconnect
void ClientDisconnect (edict_t *ent)
{
	int 	playernum;
	edict_t	*flag;  // CTF CODE -- LM_JORM
	char message[MAX_INFO_STRING];

	if (!ent->client)
		return;
	
	// STATS-BEGIN LM_Hati
	if (ent->client->p_stats_player)
	{
		ent->client->p_stats_player->dropped = true;
		ent->client->p_stats_player->info.teamnum = ent->client->ctf.teamnum;
	}
	// STATS-END LM_Hati

	// Players drop runes on quit. //QW//
	if(ent->client->rune)
		Drop_Rune(ent, ent->client->rune->item);

	// CTF CODE -- LM_JORM
	ent->client->ctf.extra_flags &= ~CTF_EXTRAFLAGS_REFEREE; // Turn off referee mode
	ent->client->ctf.extra_flags &= ~CTF_EXTRAFLAGS_RCON; //turn off rcon mode
	
	// Were we carrying a flag?  MJD Suggest Parens Here
	flag = ClientHasFlag(ent);
	if (flag)//surt to avoid compiler warns on linux/solaris (assignment in conditional)
	{
		if (flag->owner == ent) // We owned this flag
		{
			ctf_playerdropflag(ent, flag->item);
		}
	}
	
	if (ent->client->hook)
	{
		G_FreeEdict (ent->client->hook);
		ent->client->hook = NULL;
	}
	
	
	// END CTF CODE -- LM_JORM
	
	sl_LogPlayerDisconnect( &gi, level, ent ); // StdLog - Mark Davies
	
	sprintf(message, "%s disconnected\n", ent->client->pers.netname);
	ctf_BSafePrint(PRINT_HIGH, message);
	
	// send effect
	gi.WriteByte (svc_muzzleflash);
	gi.WriteShort (ent-g_edicts);
	gi.WriteByte (MZ_LOGOUT);
	gi.multicast (ent->s.origin, MULTICAST_PVS);

	gi.unlinkentity (ent);
	ent->s.modelindex = 0;
	ent->solid = SOLID_NOT;
	ent->inuse = false;
	ent->classname = "disconnected";
	ent->client->p_stats_player = NULL; // LM_Hati
	ent->client->pers.connected = false;

	playernum = ent-g_edicts-1;
	gi.configstring (CS_PLAYERSKINS+playernum, "");
	
	//ctf_ClientDisconnect(ent);
	
}

// Assembly:
movq 0x58(%rdi), %rax
testq %rax, %rax
je 0x424fe
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x368, %rsp            # imm = 0x368
movq %rdi, %rbx
movq 0x9138(%rax), %rcx
testq %rcx, %rcx
je 0x4239c
movl $0x1, (%rcx)
movl 0x1100(%rax), %edx
movl %edx, 0x204(%rcx)
movq 0xf68(%rax), %rcx
testq %rcx, %rcx
je 0x423bb
movq 0x330(%rcx), %rsi
movq %rbx, %rdi
callq 0x19b20
movq 0x58(%rbx), %rax
andb $-0x7, 0x1108(%rax)
movq %rbx, %rdi
callq 0x18150
testq %rax, %rax
je 0x423e7
cmpq %rbx, 0x110(%rax)
jne 0x423e7
movq 0x330(%rax), %rsi
movq %rbx, %rdi
callq 0x19a00
movq 0x58(%rbx), %rax
movq 0xf60(%rax), %rdi
testq %rdi, %rdi
je 0x42408
callq 0x19c50
movq 0x58(%rbx), %rax
andq $0x0, 0xf60(%rax)
movq 0x24991(%rip), %rsi     # 0x66da0
pushq $0x2b
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x241e1(%rip), %r14     # 0x66600
movq %r14, %rdi
movq %rbx, %rsi
callq 0x196a0
movl $0x2c0, %edx            # imm = 0x2C0
addq 0x58(%rbx), %rdx
leaq 0x14134(%rip), %rsi     # 0x5656e
leaq 0x160(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x198c0
pushq $0x2
popq %rdi
movq %r15, %rsi
callq 0x193f0
pushq $0x1
popq %rdi
callq *0xc8(%r14)
movq 0x240f0(%rip), %r15     # 0x66558
movq %rbx, %rax
subq (%r15), %rax
movl $0x4a8, %r12d           # imm = 0x4A8
cqto
idivq %r12
movl %eax, %edi
callq *0xd0(%r14)
pushq $0xa
popq %rdi
callq *0xc8(%r14)
leaq 0x4(%rbx), %rdi
pushq $0x2
popq %rsi
callq *0xb0(%r14)
movq %rbx, %rdi
callq *0x98(%r14)
andl $0x0, 0x28(%rbx)
andl $0x0, 0x108(%rbx)
andl $0x0, 0x60(%rbx)
leaq 0x140c5(%rip), %rax     # 0x5657f
movq %rax, 0x138(%rbx)
movq 0x58(%rbx), %rax
andq $0x0, 0x9138(%rax)
andl $0x0, 0x304(%rax)
subq (%r15), %rbx
movq %rbx, %rax
cqto
idivq %r12
leal 0x51f(%rax), %edi
leaq 0xda59(%rip), %rsi      # 0x4ff45
callq *0x30(%r14)
addq $0x368, %rsp            # imm = 0x368
popq %rbx
popq %r12
popq %r14
popq %r15
retq