// File: /workspace/github_c_makefile_star2_O2/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 $0x138, %rsp            # imm = 0x138
movl %esi, %ebp
addq $0x20, %rdi
leaq 0x9e8b(%rip), %rsi      # 0x1d7ff
callq 0x83c0
testq %rax, %rax
je 0x13c31
movq %rax, %rbx
addq $0x50, %rbx
leaq 0x9e88(%rip), %rsi      # 0x1d818
movq %rbx, %rdi
callq 0x83c0
testq %rax, %rax
jne 0x139b5
leaq 0x9e79(%rip), %rsi      # 0x1d81d
movq %rbx, %rdi
callq 0x83c0
testq %rax, %rax
je 0x13c64
callq 0x13856
xorl %eax, %eax
leaq 0x1f4cdd(%rip), %rcx    # 0x2086a0
leaq 0xa058(%rip), %r14      # 0x1da22
xorl %r13d, %r13d
movq %rax, (%rsp)
movl %eax, %eax
imulq $0x190, %rax, %rax      # imm = 0x190
leaq (%rcx,%rax), %rdx
movq %rdx, 0x28(%rsp)
leaq (%rax,%rcx), %rdx
addq $0x50, %rdx
movq %rdx, 0x20(%rsp)
leaq 0xa0(%rax,%rcx), %rbp
leaq 0xf0(%rax,%rcx), %rdx
movq %rdx, 0x18(%rsp)
addq %rcx, %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, 0x10(%rsp)
movq %rbp, 0x8(%rsp)
movl %r13d, %r12d
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0xed9c
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x13ca9
testl %eax, %eax
je 0x13bd1
leal 0x1(%r12), %r13d
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0xed9c
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x13ca9
testl %eax, %eax
je 0x13bd1
incl %r13d
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0xed9c
movq %rbp, %rdi
movq %rax, %rsi
callq 0x13ca9
testl %eax, %eax
je 0x13bd1
incl %r13d
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0xed9c
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x13ca9
testl %eax, %eax
je 0x13bd1
incl %r13d
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0xed9c
movq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x13ca9
testl %eax, %eax
je 0x13bd1
movq %rbp, %rdi
leaq 0x9d3d(%rip), %rsi      # 0x1d81d
callq 0x83c0
testq %rax, %rax
je 0x13b16
addq $0x9, %rax
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
movq %rbx, %rbp
movq %r14, %rbx
pushq $0x20
popq %r14
movq %r14, %rdx
callq 0xe97a
movq %r14, %rdx
movq %rbx, %r14
movq %rbp, %rbx
jmp 0x13b6e
movq %rbp, %rdi
leaq 0x9d07(%rip), %rsi      # 0x1d827
callq 0x83c0
testq %rax, %rax
je 0x13b3d
addq $0x4, %rax
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
pushq $0x42
jmp 0x13b62
movq %rbp, %rdi
leaq 0x9ce5(%rip), %rsi      # 0x1d82c
callq 0x83c0
testq %rax, %rax
je 0x13b93
addq $0x7, %rax
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rax, %rsi
pushq $0x11
popq %rbp
movq %rbp, %rdx
callq 0xe97a
movq %rbp, %rdx
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0xe97a
movq %rbp, %rdi
callq 0x13480
incl %r13d
testl %eax, %eax
je 0x13a18
jmp 0x13bad
movq %rbp, %rdi
leaq 0x9c7b(%rip), %rsi      # 0x1d818
callq 0x83c0
testq %rax, %rax
jne 0x13aee
jmp 0x13b7e
addl $0x5, %r12d
movq (%rsp), %rax
leal 0x1(%rax), %r15d
movl %r12d, %r13d
cmpl $0x7e, %eax
movl %r15d, %eax
leaq 0x1f4ad7(%rip), %rcx    # 0x2086a0
jbe 0x139cd
jmp 0x13bd8
movq (%rsp), %rax
movl %eax, %r15d
movslq %r15d, %rax
imulq $0x190, %rax, %rbx      # imm = 0x190
leaq 0x1f4ab7(%rip), %r14    # 0x2086a0
leaq (%r14,%rbx), %rdi
callq 0xed98
leaq (%rbx,%r14), %rdi
addq $0x50, %rdi
callq 0xed98
leaq (%rbx,%r14), %rdi
addq $0xa0, %rdi
callq 0xed98
leaq (%rbx,%r14), %rdi
addq $0xf0, %rdi
callq 0xed98
leaq (%rbx,%r14), %rdi
addq $0x140, %rdi            # imm = 0x140
callq 0xed98
jmp 0x13c4f
leaq 0x9b08(%rip), %rsi      # 0x1d740
leaq 0x9c39(%rip), %rdx      # 0x1d878
pushq $0x1
popq %rdi
movl %ebp, %ecx
xorl %eax, %eax
callq 0x1920b
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9bbc(%rip), %rsi      # 0x1d827
movq %rbx, %rdi
callq 0x83c0
movq %rax, %r14
callq 0x13856
testq %r14, %r14
jne 0x139ba
leaq 0x9ab5(%rip), %rsi      # 0x1d740
leaq 0x9ba2(%rip), %rdx      # 0x1d834
xorl %r15d, %r15d
pushq $0x4
popq %rdi
movl %ebp, %ecx
movq %rbx, %r8
xorl %eax, %eax
callq 0x1920b
jmp 0x13bd8