// File: nickgammon[P]tinymudserver/states.cpp
// Function: ProcessPlayerName(tPlayer*, std::istream&)
void ProcessPlayerName (tPlayer * p, istream & sArgs)
{
  string playername;
  sArgs >> playername;

  /* name can't be blank */
  if (playername.empty ())
    throw runtime_error ("Name cannot be blank.");
  
  /* don't allow two of the same name */
  if (FindPlayer (playername))
    throw runtime_error (playername + " is already connected.");

  if (playername.find_first_not_of (valid_player_name) != string::npos)
    throw runtime_error ("That player name contains disallowed characters.");
        
  if (tolower (playername) == "new")
    {
    p->connstate = eAwaitingNewName;
    p->prompt = "Please choose a name for your new character ... ";
    }   // end of new player
  else
    {   // old player
  
    p->playername = tocapitals (playername);
    p->Load ();   // load player so we know the password etc.
    
    p->connstate = eAwaitingPassword;
    p->prompt = "Enter your password ... ";
    p->badPasswordCount = 0;
    } // end of old player
        
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x45b0
movq -0xb0(%rbp), %rsi
movq -0x10(%rbp), %rdi
callq 0x4550
jmp 0x165f5
leaq -0x30(%rbp), %rdi
callq 0x4660
testb $0x1, %al
jne 0x16604
jmp 0x16676
movl $0x10, %edi
callq 0x4250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
leaq 0x6101(%rip), %rsi      # 0x1c723
callq 0x41c0
jmp 0x16629
movq -0xb8(%rbp), %rdi
movq 0x129b9(%rip), %rsi     # 0x28ff0
movq 0x1297a(%rip), %rdx     # 0x28fb8
callq 0x46a0
jmp 0x168d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x168c0
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x4350
jmp 0x168c0
leaq -0x30(%rbp), %rdi
callq 0x7700
movq %rax, -0xc0(%rbp)
jmp 0x16688
movq -0xc0(%rbp), %rax
cmpq $0x0, %rax
je 0x16735
movb $0x1, -0x61(%rbp)
movl $0x10, %edi
callq 0x4250
movq %rax, -0xc8(%rbp)
leaq 0x6084(%rip), %rdx      # 0x1c739
leaq -0x60(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x138e0
jmp 0x166c4
movq -0xc8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4630
jmp 0x166d6
movq -0xc8(%rbp), %rdi
movb $0x0, -0x61(%rbp)
movq 0x12908(%rip), %rsi     # 0x28ff0
movq 0x128c9(%rip), %rdx     # 0x28fb8
callq 0x46a0
jmp 0x168d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1671c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x47d8
testb $0x1, -0x61(%rbp)
jne 0x16724
jmp 0x16730
movq -0xc8(%rbp), %rdi
callq 0x4350
jmp 0x168c0
leaq -0x30(%rbp), %rdi
leaq 0x13100(%rip), %rsi     # 0x29840
xorl %eax, %eax
movl %eax, %edx
callq 0x4390
cmpq $-0x1, %rax
je 0x167b0
movl $0x10, %edi
callq 0x4250
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xd0(%rbp)
leaq 0x5fe3(%rip), %rsi      # 0x1c750
callq 0x41c0
jmp 0x16774
movq -0xd0(%rbp), %rdi
movq 0x1286e(%rip), %rsi     # 0x28ff0
movq 0x1282f(%rip), %rdx     # 0x28fb8
callq 0x46a0
jmp 0x168d2
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
callq 0x4350
jmp 0x168c0
leaq -0x88(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x6d60
jmp 0x167c2
leaq 0x5fb8(%rip), %rsi      # 0x1c781
leaq -0x88(%rbp), %rdi
callq 0x17800
movb %al, -0xd1(%rbp)
jmp 0x167dd
leaq -0x88(%rbp), %rdi
callq 0x47d8
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x167f5
jmp 0x16838
movq -0x8(%rbp), %rax
movl $0x2, 0x68(%rax)
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
leaq 0x5f76(%rip), %rsi      # 0x1c785
callq 0x45a0
jmp 0x16816
jmp 0x168ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x47d8
jmp 0x168c0
leaq -0xa8(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x6e20
jmp 0x1684a
movq -0x8(%rbp), %rdi
addq $0x90, %rdi
leaq -0xa8(%rbp), %rsi
movq %rsi, -0xe0(%rbp)
callq 0x4520
movq -0xe0(%rbp), %rdi
callq 0x47d8
movq -0x8(%rbp), %rdi
callq 0x7cf0
jmp 0x1687f
movq -0x8(%rbp), %rax
movl $0x1, 0x68(%rax)
movq -0x8(%rbp), %rdi
addq $0x70, %rdi
leaq 0x5f1d(%rip), %rsi      # 0x1c7b6
callq 0x45a0
jmp 0x168a0
movq -0x8(%rbp), %rax
movl $0x0, 0xd0(%rax)
leaq -0x30(%rbp), %rdi
callq 0x47d8
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x47d8
movq -0x38(%rbp), %rdi
callq 0x46d0
nopw %cs:(%rax,%rax)