// File: /workspace/github_c_makefile_star2_O0/schroeder-lvb[P]sissm/src/piantirush.c
// Function: piantirushPeriodicCB
int piantirushPeriodicCB( char *strIn )
{
    static int lastFastState = -1;
    int currFastState;
    int playersAlive;
    static int lastLivePlayerCount = -1;
    int currLivePlayerCount;
    long noProtectSecsL;

    currFastState = (int) p2pGetF( "piantirush.p2p.fast", 0.0 ) ;
 
    // if last state is "slow" (default) and admin wishes to run "fast"
    // (antirush-disable), then immediately disable the slow rate via
    // the RCON
    // 
    if ( (lastFastState == 0) && (currFastState != 0) ) {
        _captureSpeedForceNext();
        _captureSpeed( 0 );
    }
    lastFastState = currFastState;

    // if we are running "fast" mode then turn on lcoal mute so that this plugin 
    // stays silent.
    //
    if ( currFastState ) { _localMute = 1;  _fastMode = 1; }
    else                 { _localMute = 0;  _fastMode = 0; }

    // if enabled process territorial antirush check.
    // This periodic processing increments the offender 'time' as well
    // as handle kicking upon allowed time expiry
    //
    if ( (piantirushConfig.autoKickEarlyBreach) ) {
        _capRusherPeriodicCheck();
    }

    // Process exemption of auto-kick on LMS conditions
    //
    playersAlive = apiBPPlayerCount();

    if ( playersAlive > _peakAlivePlayer ) {           // keep track of peak# of players
        _peakAlivePlayer = playersAlive;
    }
 
    if ( kickArmed && (_peakAlivePlayer > piantirushConfig.autoKickExemptLMS) ) {              
        if ( playersAlive <= piantirushConfig.autoKickExemptLMS )  {
            _localSay( piantirushConfig.autoKickExemptMsg );

            if ( NULL != strstr( rosterGetObjectiveType(), "WeaponCache" ))  {
                alarmCancel( rPtr );  // cancel any pending 'aa' request
                _localSay( piantirushConfig.destroyOkPrompt );
                kickArmed = 0;                    // kick safety : disable kick
                alarmCancel( aPtr );
                _captureSpeed( 0 );
           }

           else if ( NULL != strstr( rosterGetObjectiveType(), "Captur" ))  {
               alarmCancel( bPtr );   // cancel any pending 'aa' request  
               _localSay( piantirushConfig.breachOkPrompt );
                kickArmed = 0;                    // kick safety : disable kick
               alarmReset( aPtr, 2L );
               _capRusherClear();

           }
        }
    }
  
    // Useful information to print to the screen or log file - to determine
    // number of live players.  Only log changes to cut down on clutter.
    //
    currLivePlayerCount = apiBPPlayerCount();
    if ( lastLivePlayerCount  != currLivePlayerCount ) {
        logPrintf( LOG_LEVEL_INFO, "piantirush", "Change in live player count: %d -> %d", 
            lastLivePlayerCount, currLivePlayerCount );
        lastLivePlayerCount = currLivePlayerCount;
    }

    // State machine to handle kickArmed2 interlock that is compatible
    // with wave-respawn option (where number of players alive may go 'up' 
    // at any time.  Kickarmed2 is initialized to 2 at start of the objective. It is
    // primed when live players exceeds threshold.  After prime it is allowed to 
    // disarm when LMS condition occurs, and it is latched at this state until start 
    // of next objective.
    // 
    switch ( kickArmed2 ) {
    case 2:   // armed because objective has just begun
        if ( currLivePlayerCount > piantirushConfig.autoKickExemptLMS ) 
            kickArmed2 = 1;
        break;
    case 1:   // armed because minimum alive count exceeded the exemption threshold
        if ( currLivePlayerCount <= piantirushConfig.autoKickExemptLMS ) 
            kickArmed2 = 0;
        break;
    default:  // =0 disarmed because we are below minimum exemption threshold
        ;;    // do nothing, wait for synthetic objective event to set it back to "2"
        break;
    }

#if 0
    // Exception processing - regardless of the condition if min player exemption is set,
    // do not kick anyone as long as # player falls below the threshold.
    //
    if ( 0 != piantirushConfig.autoKickExemptLMS  ) {              
        kickArmed2 = 1;
        if ( currLivePlayerCount <= piantirushConfig.autoKickExemptLMS ) kickArmed2 = 0;
    }
    else 
        kickArmed2 = 1;
#endif

    // Service the "no kick" protection window countdown in seconds.  If it reaches 0L
    // then nokick protection becomes disabled.
    //
    noProtectSecsL =  p2pGetL( "piantirush.p2p.nokickprotect", 0L ) ;
    if ( noProtectSecsL != 0L ) {
         if ( --noProtectSecsL < 0L ) { 
             noProtectSecsL = 0L;
             logPrintf( LOG_LEVEL_INFO, "piantirush", "Nokick Protection window is now deactivated." );
         }
         else {
             logPrintf( LOG_LEVEL_INFO, "piantirush", "Nokick Protect window is active: %ld", noProtectSecsL );
         }
         p2pSetL( "piantirush.p2p.nokickprotect", noProtectSecsL );
    }

    // Service the "no wait" speedup feature (admins/moderators) 
    //
    if ( 0L != p2pGetL( "piantirush.p2p.SigNoWait", 0L )) {
        p2pSetL( "piantirush.p2p.SigNoWait", 0L );  // clear the semaphore 
        if ( alarmStatus( aPtr ) > 2L ) {
            _capRusherClear();
            alarmReset( aPtr, 2L );
        }
    }

    // If the server goes empty, make sure Training Mode and AutoKick Exemption is cleared.
    //
    if ( 0 == apiPlayersGetCount() ) {
        p2pSetL( "piantirush.p2p.training", 0L );
        p2pSetL( "piantirush.p2p.nokickprotect", 0L );
        p2pSetL( "piantirush.p2p.SigNoWait", 0L );
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
leaq 0x75fa(%rip), %rdi      # 0x2396d
xorps %xmm0, %xmm0
callq 0x1ecf0
cvttsd2si %xmm0, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, 0x15b4f(%rip)     # 0x31ed8
jne 0x1c39d
cmpl $0x0, -0xc(%rbp)
je 0x1c39d
callq 0x1bf80
xorl %edi, %edi
callq 0x1b9c0
movl -0xc(%rbp), %eax
movl %eax, 0x15b32(%rip)     # 0x31ed8
cmpl $0x0, -0xc(%rbp)
je 0x1c3c2
movl $0x1, 0x20bab2(%rip)    # 0x227e68
movl $0x1, 0x20baac(%rip)    # 0x227e6c
jmp 0x1c3d6
movl $0x0, 0x20ba9c(%rip)    # 0x227e68
movl $0x0, 0x20ba96(%rip)    # 0x227e6c
cmpl $0x0, 0x2074eb(%rip)    # 0x2238c8
je 0x1c3e4
callq 0x1c6b0
callq 0x15430
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl 0x15aeb(%rip), %eax     # 0x31ee0
jle 0x1c400
movl -0x10(%rbp), %eax
movl %eax, 0x15ae0(%rip)     # 0x31ee0
cmpl $0x0, 0x20ba39(%rip)    # 0x227e40
je 0x1c506
movl 0x15acd(%rip), %eax     # 0x31ee0
cmpl 0x2090bf(%rip), %eax    # 0x2254d8
jle 0x1c506
movl -0x10(%rbp), %eax
cmpl 0x2090b0(%rip), %eax    # 0x2254d8
jg 0x1c504
leaq 0x20346b(%rip), %rdi    # 0x21f8a0
addq $0x5c3c, %rdi           # imm = 0x5C3C
movb $0x0, %al
callq 0x1cac0
callq 0x193d0
movq %rax, %rdi
leaq 0xa6f9(%rip), %rsi      # 0x26b4b
callq 0x8390
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x1c4a1
movq 0x20ba08(%rip), %rdi    # 0x227e70
callq 0x12a80
leaq 0x20342c(%rip), %rdi    # 0x21f8a0
addq $0x2c20, %rdi           # imm = 0x2C20
movb $0x0, %al
callq 0x1cac0
movl $0x0, 0x20b9b4(%rip)    # 0x227e40
movq 0x20b48d(%rip), %rdi    # 0x227920
callq 0x12a80
xorl %edi, %edi
callq 0x1b9c0
jmp 0x1c502
callq 0x193d0
movq %rax, %rdi
leaq 0xa6a7(%rip), %rsi      # 0x26b57
callq 0x8390
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x1c500
movq 0x20b9b2(%rip), %rdi    # 0x227e78
callq 0x12a80
leaq 0x2033ce(%rip), %rdi    # 0x21f8a0
addq $0x402c, %rdi           # imm = 0x402C
movb $0x0, %al
callq 0x1cac0
movl $0x0, 0x20b956(%rip)    # 0x227e40
movq 0x20b42f(%rip), %rdi    # 0x227920
movl $0x2, %esi
callq 0x12a40
callq 0x1bf90
jmp 0x1c502
jmp 0x1c504
jmp 0x1c506
callq 0x15430
movl %eax, -0x14(%rbp)
movl 0x159c8(%rip), %eax     # 0x31edc
cmpl -0x14(%rbp), %eax
je 0x1c546
movl 0x159bd(%rip), %ecx     # 0x31edc
movl -0x14(%rbp), %r8d
movl $0x2, %edi
leaq 0xa5c3(%rip), %rsi      # 0x26af2
leaq 0xa628(%rip), %rdx      # 0x26b5e
movb $0x0, %al
callq 0x21bf0
movl -0x14(%rbp), %eax
movl %eax, 0x15996(%rip)     # 0x31edc
movl 0x15998(%rip), %eax     # 0x31ee4
movl %eax, -0x24(%rbp)
subl $0x1, %eax
je 0x1c577
jmp 0x1c556
movl -0x24(%rbp), %eax
subl $0x2, %eax
jne 0x1c58e
jmp 0x1c560
movl -0x14(%rbp), %eax
cmpl 0x208f6f(%rip), %eax    # 0x2254d8
jle 0x1c575
movl $0x1, 0x1596f(%rip)     # 0x31ee4
jmp 0x1c590
movl -0x14(%rbp), %eax
cmpl 0x208f58(%rip), %eax    # 0x2254d8
jg 0x1c58c
movl $0x0, 0x15958(%rip)     # 0x31ee4
jmp 0x1c590
jmp 0x1c590
leaq 0x79dd(%rip), %rdi      # 0x23f74
xorl %eax, %eax
movl %eax, %esi
callq 0x1eda0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1c60f
movq -0x20(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jge 0x1c5e1
movq $0x0, -0x20(%rbp)
movl $0x2, %edi
leaq 0xa521(%rip), %rsi      # 0x26af2
leaq 0xa5ac(%rip), %rdx      # 0x26b84
movb $0x0, %al
callq 0x21bf0
jmp 0x1c5ff
movq -0x20(%rbp), %rcx
movl $0x2, %edi
leaq 0xa501(%rip), %rsi      # 0x26af2
leaq 0xa5b9(%rip), %rdx      # 0x26bb1
movb $0x0, %al
callq 0x21bf0
movq -0x20(%rbp), %rsi
leaq 0x796a(%rip), %rdi      # 0x23f74
callq 0x1ebf0
leaq 0x797b(%rip), %rdi      # 0x23f91
xorl %eax, %eax
movl %eax, %esi
callq 0x1eda0
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
je 0x1c663
leaq 0x7961(%rip), %rdi      # 0x23f91
xorl %eax, %eax
movl %eax, %esi
callq 0x1ebf0
movq 0x20b2e0(%rip), %rdi    # 0x227920
callq 0x12aa0
cmpq $0x2, %rax
jle 0x1c661
callq 0x1bf90
movq 0x20b2c9(%rip), %rdi    # 0x227920
movl $0x2, %esi
callq 0x12a40
jmp 0x1c663
callq 0x17fe0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x1c6a0
leaq 0x729b(%rip), %rdi      # 0x23912
xorl %eax, %eax
movl %eax, %esi
callq 0x1ebf0
leaq 0x78ed(%rip), %rdi      # 0x23f74
xorl %eax, %eax
movl %eax, %esi
callq 0x1ebf0
leaq 0x78fa(%rip), %rdi      # 0x23f91
xorl %eax, %eax
movl %eax, %esi
callq 0x1ebf0
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)