// File: /workspace/github_c_makefile_star2_O1/schroeder-lvb[P]sissm/src/piwebgen.c
// Function: genWebFile
static int _genWebFile( void )
{
    FILE *fpw;
    char *w;
    int   errCode = 1;
    int   i;
    char  *printWordOut, *rosterElem, rosterElem2[1024];
    char  rosterWork[PIWEBGEN_MAXROSTER];
    char  hyperLinkCode[256];
    char  timeoutStatus[256];
    char  *srvName;

    if (NULL != (fpw = fopen( piwebgenConfig.webFileName, "wt" ))) {

        if ( apiTimeGet() < (piwebgenConfig.commTimeoutSec + apiGetLastRosterTime()) )   {
            strlcpy( timeoutStatus, "[OK]", 256 );
            w = rosterGetObjective();
            if ( 0 != strlen( w ) ) strlcpy( timeoutStatus, w, 256 );
        }
        else
            strlcpy( timeoutStatus, "<font color=\"red\">[SERVER DOWN]</font> ", 256 );

        // Option for creating auto-refresh header for html.  Turn this off if you are refreshing
        // from higher level (e.g., text file inclusion or html frames).
        //
	if ( 0 != piwebgenConfig.autoRefreshHeader ) {
            fprintf( fpw, "<meta http-equiv=\"refresh\" content=\"14\" /> \n" );
        }

        // Option for UTF-8 encoding extended character sets
        //
	if ( 0 != piwebgenConfig.utf8Encoding ) {
            fprintf( fpw, "<meta charset=\"utf-8\"> \n" );
        }

        // Displaying the server name - from sissm.cfg file, or RCON
        //
        srvName = apiGetServerName();
        if ( 0 == strncmp( srvName, "*", 2 ) ) 
            srvName = apiGetServerNameRCON( 0 );
        fprintf( fpw, "<b>%s</b>\n", srvName );

        // Option for displaying extra line description
        //
        if ( 0 != strlen( piwebgenConfig.line2 ) )
            fprintf( fpw, "<br>%s\n", piwebgenConfig.line2 );

        // Option for displaying current sessino ID for playbacks
        //
        if ( piwebgenConfig.showSessionID )
            fprintf( fpw, "<br>SID: %s\n", apiGetSessionID());

        // Display map & lighting mode
        //
        fprintf( fpw, "<br>Map: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp %s (%s)\n", apiGetMapName(), apiGetLighting() );

        // Display number of players and stauts of the server
        //
        fprintf( fpw, "<br>Players: &nbsp; %d  &nbsp;&nbsp;&nbsp; Status: &nbsp;&nbsp;  %s\n", 
            apiPlayersGetCount(), timeoutStatus);

        // Option for displaying "current time" 
        //
        if ( piwebgenConfig.showCurrentTime ) {
            fprintf( fpw, "<br>Time: &nbsp;&nbsp;&nbsp;&nbsp;   %s [Now]\n", apiTimeGetHuman(0L) );
        }
 
        // Option for displaying "last reboot event & last reboot time"
        //
        if ( piwebgenConfig.showLastReboot ) {
            fprintf( fpw, "<br>Last: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   %s [%s]\n", 
                apiTimeGetHuman( apiGetLastRebootTime()), apiGetLastRebootReason() );
        }

        // Option for displaying "last reboot event & elapsed time since reboot"
        //
        if ( piwebgenConfig.showUpTime ) {
            fprintf( fpw, "<br>Uptime: &nbsp; %s since [%s]\n", 
                computeElapsedTime( apiGetLastRebootTime(), apiTimeGet()), apiGetLastRebootReason() );
        }

        // Option for displaying direct IP connection method from game client
        //
        if ( 0 != strlen( piwebgenConfig.directConnect ) )
            fprintf( fpw, "<br>Connect: %s\n", piwebgenConfig.directConnect );

        // Option for displaying hyperlink to web-based admin page
        //
        if ( 0 != strlen( piwebgenConfig.webminURL ) )  {
            snprintf( hyperLinkCode, 256, "<a href=\"%s\" target=\"_blank\">link</a>", 
                piwebgenConfig.webminURL );
            fprintf( fpw, "<br>Admin: &nbsp;&nbsp; %s\n", hyperLinkCode );
        }

        if ( 0 != piwebgenConfig.showGameMode ) {
            fprintf( fpw, "<br>Game Mode: &nbsp;&nbsp;   %s\n", gameMode );
        }

        if ( 0 != piwebgenConfig.showMutators ) {
            fprintf( fpw, "<br>Mutators: &nbsp;&nbsp;&nbsp;   %s\n", gameMutators );
        }

        switch( p2pGetL( "pigateway.p2p.lockOut", 0L )) {
        case 1L:
            fprintf( fpw, "<br>* Temporarily LOCKED for Private Session *\n" );
            break;
        case 2L:
            fprintf( fpw, "<br>*** Server LOCKED for Private Sessions ***\n" );
            break;
        case 3L:
            fprintf( fpw, "<br>*** Server RESERVED for Private Group ***\n" );
            break;
        }

        // Display list of players
        //
        fprintf( fpw, "<br>Names: &nbsp;&nbsp; ");
	if ( 0 == piwebgenConfig.hyperlinkFormat ) {
            fprintf( fpw, "<font color=\"blue\">%s</font> ", apiPlayersRoster( 0, " : " ) );
	}
	else {
            // get roster with tab for delimiter
	    strlcpy( rosterWork,  _htmlSafeFilter( apiPlayersRoster( 4, "\011" )), PIWEBGEN_MAXROSTER);  
	    if (  0 != strlen( rosterWork )) {                   // if not an empty list then
 	        for ( i=0 ;; i++ ) {

		    // walk through each player
		    //
                    strclr( rosterElem2 );
		    rosterElem = getWord( rosterWork, i, "\011" );  
		    if (NULL == rosterElem)        break;    // end of list?
		    if (strlen( rosterElem) < 35 ) break;    // element is invalid if <35 chars

                    strlcpy( rosterElem2, rosterElem, 1024 );

		    // convert each player record to hyperlink html format
		    //
                    printWordOut = _convertNameToHyperlink( rosterElem2 );

		    // write out this player info  to the html file
		    //
                    fprintf( fpw, "%s ", printWordOut );
                }
	    }
	}
        fprintf( fpw, "\n<br><br>\n");
        fclose( fpw );
        errCode = 0;
    }
    else {
        logPrintf( LOG_LEVEL_CRITICAL,
            "piwebstat", "Unable to create the html output file ::%s::",
            piwebgenConfig.webFileName );
    }
    return errCode;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4608, %rsp           # imm = 0x4608
leaq 0xbbdab(%rip), %rdi     # 0xcc2b8
leaq 0xd5d8(%rip), %rsi      # 0x1daec
callq 0x8320
testq %rax, %rax
je 0x10565
movq %rax, %rbx
callq 0x114b2
movq %rax, %r14
movslq 0xbca18(%rip), %r15     # 0xccf48
callq 0x111ac
addq %r15, %rax
cmpq %rax, %r14
jae 0x10594
movb $0x0, 0x4(%rsp)
movl $0x5d4b4f5b, (%rsp)     # imm = 0x5D4B4F5B
callq 0x1423e
cmpb $0x0, (%rax)
je 0x105ba
movq %rsp, %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf038
jmp 0x105ba
leaq 0xd8ac(%rip), %rsi      # 0x1de18
leaq 0xd8af(%rip), %rdx      # 0x1de22
leaq 0xbbd3e(%rip), %rcx     # 0xcc2b8
xorl %edi, %edi
xorl %eax, %eax
addq $0x4608, %rsp           # imm = 0x4608
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1a227
movups 0xd5bd(%rip), %xmm0     # 0x1db58
movaps %xmm0, 0x10(%rsp)
movups 0xd5a1(%rip), %xmm0     # 0x1db48
movaps %xmm0, (%rsp)
movabsq $0x203e746e6f662f, %rax # imm = 0x203E746E6F662F
movq %rax, 0x20(%rsp)
cmpl $0x0, 0xbc983(%rip)     # 0xccf44
je 0x105dc
leaq 0xd525(%rip), %rdi      # 0x1daef
movl $0x2c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
cmpl $0x0, 0xbbcd1(%rip)     # 0xcc2b4
je 0x105fe
leaq 0xd584(%rip), %rdi      # 0x1db70
movl $0x18, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
callq 0x136ce
movq %rax, %r14
leaq 0xb5ef(%rip), %rsi      # 0x1bbfc
movl $0x2, %edx
movq %rax, %rdi
callq 0x8080
testl %eax, %eax
jne 0x10628
xorl %edi, %edi
callq 0x11562
movq %rax, %r14
leaq 0xd55a(%rip), %rsi      # 0x1db89
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbc4fd(%rip)     # 0xccb40
je 0x1065d
leaq 0xd548(%rip), %rsi      # 0x1db94
leaq 0xbc4ed(%rip), %rdx     # 0xccb40
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc8e8(%rip)     # 0xccf4c
je 0x1067f
callq 0x136dd
leaq 0xd52a(%rip), %rsi      # 0x1db9c
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
callq 0x136d3
movq %rax, %r14
callq 0x136d8
leaq 0xd516(%rip), %rsi      # 0x1dba9
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
callq 0x134dc
leaq 0xd52a(%rip), %rsi      # 0x1dbd9
movq %rsp, %rcx
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc897(%rip)     # 0xccf5c
je 0x106e2
xorl %edi, %edi
callq 0x12dd9
leaq 0xd549(%rip), %rsi      # 0x1dc1e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc86f(%rip)     # 0xccf58
je 0x10717
callq 0x12cd5
movq %rax, %rdi
callq 0x12dd9
movq %rax, %r14
callq 0x12cdd
leaq 0xd546(%rip), %rsi      # 0x1dc4d
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc836(%rip)     # 0xccf54
je 0x10757
callq 0x12cd5
movq %rax, %r14
callq 0x114b2
movq %r14, %rdi
movq %rax, %rsi
callq 0xf454
movq %rax, %r14
callq 0x12cdd
leaq 0xd53a(%rip), %rsi      # 0x1dc81
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbbfe2(%rip)     # 0xcc740
je 0x10778
leaq 0xd53c(%rip), %rsi      # 0x1dca3
leaq 0xbbfd2(%rip), %rdx     # 0xcc740
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbbf41(%rip)     # 0xcc6c0
je 0x107ba
leaq 0xd52c(%rip), %rdx      # 0x1dcb4
leaq 0xbbf31(%rip), %rcx     # 0xcc6c0
leaq 0x100(%rsp), %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x8190
leaq 0xd52d(%rip), %rsi      # 0x1dcda
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc79f(%rip)     # 0xccf60
je 0x107db
leaq 0xd52c(%rip), %rsi      # 0x1dcf6
leaq 0xbc79f(%rip), %rdx     # 0xccf70
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc782(%rip)     # 0xccf64
je 0x107fc
leaq 0xd52d(%rip), %rsi      # 0x1dd18
leaq 0xbc87e(%rip), %rdx     # 0xcd070
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
leaq 0xaf83(%rip), %rdi      # 0x1b786
xorl %esi, %esi
callq 0x18004
cmpq $0x3, %rax
je 0x10833
cmpq $0x2, %rax
je 0x10825
cmpq $0x1, %rax
jne 0x1084c
leaq 0xd51c(%rip), %rdi      # 0x1dd3f
jmp 0x1082c
leaq 0xd543(%rip), %rdi      # 0x1dd6f
movl $0x2f, %esi
jmp 0x1083f
leaq 0xd565(%rip), %rdi      # 0x1dd9f
movl $0x2e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
leaq 0xd57b(%rip), %rdi      # 0x1ddce
movl $0x18, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
cmpl $0x0, 0xbc6d4(%rip)     # 0xccf40
je 0x1095b
leaq 0xe1c9(%rip), %rsi      # 0x1ea42
movl $0x4, %edi
callq 0x134e1
movq %rax, %rdi
callq 0x10418
leaq 0xbc9de(%rip), %rsi     # 0xcd270
leaq 0x600(%rsp), %r14
movl $0x4000, %edx           # imm = 0x4000
movq %r14, %rdi
callq 0xf038
cmpb $0x0, (%r14)
je 0x1097d
leaq 0x200(%rsp), %rdi
callq 0xf4dd
leaq 0xe17d(%rip), %rdx      # 0x1ea42
leaq 0x600(%rsp), %rdi
xorl %esi, %esi
callq 0xf4e1
testq %rax, %rax
je 0x1097d
movq %rax, %r12
movl $0x1, %ebp
leaq 0x200(%rsp), %r14
leaq 0xe14e(%rip), %r13      # 0x1ea42
leaq 0x600(%rsp), %r15
movq %r12, %rdi
callq 0x8120
cmpq $0x23, %rax
jb 0x1097d
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %r12, %rsi
callq 0xf038
movq %r14, %rdi
callq 0x10317
movq %rbx, %rdi
leaq 0xd4dd(%rip), %rsi      # 0x1de09
leaq 0xbc83d(%rip), %rdx     # 0xcd170
xorl %eax, %eax
callq 0x8250
movq %r14, %rdi
callq 0xf4dd
movq %r15, %rdi
movl %ebp, %esi
movq %r13, %rdx
callq 0xf4e1
movq %rax, %r12
incl %ebp
testq %rax, %rax
jne 0x108fc
jmp 0x1097d
leaq 0xd4a3(%rip), %rsi      # 0x1de05
xorl %edi, %edi
callq 0x134e1
leaq 0xd477(%rip), %rsi      # 0x1dde7
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
leaq 0xd489(%rip), %rdi      # 0x1de0d
movl $0xa, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
movq %rbx, %rdi
callq 0x8100
addq $0x4608, %rsp           # imm = 0x4608
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq