// File: lotuskip[P]yuxtapa/server/game.cpp
// Function: Game::remove_player(std::_List_iterator<Player>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
list<Player>::iterator Game::remove_player(list<Player>::iterator pit,
	const string &reason)
{
	// last_seen was updated when the player connected (and
	// adjusted after each intermission):
	if(intermission)
		pit->stats_i->last_seen += time(NULL) - pit->last_switched_cl;
	else
	{
		del_owneds(pit);
		// Remove any poisoning caused by this player!
		for(list<Player>::iterator it = cur_players.begin();
			it != cur_players.end(); ++it)
		{
			if(it->poisoner == pit)
				it->poisoner = cur_players.end();
		}
	}
	pit->stats_i->total_time += time(NULL) - pit->stats_i->last_seen;
	time(&(pit->stats_i->last_seen));

	if(pit->team != T_SPEC)
	{
		pit->own_vp->move_watchers();
		--num_players[pit->team - T_GREEN];
		send_team_upds(cur_players.end());
	}

	if(pit->is_alive())
		kill_player(pit); // this records time spent as a class
	else
	{
		pit->viewn_vp->drop_watcher(pit->stats_i->ID);
		// if is spec, record time spent as spec:
		if(pit->team == T_SPEC && !intermission)
			pit->stats_i->time_specced += time(NULL) - pit->last_switched_cl;
	}
	
	// If it is a bot, kill the process and ditch stats:
	if(pit->botpid != -1)
	{
		known_players.erase(pit->stats_i);
		Network::send_buffer.clear();
		Network::send_buffer.add((unsigned char)MID_QUIT);
		Network::send_to_player(*pit);
		int cet;
		waitpid(pit->botpid, &cet, 0);
	}
	
	string msg = pit->nick + reason;
	list<Player>::iterator retval = cur_players.erase(pit);
	Network::to_chat(msg);

	// minplayers != 0 implies (by checks in settings.cpp) that bots are around
	if(cur_players.size() < int_settings[IS_MINPLAYERS])
	{
		/* if ALL remaining players are now bots, drop them all */
		if((unsigned int)num_bots() == cur_players.size())
		{
			while(drop_a_bot()); // not fast, but simple
		}
		else // otherwise fill up with a bot
			spawn_bot();
	}

	if(cur_players.empty())
		timed_log("no more players, awaiting connections.");
	else
		active_teambal_check();

	return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x53416(%rip), %rax     # 0x8d530
testb $0x1, (%rax)
je 0x3a182
xorl %eax, %eax
movl %eax, %edi
callq 0x54c0
movq %rax, -0xd8(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rcx
movq -0xd8(%rbp), %rax
subq 0xb8(%rcx), %rax
movq %rax, -0xd0(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
addq $0x80, %rdi
callq 0x1b390
movq -0xd0(%rbp), %rcx
addq 0x128(%rax), %rcx
movq %rcx, 0x128(%rax)
jmp 0x3a220
leaq -0x20(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x18a20
movq -0x20(%rbp), %rdi
callq 0x3c230
leaq 0x56091(%rip), %rdi     # 0x90230
callq 0x1b360
movq %rax, -0x28(%rbp)
leaq 0x56081(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1b100
testb $0x1, %al
jne 0x3a1cb
jmp 0x3a21e
leaq -0x28(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
addq $0x150, %rdi            # imm = 0x150
leaq -0x10(%rbp), %rsi
callq 0x3d990
testb $0x1, %al
jne 0x3a1ed
jmp 0x3a211
leaq 0x5603c(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0x38(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x1b050
movq -0x38(%rbp), %rcx
movq %rcx, 0x150(%rax)
jmp 0x3a213
leaq -0x28(%rbp), %rdi
callq 0x1b3c0
jmp 0x3a1a8
jmp 0x3a220
xorl %eax, %eax
movl %eax, %edi
callq 0x54c0
movq %rax, -0xe8(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
addq $0x80, %rdi
callq 0x1b390
movq %rax, %rcx
movq -0xe8(%rbp), %rax
subq 0x128(%rcx), %rax
movq %rax, -0xe0(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
addq $0x80, %rdi
callq 0x1b390
movq -0xe0(%rbp), %rcx
addq 0xa0(%rax), %rcx
movq %rcx, 0xa0(%rax)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
addq $0x80, %rdi
callq 0x1b390
movq %rax, %rdi
addq $0x128, %rdi            # imm = 0x128
callq 0x54c0
leaq -0x10(%rbp), %rdi
callq 0x1b050
cmpl $0x2, 0xac(%rax)
je 0x3a32d
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq 0xc0(%rax), %rdi
callq 0x42870
leaq -0x10(%rbp), %rdi
callq 0x1b050
movl 0xac(%rax), %eax
subl $0x0, %eax
movslq %eax, %rcx
leaq 0x5709a(%rip), %rax     # 0x91391
movb (%rax,%rcx), %dl
addb $-0x1, %dl
leaq 0x5708d(%rip), %rax     # 0x91391
movb %dl, (%rax,%rcx)
leaq 0x55f22(%rip), %rdi     # 0x90230
callq 0x189f0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x18a20
movq -0x40(%rbp), %rdi
callq 0x36ce0
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
callq 0x21cd0
testb $0x1, %al
jne 0x3a344
jmp 0x3a35a
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
callq 0x546a0
jmp 0x3a416
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq 0xc8(%rax), %rax
movq %rax, -0xf0(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
addq $0x80, %rdi
callq 0x1b390
movq -0xf0(%rbp), %rdi
movzwl (%rax), %esi
callq 0x427b0
leaq -0x10(%rbp), %rdi
callq 0x1b050
cmpl $0x2, 0xac(%rax)
jne 0x3a414
leaq 0x5317f(%rip), %rax     # 0x8d530
testb $0x1, (%rax)
jne 0x3a414
xorl %eax, %eax
movl %eax, %edi
callq 0x54c0
movq %rax, -0x100(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rcx
movq -0x100(%rbp), %rax
subq 0xb8(%rcx), %rax
movq %rax, -0xf8(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rdi
addq $0x80, %rdi
callq 0x1b390
movq -0xf8(%rbp), %rcx
addq 0xa8(%rax), %rcx
movq %rcx, 0xa8(%rax)
jmp 0x3a416
leaq -0x10(%rbp), %rdi
callq 0x1b050
cmpl $-0x1, 0x164(%rax)
je 0x3a4a7
leaq -0x10(%rbp), %rdi
callq 0x1b050
movq %rax, %rsi
addq $0x80, %rsi
leaq -0x58(%rbp), %rdi
callq 0x24e10
movq -0x58(%rbp), %rsi
leaq 0x55dc9(%rip), %rdi     # 0x90218
callq 0x24dc0
movq %rax, -0x60(%rbp)
leaq 0x53e39(%rip), %rdi     # 0x8e298
callq 0x5f370
leaq 0x53e2d(%rip), %rdi     # 0x8e298
movl $0x2, %esi
callq 0x5f390
leaq -0x10(%rbp), %rdi
callq 0x28450
movq %rax, %rdi
leaq 0x53e10(%rip), %rsi     # 0x8e298
callq 0x1af60
leaq -0x10(%rbp), %rdi
callq 0x1b050
movl 0x164(%rax), %edi
leaq -0x64(%rbp), %rsi
xorl %edx, %edx
callq 0x53e0
leaq -0x10(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x1b050
movq %rax, %rsi
addq $0x88, %rsi
movq -0x18(%rbp), %rdx
leaq -0x88(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x24cb0
movq -0x110(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x18a20
movq -0x90(%rbp), %rsi
leaq 0x55d37(%rip), %rdi     # 0x90230
callq 0x3d9c0
movq -0x108(%rbp), %rdi
movq %rax, -0x8(%rbp)
callq 0x1acd0
jmp 0x3a510
leaq 0x55d19(%rip), %rdi     # 0x90230
callq 0x25070
leaq 0x554ed(%rip), %rcx     # 0x8fa10
movl 0x2c(%rcx), %ecx
cmpq %rcx, %rax
jae 0x3a5a6
callq 0x23f40
movw %ax, -0x112(%rbp)
jmp 0x3a539
movw -0x112(%rbp), %ax
cwtl
movl %eax, %eax
movq %rax, -0x120(%rbp)
leaq 0x55cdf(%rip), %rdi     # 0x90230
callq 0x25070
movq %rax, %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
jne 0x3a59b
jmp 0x3a567
callq 0x5d300
movb %al, -0x121(%rbp)
jmp 0x3a574
movb -0x121(%rbp), %al
testb $0x1, %al
jne 0x3a580
jmp 0x3a599
jmp 0x3a567
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x3a674
jmp 0x3a5a4
callq 0x5d0d0
jmp 0x3a5a2
jmp 0x3a5a4
jmp 0x3a5a6
leaq 0x55c83(%rip), %rdi     # 0x90230
callq 0x25150
testb $0x1, %al
jne 0x3a5bb
jmp 0x3a652
leaq -0xc1(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x5930
movq -0x130(%rbp), %rdx
leaq 0x29c23(%rip), %rsi     # 0x641ff
leaq -0xc0(%rbp), %rdi
callq 0x18880
jmp 0x3a5ea
leaq -0xc0(%rbp), %rdi
callq 0x28f60
jmp 0x3a5f8
leaq -0xc0(%rbp), %rdi
callq 0x5a48
leaq -0xc1(%rbp), %rdi
callq 0x5590
jmp 0x3a65b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x3a644
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x5a48
leaq -0xc1(%rbp), %rdi
callq 0x5590
jmp 0x3a674
callq 0x3c7a0
jmp 0x3a659
jmp 0x3a65b
leaq -0x88(%rbp), %rdi
callq 0x5a48
movq -0x8(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0x5a48
movq -0x98(%rbp), %rdi
callq 0x5920
nopl (%rax)