// File: /workspace/github_c_makefile_star2_O2/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 0x144b8
leaq 0xdee0(%rip), %rsi      # 0x1c272
leaq 0x10f99(%rip), %rdx     # 0x1f332
xorl %edi, %edi
movq %r14, %rcx
movq %r15, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x1920b
callq 0x12f75
leaq 0x320(%rsp), %rbx
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %rax, %rsi
callq 0xe97a
leaq 0xcc28(%rip), %rsi      # 0x1aff7
movq %rbx, %rdi
callq 0x8060
testl %eax, %eax
je 0xe3f7
leaq 0xdbd9(%rip), %rsi      # 0x1bfbb
leaq 0x320(%rsp), %rdi
callq 0x8060
testl %eax, %eax
jne 0xe5d1
callq 0x13640
leaq 0x420(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xe97a
callq 0x13664
leaq 0x220(%rsp), %rdi
movl $0xff, %edx
movq %rax, %rsi
callq 0xe97a
callq 0x1372b
movl %eax, %ebx
callq 0x83e0
movq (%rax), %rax
movsbq %bl, %rcx
movl (%rax,%rcx,4), %ebx
callq 0x117e3
testl %eax, %eax
je 0xe459
callq 0x8030
movq (%rax), %rax
movsbq %bl, %rcx
movl (%rax,%rcx,4), %ebx
leaq 0xc(%rsp), %rax
movl $0x63, (%rax)
movl $0x414, %r14d           # imm = 0x414
leaq 0x964af(%rip), %rbp     # 0xa4920
leaq 0xccd6(%rip), %r12      # 0x1b14e
leaq 0x220(%rsp), %r13
cmpq $0x1e414, %r14          # imm = 0x1E414
je 0xe528
leaq (%r14,%rbp), %r15
movq %r15, %rdi
callq 0x8120
testl %eax, %eax
je 0xe528
movq %r15, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0xed9c
movq %rax, %rdi
movq %r13, %rsi
callq 0x8060
testl %eax, %eax
je 0xe4c6
addq $0x400, %r14            # imm = 0x400
jmp 0xe480
movq %r15, %rdi
pushq $0x1
popq %rsi
movq %r12, %rdx
callq 0xed9c
testq %rax, %rax
je 0xe4bd
cmpb %bl, (%rax)
jne 0xe4bd
movq %r15, %rdi
pushq $0x2
popq %rsi
movq %r12, %rdx
callq 0xed9c
testq %rax, %rax
je 0xe4bd
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
pushq $0x10
popq %rdx
callq 0xe97a
movq %r15, %rdi
leaq 0xcbb8(%rip), %rsi      # 0x1b0c5
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x82d0
cmpl $0x1, %eax
je 0xe4bd
movl $0x63, 0xc(%rsp)
jmp 0xe4bd
movl 0xc(%rsp), %ebp
callq 0x12ab4
cmpl %ebp, %eax
jge 0xe53e
leaq 0xde20(%rip), %rdx      # 0x1c35c
jmp 0xe5ac
leaq 0x120(%rsp), %r14
movq %r14, %rdi
callq 0x13480
cmpl $0x1, %eax
je 0xe583
leaq 0x120(%rsp), %rdi
callq 0x13480
cmpl $0x2, %eax
jne 0xe56c
leaq 0x20(%rsp), %r14
jmp 0xe583
leaq 0x120(%rsp), %rdi
callq 0x13480
leaq 0x20(%rsp), %r14
cmpl $0x3, %eax
jne 0xe5e5
leaq 0xdcf2(%rip), %rsi      # 0x1c27c
movq %r14, %rdi
callq 0x129f0
leaq 0xdd2a(%rip), %rdi      # 0x1c2c3
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x125a8
leaq 0xdd41(%rip), %rdx      # 0x1c2ed
movsbl %bl, %r9d
movl %ebp, (%rsp)
leaq 0xdcb8(%rip), %rsi      # 0x1c272
pushq $0x1
popq %rdi
leaq 0x20(%rsp), %rcx
leaq 0x220(%rsp), %r8
xorl %eax, %eax
callq 0x1920b
xorl %eax, %eax
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xdd35(%rip), %rdx      # 0x1c321
jmp 0xe5ac