// File: nickgammon[P]tinymudserver/comms.cpp
// Function: ProcessNewConnection()
void ProcessNewConnection ()
  {
  static struct sockaddr_in sa;
  socklen_t sa_len = sizeof sa;   

  int s;    /* incoming socket */

  /* loop until all outstanding connections are accepted */
  while (true)
    {
    s = accept ( iControl, (struct sockaddr *) &sa, &sa_len);

    /* a bad socket probably means no more connections are outstanding */
    if (s == NO_SOCKET)
      {

      /* blocking is OK - we have accepted all outstanding connections */
      if ( errno == EWOULDBLOCK )
        return;

      perror ("accept");
      return;
      }
        
    /* here on successful accept - make sure socket doesn't block */
    
    if (fcntl (s, F_SETFL, FNDELAY) == -1)
      {
      perror ("fcntl on player socket");
      return;
      }

    string address = inet_ntoa ( sa.sin_addr);
    int port = ntohs (sa.sin_port);
            
    // immediately close connections from blocked IP addresses
    if (blockedIP.find (address) != blockedIP.end ())
      {
      cerr << "Rejected connection from " << address << endl;
      close (s);
      continue;      
      }
      
    tPlayer * p = new tPlayer (s, port, address);
    playerlist.push_back (p);
    
    cout << "New player accepted on socket " << s << 
            ", from address " << address << 
            ", port " << port << endl;
      
    *p << "\nWelcome to the Tiny MUD Server version " << VERSION << "\n"; 
    *p << messagemap ["welcome"];   // message from message file
    *p << p->prompt;    // initial prompt (Enter your name ...)
    
    } /* end of processing *all* new connections */

  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movl $0x10, -0x4(%rbp)
leaq 0xf4a7(%rip), %rax      # 0x29420
movl (%rax), %edi
leaq 0xfbde(%rip), %rsi      # 0x29b60
leaq -0x4(%rbp), %rdx
callq 0x4150
movl %eax, -0x8(%rbp)
cmpl $-0x1, -0x8(%rbp)
jne 0x19fb4
callq 0x4070
cmpl $0xb, (%rax)
jne 0x19fa3
jmp 0x1a3c7
leaq 0x2a99(%rip), %rdi      # 0x1ca43
callq 0x4380
jmp 0x1a3c7
movl -0x8(%rbp), %edi
movl $0x4, %esi
movl $0x800, %edx            # imm = 0x800
movb $0x0, %al
callq 0x4290
cmpl $-0x1, %eax
jne 0x19fde
leaq 0x2a76(%rip), %rdi      # 0x1ca4a
callq 0x4380
jmp 0x1a3c7
movl 0xfb80(%rip), %eax      # 0x29b64
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
callq 0x4210
movq %rax, -0xc0(%rbp)
leaq -0x2d(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x46e0
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
leaq -0x28(%rbp), %rdi
callq 0x67d0
jmp 0x1a01f
leaq -0x2d(%rbp), %rdi
callq 0x44a0
movzwl 0xfb33(%rip), %edi      # 0x29b62
callq 0x4720
movzwl %ax, %eax
movl %eax, -0x40(%rbp)
leaq 0xfa27(%rip), %rdi      # 0x29a68
leaq -0x28(%rbp), %rsi
callq 0x1a990
movq %rax, -0xc8(%rbp)
jmp 0x1a053
movq -0xc8(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq 0xfa03(%rip), %rdi      # 0x29a68
callq 0x1a9d0
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x8f90
testb $0x1, %al
jne 0x1a084
jmp 0x1a10f
movq 0xef5d(%rip), %rdi      # 0x28fe8
leaq 0x29cf(%rip), %rsi      # 0x1ca61
callq 0x4410
movq %rax, -0xd0(%rbp)
jmp 0x1a0a0
movq -0xd0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x43d0
movq %rax, -0xd8(%rbp)
jmp 0x1a0b9
movq -0xd8(%rbp), %rdi
movq 0xeed1(%rip), %rsi      # 0x28f98
callq 0x4480
jmp 0x1a0ce
movl -0x8(%rbp), %edi
callq 0x47a0
jmp 0x1a0d8
movl $0x2, -0x54(%rbp)
jmp 0x1a32d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x2d(%rbp), %rdi
callq 0x44a0
jmp 0x1a3d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1a3bc
movl $0x110, %edi            # imm = 0x110
callq 0x4420
movq %rax, -0xe0(%rbp)
jmp 0x1a122
movb $0x1, -0x81(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0xe4(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x41f0
jmp 0x1a14a
movl -0xe4(%rbp), %edx
movl -0xe8(%rbp), %esi
movq -0xe0(%rbp), %rdi
leaq -0x80(%rbp), %rcx
callq 0x1aa00
jmp 0x1a168
movb $0x0, -0x81(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x47d8
movq -0xe0(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq 0xf7a6(%rip), %rdi      # 0x29930
leaq -0x60(%rbp), %rsi
callq 0x1ab30
jmp 0x1a195
movq 0xee24(%rip), %rdi      # 0x28fc0
leaq 0x28d8(%rip), %rsi      # 0x1ca7b
callq 0x4410
movq %rax, -0xf0(%rbp)
jmp 0x1a1b1
movq -0xf0(%rbp), %rdi
movl -0x8(%rbp), %esi
callq 0x46c0
movq %rax, -0xf8(%rbp)
jmp 0x1a1c9
movq -0xf8(%rbp), %rdi
leaq 0x28c3(%rip), %rsi      # 0x1ca9a
callq 0x4410
movq %rax, -0x100(%rbp)
jmp 0x1a1e5
movq -0x100(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x43d0
movq %rax, -0x108(%rbp)
jmp 0x1a1fe
movq -0x108(%rbp), %rdi
leaq 0x289e(%rip), %rsi      # 0x1caaa
callq 0x4410
movq %rax, -0x110(%rbp)
jmp 0x1a21a
movq -0x110(%rbp), %rdi
movl -0x40(%rbp), %esi
callq 0x46c0
movq %rax, -0x118(%rbp)
jmp 0x1a232
movq -0x118(%rbp), %rdi
movq 0xed58(%rip), %rsi      # 0x28f98
callq 0x4480
jmp 0x1a247
movq -0x60(%rbp), %rdi
leaq 0x2860(%rip), %rsi      # 0x1cab2
callq 0x1ab70
movq %rax, -0x120(%rbp)
jmp 0x1a260
movq -0x120(%rbp), %rdi
leaq 0xf832(%rip), %rsi      # 0x29aa0
callq 0xb450
movq %rax, -0x128(%rbp)
jmp 0x1a27c
movq -0x128(%rbp), %rdi
leaq 0x1e4a(%rip), %rsi      # 0x1c0d4
callq 0x13b80
jmp 0x1a291
movq -0x60(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0xa9(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x46e0
movq -0x130(%rbp), %rdx
leaq 0x281e(%rip), %rsi      # 0x1cadb
leaq -0xa8(%rbp), %rdi
callq 0x67d0
jmp 0x1a2cb
leaq 0xf706(%rip), %rdi      # 0x299d8
leaq -0xa8(%rbp), %rsi
callq 0xc500
movq %rax, -0x140(%rbp)
jmp 0x1a2e7
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdi
callq 0xb450
jmp 0x1a2fc
leaq -0xa8(%rbp), %rdi
callq 0x47d8
leaq -0xa9(%rbp), %rdi
callq 0x44a0
movq -0x60(%rbp), %rdi
movq %rdi, %rsi
addq $0x70, %rsi
callq 0xb450
jmp 0x1a326
movl $0x0, -0x54(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x47d8
movl -0x54(%rbp), %eax
testl %eax, %eax
je 0x1a344
jmp 0x1a33f
jmp 0x19f72
jmp 0x19f72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1a36c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x47d8
testb $0x1, -0x81(%rbp)
jne 0x1a377
jmp 0x1a388
movq -0xe0(%rbp), %rdi
movl $0x110, %esi            # imm = 0x110
callq 0x4430
jmp 0x1a3bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1a3b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x47d8
leaq -0xa9(%rbp), %rdi
callq 0x44a0
leaq -0x28(%rbp), %rdi
callq 0x47d8
jmp 0x1a3d0
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x46d0
nopl (%rax)