// File: /workspace/github_cpp_makefile_star2_O1/lotuskip[P]yuxtapa/server/server.cpp
// Function: main
int main(int argc, char *argv[])
{
#ifdef MAPTEST
	unsigned short size;
	if(argc < 2 || (size = atoi(argv[1])) < MIN_MAP_SIZE || size > MAX_MAP_SIZE)
	{
		std::cout << "Try: ./yuxtapa_sv [mapsize, " << MIN_MAP_SIZE
			<< "--" << MAX_MAP_SIZE << ']' << std::endl;
		std::cout << "Third argument, if present, is a filename to save the map as "
			"(it will be saved in the working directory)." << std::endl;
		return 1;
	}
	srandom(time(NULL));
	Map a_map(size, 0, 10); // will generate and print the map
	if(argc > 2)
	{
		if(!a_map.save_to_file(argv[2]))
			std::cout << "Failed to save the map as \'" << argv[2] << "\'!" << std::endl;
	}
#else
	setlocale(LC_ALL, "");
	string str = "";
	if(argc >= 2)
		str = argv[1];
	
	if(str == "--help" || str == "-h")
	{
		std::cout << "Recognised options are: \'-v\' (print version) and \'"
			<< print_stats_handle << "\' (print player stats)" << std::endl;
		return 0;
	}
	if(str == "-v" || str == "--version")
	{
		std::cout << PACKAGE << " server v." << VERSION << std::endl;
		return 0;
	}

	using namespace Config;
	if(str == print_stats_handle)
	{
		init_known_players(true);
		output_stats();
		return 0;
	}
	// else going to start the server for real
	std::cout << "(__)ux+apa " << VERSION << std::endl;
	std::cout << " ._)" << std::endl << std::endl;
	if(!str.empty())
		std::cout << "Uknown argument \"" << str << '\"' << std::endl;
	reg_sig_handlers();
	read_config();
	init_known_players(false);

	if(!Network::startup())
		return 1;

	srandom(time(NULL));

	msTimer test_clock;
	time(&last_time);
	time_t last_minute = time(NULL);
	interm_over = last_time + int_settings[IS_INTERM_SECS];
	tm *loctime;
	bool no_traffic;
	while(!any_signs())
	{
		no_traffic = Network::receive_n_handle();

		if(intermission)
		{
			Game::init_game();
			if(time(NULL) >= interm_over) // time to end intermission
				goto_next_map();
			else if(no_traffic)
				usleep(500000); // half a second
		}
		else // not intermission
		{
			// high-res (ms-scale) time checks: check if a turn has passed
			if(test_clock.update() - last_clock > int_settings[IS_TURNMS])
			{
				// Lag check:
				turns_lagged += (test_clock - last_clock)/int_settings[IS_TURNMS]-1;
				last_clock.update();
				if(Game::process_turn())
					goto_intermission("");
			}
			else if(no_traffic) // micro-hibernation
				usleep(int_settings[IS_TURNMS]*10); // sleep for 1/100th of a turn (2.5ms on normal config)
		}

		// low-res (second scale) time checks:
		if(time(NULL) - last_time > 5) // 5 seconds have passed
		{
			last_time = time(NULL);
			// Send clock update every 5 seconds
			if(intermission)
				Network::clocksync(interm_over - time(NULL), 0);
			else
				Game::send_times(cur_players.end());
		}
		if(time(NULL) - last_minute > 60) // a minute has passed
		{
			last_minute = time(NULL);
			loctime = localtime(&last_minute);
			if(!(loctime->tm_min % 30)) // usage check every 30 minutes
			{
				if(check_date_change(loctime->tm_mday)) // the day has changed
					usage_report();
				else
					usage_update();
			}
		} // minute passed
	} // for eva

	std::cout << "Quitting..." << std::endl;
	Network::shutdown();
	timed_log("Shutdown");
	usage_report();
	to_log("---------------------------------");
	store_known_players();
#endif
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x1e94a(%rip), %r15     # 0x2c2f0
movl $0x6, %edi
movq %r15, %rsi
callq 0x4380
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x68(%rbp), %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0xdfec
cmpl $0x2, %r14d
jl 0xd9f7
movq 0x8(%rbx), %rbx
leaq -0x68(%rbp), %r14
movq 0x8(%r14), %r15
movq %rbx, %rdi
callq 0x41a0
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
movq %rax, %r8
callq 0x4640
leaq 0x1e6d2(%rip), %rsi     # 0x2c0d0
leaq -0x68(%rbp), %rdi
callq 0x4120
testl %eax, %eax
je 0xddd1
leaq 0x1e6c1(%rip), %rsi     # 0x2c0d7
leaq -0x68(%rbp), %rdi
callq 0x4120
testl %eax, %eax
je 0xddd1
leaq 0x1e6f6(%rip), %rsi     # 0x2c124
leaq -0x68(%rbp), %rdi
callq 0x4120
testl %eax, %eax
je 0xde30
leaq 0x1e6e1(%rip), %rsi     # 0x2c127
leaq -0x68(%rbp), %rdi
callq 0x4120
testl %eax, %eax
je 0xde30
movq -0x60(%rbp), %rdx
cmpq 0x33036(%rip), %rdx     # 0x40a98
jne 0xda85
testq %rdx, %rdx
je 0xdf86
movq 0x3301c(%rip), %rsi     # 0x40a90
movq -0x68(%rbp), %rdi
callq 0x4400
testl %eax, %eax
je 0xdf86
movq 0x32534(%rip), %rdi     # 0x3ffc0
leaq 0x1e6b4(%rip), %rsi     # 0x2c147
movl $0xb, %edx
callq 0x4460
movq 0x3251c(%rip), %rbx     # 0x3ffc0
leaq 0x1e699(%rip), %rsi     # 0x2c144
movl $0x2, %edx
movq %rbx, %rdi
callq 0x4460
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x43d0
movsbl %al, %esi
movq 0x324ea(%rip), %rdi     # 0x3ffc0
callq 0x4040
movq %rax, %rdi
callq 0x4250
movq 0x324d6(%rip), %rbx     # 0x3ffc0
leaq 0x1e662(%rip), %rsi     # 0x2c153
movl $0x4, %edx
movq %rbx, %rdi
callq 0x4460
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x43d0
movsbl %al, %esi
movq 0x324a4(%rip), %rdi     # 0x3ffc0
callq 0x4040
movq %rax, %rdi
callq 0x4250
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x43d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4250
cmpq $0x0, -0x60(%rbp)
je 0xdba2
movq 0x3245f(%rip), %rdi     # 0x3ffc0
leaq 0x1e5f0(%rip), %rsi     # 0x2c158
movl $0x11, %edx
callq 0x4460
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq 0x3243f(%rip), %rdi     # 0x3ffc0
callq 0x4460
leaq -0x48(%rbp), %rsi
movb $0x22, (%rsi)
movl $0x1, %edx
movq %rax, %rdi
callq 0x4460
movq %rax, %rdi
callq 0x41b0
callq 0x12460
callq 0x11477
xorl %edi, %edi
callq 0x12799
callq 0xe088
movl $0x1, %ebx
testb %al, %al
je 0xdea4
xorl %edi, %edi
callq 0x43b0
movl %eax, %edi
callq 0x40d0
leaq 0x32ed6(%rip), %rdi     # 0x40ab0
callq 0x43b0
xorl %edi, %edi
callq 0x43b0
leaq -0x70(%rbp), %rcx
movq %rax, (%rcx)
leaq 0x34cac(%rip), %r15     # 0x428a0
movl 0x18(%r15), %eax
addq 0x32eb1(%rip), %rax     # 0x40ab0
movq %rax, 0x32eb2(%rip)     # 0x40ab8
leaq 0x32eb3(%rip), %r14     # 0x40ac0
movl $0x8888888, %ebx        # imm = 0x8888888
leaq -0x80(%rbp), %r12
callq 0x12450
testb %al, %al
jne 0xdece
callq 0xe3f0
movl %eax, %r13d
cmpb $0x1, 0x327de(%rip)     # 0x40410
jne 0xdc60
callq 0x1aafc
xorl %edi, %edi
callq 0x43b0
cmpq 0x32e71(%rip), %rax     # 0x40ab8
jge 0xdcf2
movl $0x7a120, %edi          # imm = 0x7A120
testb %r13b, %r13b
jne 0xdd1b
jmp 0xdd20
movq %r12, %rdi
callq 0x2b2dc
movq %rax, %rdi
movq %r14, %rsi
callq 0x2b2f6
movl 0x14(%r15), %ecx
cmpl %ecx, %eax
jbe 0xdd11
movq %r12, %rdi
movq %r14, %rsi
callq 0x2b2f6
xorl %edx, %edx
divl 0x14(%r15)
addw 0x32e39(%rip), %ax      # 0x40ad0
decl %eax
movw %ax, 0x32e30(%rip)      # 0x40ad0
movq %r14, %rdi
callq 0x2b2dc
callq 0x1b435
testb %al, %al
je 0xdd20
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %r13
movq %r13, %rdi
leaq 0x1e629(%rip), %rdx     # 0x2c2f0
movq %rdx, %rsi
callq 0xdfec
movq %r13, %rdi
callq 0xd7d2
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xdd20
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0xdd20
movb $0x0, 0x32717(%rip)     # 0x40410
movw $0x0, 0x32dce(%rip)     # 0x40ad0
callq 0x1b0a0
movq %r14, %rdi
callq 0x2b2dc
jmp 0xdd20
testb %r13b, %r13b
je 0xdd20
addl %ecx, %ecx
leal (%rcx,%rcx,4), %edi
callq 0x45c0
xorl %edi, %edi
callq 0x43b0
subq 0x32d82(%rip), %rax     # 0x40ab0
cmpq $0x6, %rax
jl 0xdd75
xorl %edi, %edi
callq 0x43b0
movq %rax, 0x32d6e(%rip)     # 0x40ab0
cmpb $0x1, 0x326c7(%rip)     # 0x40410
jne 0xdd69
movl 0x32d66(%rip), %r13d    # 0x40ab8
xorl %edi, %edi
callq 0x43b0
subl %eax, %r13d
movzwl %r13w, %edi
xorl %esi, %esi
callq 0xf83a
jmp 0xdd75
leaq 0x35350(%rip), %rdi     # 0x430c0
callq 0x1b1bc
xorl %edi, %edi
callq 0x43b0
subq -0x70(%rbp), %rax
cmpq $0x3d, %rax
jl 0xdc16
xorl %edi, %edi
callq 0x43b0
movq %rax, -0x70(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x42b0
imull $0xeeeeeeef, 0x4(%rax), %ecx # imm = 0xEEEEEEEF
addl %ebx, %ecx
rorl %ecx
cmpl %ebx, %ecx
ja 0xdc16
movl 0xc(%rax), %edi
callq 0x15388
testb %al, %al
je 0xddc7
callq 0x13eed
jmp 0xdc16
callq 0x13bcc
jmp 0xdc16
movq 0x321e8(%rip), %rdi     # 0x3ffc0
leaq 0x1e2fb(%rip), %rsi     # 0x2c0da
movl $0x32, %edx
callq 0x4460
movq 0x32ca0(%rip), %rsi     # 0x40a90
movq 0x32ca1(%rip), %rdx     # 0x40a98
movq 0x321c2(%rip), %rdi     # 0x3ffc0
callq 0x4460
movq %rax, %rbx
leaq 0x1e300(%rip), %rsi     # 0x2c10d
movl $0x16, %edx
movq %rax, %rdi
callq 0x4460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x43d0
jmp 0xde8f
movq 0x32189(%rip), %rdi     # 0x3ffc0
leaq 0x1e2f3(%rip), %rsi     # 0x2c131
movl $0x7, %edx
callq 0x4460
movq 0x32171(%rip), %rdi     # 0x3ffc0
leaq 0x1e2e3(%rip), %rsi     # 0x2c139
movl $0xa, %edx
callq 0x4460
movq 0x32159(%rip), %rbx     # 0x3ffc0
leaq 0x1e2d6(%rip), %rsi     # 0x2c144
movl $0x2, %edx
movq %rbx, %rdi
callq 0x4460
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x43d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x4250
xorl %ebx, %ebx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xdebd
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x320eb(%rip), %rdi     # 0x3ffc0
leaq 0x1e28e(%rip), %rsi     # 0x2c16a
movl $0xb, %edx
callq 0x4460
movq 0x320d3(%rip), %rdi     # 0x3ffc0
callq 0x41b0
callq 0xe343
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x1e26d(%rip), %rsi     # 0x2c176
leaq 0x1e26e(%rip), %rdx     # 0x2c17e
callq 0xdfec
leaq -0x48(%rbp), %rdi
callq 0x15254
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xdf37
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43f0
callq 0x13eed
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, (%rdi)
leaq 0x1e231(%rip), %rsi     # 0x2c17f
leaq 0x1e24b(%rip), %rdx     # 0x2c1a0
callq 0xdfec
leaq -0x48(%rbp), %rdi
callq 0x15050
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xdf7c
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43f0
callq 0x12e7e
jmp 0xdea2
movl $0x1, %edi
callq 0x12799
callq 0x1404a
jmp 0xdea2
jmp 0xdfa2
jmp 0xdfc8
jmp 0xdfa2
jmp 0xdfc8
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xdfcb
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43f0
jmp 0xdfcb
jmp 0xdfc8
jmp 0xdfc8
jmp 0xdfc8
jmp 0xdfc8
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xdfe4
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43f0
movq %rbx, %rdi
callq 0x4750