// File: /workspace/github_c_makefile_star2_O3/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 0x15427
leaq 0xe502(%rip), %rsi      # 0x1d26a
leaq 0x11603(%rip), %rdx     # 0x20372
xorl %edi, %edi
movq %r14, %rcx
movq %r15, %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x1a3e3
callq 0x13dc1
leaq 0x320(%rsp), %rbx
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf384
leaq 0xd252(%rip), %rsi      # 0x1bff7
movq %rbx, %rdi
callq 0x8060
testl %eax, %eax
je 0xedcd
leaq 0xe1fb(%rip), %rsi      # 0x1cfb3
leaq 0x320(%rsp), %rdi
callq 0x8060
testl %eax, %eax
jne 0xefad
callq 0x1455b
leaq 0x420(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf384
callq 0x1457f
leaq 0x220(%rsp), %rdi
movl $0xff, %edx
movq %rax, %rsi
callq 0xf384
callq 0x1464a
movl %eax, %ebx
callq 0x83d0
movq (%rax), %rax
movsbq %bl, %rcx
movl (%rax,%rcx,4), %r15d
callq 0x124aa
testl %eax, %eax
je 0xee31
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 0x95ad8(%rip), %r14     # 0xa4920
leaq 0xd2ff(%rip), %r12      # 0x1c14e
leaq 0x220(%rsp), %r13
leaq (%r14,%rbp), %rbx
movq %rbx, %rdi
callq 0x8120
testl %eax, %eax
je 0xef02
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0xf82d
movq %rax, %rdi
movq %r13, %rsi
callq 0x8060
testl %eax, %eax
je 0xee99
addq $0x400, %rbp            # imm = 0x400
cmpq $0x1e414, %rbp          # imm = 0x1E414
jne 0xee57
jmp 0xef02
movq %rbx, %rdi
movl $0x1, %esi
movq %r12, %rdx
callq 0xf82d
testq %rax, %rax
je 0xee87
cmpb %r15b, (%rax)
jne 0xee87
movq %rbx, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0xf82d
testq %rax, %rax
je 0xee87
movl $0x10, %edx
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf384
movq %rbx, %rdi
leaq 0xd1de(%rip), %rsi      # 0x1c0c5
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x82d0
cmpl $0x1, %eax
je 0xee87
movl $0x63, 0xc(%rsp)
jmp 0xee87
movl 0xc(%rsp), %ebx
callq 0x13853
cmpl %ebx, %eax
jge 0xef18
leaq 0xe43e(%rip), %rdx      # 0x1d354
jmp 0xef86
leaq 0x120(%rsp), %r14
movq %r14, %rdi
callq 0x14378
cmpl $0x1, %eax
je 0xef5d
leaq 0x120(%rsp), %rdi
callq 0x14378
cmpl $0x2, %eax
jne 0xef46
leaq 0x20(%rsp), %r14
jmp 0xef5d
leaq 0x120(%rsp), %rdi
callq 0x14378
leaq 0x20(%rsp), %r14
cmpl $0x3, %eax
jne 0xefc1
leaq 0xe310(%rip), %rsi      # 0x1d274
movq %r14, %rdi
callq 0x13789
leaq 0xe348(%rip), %rdi      # 0x1d2bb
leaq 0x20(%rsp), %rsi
xorl %eax, %eax
callq 0x13337
leaq 0xe35f(%rip), %rdx      # 0x1d2e5
movsbl %r15b, %r9d
movl %ebx, (%rsp)
leaq 0xe2d6(%rip), %rsi      # 0x1d26a
leaq 0x20(%rsp), %rcx
leaq 0x220(%rsp), %r8
movl $0x1, %edi
xorl %eax, %eax
callq 0x1a3e3
xorl %eax, %eax
addq $0x628, %rsp            # imm = 0x628
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe351(%rip), %rdx      # 0x1d319
jmp 0xef86