// File: /workspace/github_cpp_makefile_star2_O1/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
movb $0x1, %r14b
leaq 0xbbbc(%rip), %rbx      # 0x18168
leaq -0x48(%rbp), %r13
callq 0xc4cc
cmpw $-0x1, %ax
je 0xc8c7
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf480
movzbl %al, %eax
addl $-0x2, %eax
cmpl $0xd, %eax
ja 0xc8ba
leaq 0x40b0(%rip), %rcx      # 0x10690
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0xf468
movw %ax, 0xcc62(%rip)       # 0x1925a
movb $0x0, 0xcc5d(%rip)      # 0x1925c
leaq 0xc372(%rip), %r12      # 0x18978
movq %r12, %rdi
callq 0xf34c
movq %r12, %rdi
movl $0x3, %esi
callq 0xf360
movzwl 0xcc36(%rip), %esi      # 0x19258
movq %r12, %rdi
callq 0xf374
movzwl 0xcc29(%rip), %esi      # 0x1925a
movq %r12, %rdi
callq 0xf374
movl 0xcc01(%rip), %edi      # 0x19240
movswq 0xc339(%rip), %rdx      # 0x18980
movq 0xcbea(%rip), %rax      # 0x19238
movq 0x18(%rax), %r8
movl 0x10(%rax), %r9d
leaq 0xc325(%rip), %rsi      # 0x18982
xorl %ecx, %ecx
callq 0x4060
cmpw $0x6, %r15w
jl 0xc698
movq %rbx, %rdi
leaq 0xd04b(%rip), %rsi      # 0x196c0
callq 0xf4f0
testb %al, %al
jne 0xc8ba
leaq 0xb7f7(%rip), %rax      # 0x17e80
movl (%rax), %eax
addl $-0x6, %eax
cmpl $-0x4, %eax
ja 0xc698
callq 0xebd3
callq 0x6c67
jmp 0xc8ba
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movb $0x9, %r15b
movq %rbx, %rdi
callq 0xf480
movsbl %al, %esi
movq %r13, %rdi
callq 0x4310
decb %r15b
jne 0xc6b9
movq %r13, %rdi
callq 0x70fe
jmp 0xc880
movq %rbx, %rdi
callq 0xf480
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf480
movl %eax, %r12d
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
xorl %ecx, %ecx
movq %rcx, -0x40(%rbp)
movb %cl, -0x38(%rbp)
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq %rcx, -0x60(%rbp)
movb %cl, -0x58(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf492
movq %rbx, %rdi
leaq -0x68(%rbp), %rsi
callq 0xf492
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %r13, %rdi
callq 0x4120
movzbl %r15b, %edi
movzbl %r12b, %esi
movq %rax, %rdx
callq 0x6d6c
jmp 0xc867
movq %rbx, %rdi
leaq 0xd766(%rip), %rsi      # 0x19ec0
callq 0xf4f0
testb %al, %al
jne 0xc8ba
callq 0xf095
leaq 0xb70d(%rip), %rax      # 0x17e80
movl $0x5, (%rax)
xorl %edi, %edi
callq 0x6c36
jmp 0xc8ba
movq %rbx, %rdi
callq 0x79f2
jmp 0xc8ba
movq %rbx, %rdi
callq 0xf468
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf480
movzwl %r15w, %edi
movzbl %al, %esi
callq 0xb0f7
jmp 0xc8ba
movq %rbx, %rdi
callq 0xf480
movl %eax, %r12d
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movq %rbx, %rdi
callq 0xf480
movl %eax, %r15d
testb %al, %al
je 0xc880
movzbl %r12b, %r12d
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf492
movq %r13, %rdi
movl %r12d, %esi
callq 0x9c17
decb %r15b
jne 0xc7ec
jmp 0xc880
movq %rbx, %rdi
callq 0xf468
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf492
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
movq %rbx, %rdi
leaq -0x68(%rbp), %rsi
callq 0xf492
movq %rbx, %rdi
callq 0xf480
movzbl %al, %edx
movq %r13, %rdi
leaq -0x68(%rbp), %rsi
callq 0xa733
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xc880
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43a0
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xc8ba
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43a0
jmp 0xc8ba
movq %rbx, %rdi
callq 0xf480
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf480
movzbl %r15b, %edi
movzbl %al, %esi
callq 0x78d7
incb %r14b
cmpb $0x6, %r14b
jne 0xc5b0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0xc8c9
jmp 0xc904
jmp 0xc904
jmp 0xc904
jmp 0xc8e4
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xc907
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x43a0
jmp 0xc907
jmp 0xc904
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xc920
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x43a0
movq %rbx, %rdi
callq 0x4670