// File: /workspace/github_c_makefile_star2_O1/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 $0x148, %rsp            # imm = 0x148
movl %esi, %ebp
addq $0x20, %rdi
leaq 0xa2a0(%rip), %rsi      # 0x1e81f
callq 0x83b0
testq %rax, %rax
je 0x14885
movq %rax, %rbx
addq $0x50, %rbx
leaq 0xa29d(%rip), %rsi      # 0x1e838
movq %rbx, %rdi
callq 0x83b0
testq %rax, %rax
movq %rbx, 0x8(%rsp)
jne 0x145c5
leaq 0xa289(%rip), %rsi      # 0x1e83d
movq %rbx, %rdi
callq 0x83b0
testq %rax, %rax
je 0x148bc
callq 0x14464
xorl %r15d, %r15d
leaq 0x1f40cc(%rip), %rcx    # 0x2086a0
leaq 0xa467(%rip), %r14      # 0x1ea42
xorl %ebp, %ebp
movl %r15d, %eax
imulq $0x190, %rax, %rax      # imm = 0x190
leaq (%rcx,%rax), %rdx
movq %rdx, 0x38(%rsp)
leaq (%rax,%rcx), %rdx
addq $0x50, %rdx
movq %rdx, 0x30(%rsp)
leaq 0xa0(%rax,%rcx), %r13
leaq 0xf0(%rax,%rcx), %rdx
movq %rdx, 0x28(%rsp)
addq %rcx, %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, 0x20(%rsp)
movq %r15, 0x18(%rsp)
movq %r13, 0x10(%rsp)
leal 0x1(%rbp), %r12d
movq %rbx, %r15
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0xf4e1
movq 0x38(%rsp), %rdi
movq %rax, %rsi
callq 0x14908
movb $0x1, %r13b
testl %eax, %eax
je 0x1467a
addl $0x2, %ebp
movq %r15, %rdi
movl %r12d, %esi
movq %r14, %rdx
callq 0xf4e1
movq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x14908
testl %eax, %eax
sete %al
movl %ebp, %r12d
jmp 0x1467c
movb $0x1, %al
testb %al, %al
jne 0x146ad
leal 0x1(%r12), %ebp
movq %rbx, %rdi
movl %r12d, %esi
leaq 0xa3b0(%rip), %rdx      # 0x1ea42
callq 0xf4e1
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x14908
testl %eax, %eax
sete %r13b
movl %ebp, %r12d
movb $0x1, %r14b
testb %r13b, %r13b
je 0x146b9
movb $0x1, %al
jmp 0x146e7
leal 0x1(%r12), %ebp
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0xa375(%rip), %rdx      # 0x1ea42
callq 0xf4e1
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x14908
testl %eax, %eax
sete %al
movl %ebp, %r12d
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %r13
testb %al, %al
je 0x146fa
movl %r12d, %ebp
jmp 0x14726
leal 0x1(%r12), %ebp
movq 0x8(%rsp), %rdi
movl %r12d, %esi
leaq 0xa334(%rip), %rdx      # 0x1ea42
callq 0xf4e1
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x14908
testl %eax, %eax
sete %r14b
testb %r14b, %r14b
jne 0x14829
movq %r13, %rdi
leaq 0xa104(%rip), %rsi      # 0x1e83d
callq 0x83b0
testq %rax, %rax
je 0x14769
addq $0x9, %rax
movl $0x20, %r12d
movl $0x20, %edx
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf038
movq 0x8(%rsp), %r14
jmp 0x147e7
movq %r13, %rdi
leaq 0xa0d4(%rip), %rsi      # 0x1e847
callq 0x83b0
testq %rax, %rax
movq 0x8(%rsp), %r14
leaq 0x40(%rsp), %rbx
je 0x14798
addq $0x4, %rax
movl $0x42, %r12d
movl $0x42, %edx
jmp 0x147dc
movq %r13, %rdi
leaq 0xa0aa(%rip), %rsi      # 0x1e84c
callq 0x83b0
testq %rax, %rax
je 0x147bd
addq $0x7, %rax
movl $0x11, %r12d
movl $0x11, %edx
jmp 0x147dc
movq %r13, %rdi
leaq 0xa071(%rip), %rsi      # 0x1e838
callq 0x83b0
testq %rax, %rax
je 0x147f5
movl $0x20, %r12d
movl $0x20, %edx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xf038
movq %r13, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xf038
movq %r14, %rbx
movq %r13, %rdi
callq 0x1403c
testl %eax, %eax
leaq 0xa239(%rip), %r14      # 0x1ea42
je 0x1462a
leal 0x1(%r15), %r12d
cmpl $0x7e, %r15d
movl %r12d, %r15d
leaq 0x1f3e7f(%rip), %rcx    # 0x2086a0
jbe 0x145dd
jmp 0x1482c
movl %r15d, %r12d
movslq %r12d, %rax
imulq $0x190, %rax, %rbx      # imm = 0x190
leaq 0x1f3e63(%rip), %r14    # 0x2086a0
leaq (%r14,%rbx), %rdi
callq 0xf4dd
leaq (%rbx,%r14), %rdi
addq $0x50, %rdi
callq 0xf4dd
leaq (%rbx,%r14), %rdi
addq $0xa0, %rdi
callq 0xf4dd
leaq (%rbx,%r14), %rdi
addq $0xf0, %rdi
callq 0xf4dd
leaq (%rbx,%r14), %rdi
addq $0x140, %rdi            # imm = 0x140
callq 0xf4dd
jmp 0x148a7
leaq 0x9ed4(%rip), %rsi      # 0x1e760
leaq 0xa005(%rip), %rdx      # 0x1e898
movl $0x1, %edi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1a227
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl %r12d, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9f84(%rip), %rsi      # 0x1e847
movq %rbx, %rdi
callq 0x83b0
movq %rax, %r14
callq 0x14464
testq %r14, %r14
movq 0x8(%rsp), %rbx
jne 0x145ca
leaq 0x9e78(%rip), %rsi      # 0x1e760
leaq 0x9f65(%rip), %rdx      # 0x1e854
xorl %r12d, %r12d
movl $0x4, %edi
movl %ebp, %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x1a227
jmp 0x1482c