// File: /workspace/github_c_makefile_star2_O3/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 0x46064
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x368, %rsp            # imm = 0x368
movq %rdi, %rbx
movq 0x9138(%rax), %rcx
testq %rcx, %rcx
je 0x45ef6
movl $0x1, (%rcx)
movl 0x1100(%rax), %edx
movl %edx, 0x204(%rcx)
movq 0xf68(%rax), %rcx
testq %rcx, %rcx
je 0x45f15
movq 0x330(%rcx), %rsi
movq %rbx, %rdi
callq 0x19940
movq 0x58(%rbx), %rax
andb $-0x7, 0x1108(%rax)
movq %rbx, %rdi
callq 0x18150
testq %rax, %rax
je 0x45f41
cmpq %rbx, 0x110(%rax)
jne 0x45f41
movq 0x330(%rax), %rsi
movq %rbx, %rdi
callq 0x19820
movq 0x58(%rbx), %rax
movq 0xf60(%rax), %rdi
testq %rdi, %rdi
je 0x45f65
callq 0x19a50
movq 0x58(%rbx), %rax
movq $0x0, 0xf60(%rax)
movq 0x22e34(%rip), %rsi     # 0x68da0
movl $0x2b, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq 0x22682(%rip), %r14     # 0x68600
movq %r14, %rdi
movq %rbx, %rsi
callq 0x194f0
movl $0x2c0, %edx            # imm = 0x2C0
addq 0x58(%rbx), %rdx
leaq 0x145e5(%rip), %rsi     # 0x5a57e
xorl %ebp, %ebp
leaq 0x160(%rsp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x196f0
movl $0x2, %edi
movq %r15, %rsi
callq 0x19270
movl $0x1, %edi
callq *0xc8(%r14)
movq 0x2258b(%rip), %r15     # 0x68558
movq %rbx, %rax
subq (%r15), %rax
shrq $0x3, %rax
imull $0x8ce2cabd, %eax, %edi # imm = 0x8CE2CABD
callq *0xd0(%r14)
movl $0xa, %edi
callq *0xc8(%r14)
leaq 0x4(%rbx), %rdi
movl $0x2, %esi
callq *0xb0(%r14)
movq %rbx, %rdi
callq *0x98(%r14)
movl %ebp, 0x28(%rbx)
movl %ebp, 0x108(%rbx)
movl %ebp, 0x60(%rbx)
leaq 0x14572(%rip), %rax     # 0x5a58f
movq %rax, 0x138(%rbx)
movq 0x58(%rbx), %rax
movq $0x0, 0x9138(%rax)
movl %ebp, 0x304(%rax)
subq (%r15), %rbx
shrq $0x3, %rbx
imull $0x8ce2cabd, %ebx, %edi # imm = 0x8CE2CABD
addl $0x51f, %edi            # imm = 0x51F
leaq 0xdef2(%rip), %rsi      # 0x53f45
callq *0x30(%r14)
addq $0x368, %rsp            # imm = 0x368
popq %rbx
popq %r14
popq %r15
popq %rbp
retq