// File: /workspace/github_cpp_makefile_star2_O3/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 0xbc86(%rip), %rbx      # 0x18168
leaq -0x48(%rbp), %r13
callq 0xc402
cmpw $-0x1, %ax
je 0xc7fd
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf344
movzbl %al, %eax
addl $-0x2, %eax
cmpl $0xd, %eax
ja 0xc7f0
leaq 0x416a(%rip), %rcx      # 0x10680
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0xf32c
movw %ax, 0xcd2c(%rip)       # 0x1925a
movb $0x0, 0xcd27(%rip)      # 0x1925c
leaq 0xc43c(%rip), %r12      # 0x18978
movq %r12, %rdi
callq 0xf218
movq %r12, %rdi
movl $0x3, %esi
callq 0xf22c
movzwl 0xcd00(%rip), %esi      # 0x19258
movq %r12, %rdi
callq 0xf240
movzwl 0xccf3(%rip), %esi      # 0x1925a
movq %r12, %rdi
callq 0xf240
movl 0xcccb(%rip), %edi      # 0x19240
movswq 0xc403(%rip), %rdx      # 0x18980
movq 0xccb4(%rip), %rax      # 0x19238
movq 0x18(%rax), %r8
movl 0x10(%rax), %r9d
leaq 0xc3ef(%rip), %rsi      # 0x18982
xorl %ecx, %ecx
callq 0x4060
cmpw $0x6, %r15w
jl 0xc5ce
movq %rbx, %rdi
leaq 0xd115(%rip), %rsi      # 0x196c0
callq 0xf3ba
testb %al, %al
jne 0xc7f0
leaq 0xb8c1(%rip), %rax      # 0x17e80
movl (%rax), %eax
addl $-0x6, %eax
cmpl $-0x4, %eax
ja 0xc5ce
callq 0xead1
callq 0x6c25
jmp 0xc7f0
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movb $0x9, %r15b
movq %rbx, %rdi
callq 0xf344
movsbl %al, %esi
movq %r13, %rdi
callq 0x4300
decb %r15b
jne 0xc5ef
movq %r13, %rdi
callq 0x70f8
jmp 0xc7b6
movq %rbx, %rdi
callq 0xf344
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf344
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 0xf356
movq %rbx, %rdi
leaq -0x68(%rbp), %rsi
callq 0xf356
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq %r13, %rdi
callq 0x4120
movzbl %r15b, %edi
movzbl %r12b, %esi
movq %rax, %rdx
callq 0x6d48
jmp 0xc79d
movq %rbx, %rdi
leaq 0xd830(%rip), %rsi      # 0x19ec0
callq 0xf3ba
testb %al, %al
jne 0xc7f0
callq 0xef73
leaq 0xb7d7(%rip), %rax      # 0x17e80
movl $0x5, (%rax)
xorl %edi, %edi
callq 0x6bf4
jmp 0xc7f0
movq %rbx, %rdi
callq 0x79fe
jmp 0xc7f0
movq %rbx, %rdi
callq 0xf32c
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf344
movzwl %r15w, %edi
movzbl %al, %esi
callq 0xb0ef
jmp 0xc7f0
movq %rbx, %rdi
callq 0xf344
movl %eax, %r12d
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movq %rbx, %rdi
callq 0xf344
movl %eax, %r15d
testb %al, %al
je 0xc7b6
movzbl %r12b, %r12d
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf356
movq %r13, %rdi
movl %r12d, %esi
callq 0x9bb7
decb %r15b
jne 0xc722
jmp 0xc7b6
movq %rbx, %rdi
callq 0xf32c
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x38(%rbp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xf356
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x60(%rbp)
movb $0x0, -0x58(%rbp)
movq %rbx, %rdi
leaq -0x68(%rbp), %rsi
callq 0xf356
movq %rbx, %rdi
callq 0xf344
movzbl %al, %edx
movq %r13, %rdi
leaq -0x68(%rbp), %rsi
callq 0xa6ee
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xc7b6
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x4390
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xc7f0
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x4390
jmp 0xc7f0
movq %rbx, %rdi
callq 0xf344
movl %eax, %r15d
movq %rbx, %rdi
callq 0xf344
movzbl %r15b, %edi
movzbl %al, %esi
callq 0x78e3
incb %r14b
cmpb $0x6, %r14b
jne 0xc4e6
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0xc7ff
jmp 0xc83a
jmp 0xc83a
jmp 0xc83a
jmp 0xc81a
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xc83d
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x4390
jmp 0xc83d
jmp 0xc83a
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0xc856
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x4390
movq %rbx, %rdi
callq 0x4660