// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl $0x1, -0x18(%rbp)
movl $0x0, -0x10(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
leaq 0xcf0d(%rip), %rsi      # 0x26833
callq 0x8390
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x19e8f
movq -0x20(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
leaq 0xcefb(%rip), %rsi      # 0x2684c
callq 0x8390
movq %rax, %rcx
movq %rcx, -0x30(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x19998
movq -0x28(%rbp), %rdi
leaq 0xcee2(%rip), %rsi      # 0x26851
callq 0x8390
movq %rax, %rcx
movq %rcx, -0x30(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x19996
movq -0x28(%rbp), %rdi
leaq 0xcece(%rip), %rsi      # 0x2685b
callq 0x8390
movq %rax, -0x30(%rbp)
jmp 0x19998
movl $0x0, -0x14(%rbp)
callq 0x19750
xorl %eax, %eax
cmpq -0x30(%rbp), %rax
je 0x19dd1
jmp 0x199b2
cmpl $0x0, -0x18(%rbp)
je 0x19a06
movslq -0x14(%rbp), %rcx
leaq 0x1f6cdd(%rip), %rax    # 0x2106a0
imulq $0x190, %rcx, %rcx      # imm = 0x190
addq %rcx, %rax
movq %rax, -0x140(%rbp)
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
leaq 0xd06c(%rip), %rdx      # 0x26a56
callq 0x122d0
movq -0x140(%rbp), %rdi
movq %rax, %rsi
movl $0x50, %edx
callq 0x19ec0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x19a5e
movslq -0x14(%rbp), %rcx
leaq 0x1f6c89(%rip), %rax    # 0x2106a0
imulq $0x190, %rcx, %rcx      # imm = 0x190
addq %rcx, %rax
addq $0x50, %rax
movq %rax, -0x148(%rbp)
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
leaq 0xd014(%rip), %rdx      # 0x26a56
callq 0x122d0
movq -0x148(%rbp), %rdi
movq %rax, %rsi
movl $0x50, %edx
callq 0x19ec0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x19ab8
movslq -0x14(%rbp), %rcx
leaq 0x1f6c31(%rip), %rax    # 0x2106a0
imulq $0x190, %rcx, %rcx      # imm = 0x190
addq %rcx, %rax
addq $0xa0, %rax
movq %rax, -0x150(%rbp)
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
leaq 0xcfba(%rip), %rdx      # 0x26a56
callq 0x122d0
movq -0x150(%rbp), %rdi
movq %rax, %rsi
movl $0x50, %edx
callq 0x19ec0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x19b12
movslq -0x14(%rbp), %rcx
leaq 0x1f6bd7(%rip), %rax    # 0x2106a0
imulq $0x190, %rcx, %rcx      # imm = 0x190
addq %rcx, %rax
addq $0xf0, %rax
movq %rax, -0x158(%rbp)
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
leaq 0xcf60(%rip), %rdx      # 0x26a56
callq 0x122d0
movq -0x158(%rbp), %rdi
movq %rax, %rsi
movl $0x50, %edx
callq 0x19ec0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x19b6c
movslq -0x14(%rbp), %rcx
leaq 0x1f6b7d(%rip), %rax    # 0x2106a0
imulq $0x190, %rcx, %rcx      # imm = 0x190
addq %rcx, %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x160(%rbp)
movq -0x28(%rbp), %rdi
movl -0x10(%rbp), %esi
movl %esi, %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
leaq 0xcf06(%rip), %rdx      # 0x26a56
callq 0x122d0
movq -0x160(%rbp), %rdi
movq %rax, %rsi
movl $0x50, %edx
callq 0x19ec0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
jne 0x19b77
jmp 0x19dcf
movslq -0x14(%rbp), %rax
leaq 0x1f6b1e(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
leaq 0xccb7(%rip), %rsi      # 0x26851
callq 0x8390
movq %rax, %rcx
movq %rcx, -0x138(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x19bfe
leaq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rsi
addq $0x9, %rsi
movl $0x20, %edx
callq 0x11bc0
movslq -0x14(%rbp), %rax
leaq 0x1f6ac9(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
leaq -0x130(%rbp), %rsi
movl $0x20, %edx
callq 0x11bc0
jmp 0x19d90
movslq -0x14(%rbp), %rax
leaq 0x1f6a97(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
leaq 0xcc3a(%rip), %rsi      # 0x2685b
callq 0x8390
movq %rax, %rcx
movq %rcx, -0x138(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x19c85
leaq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rsi
addq $0x4, %rsi
movl $0x42, %edx
callq 0x11bc0
movslq -0x14(%rbp), %rax
leaq 0x1f6a42(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
leaq -0x130(%rbp), %rsi
movl $0x42, %edx
callq 0x11bc0
jmp 0x19d8e
movslq -0x14(%rbp), %rax
leaq 0x1f6a10(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
leaq 0xcbb8(%rip), %rsi      # 0x26860
callq 0x8390
movq %rax, %rcx
movq %rcx, -0x138(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x19d0c
leaq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rsi
addq $0x7, %rsi
movl $0x11, %edx
callq 0x11bc0
movslq -0x14(%rbp), %rax
leaq 0x1f69bb(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
leaq -0x130(%rbp), %rsi
movl $0x11, %edx
callq 0x11bc0
jmp 0x19d8c
movslq -0x14(%rbp), %rax
leaq 0x1f6989(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
leaq 0xcb1d(%rip), %rsi      # 0x2684c
callq 0x8390
movq %rax, %rcx
movq %rcx, -0x138(%rbp)
xorl %eax, %eax
cmpq %rcx, %rax
je 0x19d8a
leaq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rsi
movl $0x20, %edx
callq 0x11bc0
movslq -0x14(%rbp), %rax
leaq 0x1f6938(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
leaq -0x130(%rbp), %rsi
movl $0x20, %edx
callq 0x11bc0
jmp 0x19d8c
jmp 0x19d8e
jmp 0x19d90
movslq -0x14(%rbp), %rax
leaq 0x1f6905(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
callq 0x190a0
cmpl $0x0, %eax
je 0x19dca
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
cmpl $0x80, %eax
jl 0x19dc8
jmp 0x19dcf
jmp 0x19dca
jmp 0x199b2
jmp 0x19df2
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %r8
movl $0x4, %edi
leaq 0xc990(%rip), %rsi      # 0x26774
leaq 0xca7d(%rip), %rdx      # 0x26868
movb $0x0, %al
callq 0x21bf0
movslq -0x14(%rbp), %rax
leaq 0x1f68a3(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
callq 0x122b0
movslq -0x14(%rbp), %rax
leaq 0x1f6889(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0x50, %rdi
callq 0x122b0
movslq -0x14(%rbp), %rax
leaq 0x1f686b(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xa0, %rdi
callq 0x122b0
movslq -0x14(%rbp), %rax
leaq 0x1f684a(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0xf0, %rdi
callq 0x122b0
movslq -0x14(%rbp), %rax
leaq 0x1f6829(%rip), %rdi    # 0x2106a0
imulq $0x190, %rax, %rax      # imm = 0x190
addq %rax, %rdi
addq $0x140, %rdi            # imm = 0x140
callq 0x122b0
jmp 0x19eac
movl -0xc(%rbp), %ecx
movl $0x1, %edi
leaq 0xc8d6(%rip), %rsi      # 0x26774
leaq 0xca07(%rip), %rdx      # 0x268ac
movb $0x0, %al
callq 0x21bf0
movl -0x14(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
nopl (%rax,%rax)