// File: /workspace/github_c_makefile_star2_O2/schroeder-lvb[P]sissm/src/picladmin.c
// Function: cmdMap
int _cmdMap( char *arg, char *arg2, char *passThru )
{
    int errCode = 0;
    int isNight = 0, isIns = 0, clearMutators = 0;
    char *w, gameMode[80], wordBuf[80], mutName[80];
    char mutatorsList[256];
    int i, j, c;

    strclr( mutatorsList );
    strclr( gameMode );

    if ( 0 == strlen( arg ) ) {
        apiSaySys( "You must specify a map.  Type !maplist");
        errCode = 1;
    }
    else {
        //
        // Walk through each word to determine if it is "ins", "sec", 
        // "day", "night" or any of the approved mutators or game modes.
        // The check order may be important in the future.
        //
        j = 2;
        while ( errCode == 0 ) {

            w = getWord( passThru, j++, " " );
            if ( w == NULL )       break;
            if ( 0 == strlen( w )) break;
         
            strlcpy( wordBuf, w, 80 );

            // alias 
            //
            if ( 0 == strcasecmp( wordBuf, "hardcore" )) strlcpy( wordBuf, "checkpointhardcore", 80 );

            // process each word
            //
            if ( 0 == strcmp( wordBuf, "@" ) ) 
                clearMutators = 1;
            else if (NULL != strcasestr( wordBuf, "night" )) 
                isNight = 1;
            else if (NULL != strcasestr( wordBuf, "ins"   )) 
                isIns   = 1;
            else if ( apiIsSupportedGameMode( wordBuf ) ) {
                strlcpy( gameMode, wordBuf, 80 );
            }
            else {
                c = apiMutLookup( wordBuf, mutName, 80 );
                switch (c) {
                    case 0:
                        apiSaySys("Unknown game mode or mutator '%s'", wordBuf );
                        logPrintf(  LOG_LEVEL_INFO, "picladmin", "Unknown game mode or mutator '%s'", wordBuf );
                        errCode = 1;
                        break;
                    case 1:
                        strlcat( mutatorsList, mutName, 256 );
                        strlcat( mutatorsList, ",",     256 );
                        break;
                    default:
                        apiSaySys("Ambiguious mutator name '%s'", wordBuf );
                        logPrintf(  LOG_LEVEL_INFO, "picladmin", "Ambiguious mutator name '%s'", wordBuf );
                        errCode = 1;
                        break;
                }
            }
        }

        // clean up the mutatorsList (remove trailing comma)
        //
        if ( 0 != ( i = (int) strlen( mutatorsList ) )) {
            mutatorsList[ i-1 ] = 0;
        }

        if ( 0 == errCode ) {
            // change map
            logPrintf(  LOG_LEVEL_INFO, "picladmin", "----------------------------------------------------" );
            logPrintf(  LOG_LEVEL_INFO, "picladmin", "Map change to '%s' Mode '%s'  Sec/Ins '%d' Day/Night '%d'", arg, gameMode, isIns, isNight );
            logPrintf(  LOG_LEVEL_INFO, "picladmin", "Mutators: '%s'  clear: %d", mutatorsList, clearMutators );
            errCode = apiMapChange( arg, gameMode, isIns, isNight, mutatorsList, clearMutators );
        }

        if ( errCode ) {
            apiSaySys( "Map/mode/side/mutator not found" );
        }
    }
    return errCode;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %r12
movq %rdi, %rbx
leaq 0x120(%rsp), %rdi
callq 0xed98
leaq 0x80(%rsp), %rdi
callq 0xed98
cmpb $0x0, (%rbx)
je 0xb5d2
movq %rbx, 0x20(%rsp)
pushq $0x2
popq %rbx
movl $0x0, 0x18(%rsp)
leaq 0xfe1b(%rip), %rbp      # 0x1b14e
leaq 0x30(%rsp), %r14
pushq $0x50
popq %r15
movl $0x0, 0x14(%rsp)
movl $0x0, 0x1c(%rsp)
movq %r12, 0x28(%rsp)
movb $0x1, %r13b
testb $0x1, %r13b
je 0xb4fc
movq %r12, %rdi
movl %ebx, %esi
movq %rbp, %rdx
callq 0xed9c
testq %rax, %rax
je 0xb4fc
cmpb $0x0, (%rax)
je 0xb4fc
movq %r14, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0xe97a
movq %r14, %rdi
leaq 0xfc62(%rip), %rsi      # 0x1aff7
callq 0x8060
testl %eax, %eax
je 0xb3ab
cmpw $0x40, 0x30(%rsp)
jne 0xb3bf
jmp 0xb4ee
movups 0xfc3b(%rip), %xmm0     # 0x1afed
movaps %xmm0, 0x30(%rsp)
movl $0x65726f, 0x3f(%rsp)   # imm = 0x65726F
movq %r14, %rdi
leaq 0xfc01(%rip), %rsi      # 0x1afca
callq 0x8360
testq %rax, %rax
jne 0xb4d2
movq %r14, %rdi
leaq 0xfbf0(%rip), %rsi      # 0x1afd1
callq 0x8360
testq %rax, %rax
jne 0xb4e0
movq %r14, %rdi
callq 0x13038
testl %eax, %eax
je 0xb416
leaq 0x80(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xe97a
movb $0x1, %r13b
jmp 0xb4cb
movq %r14, %rdi
leaq 0xd0(%rsp), %rsi
pushq $0x50
popq %rdx
callq 0x1326b
cmpl $0x1, %eax
je 0xb469
xorl %r13d, %r13d
testl %eax, %eax
jne 0xb49f
movq %r15, %r12
movq %rbp, %r15
leaq 0xfbbe(%rip), %rbp      # 0x1b000
movq %rbp, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x12753
pushq $0x2
popq %rdi
leaq 0xf826(%rip), %rsi      # 0x1ac7f
movq %rbp, %rdx
movq %r15, %rbp
movq %r12, %r15
movq 0x28(%rsp), %r12
jmp 0xb4c1
movl $0x100, %edx            # imm = 0x100
leaq 0x120(%rsp), %r13
movq %r13, %rdi
leaq 0xd0(%rsp), %rsi
callq 0xe918
movl $0x100, %edx            # imm = 0x100
movq %r13, %rdi
leaq 0x12510(%rip), %rsi     # 0x1d9a5
callq 0xe918
jmp 0xb40e
leaq 0xfb7c(%rip), %rdi      # 0x1b022
movq %r14, %rsi
xorl %eax, %eax
callq 0x12753
pushq $0x2
popq %rdi
leaq 0xf7c5(%rip), %rsi      # 0x1ac7f
leaq 0xfb61(%rip), %rdx      # 0x1b022
movq %r14, %rcx
xorl %eax, %eax
callq 0x1920b
incl %ebx
jmp 0xb354
incl %ebx
pushq $0x1
popq %rax
movl %eax, 0x1c(%rsp)
jmp 0xb351
incl %ebx
pushq $0x1
popq %rax
movl %eax, 0x18(%rsp)
jmp 0xb351
incl %ebx
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
jmp 0xb351
leaq 0x120(%rsp), %rdi
callq 0x8120
testl %eax, %eax
je 0xb519
decl %eax
cltq
movb $0x0, 0x120(%rsp,%rax)
leaq 0xfba8(%rip), %rbx      # 0x1b0c8
testb $0x1, %r13b
je 0xb5df
leaq 0xf74e(%rip), %r14      # 0x1ac7f
leaq 0xfb07(%rip), %rdx      # 0x1b03f
xorl %ebp, %ebp
pushq $0x2
popq %r15
movl %r15d, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x1920b
movl 0x1c(%rsp), %r13d
movl %r13d, (%rsp)
leaq 0xfb19(%rip), %rdx      # 0x1b074
leaq 0x80(%rsp), %r8
movl %r15d, %edi
movq %r14, %rsi
movq 0x20(%rsp), %r12
movq %r12, %rcx
movl 0x18(%rsp), %r14d
movl %r14d, %r9d
xorl %eax, %eax
callq 0x1920b
leaq 0xfb27(%rip), %rdx      # 0x1b0ae
leaq 0x120(%rsp), %rcx
movl %r15d, %edi
leaq 0xf6e6(%rip), %rsi      # 0x1ac7f
movl 0x14(%rsp), %r15d
movl %r15d, %r8d
xorl %eax, %eax
callq 0x1920b
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
movl %r14d, %edx
movl %r13d, %ecx
leaq 0x120(%rsp), %r8
movl %r15d, %r9d
callq 0x13086
movl %eax, %r14d
testl %eax, %eax
jne 0xb5e3
jmp 0xb5f0
pushq $0x1
popq %r14
leaq 0xf9c5(%rip), %rbx      # 0x1afa2
jmp 0xb5e3
pushq $0x1
popq %r14
movq %rbx, %rdi
xorl %eax, %eax
callq 0x12753
movl %r14d, %ebp
movl %ebp, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq