// File: /workspace/github_c_makefile_star2_O1/schroeder-lvb[P]sissm/src/piprotect.c
// Function: piprotectClientAddCB
int piprotectClientAddCB( char *strIn )
{
    char playerName[256], playerGUID[256], playerIP[256];
    char gameMode[256], objName[256], mapName[256], objLetter;
    int limitPlayers;

    rosterParsePlayerConn( strIn, 256, playerName, playerGUID, playerIP );
    logPrintf( LOG_LEVEL_CRITICAL, "piprotect", "Add Client ::%s::%s::%s::", playerName, playerGUID, playerIP );


    // get current game mode - only process if 'checkpoint' or 'hardcore' 
    // 
    strlcpy( gameMode, apiGetServerMode(), 256 );
    if ( (0 == strcasecmp( gameMode, "hardcore" ) ) || (0 == strcasecmp( gameMode, "checkpoint" )) ) {

        // get current map/objective information
        //
        strlcpy( objName, rosterGetObjective(), 256 );       // e.g., "OCCheckpoint_A"
        strlcpy( mapName, rosterGetMapName(), 255 );   // e.g., "Farmhouse_Checkpoint_Security"
        objLetter = rosterGetCoopObjectiveLetter();          // e.g., 'A', 'B', 'C', ... ' '

        objLetter = tolower( objLetter ) ; 
        if ( apiIsCounterAttack() )             // non-zero if in counterattack state
            objLetter = toupper( objLetter );

        // Check join limit criteria - kick players if join limit criteria is met
        // 
        limitPlayers = _joinLimit( objName, mapName, objLetter ) ;
        if ( apiPlayersGetCount() >= limitPlayers ) {
            if ( 1 == rosterIsValidGUID( playerGUID ) ) {        // if Steam
                apiKick( playerGUID, "Join temporarily blocked for this objective - try again in few minutes" );
                apiSay( "Unable to connect '%s' for this objective", playerName );
                logPrintf( LOG_LEVEL_WARN, "piprotect", "Protective Kick: '%s'  Map: '%s' Obj: '%c' Limit %d", playerName, mapName, objLetter, limitPlayers );
            }
            else if ( 2 == rosterIsValidGUID( playerGUID ) ) {   // if EPIC
                apiKick( playerName, "Join temporarily blocked for this objective - try again in few minutes" );
                apiSay( "Unable to connect '%s' for this objective", playerName );
                logPrintf( LOG_LEVEL_WARN, "piprotect", "Protective Kick: '%s'  Map: '%s' Obj: '%c' Limit %d", playerName, mapName, objLetter, limitPlayers );
            }
            else if ( 3 == rosterIsValidGUID( playerGUID ) ) {   // if WinGDK
                apiKick( playerName, "Join temporarily blocked for this objective - try again in few minutes" );
                apiSay( "Unable to connect '%s' for this objective", playerName );
                logPrintf( LOG_LEVEL_WARN, "piprotect", "Protective Kick: '%s'  Map: '%s' Obj: '%c' Limit %d", playerName, mapName, objLetter, limitPlayers );
            }
            else {
                logPrintf( LOG_LEVEL_WARN, "piprotect", "Protective kick failed: '%s'  Map: '%s' Obj: '%c' Limit %d", playerName, mapName, objLetter, limitPlayers );
            }
        }
        else {
            logPrintf( LOG_LEVEL_WARN, "piprotect", "Join permitted: '%s'  Map: '%s' Obj: '%c' Limit %d", playerName, mapName, objLetter, limitPlayers );
        }
    }
   
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x628, %rsp            # imm = 0x628
leaq 0x20(%rsp), %r14
leaq 0x120(%rsp), %r15
leaq 0x520(%rsp), %rbx
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x15182
leaq 0xe87a(%rip), %rsi      # 0x1d292
leaq 0x11963(%rip), %rdx     # 0x20382
xorl %edi, %edi
movq %r14, %rcx
movq %r15, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x1a227
callq 0x13a76
leaq 0x320(%rsp), %rbx
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf038
leaq 0xd5aa(%rip), %rsi      # 0x1bfff
movq %rbx, %rdi
callq 0x8060
testl %eax, %eax
je 0xea7d
leaq 0xe573(%rip), %rsi      # 0x1cfdb
leaq 0x320(%rsp), %rdi
callq 0x8060
testl %eax, %eax
jne 0xec5d
callq 0x1423e
leaq 0x420(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf038
callq 0x14262
leaq 0x220(%rsp), %rdi
movl $0xff, %edx
movq %rax, %rsi
callq 0xf038
callq 0x1432d
movl %eax, %ebx
callq 0x83d0
movq (%rax), %rax
movsbq %bl, %rcx
movl (%rax,%rcx,4), %r15d
callq 0x1212d
testl %eax, %eax
je 0xeae1
callq 0x8030
movq (%rax), %rax
movsbq %r15b, %rcx
movl (%rax,%rcx,4), %r15d
leaq 0xc(%rsp), %rax
movl $0x63, (%rax)
movl $0x414, %ebp            # imm = 0x414
leaq 0x95e28(%rip), %r14     # 0xa4920
leaq 0xd657(%rip), %r12      # 0x1c156
leaq 0x220(%rsp), %r13
leaq (%r14,%rbp), %rbx
movq %rbx, %rdi
callq 0x8120
testl %eax, %eax
je 0xebb2
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0xf4e1
movq %rax, %rdi
movq %r13, %rsi
callq 0x8060
testl %eax, %eax
je 0xeb49
addq $0x400, %rbp            # imm = 0x400
cmpq $0x1e414, %rbp          # imm = 0x1E414
jne 0xeb07
jmp 0xebb2
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0xf4e1
testq %rax, %rax
je 0xeb37
cmpb %r15b, (%rax)
jne 0xeb37
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0xf4e1
testq %rax, %rax
je 0xeb37
movl $0x10, %edx
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf038
movq %rbx, %rdi
leaq 0xd536(%rip), %rsi      # 0x1c0cd
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x82d0
cmpl $0x1, %eax
je 0xeb37
movl $0x63, 0xc(%rsp)
jmp 0xeb37
movl 0xc(%rsp), %ebx
callq 0x134dc
cmpl %ebx, %eax
jge 0xebc8
leaq 0xe7b6(%rip), %rdx      # 0x1d37c
jmp 0xec36
leaq 0x120(%rsp), %r14
movq %r14, %rdi
callq 0x1403c
cmpl $0x1, %eax
je 0xec0d
leaq 0x120(%rsp), %rdi
callq 0x1403c
cmpl $0x2, %eax
jne 0xebf6
leaq 0x20(%rsp), %r14
jmp 0xec0d
leaq 0x120(%rsp), %rdi
callq 0x1403c
leaq 0x20(%rsp), %r14
cmpl $0x3, %eax
jne 0xec71
leaq 0xe688(%rip), %rsi      # 0x1d29c
movq %r14, %rdi
callq 0x13412
leaq 0xe6c0(%rip), %rdi      # 0x1d2e3
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x12fba
leaq 0xe6d7(%rip), %rdx      # 0x1d30d
movsbl %r15b, %r9d
movl %ebx, (%rsp)
leaq 0xe64e(%rip), %rsi      # 0x1d292
leaq 0x20(%rsp), %rcx
leaq 0x220(%rsp), %r8
movl $0x1, %edi
xorl %eax, %eax
callq 0x1a227
xorl %eax, %eax
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe6c9(%rip), %rdx      # 0x1d341
jmp 0xec36