// File: nesro[P]NCursesGomoku/src/client.cpp
// Function: CClient::CClient(CBoard*, char, CGame*)
CClient::CClient(CBoard * board, char mark, CGame * game) :
CPlayer(board, mark), CNetwork(game) {

    if (m_Game->m_IsConnectionUp == true) {
        return;
    } else {
        m_Game->m_IsConnectionUp = true;
    }

    hostent * host;

    if ((host = gethostbyname(m_Game->m_Host.c_str())) == NULL) {
        throw CNetworkException("Fatal network error: Client host is invalid.");
    }

    if ((m_Game->m_ConnectionSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))
            == -1) {
        throw CNetworkException("Fatal network error: Client socket error.");
    }

    sockaddr_in serverSock;

    serverSock.sin_family = AF_INET;
    serverSock.sin_port = htons(m_Game->m_Port);
    memcpy(&(serverSock.sin_addr), host->h_addr, host->h_length);

    if (connect(m_Game->m_ConnectionSocket, (sockaddr *) & serverSock,
            sizeof (serverSock)) == -1) {
        throw CNetworkException("Fatal network error: Client connect failed.");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x50(%rbp)
movq -0x10(%rbp), %rsi
movsbl -0x11(%rbp), %edx
callq 0x6910
movq -0x50(%rbp), %rdi
addq $0x18, %rdi
movq -0x20(%rbp), %rsi
callq 0x6450
jmp 0x4dc4
movq -0x50(%rbp), %rax
leaq 0x6e19(%rip), %rcx      # 0xbbe8
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x20(%rax), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0x4dfd
jmp 0x4fc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4fdc
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movb $0x1, 0x10(%rax)
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rdi
addq $0x18, %rdi
callq 0x3130
movq %rax, %rdi
callq 0x3300
movq %rax, -0x58(%rbp)
jmp 0x4e28
movq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0x4e9f
movl $0x28, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
leaq 0x3a3f(%rip), %rsi      # 0x8890
callq 0x6480
jmp 0x4e58
movq -0x60(%rbp), %rdi
leaq 0x6e5d(%rip), %rsi      # 0xbcc0
leaq 0x16b6(%rip), %rdx      # 0x6520
callq 0x3400
jmp 0x4fee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x4fcf
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x31d0
jmp 0x4fcf
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x30a0
movq -0x50(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl %eax, 0xc(%rcx)
cmpl $-0x1, %eax
jne 0x4f1b
movl $0x28, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x68(%rbp)
leaq 0x39df(%rip), %rsi      # 0x88bd
callq 0x6480
jmp 0x4ee5
movq -0x68(%rbp), %rdi
leaq 0x6dd0(%rip), %rsi      # 0xbcc0
leaq 0x1629(%rip), %rdx      # 0x6520
callq 0x3400
jmp 0x4fee
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x31d0
jmp 0x4fcf
movq -0x50(%rbp), %rax
movw $0x2, -0x48(%rbp)
movq 0x20(%rax), %rax
movzwl 0x38(%rax), %edi
callq 0x3040
movw %ax, -0x46(%rbp)
leaq -0x44(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rcx
movq (%rcx), %rsi
movslq 0x14(%rax), %rdx
callq 0x3200
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movl 0xc(%rax), %edi
leaq -0x48(%rbp), %rsi
movl $0x10, %edx
callq 0x3210
movl %eax, -0x6c(%rbp)
jmp 0x4f6c
movl -0x6c(%rbp), %eax
cmpl $-0x1, %eax
jne 0x4fc6
movl $0x28, %edi
callq 0x3160
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
leaq 0x3958(%rip), %rsi      # 0x88e7
callq 0x6480
jmp 0x4f96
movq -0x78(%rbp), %rdi
leaq 0x6d1f(%rip), %rsi      # 0xbcc0
leaq 0x1578(%rip), %rdx      # 0x6520
callq 0x3400
jmp 0x4fee
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x31d0
jmp 0x4fcf
addq $0x80, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
addq $0x18, %rdi
callq 0x6470
movq -0x50(%rbp), %rdi
callq 0x6950
movq -0x28(%rbp), %rdi
callq 0x3410
nop