// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
leaq 0x5838(%rip), %rdi      # 0x1b96d
xorpd %xmm0, %xmm0
callq 0x17f65
cvttsd2si %xmm0, %ebx
cmpl $0x0, 0x13d8b(%rip)     # 0x29ed4
sete %al
testl %ebx, %ebx
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x16169
movl $0xffffffff, 0x13d82(%rip) # imm = 0xFFFFFFFF
xorl %edi, %edi
callq 0x15a74
testl %ebx, %ebx
setne 0x209cf6(%rip)          # 0x21fe68
setne 0x209cf3(%rip)          # 0x21fe6c
movl %ebx, 0x13d55(%rip)     # 0x29ed4
cmpl $0x0, 0x205742(%rip)    # 0x21b8c8
je 0x16316
cmpl $0x0, 0x13d4d(%rip)     # 0x29ee0
je 0x16316
testb $0x1, 0x209ca0(%rip)    # 0x21fe40
je 0x16316
movl 0x205f24(%rip), %eax    # 0x21c0d0
movl 0x205f22(%rip), %ecx    # 0x21c0d4
xorl %r15d, %r15d
leaq 0x209cd4(%rip), %r12    # 0x21fe90
cmpb $0x0, (%r15,%r12)
je 0x16200
cmpl $0x0, 0x88(%r15,%r12)
je 0x161e5
movl 0x84(%r15,%r12), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x84(%r15,%r12)
cmpl %eax, %edx
jg 0x16215
testl %ecx, %ecx
je 0x16200
movl 0x80(%r15,%r12), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x80(%r15,%r12)
cmpl %ecx, %edx
jg 0x1627c
addq $0x8c, %r15
cmpq $0x2300, %r15           # imm = 0x2300
jne 0x161bc
jmp 0x16316
leaq (%r15,%r12), %rbx
addq $0x40, %rbx
movq %rbx, %rdi
callq 0x14b50
testq %rax, %rax
je 0x16316
movq %rsp, %r14
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
movq %rax, %rsi
callq 0xf038
leaq 0x206690(%rip), %rdx    # 0x21c8d8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x167e2
testl %eax, %eax
jne 0x162ef
leaq 0x9522(%rip), %rdi      # 0x1f784
movq %rbx, %rsi
xorl %eax, %eax
callq 0x16554
leaq 0x8877(%rip), %rsi      # 0x1eaea
leaq 0x952c(%rip), %rdx      # 0x1f7a6
jmp 0x162dd
leaq (%r15,%r12), %rbx
addq $0x40, %rbx
movq %rbx, %rdi
callq 0x14b50
testq %rax, %rax
je 0x16316
movq %rsp, %r14
movl $0x100, %edx            # imm = 0x100
movq %r14, %rdi
movq %rax, %rsi
callq 0xf038
leaq 0x206229(%rip), %rdx    # 0x21c4d8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x167e2
testl %eax, %eax
jne 0x162ef
leaq 0x9506(%rip), %rdi      # 0x1f7cb
movq %rbx, %rsi
xorl %eax, %eax
callq 0x16554
leaq 0x8814(%rip), %rsi      # 0x1eaea
leaq 0x951e(%rip), %rdx      # 0x1f7fb
movq %rsp, %r8
movl $0x1, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1a227
xorl %eax, %eax
movb %al, (%r15,%r12)
movb %al, 0x40(%r15,%r12)
movl %eax, 0x88(%r15,%r12)
movl %eax, 0x80(%r15,%r12)
movl $0x0, 0x84(%r15,%r12)
callq 0x1172e
cmpl 0x13bbb(%rip), %eax     # 0x29edc
jle 0x16329
movl %eax, 0x13bb3(%rip)     # 0x29edc
cmpb $0x1, 0x209b10(%rip)    # 0x21fe40
jne 0x163ff
movl 0x20719c(%rip), %ecx    # 0x21d4d8
cmpl %ecx, 0x13b9a(%rip)     # 0x29edc
setle %dl
cmpl %ecx, %eax
setg %al
orb %dl, %al
jne 0x163ff
leaq 0x207183(%rip), %rdi    # 0x21d4dc
xorl %eax, %eax
callq 0x16554
callq 0x14246
leaq 0x87d7(%rip), %rsi      # 0x1eb43
movq %rax, %rdi
callq 0x83b0
testq %rax, %rax
je 0x163af
movq 0x209af0(%rip), %rdi    # 0x21fe70
callq 0xf974
leaq 0x204134(%rip), %rdi    # 0x21a4c0
xorl %eax, %eax
callq 0x16554
movb $0x0, 0x209aa6(%rip)    # 0x21fe40
movq 0x20957f(%rip), %rdi    # 0x21f920
callq 0xf974
xorl %edi, %edi
callq 0x15a74
jmp 0x163ff
callq 0x14246
leaq 0x8794(%rip), %rsi      # 0x1eb4f
movq %rax, %rdi
callq 0x83b0
testq %rax, %rax
je 0x163ff
movq 0x209aa9(%rip), %rdi    # 0x21fe78
callq 0xf974
leaq 0x2054f1(%rip), %rdi    # 0x21b8cc
xorl %eax, %eax
callq 0x16554
movb $0x0, 0x209a57(%rip)    # 0x21fe40
movq 0x209530(%rip), %rdi    # 0x21f920
movl $0x2, %esi
callq 0xf953
callq 0x15ec8
callq 0x1172e
movl %eax, %ebx
movl 0x13acc(%rip), %ecx     # 0x29ed8
cmpl %eax, %ecx
je 0x16433
leaq 0x86d3(%rip), %rsi      # 0x1eaea
leaq 0x8738(%rip), %rdx      # 0x1eb56
movl $0x2, %edi
movl %ebx, %r8d
xorl %eax, %eax
callq 0x1a227
movl %ebx, 0x13aa5(%rip)     # 0x29ed8
movl 0x13aa7(%rip), %eax     # 0x29ee0
cmpl $0x1, %eax
je 0x16490
cmpl $0x2, %eax
jne 0x16456
movl $0x1, %eax
cmpl 0x20708a(%rip), %ebx    # 0x21d4d8
jle 0x16456
movl %eax, 0x13a8a(%rip)     # 0x29ee0
leaq 0x5b17(%rip), %rdi      # 0x1bf74
xorl %esi, %esi
callq 0x18004
testq %rax, %rax
je 0x164c7
jle 0x1649c
movq %rax, %rbx
decq %rbx
leaq 0x8672(%rip), %rsi      # 0x1eaea
leaq 0x872a(%rip), %rdx      # 0x1eba9
movl $0x2, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x1a227
jmp 0x164b8
xorl %eax, %eax
cmpl 0x207040(%rip), %ebx    # 0x21d4d8
jle 0x16450
jmp 0x16456
leaq 0x8647(%rip), %rsi      # 0x1eaea
leaq 0x86d2(%rip), %rdx      # 0x1eb7c
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq 0x1a227
leaq 0x5ab5(%rip), %rdi      # 0x1bf74
movq %rbx, %rsi
callq 0x17ea8
leaq 0x5ac3(%rip), %rdi      # 0x1bf91
xorl %esi, %esi
callq 0x18004
testq %rax, %rax
je 0x16510
leaq 0x5ab0(%rip), %rdi      # 0x1bf91
xorl %esi, %esi
callq 0x17ea8
movq 0x209431(%rip), %rdi    # 0x21f920
callq 0xf97e
cmpq $0x3, %rax
jl 0x16510
callq 0x15ec8
movq 0x20941a(%rip), %rdi    # 0x21f920
movl $0x2, %esi
callq 0xf953
callq 0x134dc
testl %eax, %eax
jne 0x16543
leaq 0x53f2(%rip), %rdi      # 0x1b912
xorl %esi, %esi
callq 0x17ea8
leaq 0x5a46(%rip), %rdi      # 0x1bf74
xorl %esi, %esi
callq 0x17ea8
leaq 0x5a55(%rip), %rdi      # 0x1bf91
xorl %esi, %esi
callq 0x17ea8
xorl %eax, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r14
popq %r15
retq