// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/server/players.cpp
// Function: player_hello(unsigned short, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, sockaddr_storage&, bool)
unsigned short player_hello(const unsigned short id, string &passw,
	const string &nick, sockaddr_storage &sas, const bool is_bot)
{
	/* First check if this client is already registered, because the same
	 * client might send multiple hellos having lost the reply. We don't want
	 * to first accept them and then kick them out because they didn't hear
	 * our first reply. */
	list<Player>::const_iterator it = find_pl_by_sas(sas);
	if(it != cur_players.end())
	{
		// we have already replied; figure out what:
		if(it->stats_i->ID == id)
			return JOIN_OK_ID_OK;
		// else we assigned them a new id already
		passw.assign(it->stats_i->password);
		return it->stats_i->ID;
	}

	// Check if IP is banned:
	for(list<sockaddr_storage>::const_iterator sit = banned_ips.begin();
		sit != banned_ips.end(); ++sit)
	{
		if(equal_ip(&sas, &(*sit)))
			return IP_BANNED;
	}

	// Check server being at full capacity:
	if(cur_players.size() >= Config::int_settings[Config::IS_MAXPLAYERS])
	{
		// There are too many players, but some of them might be bots.
		if(!drop_a_bot()) // no bots to drop!
			return SERVER_FULL;
		// else a bot was dropped and there is room again, proceed:
	}

	if(id == 0xFFFF) // a new player
		return add_and_register_player(nick, passw, sas, is_bot);

	// Check if ID is already playing:
	for(it = cur_players.begin(); it != cur_players.end(); ++it)
	{
		if(it->stats_i->ID == id)
			return ID_STEAL;
	}

	// Check if we actually know this player like they claim:
	list<PlayerStats>::iterator si;
	for(si = known_players.begin(); si != known_players.end(); ++si)
	{
		if(si->ID == id) // it is a returning customer
		{
			if(passw != si->password) // received wrong password!
				return ID_STEAL;
			// else all is good:
			register_player(nick, sas, si, is_bot);
			return JOIN_OK_ID_OK;
		}
	}
	// If here, we have forgotten about this player, most likely
	return add_and_register_player(nick, passw, sas, is_bot);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, -0x2c(%rbp)
movq %rcx, %rbx
movq %rdx, -0x40(%rbp)
movq %rsi, -0x38(%rbp)
movl %edi, %r13d
movzwl 0x2(%rcx), %r15d
leaq 0x3109e(%rip), %r12     # 0x400b0
movq %r12, %r14
movq (%r14), %r14
cmpq %r12, %r14
je 0xf069
leaq 0x10(%r14), %rdi
movq %rbx, %rsi
callq 0xf18f
testb %al, %al
je 0xf015
cmpw %r15w, 0x12(%r14)
jne 0xf015
movq 0x90(%r14), %rsi
movw $0xffff, %r15w          # imm = 0xFFFF
cmpw %r13w, 0x10(%rsi)
je 0xf14a
addq $0x12, %rsi
movq -0x38(%rbp), %rdi
callq 0x4780
movq 0x90(%r14), %rax
movzwl 0x10(%rax), %r15d
jmp 0xf14a
leaq 0x31058(%rip), %r14     # 0x400c8
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0xf095
leaq 0x10(%r15), %rsi
movq %rbx, %rdi
callq 0xf18f
testb %al, %al
je 0xf073
movw $0xfffd, %r15w          # imm = 0xFFFD
jmp 0xf14a
leaq 0x307f4(%rip), %rax     # 0x3f890
movl (%rax), %eax
cmpq %rax, 0x3101b(%rip)     # 0x400c0
jb 0xf0b9
movw $0xfffc, %r15w          # imm = 0xFFFC
callq 0x23ecd
testb %al, %al
je 0xf14a
cmpw $-0x1, %r13w
je 0xf15c
leaq 0x30fe5(%rip), %rax     # 0x400b0
movq %rax, %rcx
movq (%rcx), %rcx
cmpq %rax, %rcx
je 0xf0eb
movq 0x90(%rcx), %rdx
cmpw %r13w, 0x10(%rdx)
jne 0xf0ce
movw $0xfffe, %r15w          # imm = 0xFFFE
jmp 0xf14a
leaq 0x30fa6(%rip), %rax     # 0x40098
movq %rax, %r14
movq (%r14), %r14
cmpq %rax, %r14
je 0xf15c
cmpw %r13w, 0x10(%r14)
jne 0xf0f5
leaq 0x12(%r14), %rsi
movq -0x38(%rbp), %rdi
callq 0xfe80
movw $0xfffe, %r15w          # imm = 0xFFFE
testb %al, %al
jne 0xf14a
leaq -0x60(%rbp), %r15
movq %r15, %rdi
movq -0x40(%rbp), %rsi
callq 0x4590
movzbl -0x2c(%rbp), %ecx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0xf305
leaq -0x60(%rbp), %rdi
callq 0x47e8
movw $0xffff, %r15w          # imm = 0xFFFF
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl -0x2c(%rbp), %ecx
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf1c9
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x47e8
movq %rbx, %rdi
callq 0x4710