// File: /workspace/github_cpp_makefile_star2_O1/syky27[P]TicTacToe/src/DNNetworkConnection.cpp
// Function: DNNetworkConnection::startServer()
int DNNetworkConnection::startServer()
{
    DNWindow::getInstance().clearScreen();
    DNWindow::getInstance().drawHeader();
    
    

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

    /* bind socket to any addr and port 7777 */
    sockaddr_in localAddr;
    memset(& localAddr, 0, sizeof ( localAddr)); //clear it from garbage
    localAddr.sin_family = AF_INET;
    localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    localAddr.sin_port = htons(7777);

    if (bind(sockDesc, (sockaddr *) & localAddr, sizeof ( sockaddr_in)) < 0) {
        DNLogService::sharedObject() << "ERROR => " << "Can not bind!" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Cannot bind to port"));
       
    }

    /* get local address */
    sockaddr_in addr;
    unsigned int addr_len = sizeof (addr);
    if (getsockname(sockDesc, (sockaddr *) & addr, (socklen_t *) & addr_len) < 0) {
        DNLogService::sharedObject() << "ERROR => " << "Unable to fetch local ip address!" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Unable to fetch local IP address"));
    }
    DNLogService::sharedObject() << "INFO => " << "Started server on: " << inet_ntoa(addr.sin_addr) << ":7777" << "\n";
    DNWindow::getInstance().middleString(string("Server started on port 7777"), 5);
    DNWindow::getInstance().refreshDN();
    

    /* start listening */
    if (listen(sockDesc, 3) < 0) //3 is just in case.. one never know..
    {
        DNLogService::sharedObject() << "ERROR => " << "Set listening socket failed!" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Set listening socket failed!"));
    }
    
    DNLogService::sharedObject() << "INFO => " << "Waiting for client to connect." << "\n";
    DNWindow::getInstance().middleString(string("Waiting for client to connect"), 6);
    DNWindow::getInstance().refreshDN();
    /* accept client */
    int clientSockDesc;
    if ((clientSockDesc = accept(sockDesc, NULL, 0)) < 0) {
        DNLogService::sharedObject() << "ERROR => " << "Accept failed!" << "\n";
        DNWindow::getInstance().terminateWithErrorMessage(string("Accept failed"));
                
    }

    DNLogService::sharedObject() << "INFO => " << "Client connected, starting game" << "\n";
    DNWindow::getInstance().middleString(string("Client connected, starting game"), 7);
    sleep(1);

    return clientSockDesc;


    //Game l_game (PLAYER_VS_PLAYER_NETWORK, clientSockDesc);
    //   createServerGame ( clientSockDesc );    
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x130, %rsp            # imm = 0x130
movq %rdi, %rbx
callq 0x39ee
movq %rax, %rdi
callq 0x82a6
callq 0x39ee
movq %rax, %rdi
callq 0x76a2
movl $0x2, %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x30a0
movl %eax, (%rbx)
testl %eax, %eax
jns 0x5506
callq 0x3f9a
leaq 0x3c28(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4cb0
leaq 0x3c23(%rip), %r14      # 0x90b9
movq %rax, %rdi
movq %r14, %rsi
callq 0x4cb0
leaq 0x4066(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r15
leaq 0x100(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3c04(%rip), %rdx      # 0x90cf
leaq 0xf0(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4048
movq %r15, %rdi
movq %r12, %rsi
callq 0x82c0
movq 0xf0(%rsp), %rdi
cmpq %r13, %rdi
je 0x5506
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x32f0
xorps %xmm0, %xmm0
leaq 0x120(%rsp), %rsi
movaps %xmm0, (%rsi)
movq $0x611e0002, (%rsi)     # imm = 0x611E0002
movl (%rbx), %edi
movl $0x10, %edx
callq 0x3050
testl %eax, %eax
jns 0x55bd
callq 0x3f9a
leaq 0x3b74(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4cb0
leaq 0x3b86(%rip), %rsi      # 0x90d0
movq %rax, %rdi
callq 0x4cb0
leaq 0x3fb5(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0xe0(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3b62(%rip), %rsi      # 0x90de
leaq 0x3b6e(%rip), %rdx      # 0x90f1
leaq 0xd0(%rsp), %rdi
callq 0x4048
leaq 0xd0(%rsp), %rsi
movq %r14, %rdi
callq 0x82c0
movq 0xd0(%rsp), %rdi
cmpq %r15, %rdi
je 0x55bd
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x32f0
leaq 0xc(%rsp), %rdx
movl $0x10, (%rdx)
movl (%rbx), %edi
leaq 0x110(%rsp), %rsi
callq 0x32a0
testl %eax, %eax
jns 0x566d
callq 0x3f9a
leaq 0x3ac4(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4cb0
leaq 0x3af8(%rip), %rsi      # 0x90f2
movq %rax, %rdi
callq 0x4cb0
leaq 0x3f05(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0xc0(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3ae8(%rip), %rsi      # 0x9114
leaq 0x3b01(%rip), %rdx      # 0x9134
leaq 0xb0(%rsp), %rdi
callq 0x4048
leaq 0xb0(%rsp), %rsi
movq %r14, %rdi
callq 0x82c0
movq 0xb0(%rsp), %rdi
cmpq %r15, %rdi
je 0x566d
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x32f0
callq 0x3f9a
leaq 0x3abc(%rip), %rsi      # 0x9135
movq %rax, %rdi
callq 0x4cb0
leaq 0x3ab6(%rip), %rsi      # 0x913e
movq %rax, %rdi
callq 0x4cb0
movq %rax, %r14
movl 0x114(%rsp), %edi
callq 0x3180
movq %r14, %rdi
movq %rax, %rsi
callq 0x4cb0
leaq 0x3aa1(%rip), %rsi      # 0x9152
movq %rax, %rdi
callq 0x4cb0
leaq 0x3e4e(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0xa0(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3a75(%rip), %rsi      # 0x9158
leaq 0x3a89(%rip), %rdx      # 0x9173
leaq 0x90(%rsp), %rdi
callq 0x4048
leaq 0x90(%rsp), %rsi
movq %r14, %rdi
movl $0x5, %edx
callq 0x7b56
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x5729
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x32f0
callq 0x39ee
movq %rax, %rdi
callq 0x77a4
movl (%rbx), %edi
movl $0x3, %esi
callq 0x3340
testl %eax, %eax
jns 0x57cf
callq 0x3f9a
leaq 0x3959(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4cb0
leaq 0x3a0f(%rip), %r15      # 0x9174
movq %rax, %rdi
movq %r15, %rsi
callq 0x4cb0
leaq 0x3d97(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0x80(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x39f5(%rip), %rdx      # 0x9190
leaq 0x70(%rsp), %rdi
movq %r15, %rsi
callq 0x4048
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x82c0
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x57cf
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x32f0
callq 0x3f9a
leaq 0x395a(%rip), %rsi      # 0x9135
movq %rax, %rdi
callq 0x4cb0
leaq 0x39a7(%rip), %rsi      # 0x9191
movq %rax, %rdi
callq 0x4cb0
leaq 0x3d15(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0x60(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3997(%rip), %rsi      # 0x91b0
leaq 0x39ad(%rip), %rdx      # 0x91cd
leaq 0x50(%rsp), %rdi
callq 0x4048
leaq 0x50(%rsp), %rsi
movq %r14, %rdi
movl $0x6, %edx
callq 0x7b56
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x5853
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x32f0
callq 0x39ee
movq %rax, %rdi
callq 0x77a4
movl (%rbx), %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3100
movl %eax, %ebx
testl %eax, %eax
jns 0x58f0
callq 0x3f9a
leaq 0x3832(%rip), %rsi      # 0x90af
movq %rax, %rdi
callq 0x4cb0
leaq 0x3942(%rip), %rsi      # 0x91ce
movq %rax, %rdi
callq 0x4cb0
leaq 0x3c73(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3922(%rip), %rsi      # 0x91dd
leaq 0x3928(%rip), %rdx      # 0x91ea
leaq 0x30(%rsp), %rdi
callq 0x4048
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
callq 0x82c0
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x58f0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x32f0
callq 0x3f9a
leaq 0x3839(%rip), %rsi      # 0x9135
movq %rax, %rdi
callq 0x4cb0
leaq 0x38e0(%rip), %r15      # 0x91eb
movq %rax, %rdi
movq %r15, %rsi
callq 0x4cb0
leaq 0x3bf1(%rip), %rsi      # 0x950e
movq %rax, %rdi
callq 0x4cb0
callq 0x39ee
movq %rax, %r14
leaq 0x20(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x38cc(%rip), %rdx      # 0x920a
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x4048
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movl $0x7, %edx
callq 0x7b56
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x5974
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x32f0
movl $0x1, %edi
callq 0x3230
movl %ebx, %eax
addq $0x130, %rsp            # imm = 0x130
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x5a7b
movq 0x40(%rsp), %rsi
jmp 0x5a6e
jmp 0x5a78
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x5a7b
movq 0x80(%rsp), %rsi
jmp 0x5a6e
jmp 0x5a78
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r15, %rdi
je 0x5a7b
movq 0xc0(%rsp), %rsi
jmp 0x5a6e
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
cmpq %r15, %rdi
je 0x5a7b
movq 0xe0(%rsp), %rsi
jmp 0x5a6e
jmp 0x5a78
jmp 0x5a78
movq %rax, %rbx
movq 0xf0(%rsp), %rdi
cmpq %r13, %rdi
je 0x5a7b
movq 0x100(%rsp), %rsi
jmp 0x5a6e
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r12, %rdi
je 0x5a7b
movq 0x20(%rsp), %rsi
jmp 0x5a6e
jmp 0x5a78
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r15, %rdi
je 0x5a7b
movq 0x60(%rsp), %rsi
jmp 0x5a6e
jmp 0x5a78
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r15, %rdi
je 0x5a7b
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x32f0
jmp 0x5a7b
movq %rax, %rbx
movq %rbx, %rdi
callq 0x34b0
nop