// File: /workspace/github_cpp_makefile_star2_O2/ccf19881030[P]UDP_Chat/client.cpp
// Function: chat_cli(int)
void chat_cli(int sock)
{
	struct sockaddr_in servaddr;
	memset(&servaddr,0,sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port = htons(9999);
	servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
 
	struct sockaddr_in peeraddr;
	socklen_t peerlen;
 
	MESSAGE msg;
	while (1)
	{
		memset(username,0,sizeof(username));
		printf("please input your name:");
		fflush(stdout);
		scanf("%s",username);
 
		memset(&msg,0,sizeof(msg));
		msg.cmd = htonl(C2S_LOGIN);
		strcpy(msg.body,username);
 
		sendto(sock, &msg, sizeof(msg), 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
	
		memset(&msg,0,sizeof(msg));
		recvfrom(sock,&msg,sizeof(msg),0,NULL,NULL);
		int cmd = ntohl(msg.cmd);
		if (cmd == S2C_ALREADY_LOGINED)
			printf("user %s already logined server please use another username\n",username);
		else if(cmd == S2C_LOGIN_OK)
		{
			printf("user %s already logined server\n",username);
			break;
		}
	}
	int count;
	recvfrom(sock,&count,sizeof(int),0,NULL,NULL);
	//���ܵ�¼�б�
	int n = ntohl(count);
	printf("has %d users logined server\n",n);
	//���ܵ�¼�û�����ip���˿�
	for(int i=0; i<n;i++)
	{
		USER_INFO user;
		recvfrom(sock,&user,sizeof(USER_INFO),0,NULL,NULL);
		client_list.push_back(user);
		in_addr tmp;
		tmp.s_addr = user.ip;
 
		printf("%d %s <-> %s:%d\n",i,user.username,inet_ntoa(tmp),ntohs(user.port));
	}
	
	printf("**********************************COMMANDS:*******************************\n");
	printf(" 			send username msg\n");
	printf("			list\n");
	printf("			exit\n");
	
	fd_set rset;
	FD_ZERO(&rset);
	int nready;
	while(1)
	{
		//�ѱ�׼����IO���ӵ�select������
		FD_SET(STDIN_FILENO,&rset);
		//���׽ӿ�IO���ӵ�select������
		FD_SET(sock,&rset);
		nready = select(sock+1,&rset,NULL,NULL,NULL);
 
		if(nready == -1)
			ERR_EXIT("select");
		if(nready == 0)
			continue;
		//���⵽�׽ӿ��¼�
		if(FD_ISSET(sock,&rset))
		{
			printf("���⵽sock�¼�\n");
			peerlen = sizeof(peeraddr);
			memset(&msg,0,sizeof(msg));
			recvfrom(sock,&msg,sizeof(msg),0,(struct sockaddr*)&peeraddr,&peerlen);
			int cmd = ntohl(msg.cmd);
			printf("cmd=%d\n",cmd);
			switch(cmd)
			{
				case S2C_SOMEONE_LOGIN:
					do_someone_login(msg);
					break;
				case S2C_SOMEONE_LOGOUT:
					do_someone_logout(msg);
					break;
				case S2C_ONLINE_USER:
					do_getlist(sock);
					break;
				case C2C_CHAT:
					do_chat(msg);
					break;
				default:
					break;
			}
		}
		//�����Ǳ�׼�����������¼�
		if(FD_ISSET(STDIN_FILENO,&rset))
		{
			printf("���⵽��׼�����¼�\n");
			char cmdline[100] = {0};
			if(fgets(cmdline,sizeof(cmdline),stdin) == NULL)
				break;
			if(cmdline[0] == '\n')
				continue;
			cmdline[strlen(cmdline) - 1] = '\0';
			//����������������
			parse_cmd(cmdline,sock,&servaddr);
		}
		
	}
 
 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x328, %rsp            # imm = 0x328
movl %edi, %ebx
leaq 0x10(%rsp), %r14
andq $0x0, 0x8(%r14)
movl $0xf270002, (%r14)      # imm = 0xF270002
leaq 0xcc0(%rip), %rdi       # 0x2027
callq 0x1140
movl %eax, 0x4(%r14)
leaq 0x128(%rsp), %r15
leaq 0x2d91(%rip), %r12      # 0x4110
leaq 0xcc3(%rip), %rbp       # 0x2049
leaq 0x124(%rsp), %r14
pushq $0x10
popq %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x2d74(%rip)     # 0x4110
leaq 0xc8e(%rip), %rdi       # 0x2031
xorl %eax, %eax
callq 0x1030
movq 0x2c17(%rip), %rax      # 0x3fc8
movq (%rax), %rdi
callq 0x1180
movq %rbp, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x1170
movl $0x200, %edx            # imm = 0x200
movq %r15, %rdi
xorl %esi, %esi
callq 0x10b0
movl $0x1000000, 0x124(%rsp) # imm = 0x1000000
movq %r15, %rdi
movq %r12, %rsi
callq 0x1110
movl $0x204, %edx            # imm = 0x204
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
movl %r13d, %r9d
callq 0x1040
movl $0x204, %edx            # imm = 0x204
movq %r14, %rdi
xorl %esi, %esi
callq 0x10b0
movl $0x204, %edx            # imm = 0x204
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x10c0
movl 0x124(%rsp), %eax
bswapl %eax
cmpl $0x2, %eax
je 0x1443
cmpl $0x1, %eax
jne 0x1392
jmp 0x1459
leaq 0xc02(%rip), %rdi       # 0x204c
movq %r12, %rsi
xorl %eax, %eax
callq 0x1030
jmp 0x1392
leaq 0xc28(%rip), %rdi       # 0x2088
leaq 0x2ca9(%rip), %rsi      # 0x4110
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x1030
leaq 0xc(%rsp), %r14
pushq $0x4
popq %rdx
movl %ebx, %edi
movq %r14, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x10c0
movl (%r14), %ebp
bswapl %ebp
leaq 0xc11(%rip), %rdi       # 0x20a8
movl %ebp, %esi
xorl %eax, %eax
callq 0x1030
testl %ebp, %ebp
cmovlel %r15d, %ebp
leaq 0x90(%rsp), %r14
leaq 0x2c6b(%rip), %r12      # 0x4120
leaq 0xc09(%rip), %r13       # 0x20c5
xorl %r15d, %r15d
cmpl %r15d, %ebp
je 0x1518
movl %ebx, %edi
movq %r14, %rsi
pushq $0x18
popq %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x10c0
movq %r12, %rdi
movq %r14, %rsi
callq 0x1c48
movl 0xa0(%rsp), %edi
callq 0x10a0
movzwl 0xa4(%rsp), %ecx
rolw $0x8, %cx
movzwl %cx, %r8d
movq %r13, %rdi
movl %r15d, %esi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x1030
incl %r15d
jmp 0x14bf
leaq 0xcda(%rip), %rdi       # 0x21f9
callq 0x11b0
leaq 0xc71(%rip), %rdi       # 0x219c
callq 0x11b0
leaq 0xc7b(%rip), %rdi       # 0x21b2
callq 0x11b0
leaq 0xc77(%rip), %rdi       # 0x21ba
callq 0x11b0
xorl %eax, %eax
cmpq $0x10, %rax
je 0x155e
andq $0x0, 0x90(%rsp,%rax,8)
incq %rax
jmp 0x154a
pushq $0x40
popq %rcx
movl %ebx, %eax
cltd
idivl %ecx
movslq %eax, %r12
shll $0x6, %eax
movl %ebx, %ecx
subl %eax, %ecx
pushq $0x1
popq %r13
shlq %cl, %r13
leal 0x1(%rbx), %ebp
leaq 0x90(%rsp), %r14
orb $0x1, 0x90(%rsp)
orq %r13, 0x90(%rsp,%r12,8)
movl %ebp, %edi
movq %r14, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1120
testl %eax, %eax
je 0x1582
cmpl $-0x1, %eax
je 0x1712
testq %r13, 0x90(%rsp,%r12,8)
je 0x166f
leaq 0xbfd(%rip), %rdi       # 0x21c2
callq 0x11b0
movl $0x10, 0x8(%rsp)
movl $0x204, %edx            # imm = 0x204
leaq 0x124(%rsp), %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x10b0
movl $0x204, %edx            # imm = 0x204
movl %ebx, %edi
movq %r15, %rsi
xorl %ecx, %ecx
leaq 0x114(%rsp), %r8
leaq 0x8(%rsp), %r9
callq 0x10c0
movl 0x124(%rsp), %r15d
bswapl %r15d
leaq 0xac4(%rip), %rdi       # 0x20dd
movl %r15d, %esi
xorl %eax, %eax
callq 0x1030
cmpl $0x10, %r15d
je 0x1662
cmpl $0x4, %r15d
je 0x164a
cmpl $0x5, %r15d
je 0x1659
cmpl $0x3, %r15d
jne 0x166f
leaq 0x124(%rsp), %rdi
callq 0x1726
jmp 0x166f
leaq 0x124(%rsp), %rdi
callq 0x176e
jmp 0x166f
movl %ebx, %edi
callq 0x17c1
jmp 0x166f
leaq 0x124(%rsp), %rdi
callq 0x188c
testb $0x1, 0x90(%rsp)
je 0x1582
leaq 0xb4d(%rip), %rdi       # 0x21d1
callq 0x11b0
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
andl $0x0, 0x80(%rsp)
movq 0x2927(%rip), %rax      # 0x3fe0
movq (%rax), %rdx
leaq 0x20(%rsp), %rdi
pushq $0x64
popq %rsi
callq 0x11c0
testq %rax, %rax
je 0x1700
cmpb $0xa, 0x20(%rsp)
je 0x1582
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x1090
movb $0x0, -0x1(%rax,%r15)
movq %r15, %rdi
movl %ebx, %esi
leaq 0x10(%rsp), %rdx
callq 0x18a2
jmp 0x1582
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9bd(%rip), %rdi       # 0x20d6
callq 0x10f0
pushq $0x1
popq %rdi
callq 0x1190