// File: /workspace/github_c_makefile_star2_O3/schroeder-lvb[P]sissm/src/roster.c
// Function: rosterParse
int rosterParse( char *buf, int n )
{
    int i, j, validFlag;
    char *headStr, *recdStr, *atLeastOne;
    char tmpStr[256], *w;    // EPIC

    validFlag = 1;  i = 0;  j = -1;
    
    headStr = strstr( &buf[32], "========================" );    // look for start of separator == valid input
    if ( headStr != NULL ) {
        recdStr = &headStr[80];                                  // look for start of first record
      
        // Quick check to make sure at least one player connected.
        //
        if ( NULL == ( atLeastOne = strstr( recdStr, "7656" )))                   // legacy support
            if ( NULL == ( atLeastOne = strstr( recdStr, "SteamNWI:" )))          // new format
                atLeastOne = strstr( recdStr, "EOS:" );                           // new format

        j = 0;
        rosterReset();

        if ( NULL != atLeastOne ) {
            while ( 1 == 1 ) {

                // parse through data fields that are tab-delimited
                // _copy3 routine eliminates some field artifacts and checks if getWord return a NULL.
                //
                if (validFlag) validFlag = _copy3( masterRoster[j].netID,      getWord( recdStr, i++, "\011"), ROSTER_FIELD_MAX); 
                if (validFlag) validFlag = _copy3( masterRoster[j].playerName, getWord( recdStr, i++, "\011"), ROSTER_FIELD_MAX); 
                if (validFlag) validFlag = _copy3( masterRoster[j].steamID,    getWord( recdStr, i++, "\011"), ROSTER_FIELD_MAX); 
                if (validFlag) validFlag = _copy3( masterRoster[j].IPaddress,  getWord( recdStr, i++, "\011"), ROSTER_FIELD_MAX); 
                if (validFlag) validFlag = _copy3( masterRoster[j].score,      getWord( recdStr, i++, "\011"), ROSTER_FIELD_MAX); 

                // getWord returning a NULL indicates end of buffer, resulting in validFlag being cleared.. Exit the loop.
                //
                if (!validFlag) break;

                // Process Sandstorm 1.11 format change 
                // Remove SteamNWI: and EOS: prefix headers and re-write to masterRoster database
                // 
                if ( NULL != ( w = strstr( masterRoster[j].steamID, "SteamNWI:" )) ) {
                    strlcpy( tmpStr, &w[9],  32 );
                    strlcpy( masterRoster[j].steamID, tmpStr, 32 );
                }
                else if ( NULL != ( w = strstr( masterRoster[j].steamID, "EOS:" )) ) {   // EPIC
                    strlcpy( tmpStr, &w[4], 66 );
                    strlcpy( masterRoster[j].steamID, tmpStr, 66 );
                } 
                else if ( NULL != ( w = strstr( masterRoster[j].steamID, "WinGDK:" )) ) { // WinGDK
                    strlcpy( tmpStr, &w[7], 17 );
                    strlcpy( masterRoster[j].steamID, tmpStr, 17 );
                } 
                else if ( NULL != ( w = strstr( masterRoster[j].steamID, "7656" )) ) {  // pre-v1.11 backword compat
                    strlcpy( tmpStr, w,  32 );
                    strlcpy( masterRoster[j].steamID, tmpStr, 32 );
                }

                // This block was added as safety in case the data is corrupted.  
                // It has strict checking for valid Steam GUID before the data is saved.
                //
                if ( rosterIsValidGUID( masterRoster[j].steamID )) {   // safety stop
                    if ( (++j) >= ROSTER_MAX) break;
                }

            }
        }
        else {
            logPrintf( LOG_LEVEL_RAWDUMP, "roster", "Received empty or malformed listplayer rcon response size %d ::%s::", n, recdStr );
        }
        strclr( masterRoster[j].netID );
        strclr( masterRoster[j].playerName );
        strclr( masterRoster[j].steamID );
        strclr( masterRoster[j].IPaddress );
        strclr( masterRoster[j].score );

    }
    else {
        logPrintf( LOG_LEVEL_WARN, "roster", "Received non-divider listplayer rcon response size %d", n );
    }

    return( j ); 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %esi, %ebp
addq $0x20, %rdi
leaq 0x9f77(%rip), %rsi      # 0x1e80f
callq 0x83b0
testq %rax, %rax
je 0x14b29
movq %rax, %r14
addq $0x50, %r14
leaq 0x9f74(%rip), %rsi      # 0x1e828
movq %r14, %rdi
callq 0x83b0
testq %rax, %rax
movq %r14, 0x10(%rsp)
jne 0x148de
leaq 0x9f60(%rip), %rsi      # 0x1e82d
movq %r14, %rdi
callq 0x83b0
testq %rax, %rax
je 0x14bbd
callq 0x1477d
leaq 0xa148(%rip), %rdx      # 0x1ea32
xorl %r13d, %r13d
movq %r14, %rdi
xorl %esi, %esi
callq 0xf82d
leaq 0x1f3da2(%rip), %rbp    # 0x2086a0
movq %rbp, %rdi
movq %rax, %rsi
callq 0x14c09
testl %eax, %eax
je 0x14b51
xorl %r15d, %r15d
movl $0x5, %ebx
leaq 0xa112(%rip), %r12      # 0x1ea32
xorl %r13d, %r13d
leal -0x4(%rbx), %esi
imulq $0x190, %r15, %r15      # imm = 0x190
leaq (%r15,%rbp), %rax
addq $0x50, %rax
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rdx
callq 0xf82d
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x14c09
testl %eax, %eax
je 0x14b51
movq %r13, (%rsp)
leal -0x3(%rbx), %esi
leaq (%r15,%rbp), %r13
addq $0xa0, %r13
movq %r14, %rdi
movq %r12, %rdx
callq 0xf82d
movq %r13, 0x18(%rsp)
movq %r13, %rdi
movq %rax, %rsi
callq 0x14c09
testl %eax, %eax
je 0x14b4d
leal -0x2(%rbx), %esi
leaq (%r15,%rbp), %r13
addq $0xf0, %r13
movq %r14, %rdi
movq %r12, %rdx
callq 0xf82d
movq %r13, %rdi
movq %rax, %rsi
callq 0x14c09
testl %eax, %eax
je 0x14b4d
movq %rbx, 0x8(%rsp)
leal -0x1(%rbx), %esi
leaq (%r15,%rbp), %r13
addq $0x140, %r13            # imm = 0x140
movq %r14, %rdi
movq %r12, %rdx
callq 0xf82d
movq %r13, %rdi
movq %rax, %rsi
callq 0x14c09
testl %eax, %eax
je 0x14b4d
movq 0x18(%rsp), %r15
movq %r15, %rdi
leaq 0x9e32(%rip), %rsi      # 0x1e82d
callq 0x83b0
testq %rax, %rax
je 0x14a1b
addq $0x9, %rax
movl $0x20, %r13d
movl $0x20, %edx
leaq 0x20(%rsp), %rbx
jmp 0x14a89
movq %r15, %rdi
leaq 0x9e12(%rip), %rsi      # 0x1e837
callq 0x83b0
testq %rax, %rax
leaq 0x20(%rsp), %rbx
je 0x14a45
addq $0x4, %rax
movl $0x42, %r13d
movl $0x42, %edx
jmp 0x14a89
movq %r15, %rdi
leaq 0x9ded(%rip), %rsi      # 0x1e83c
callq 0x83b0
testq %rax, %rax
je 0x14a6a
addq $0x7, %rax
movl $0x11, %r13d
movl $0x11, %edx
jmp 0x14a89
movq %r15, %rdi
leaq 0x9db4(%rip), %rsi      # 0x1e828
callq 0x83b0
testq %rax, %rax
je 0x14aa2
movl $0x20, %r13d
movl $0x20, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf384
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0xf384
movq %r15, %rdi
callq 0x14378
testl %eax, %eax
je 0x14ace
movq (%rsp), %rcx
leal 0x1(%rcx), %eax
cmpl $0x7e, %ecx
movl %eax, %r13d
leaq 0x1f3bde(%rip), %rbp    # 0x2086a0
movq 0x10(%rsp), %r14
jle 0x14ade
jmp 0x14b51
leaq 0x1f3bcb(%rip), %rbp    # 0x2086a0
movq 0x10(%rsp), %r14
movq (%rsp), %r13
movslq %r13d, %r15
movq %r13, %rbx
imulq $0x190, %r15, %r13      # imm = 0x190
addq %rbp, %r13
movq %r14, %rdi
movq 0x8(%rsp), %rsi
leaq 0x9f35(%rip), %rdx      # 0x1ea32
callq 0xf82d
movq %r13, %rdi
movq %rbx, %r13
movq 0x8(%rsp), %rbx
movq %rax, %rsi
callq 0x14c09
leaq 0x9f16(%rip), %r12      # 0x1ea32
addl $0x5, %ebx
testl %eax, %eax
jne 0x14923
jmp 0x14b51
leaq 0x9c20(%rip), %rsi      # 0x1e750
leaq 0x9d51(%rip), %rdx      # 0x1e888
movl $0x1, %edi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1a3e3
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x14ba8
movq (%rsp), %r13
movslq %r13d, %rax
imulq $0x190, %rax, %rbx      # imm = 0x190
leaq 0x1f3b3e(%rip), %r15    # 0x2086a0
leaq (%r15,%rbx), %rdi
callq 0xf829
leaq (%rbx,%r15), %rdi
addq $0x50, %rdi
callq 0xf829
leaq (%rbx,%r15), %rdi
addq $0xa0, %rdi
callq 0xf829
leaq (%rbx,%r15), %rdi
addq $0xf0, %rdi
callq 0xf829
leaq (%rbx,%r15), %rdi
addq $0x140, %rdi            # imm = 0x140
callq 0xf829
movl %r13d, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9c73(%rip), %rsi      # 0x1e837
movq %r14, %rdi
callq 0x83b0
movq %rax, %r14
callq 0x1477d
testq %r14, %r14
movq 0x10(%rsp), %r14
jne 0x148e3
leaq 0x9b67(%rip), %rsi      # 0x1e750
leaq 0x9c54(%rip), %rdx      # 0x1e844
xorl %r13d, %r13d
movl $0x4, %edi
movl %ebp, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x1a3e3
jmp 0x14b51