// File: syky27[P]TicTacToe/src/DNNetworkConnection.cpp
// Function: DNNetworkConnection::connectToServer()
int DNNetworkConnection::connectToServer()
{
    /* get address from user */
    string remoteAddr;
    int port = 7777;
    DNLogService::sharedObject() << "INFO => " << "Enter remote address: ";
    DNWindow::getInstance().enterServerIPAdress(remoteAddr);

    if (remoteAddr.length() == 0) {
        DNLogService::sharedObject() << "ERROR => " << "Bad input! -- ip address sucked" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Empty ip address  -- exiting"));
    }

    if ((sockDesc = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0){
        DNLogService::sharedObject() << "ERROR => " << "Can not create socket!" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Cannot create socket!!!"));
    }

    
    sockaddr_in addr;
    memset(&addr, 0, sizeof (addr));
    addr.sin_family = AF_INET;
    hostent * host;
    if ((host = gethostbyname(remoteAddr . c_str())) == NULL) {
        string fekalError("Cannot Resolve Hostname -- exiting !!!");
        DNWindow::getInstance().terminateWithErrorMessage(fekalError);
    }
    addr.sin_addr.s_addr = *((unsigned long *) host -> h_addr_list[0]);
    addr.sin_port = htons(port);

    DNWindow::getInstance().clearScreen();
    DNWindow::getInstance().drawHeader();
    DNWindow::getInstance().middleString(string("Connecting..."), 10);
    DNWindow::getInstance().refreshDN();
    sleep(2);
    
    
    if (connect(sockDesc, (sockaddr *) & addr, sizeof ( addr)) < 0) {
        DNLogService::sharedObject() << "ERROR => " << "Can not connect!" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Can not connect!"));
    }

    return sockDesc;


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x34e0
movl $0x1e61, -0x2c(%rbp)    # imm = 0x1E61
callq 0x43c0
movq %rax, -0x148(%rbp)
jmp 0x6738
movq -0x148(%rbp), %rdi
leaq 0x5a4b(%rip), %rsi      # 0xc191
callq 0x5520
movq %rax, -0x158(%rbp)
jmp 0x6754
movq -0x158(%rbp), %rdi
leaq 0x5b05(%rip), %rsi      # 0xc267
callq 0x5520
jmp 0x6769
callq 0x3a90
movq %rax, -0x160(%rbp)
jmp 0x6777
movq -0x160(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xbe00
jmp 0x6789
leaq -0x28(%rbp), %rdi
callq 0x3540
cmpq $0x0, %rax
jne 0x6896
callq 0x43c0
movq %rax, -0x168(%rbp)
jmp 0x67aa
movq -0x168(%rbp), %rdi
leaq 0x5953(%rip), %rsi      # 0xc10b
callq 0x5520
movq %rax, -0x170(%rbp)
jmp 0x67c6
movq -0x170(%rbp), %rdi
leaq 0x5aaa(%rip), %rsi      # 0xc27e
callq 0x5520
movq %rax, -0x178(%rbp)
jmp 0x67e2
movq -0x178(%rbp), %rdi
leaq 0x5d6a(%rip), %rsi      # 0xc55a
callq 0x5520
jmp 0x67f7
callq 0x3a90
movq %rax, -0x180(%rbp)
jmp 0x6805
leaq -0x61(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x35e0
movq -0x188(%rbp), %rdx
leaq 0x5a7b(%rip), %rsi      # 0xc29e
leaq -0x60(%rbp), %rdi
callq 0x42f0
jmp 0x682e
movq -0x180(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0xaf80
jmp 0x6840
leaq -0x60(%rbp), %rdi
callq 0x3200
leaq -0x61(%rbp), %rdi
callq 0x3400
jmp 0x6896
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6d5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6888
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x3200
leaq -0x61(%rbp), %rdi
callq 0x3400
jmp 0x6d5c
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x30c0
movq -0x150(%rbp), %rcx
movl %eax, (%rcx)
cmpl $0x0, %eax
jge 0x69ba
callq 0x43c0
movq %rax, -0x190(%rbp)
jmp 0x68ca
movq -0x190(%rbp), %rdi
leaq 0x5833(%rip), %rsi      # 0xc10b
callq 0x5520
movq %rax, -0x198(%rbp)
jmp 0x68e6
movq -0x198(%rbp), %rdi
leaq 0x5821(%rip), %rsi      # 0xc115
callq 0x5520
movq %rax, -0x1a0(%rbp)
jmp 0x6902
movq -0x1a0(%rbp), %rdi
leaq 0x5c4a(%rip), %rsi      # 0xc55a
callq 0x5520
jmp 0x6917
callq 0x3a90
movq %rax, -0x1a8(%rbp)
jmp 0x6925
leaq -0x89(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x35e0
movq -0x1b0(%rbp), %rdx
leaq 0x5975(%rip), %rsi      # 0xc2bb
leaq -0x88(%rbp), %rdi
callq 0x42f0
jmp 0x6954
movq -0x1a8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xaf80
jmp 0x6969
leaq -0x88(%rbp), %rdi
callq 0x3200
leaq -0x89(%rbp), %rdi
callq 0x3400
jmp 0x69ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x69a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x3200
leaq -0x89(%rbp), %rdi
callq 0x3400
jmp 0x6d5c
xorps %xmm0, %xmm0
movaps %xmm0, -0xa0(%rbp)
movw $0x2, -0xa0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3180
movq %rax, %rdi
callq 0x3440
movq %rax, -0x1b8(%rbp)
jmp 0x69e7
movq -0x1b8(%rbp), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, %rax
jne 0x6ae0
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x35e0
movq -0x1c0(%rbp), %rdx
leaq 0x58b3(%rip), %rsi      # 0xc2d3
leaq -0xc8(%rbp), %rdi
callq 0x42f0
jmp 0x6a2e
leaq -0xc9(%rbp), %rdi
callq 0x3400
callq 0x3a90
movq %rax, -0x1c8(%rbp)
jmp 0x6a48
leaq -0xf0(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x3190
jmp 0x6a5d
movq -0x1c8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xaf80
jmp 0x6a72
leaq -0xf0(%rbp), %rdi
callq 0x3200
leaq -0xc8(%rbp), %rdi
callq 0x3200
jmp 0x6ae0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xc9(%rbp), %rdi
callq 0x3400
jmp 0x6d5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6acf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x3200
leaq -0xc8(%rbp), %rdi
callq 0x3200
jmp 0x6d5c
movq -0xa8(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
movzwl -0x2c(%rbp), %edi
callq 0x3050
movw %ax, -0x9e(%rbp)
callq 0x3a90
movq %rax, -0x1d0(%rbp)
jmp 0x6b14
movq -0x1d0(%rbp), %rdi
callq 0xaf40
jmp 0x6b22
callq 0x3a90
movq %rax, -0x1d8(%rbp)
jmp 0x6b30
movq -0x1d8(%rbp), %rdi
callq 0x9b30
jmp 0x6b3e
callq 0x3a90
movq %rax, -0x1e0(%rbp)
jmp 0x6b4c
leaq -0x111(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x35e0
movq -0x1e8(%rbp), %rdx
leaq 0x578d(%rip), %rsi      # 0xc2fa
leaq -0x110(%rbp), %rdi
callq 0x42f0
jmp 0x6b7b
movq -0x1e0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl $0xa, %edx
callq 0xa260
jmp 0x6b95
leaq -0x110(%rbp), %rdi
callq 0x3200
leaq -0x111(%rbp), %rdi
callq 0x3400
callq 0x3a90
movq %rax, -0x1f0(%rbp)
jmp 0x6bbb
movq -0x1f0(%rbp), %rdi
callq 0x9ce0
jmp 0x6bc9
movl $0x2, %edi
callq 0x32a0
jmp 0x6bd5
movq -0x150(%rbp), %rax
movl (%rax), %edi
leaq -0xa0(%rbp), %rsi
movl $0x10, %edx
callq 0x32e0
movl %eax, -0x1f4(%rbp)
jmp 0x6bf7
movl -0x1f4(%rbp), %eax
cmpl $0x0, %eax
jge 0x6d35
callq 0x43c0
movq %rax, -0x200(%rbp)
jmp 0x6c14
movq -0x200(%rbp), %rdi
leaq 0x54e9(%rip), %rsi      # 0xc10b
callq 0x5520
movq %rax, -0x208(%rbp)
jmp 0x6c30
movq -0x208(%rbp), %rdi
leaq 0x56ca(%rip), %rsi      # 0xc308
callq 0x5520
movq %rax, -0x210(%rbp)
jmp 0x6c4c
movq -0x210(%rbp), %rdi
leaq 0x5900(%rip), %rsi      # 0xc55a
callq 0x5520
jmp 0x6c61
callq 0x3a90
movq %rax, -0x218(%rbp)
jmp 0x6c6f
leaq -0x139(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x35e0
movq -0x220(%rbp), %rdx
leaq 0x5678(%rip), %rsi      # 0xc308
leaq -0x138(%rbp), %rdi
callq 0x42f0
jmp 0x6c9e
movq -0x218(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xaf80
jmp 0x6cb3
leaq -0x138(%rbp), %rdi
callq 0x3200
leaq -0x139(%rbp), %rdi
callq 0x3400
jmp 0x6d35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6cf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x3200
leaq -0x111(%rbp), %rdi
callq 0x3400
jmp 0x6d5c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x6d27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x3200
leaq -0x139(%rbp), %rdi
callq 0x3400
jmp 0x6d5c
movq -0x150(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x224(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x3200
movl -0x224(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
leaq -0x28(%rbp), %rdi
callq 0x3200
movq -0x38(%rbp), %rdi
callq 0x35d0
nop