// File: /workspace/github_cpp_makefile_star2_O3/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
movq 0x2ff55(%rip), %r15     # 0x430c0
leaq 0x2ff4e(%rip), %r12     # 0x430c0
cmpq %r12, %r15
je 0x1319f
movzwl 0x2(%rbx), %r14d
leaq 0x10(%r15), %rdi
movq %rbx, %rsi
callq 0x1333e
testb %al, %al
je 0x13197
cmpw %r14w, 0x12(%r15)
je 0x1321d
movq (%r15), %r15
cmpq %r12, %r15
jne 0x1317c
leaq 0x2ff32(%rip), %r14     # 0x430d8
movq %r14, %r15
movq (%r15), %r15
cmpq %r14, %r15
je 0x131cb
leaq 0x10(%r15), %rsi
movq %rbx, %rdi
callq 0x1333e
testb %al, %al
je 0x131a9
movw $0xfffd, %r14w          # imm = 0xFFFD
jmp 0x132ed
leaq 0x2f6ce(%rip), %rax     # 0x428a0
movl (%rax), %eax
cmpq %rax, 0x2fef5(%rip)     # 0x430d0
jb 0x131ef
movw $0xfffc, %r14w          # imm = 0xFFFC
callq 0x2a7f1
testb %al, %al
je 0x132ed
cmpw $-0x1, %r13w
je 0x132ff
movq %r12, %rax
movq (%rax), %rax
cmpq %r12, %rax
je 0x1326d
movq 0x90(%rax), %rcx
cmpw %r13w, 0x10(%rcx)
jne 0x131fd
movw $0xfffe, %r14w          # imm = 0xFFFE
jmp 0x132ed
movq 0x90(%r15), %rbx
movw $0xffff, %r14w          # imm = 0xFFFF
cmpw %r13w, 0x10(%rbx)
je 0x132ed
addq $0x12, %rbx
movq -0x38(%rbp), %r12
movq 0x8(%r12), %r14
movq %rbx, %rdi
callq 0x41a0
movq %r12, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x4630
movq 0x90(%r15), %rax
movzwl 0x10(%rax), %r14d
jmp 0x132ed
leaq 0x2fe34(%rip), %rax     # 0x430a8
movq %rax, %r12
movq (%r12), %r12
cmpq %rax, %r12
je 0x132ff
cmpw %r13w, 0x10(%r12)
jne 0x13277
leaq 0x12(%r12), %rsi
movq -0x38(%rbp), %rdi
callq 0x4120
movw $0xfffe, %r14w          # imm = 0xFFFE
testl %eax, %eax
jne 0x132ed
leaq -0x50(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %r14
movq %r14, %rdi
callq 0xf988
movzbl -0x2c(%rbp), %ecx
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x13561
movq -0x60(%rbp), %rdi
movw $0xffff, %r14w          # imm = 0xFFFF
cmpq %r15, %rdi
je 0x132ed
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x43f0
movl %r14d, %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 0x13378
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r15, %rdi
je 0x13336
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x43f0
movq %rbx, %rdi
callq 0x4740