// File: /workspace/github_c_makefile_star2_O3/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 0xbba71(%rip), %rdi     # 0xcc2b8
leaq 0xd276(%rip), %rsi      # 0x1dac4
callq 0x8320
testq %rax, %rax
je 0x1089f
movq %rax, %rbx
callq 0x117c0
movq %rax, %r14
movslq 0xbc6de(%rip), %r15     # 0xccf48
callq 0x114ba
addq %r15, %rax
cmpq %rax, %r14
jae 0x108ce
movb $0x0, 0x4(%rsp)
movl $0x5d4b4f5b, (%rsp)     # imm = 0x5D4B4F5B
callq 0x1455b
cmpb $0x0, (%rax)
je 0x108f4
movq %rsp, %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xf384
jmp 0x108f4
leaq 0xd54a(%rip), %rsi      # 0x1ddf0
leaq 0xd54d(%rip), %rdx      # 0x1ddfa
leaq 0xbba04(%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 0x1a3e3
movups 0xd25b(%rip), %xmm0     # 0x1db30
movaps %xmm0, 0x10(%rsp)
movups 0xd23f(%rip), %xmm0     # 0x1db20
movaps %xmm0, (%rsp)
movabsq $0x203e746e6f662f, %rax # imm = 0x203E746E6F662F
movq %rax, 0x20(%rsp)
cmpl $0x0, 0xbc649(%rip)     # 0xccf44
je 0x10916
leaq 0xd1c3(%rip), %rdi      # 0x1dac7
movl $0x2c, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
cmpl $0x0, 0xbb997(%rip)     # 0xcc2b4
je 0x10938
leaq 0xd222(%rip), %rdi      # 0x1db48
movl $0x18, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
callq 0x13a47
cmpb $0x2a, (%rax)
jne 0x1094f
cmpb $0x0, 0x1(%rax)
jne 0x1094f
xorl %edi, %edi
callq 0x11870
leaq 0xd20b(%rip), %rsi      # 0x1db61
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbc1d6(%rip)     # 0xccb40
je 0x10984
leaq 0xd1f9(%rip), %rsi      # 0x1db6c
leaq 0xbc1c6(%rip), %rdx     # 0xccb40
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc5c1(%rip)     # 0xccf4c
je 0x109a6
callq 0x13a56
leaq 0xd1db(%rip), %rsi      # 0x1db74
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
callq 0x13a4c
movq %rax, %r14
callq 0x13a51
leaq 0xd1c7(%rip), %rsi      # 0x1db81
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
callq 0x13853
leaq 0xd1db(%rip), %rsi      # 0x1dbb1
movq %rsp, %rcx
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc570(%rip)     # 0xccf5c
je 0x10a09
xorl %edi, %edi
callq 0x13156
leaq 0xd1fa(%rip), %rsi      # 0x1dbf6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc548(%rip)     # 0xccf58
je 0x10a3e
callq 0x13052
movq %rax, %rdi
callq 0x13156
movq %rax, %r14
callq 0x1305a
leaq 0xd1f7(%rip), %rsi      # 0x1dc25
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc50f(%rip)     # 0xccf54
je 0x10a7e
callq 0x13052
movq %rax, %r14
callq 0x117c0
movq %r14, %rdi
movq %rax, %rsi
callq 0xf7a0
movq %rax, %r14
callq 0x1305a
leaq 0xd1eb(%rip), %rsi      # 0x1dc59
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbbcbb(%rip)     # 0xcc740
je 0x10a9f
leaq 0xd1ed(%rip), %rsi      # 0x1dc7b
leaq 0xbbcab(%rip), %rdx     # 0xcc740
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbbc1a(%rip)     # 0xcc6c0
je 0x10ae1
leaq 0xd1dd(%rip), %rdx      # 0x1dc8c
leaq 0xbbc0a(%rip), %rcx     # 0xcc6c0
leaq 0x100(%rsp), %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x8190
leaq 0xd1de(%rip), %rsi      # 0x1dcb2
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc478(%rip)     # 0xccf60
je 0x10b02
leaq 0xd1dd(%rip), %rsi      # 0x1dcce
leaq 0xbc478(%rip), %rdx     # 0xccf70
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbc45b(%rip)     # 0xccf64
je 0x10b23
leaq 0xd1de(%rip), %rsi      # 0x1dcf0
leaq 0xbc557(%rip), %rdx     # 0xcd070
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
leaq 0xac54(%rip), %rdi      # 0x1b77e
xorl %esi, %esi
callq 0x181e1
cmpq $0x3, %rax
je 0x10b5a
cmpq $0x2, %rax
je 0x10b4c
cmpq $0x1, %rax
jne 0x10b73
leaq 0xd1cd(%rip), %rdi      # 0x1dd17
jmp 0x10b53
leaq 0xd1f4(%rip), %rdi      # 0x1dd47
movl $0x2f, %esi
jmp 0x10b66
leaq 0xd216(%rip), %rdi      # 0x1dd77
movl $0x2e, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
leaq 0xd22c(%rip), %rdi      # 0x1dda6
movl $0x18, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x8390
cmpl $0x0, 0xbc3ad(%rip)     # 0xccf40
je 0x10c82
leaq 0xde92(%rip), %rsi      # 0x1ea32
movl $0x4, %edi
callq 0x13858
movq %rax, %rdi
callq 0x10752
leaq 0xbc6b7(%rip), %rsi     # 0xcd270
leaq 0x600(%rsp), %r14
movl $0x4000, %edx           # imm = 0x4000
movq %r14, %rdi
callq 0xf384
cmpb $0x0, (%r14)
je 0x10ca4
leaq 0x200(%rsp), %rdi
callq 0xf829
leaq 0xde46(%rip), %rdx      # 0x1ea32
leaq 0x600(%rsp), %rdi
xorl %esi, %esi
callq 0xf82d
testq %rax, %rax
je 0x10ca4
movq %rax, %r12
movl $0x1, %ebp
leaq 0x200(%rsp), %r14
leaq 0xde17(%rip), %r13      # 0x1ea32
leaq 0x600(%rsp), %r15
movq %r12, %rdi
callq 0x8120
cmpq $0x23, %rax
jb 0x10ca4
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %r12, %rsi
callq 0xf384
movq %r14, %rdi
callq 0x1065b
movq %rbx, %rdi
leaq 0xd18e(%rip), %rsi      # 0x1dde1
leaq 0xbc516(%rip), %rdx     # 0xcd170
xorl %eax, %eax
callq 0x8250
movq %r14, %rdi
callq 0xf829
movq %r15, %rdi
movl %ebp, %esi
movq %r13, %rdx
callq 0xf82d
movq %rax, %r12
incl %ebp
testq %rax, %rax
jne 0x10c23
jmp 0x10ca4
leaq 0xd154(%rip), %rsi      # 0x1dddd
xorl %edi, %edi
callq 0x13858
leaq 0xd128(%rip), %rsi      # 0x1ddbf
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
leaq 0xd13a(%rip), %rdi      # 0x1dde5
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