// File: /workspace/github_cpp_makefile_star2_O2/lotuskip[P]yuxtapa/client/network.cpp
// Function: Network::receive_n_handle()
bool Network::receive_n_handle()
{
	unsigned char mid;
	char handled = 0;
	short msglen;
	while(handled++ < 5 && // handle at most 5 messages; then return control
		(msglen = do_receive()) != -1)
	{
		mid = recv_buffer.read_ch();
		switch(mid)
		{
		case MID_QUIT:
			return true;
		case MID_VIEW_UPD:
		{
			curturn = recv_buffer.read_sh(); // new turn number
			// NOTE: if an earlier turn update should arrive later than a
			// newer one, we might "fall back". This is rare enough to
			// bypass, hopefully.
			axn_counter = 0;

			// Return a "pong":
			send_buffer.clear();
			send_buffer.add((unsigned char)MID_VIEW_UPD);
			send_buffer.add(cur_id);
			send_buffer.add(curturn);
			do_send();

			if(msglen > 5) // msg is not very small => view has changed
			{
				if(recv_buffer.read_compressed(viewbuffer))
					break; // could not read package, ignore it...
				if(clientstate != CS_LIMBO && clientstate != CS_HELP
					&& clientstate != CS_TEAM_INFO)
					redraw_view();
			}
			Base::viewtick();
			break;
		}
		case MID_ADD_MSG:
		{
			unsigned char cp = recv_buffer.read_ch();
			string msg_str;
			for(mid = recv_buffer.read_ch(); mid > 0; --mid)
			{
				recv_buffer.read_str(msg_str);
				add_msg(msg_str, cp);
			}
			break;
		}
		case MID_SAY_CHAT:
		{
			recv_buffer.read_sh(); // skip id
			string line;
			recv_buffer.read_str(line);
			string speaker_nick;
			recv_buffer.read_str(speaker_nick);
			add_to_chat(line, speaker_nick, recv_buffer.read_ch());
			break;
		}
		case MID_STATE_UPD:
			ClassCPV::state_upd(recv_buffer);
			break;
		case MID_STATE_CHANGE:
			mid = recv_buffer.read_ch(); // class
			ClassCPV::state_change(mid, recv_buffer.read_ch()); // and team
			break;
		case MID_GAME_UPD:
		{
			mid = recv_buffer.read_ch(); // # of green
			unsigned char ch = recv_buffer.read_ch(); // # of purples
			string st_str1, st_str2;
			recv_buffer.read_str(st_str1);
			recv_buffer.read_str(st_str2);
			Base::print_teams_upd(mid, ch, st_str1 += st_str2);	
			break;
		}
		case MID_FLAG_UPD:
		{
			string tmp;
			for(char ch = 0; ch < MAX_D+1; ++ch)
				tmp += recv_buffer.read_ch();
			Base::print_flags(tmp);
			break;
		}
		case MID_TIME_UPD:
		{
			unsigned short sh = recv_buffer.read_sh();
			clocksync(sh, recv_buffer.read_ch());
			break;
		}
		case MID_TEAM_INFO:
			// This is a respond to player's request, so view the info now
			if(recv_buffer.read_compressed(teambuffer))
				break;// corrupt package? Ignore and don't switch cs
			draw_team_info();
			clientstate = CS_TEAM_INFO;
			Base::type_cursor(0);
			break;
		default: break;
		}
	}
	return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
leaq 0xcb7f(%rip), %rbx      # 0x17168
leaq -0x48(%rbp), %r13
xorl %r12d, %r12d
cmpb $0x5, %r12b
je 0xa8ae
callq 0xa534
cmpw $-0x1, %ax
je 0xa8ae
movl %eax, %r15d
incb %r12b
movq %rbx, %rdi
callq 0xcd50
movzbl %al, %eax
addl $-0x2, %eax
cmpl $0xd, %eax
ja 0xa5f0
leaq 0x4067(%rip), %rcx      # 0xe690
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0xcd38
movw %ax, 0xdc19(%rip)       # 0x1825a
movb $0x0, 0xdc14(%rip)      # 0x1825c
leaq 0xd329(%rip), %r14      # 0x17978
movq %r14, %rdi
callq 0xcc4a
movq %r14, %rdi
pushq $0x3
popq %rsi
callq 0xcc5c
movzwl 0xdbef(%rip), %esi      # 0x18258
movq %r14, %rdi
callq 0xcc70
movzwl 0xdbe2(%rip), %esi      # 0x1825a
movq %r14, %rdi
callq 0xcc70
callq 0xa4fc
cmpw $0x6, %r15w
jl 0xa6b9
movq %rbx, %rdi
leaq 0xe02a(%rip), %rsi      # 0x186c0
callq 0xcdbe
testb %al, %al
jne 0xa5f0
leaq 0xc7d6(%rip), %rax      # 0x16e80
movl (%rax), %eax
addl $-0x6, %eax
cmpl $-0x4, %eax
ja 0xa6b9
callq 0xc5e5
callq 0x653d
jmp 0xa5f0
movq %rbx, %rdi
leaq 0xe7f3(%rip), %rsi      # 0x18ec0
callq 0xcdbe
testb %al, %al
jne 0xa5f0
callq 0xc9ee
leaq 0xc79a(%rip), %rax      # 0x16e80
movl $0x5, (%rax)
xorl %edi, %edi
callq 0x6523
jmp 0xa5f0
movq %rbx, %rdi
callq 0xcd50
movl %eax, %r15d
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
andq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movq %rbx, %rdi
callq 0xcd50
movl %eax, %r14d
movzbl %r15b, %r15d
subb $0x1, %r14b
jb 0xa8a1
movq %rbx, %rdi
movq %r13, %rsi
callq 0xcd62
movq %r13, %rdi
movl %r15d, %esi
callq 0x86ae
jmp 0xa723
movq %rbx, %rdi
callq 0xcd38
movl %eax, %r14d
movq %rbx, %rdi
callq 0xcd50
movzwl %r14w, %edi
movzbl %al, %esi
callq 0x97aa
jmp 0xa5f0
movq %rbx, %rdi
callq 0xcd50
movl %eax, %r14d
movq %rbx, %rdi
callq 0xcd50
movzbl %r14b, %edi
movzbl %al, %esi
callq 0x6fee
jmp 0xa5f0
movq %rbx, %rdi
callq 0xcd38
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
andq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xcd62
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
movq %rbx, %rdi
leaq -0x68(%rbp), %rsi
callq 0xcd62
movq %rbx, %rdi
callq 0xcd50
movzbl %al, %edx
movq %r13, %rdi
leaq -0x68(%rbp), %rsi
callq 0x8fec
jmp 0xa852
movq %rbx, %rdi
callq 0xcd50
movl %eax, %r15d
movq %rbx, %rdi
callq 0xcd50
leaq -0x38(%rbp), %rcx
movq %rcx, -0x48(%rbp)
andq $0x0, -0x40(%rbp)
movl %eax, %r14d
xorl %ecx, %ecx
movb %cl, -0x38(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
andq $0x0, -0x60(%rbp)
movb %cl, -0x58(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xcd62
movq %rbx, %rdi
leaq -0x68(%rbp), %rsi
callq 0xcd62
movq %r13, %rdi
leaq -0x68(%rbp), %rsi
callq 0x46f0
movzbl %r15b, %edi
movzbl %r14b, %esi
movq %rax, %rdx
callq 0x6634
leaq -0x68(%rbp), %rdi
callq 0x4748
jmp 0xa8a1
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
andq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movb $0x9, %r14b
subb $0x1, %r14b
jb 0xa899
movq %rbx, %rdi
callq 0xcd50
movsbl %al, %esi
movq %r13, %rdi
callq 0x4310
jmp 0xa871
movq %rbx, %rdi
callq 0x7106
jmp 0xa5f0
movq %r13, %rdi
callq 0x6819
movq %r13, %rdi
callq 0x4748
jmp 0xa5f0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0xa8b0
jmp 0xa8db
jmp 0xa8db
jmp 0xa8db
jmp 0xa8cb
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x4748
jmp 0xa8de
jmp 0xa8db
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x4748
movq %rbx, %rdi
callq 0x4650