// File: st0ne[P]XReflectorPlus/dxrfd.cpp
// Function: handle_cmd(char*)
static void handle_cmd(char *buf)
{
   char *p = NULL;
   char call[CALL_SIZE + 1];
   char cmd[4];
   unsigned short i;
   char nak[5];

   char *ptr_cmd = NULL;
   char *ptr_call = NULL;
   const char *delim = " ";

   blocks_type::iterator pos;

   int rc = -1;

   nak[0] = '\0';

   p = strchr(buf, '\r');
   if (p)
      *p = '\0';

   p = strchr(buf, '\n');
   if (p)
      *p = '\0';

   if (strlen(buf) < 2)
      return;

   traceit("Received command [%s] from [%s]\n", buf, inet_ntoa(fromCmd.sin_addr));

   if (strcmp(buf, "sh") == 0)  /* shutdown reflector */
      keep_running = false;
   else
   if (strcmp(buf, "mu") == 0) /* mute users */
      mute_users(true);
   else
   if (strcmp(buf, "uu") == 0) /* un-mute users */
      mute_users(false);
   else
   if (strcmp(buf, "qsoy") == 0)  /* QSO_DETAILS yes */
      QSO_DETAILS = true;
   else
   if (strcmp(buf, "qson") == 0)
      QSO_DETAILS = false;       /* QSO_DETAILS no */
   else
   if (strcmp(buf, "pu") == 0)   /* print users */
      print_users();
   else
   if (strcmp(buf, "pv") == 0)   /* print version */
      print_version();
   else
   if (strcmp(buf, "pb") == 0)   /* print blocked users */
      print_blocks();
   else
   if (strcmp(buf, "pl") == 0)   /* print links */
      print_links_screen();
   else
   if (strcmp(buf, "upd") == 0)  /* reaload the database */
   {
      rc = open_users(USERS);
      if (rc != 0)
         traceit("Failed to reload %s\n", USERS);
   }
   else
   {
      ptr_cmd = strtok(buf, delim);
      ptr_call = strtok(NULL, delim);

      if (!ptr_cmd || !ptr_call)
      {
         traceit("Missing command parameters\n");
         strcpy(nak, "NAK\n");
      }
      else
      if (strlen(ptr_cmd) > 3)
      {
         traceit("Invalid command length\n");
         strcpy(nak, "NAK\n");
      }
      else
      {
         strcpy(cmd, ptr_cmd);
         if (strlen(ptr_call) <= CALL_SIZE)
         {
            strcpy(call, ptr_call);

            if (strlen(call) < CALL_SIZE)
            {
               for (i = strlen(call); i < CALL_SIZE; i++)
                  call[i] = ' ';
               call[CALL_SIZE] = '\0';
            }
            for (i = 0; i < CALL_SIZE; i++)
            {
               if (call[i] == '_')
                  call[i] = ' ';
            }

            if (strcmp(cmd, "ab") == 0)   /* ab <CALLSIGN>    this will block the callsign */
            {
               pos = blocks.find(call);
               if (pos != blocks.end())
               {
                  traceit("Call %s already blocked\n", call);
                  strcpy(nak, "NAK\n");
               }
               else
               if (blocks.insert(call).second)
                  traceit("call %s is now blocked\n", call);
               else
               {
                  traceit("Failed to block call %s\n",call);
                  strcpy(nak, "NAK\n");
               }
            }
            else
            if (strcmp(cmd, "rb") == 0)   /* rb  <CALLSIGN>     this will remove the block on the callsign */
            {
               if (blocks.erase(call) > 0)
                  traceit("call %s is now unblocked\n", call);
               else
               {
                  traceit("Could not find blocked call %s\n", call);
                  strcpy(nak, "NAK\n");
               }
            }
            else
            if (strcmp(cmd, "mc") == 0) /* mute a user by callsign */
            {
               if (!mute_call(call, true))
                  strcpy(nak, "NAK\n");
            }
            else
            if (strcmp(cmd, "uc") == 0) /* un-mute a user by callsign */
            {
               if (!mute_call(call, false))
                  strcpy(nak, "NAK\n");
            }
            else
            if (strcmp(cmd, "lrf") == 0)  /* link to ref */
            {
               rc = link_to_ref(call);
               if (rc != 0)
                  strcpy(nak, "NAK\n");
            }
            else
            {
               traceit("Unknown command or bad parameter\n", cmd);
               strcpy(nak, "NAK\n");
            }
         }
      }
   }

   if (nak[0] == '\0')
      strcpy(nak, "OK\n");

   sendto(cmd_sock,nak,4,
          0, (struct sockaddr *)&fromCmd,
          sizeof(struct sockaddr_in));
   return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
leaq 0x9f8e(%rip), %rax      # 0x17fec
movq %rax, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x13370
movl $0xffffffff, -0x4c(%rbp) # imm = 0xFFFFFFFF
movb $0x0, -0x25(%rbp)
movq -0x8(%rbp), %rdi
movl $0xd, %esi
callq 0x3120
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe096
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
movl $0xa, %esi
callq 0x3120
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0xe0b6
movq -0x10(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rdi
callq 0x3150
cmpq $0x2, %rax
jae 0xe0ca
jmp 0xe7f7
movq -0x8(%rbp), %rax
movq %rax, -0x110(%rbp)
movl 0x14f99(%rip), %eax     # 0x23074
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %edi
callq 0x3160
movq -0x110(%rbp), %rsi
movq %rax, %rdx
leaq 0x9bb0(%rip), %rdi      # 0x17ca7
movb $0x0, %al
callq 0x3820
movq -0x8(%rbp), %rdi
leaq 0x9bbf(%rip), %rsi      # 0x17cc8
callq 0x3460
cmpl $0x0, %eax
jne 0xe11f
movb $0x0, 0x111ca(%rip)     # 0x1f2e4
jmp 0xe7bb
movq -0x8(%rbp), %rdi
leaq 0x9ba1(%rip), %rsi      # 0x17ccb
callq 0x3460
cmpl $0x0, %eax
jne 0xe143
movl $0x1, %edi
callq 0xea20
jmp 0xe7b9
movq -0x8(%rbp), %rdi
leaq 0x9b80(%rip), %rsi      # 0x17cce
callq 0x3460
cmpl $0x0, %eax
jne 0xe164
xorl %edi, %edi
callq 0xea20
jmp 0xe7b7
movq -0x8(%rbp), %rdi
leaq 0x9b62(%rip), %rsi      # 0x17cd1
callq 0x3460
cmpl $0x0, %eax
jne 0xe185
movb $0x1, 0x14a30(%rip)     # 0x22bb0
jmp 0xe7b5
movq -0x8(%rbp), %rdi
leaq 0x9b46(%rip), %rsi      # 0x17cd6
callq 0x3460
cmpl $0x0, %eax
jne 0xe1a6
movb $0x0, 0x14a0f(%rip)     # 0x22bb0
jmp 0xe7b3
movq -0x8(%rbp), %rdi
leaq 0x9b2a(%rip), %rsi      # 0x17cdb
callq 0x3460
cmpl $0x0, %eax
jne 0xe1c5
callq 0xeb20
jmp 0xe7b1
movq -0x8(%rbp), %rdi
leaq 0x9b0e(%rip), %rsi      # 0x17cde
callq 0x3460
cmpl $0x0, %eax
jne 0xe1e4
callq 0xee80
jmp 0xe7af
movq -0x8(%rbp), %rdi
leaq 0x9af2(%rip), %rsi      # 0x17ce1
callq 0x3460
cmpl $0x0, %eax
jne 0xe203
callq 0xeef0
jmp 0xe7ad
movq -0x8(%rbp), %rdi
leaq 0x9ad6(%rip), %rsi      # 0x17ce4
callq 0x3460
cmpl $0x0, %eax
jne 0xe222
callq 0xefd0
jmp 0xe7ab
movq -0x8(%rbp), %rdi
leaq 0x9aba(%rip), %rsi      # 0x17ce7
callq 0x3460
cmpl $0x0, %eax
jne 0xe266
leaq 0x11292(%rip), %rdi     # 0x1f4d0
callq 0x4610
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0xe261
leaq 0x9a98(%rip), %rdi      # 0x17ceb
leaq 0x11276(%rip), %rsi     # 0x1f4d0
movb $0x0, %al
callq 0x3820
jmp 0xe7a9
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x34a0
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x34a0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xe296
cmpq $0x0, -0x38(%rbp)
jne 0xe2b9
leaq 0x9a63(%rip), %rdi      # 0x17d00
movb $0x0, %al
callq 0x3820
leaq -0x25(%rbp), %rdi
leaq 0x9a6d(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe7a7
movq -0x30(%rbp), %rdi
callq 0x3150
cmpq $0x3, %rax
jbe 0xe2eb
leaq 0x9a52(%rip), %rdi      # 0x17d21
movb $0x0, %al
callq 0x3820
leaq -0x25(%rbp), %rdi
leaq 0x9a3b(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe7a5
leaq -0x1d(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x32b0
movq -0x38(%rbp), %rdi
callq 0x3150
cmpq $0x8, %rax
ja 0xe7a3
leaq -0x19(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x32b0
leaq -0x19(%rbp), %rdi
callq 0x3150
cmpq $0x8, %rax
jae 0xe358
leaq -0x19(%rbp), %rdi
callq 0x3150
movw %ax, -0x20(%rbp)
movzwl -0x20(%rbp), %eax
cmpl $0x8, %eax
jge 0xe354
movzwl -0x20(%rbp), %eax
movb $0x20, -0x19(%rbp,%rax)
movw -0x20(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x20(%rbp)
jmp 0xe334
movb $0x0, -0x11(%rbp)
movw $0x0, -0x20(%rbp)
movzwl -0x20(%rbp), %eax
cmpl $0x8, %eax
jge 0xe38e
movzwl -0x20(%rbp), %eax
movsbl -0x19(%rbp,%rax), %eax
cmpl $0x5f, %eax
jne 0xe37e
movzwl -0x20(%rbp), %eax
movb $0x20, -0x19(%rbp,%rax)
jmp 0xe380
movw -0x20(%rbp), %ax
addw $0x1, %ax
movw %ax, -0x20(%rbp)
jmp 0xe35e
leaq -0x1d(%rbp), %rdi
leaq 0x99a0(%rip), %rsi      # 0x17d39
callq 0x3460
cmpl $0x0, %eax
jne 0xe5c8
leaq -0x79(%rbp), %rdi
movq %rdi, -0x118(%rbp)
callq 0x3520
movq -0x118(%rbp), %rdx
leaq -0x78(%rbp), %rdi
leaq -0x19(%rbp), %rsi
callq 0x11f00
jmp 0xe3cd
leaq 0x1100c(%rip), %rdi     # 0x1f3e0
leaq -0x78(%rbp), %rsi
callq 0x14250
movq %rax, -0x120(%rbp)
jmp 0xe3e6
movq -0x120(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x31e0
leaq -0x79(%rbp), %rdi
callq 0x3330
leaq 0x10fce(%rip), %rdi     # 0x1f3e0
callq 0x13480
movq %rax, -0x98(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x13450
testb $0x1, %al
jne 0xe434
jmp 0xe498
leaq -0x19(%rbp), %rsi
leaq 0x98fd(%rip), %rdi      # 0x17d3c
movb $0x0, %al
callq 0x3820
leaq -0x25(%rbp), %rdi
leaq 0x98cb(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe5c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xe48a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x31e0
leaq -0x79(%rbp), %rdi
callq 0x3330
jmp 0xe800
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x3520
movq -0x128(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
leaq -0x19(%rbp), %rsi
callq 0x11f00
jmp 0xe4c4
leaq 0x10f15(%rip), %rdi     # 0x1f3e0
leaq -0xc8(%rbp), %rsi
callq 0x133b0
movb %dl, -0x131(%rbp)
movq %rax, -0x130(%rbp)
jmp 0xe4e6
movb -0x131(%rbp), %al
movq -0x130(%rbp), %rcx
movq %rcx, -0xe0(%rbp)
movb %al, -0xd8(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movb -0xd8(%rbp), %al
movb %al, -0xa0(%rbp)
movb -0xa0(%rbp), %al
movb %al, -0x132(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x31e0
leaq -0xc9(%rbp), %rdi
callq 0x3330
movb -0x132(%rbp), %al
testb $0x1, %al
je 0xe59f
leaq -0x19(%rbp), %rsi
leaq 0x9802(%rip), %rdi      # 0x17d55
movb $0x0, %al
callq 0x3820
jmp 0xe5c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xe58e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x31e0
leaq -0xc9(%rbp), %rdi
callq 0x3330
jmp 0xe800
leaq -0x19(%rbp), %rsi
leaq 0x97c3(%rip), %rdi      # 0x17d6d
movb $0x0, %al
callq 0x3820
leaq -0x25(%rbp), %rdi
leaq 0x9760(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe5c3
jmp 0xe7a1
leaq -0x1d(%rbp), %rdi
leaq 0x97b3(%rip), %rsi      # 0x17d86
callq 0x3460
cmpl $0x0, %eax
jne 0xe6cc
leaq -0x101(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x3520
movq -0x140(%rbp), %rdx
leaq -0x100(%rbp), %rdi
leaq -0x19(%rbp), %rsi
callq 0x11f00
jmp 0xe60d
leaq 0x10dcc(%rip), %rdi     # 0x1f3e0
leaq -0x100(%rbp), %rsi
callq 0x148c0
movq %rax, -0x148(%rbp)
jmp 0xe629
leaq -0x100(%rbp), %rdi
callq 0x31e0
leaq -0x101(%rbp), %rdi
callq 0x3330
movq -0x148(%rbp), %rax
cmpq $0x0, %rax
jbe 0xe6a5
leaq -0x19(%rbp), %rsi
leaq 0x9730(%rip), %rdi      # 0x17d89
movb $0x0, %al
callq 0x3820
jmp 0xe6c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0xe694
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x31e0
leaq -0x101(%rbp), %rdi
callq 0x3330
jmp 0xe800
leaq -0x19(%rbp), %rsi
leaq 0x96f3(%rip), %rdi      # 0x17da3
movb $0x0, %al
callq 0x3820
leaq -0x25(%rbp), %rdi
leaq 0x965a(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe79f
leaq -0x1d(%rbp), %rdi
leaq 0x96ec(%rip), %rsi      # 0x17dc3
callq 0x3460
cmpl $0x0, %eax
jne 0xe708
leaq -0x19(%rbp), %rdi
movl $0x1, %esi
callq 0xf580
testb $0x1, %al
jne 0xe703
leaq -0x25(%rbp), %rdi
leaq 0x961e(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe79d
leaq -0x1d(%rbp), %rdi
leaq 0x96b3(%rip), %rsi      # 0x17dc6
callq 0x3460
cmpl $0x0, %eax
jne 0xe73e
leaq -0x19(%rbp), %rdi
xorl %esi, %esi
callq 0xf580
testb $0x1, %al
jne 0xe73c
leaq -0x25(%rbp), %rdi
leaq 0x95e5(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe79b
leaq -0x1d(%rbp), %rdi
leaq 0x9680(%rip), %rsi      # 0x17dc9
callq 0x3460
cmpl $0x0, %eax
jne 0xe777
leaq -0x19(%rbp), %rdi
callq 0xf6c0
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
je 0xe775
leaq -0x25(%rbp), %rdi
leaq 0x95ac(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe799
leaq -0x1d(%rbp), %rsi
leaq 0x964b(%rip), %rdi      # 0x17dcd
movb $0x0, %al
callq 0x3820
leaq -0x25(%rbp), %rdi
leaq 0x9588(%rip), %rsi      # 0x17d1c
callq 0x32b0
jmp 0xe79b
jmp 0xe79d
jmp 0xe79f
jmp 0xe7a1
jmp 0xe7a3
jmp 0xe7a5
jmp 0xe7a7
jmp 0xe7a9
jmp 0xe7ab
jmp 0xe7ad
jmp 0xe7af
jmp 0xe7b1
jmp 0xe7b3
jmp 0xe7b5
jmp 0xe7b7
jmp 0xe7b9
jmp 0xe7bb
movsbl -0x25(%rbp), %eax
cmpl $0x0, %eax
jne 0xe7d4
leaq -0x25(%rbp), %rdi
leaq 0x9620(%rip), %rsi      # 0x17def
callq 0x32b0
movl 0x10b02(%rip), %edi     # 0x1f2dc
leaq -0x25(%rbp), %rsi
movl $0x4, %edx
xorl %ecx, %ecx
leaq 0x14884(%rip), %r8      # 0x23070
movl $0x10, %r9d
callq 0x3080
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x88(%rbp), %rdi
callq 0x3500
nopl (%rax)