// File: /workspace/github_c_makefile_star2_O2/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 0xbc5b5(%rip), %rdi     # 0xcc2b8
leaq 0xcdc2(%rip), %rsi      # 0x1cacc
callq 0x8330
testq %rax, %rax
je 0xfd5b
movq %rax, %rbx
callq 0x10b6a
movq %rax, %r14
movslq 0xbd222(%rip), %r15     # 0xccf48
callq 0x10874
addq %r15, %rax
cmpq %rax, %r14
jae 0xfd8a
movb $0x0, 0x4(%rsp)
movl $0x5d4b4f5b, (%rsp)     # imm = 0x5D4B4F5B
callq 0x13640
cmpb $0x0, (%rax)
je 0xfdb0
movq %rsp, %rdi
movl $0x100, %edx            # imm = 0x100
movq %rax, %rsi
callq 0xe97a
jmp 0xfdb0
leaq 0xd096(%rip), %rsi      # 0x1cdf8
leaq 0xd099(%rip), %rdx      # 0x1ce02
leaq 0xbc548(%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 0x1920b
movups 0xcda7(%rip), %xmm0     # 0x1cb38
movaps %xmm0, 0x10(%rsp)
movups 0xcd8b(%rip), %xmm0     # 0x1cb28
movaps %xmm0, (%rsp)
movabsq $0x203e746e6f662f, %rax # imm = 0x203E746E6F662F
movq %rax, 0x20(%rsp)
cmpl $0x0, 0xbd18d(%rip)     # 0xccf44
je 0xfdce
leaq 0xcd0f(%rip), %rdi      # 0x1cacf
pushq $0x2c
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x83a0
cmpl $0x0, 0xbc4df(%rip)     # 0xcc2b4
je 0xfdec
leaq 0xcd72(%rip), %rdi      # 0x1cb50
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x83a0
callq 0x12ca6
cmpb $0x2a, (%rax)
jne 0xfe03
cmpb $0x0, 0x1(%rax)
jne 0xfe03
xorl %edi, %edi
callq 0x10c16
leaq 0xcd5f(%rip), %rsi      # 0x1cb69
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbcd22(%rip)     # 0xccb40
je 0xfe38
leaq 0xcd4d(%rip), %rsi      # 0x1cb74
leaq 0xbcd12(%rip), %rdx     # 0xccb40
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbd10d(%rip)     # 0xccf4c
je 0xfe5a
callq 0x12cb5
leaq 0xcd2f(%rip), %rsi      # 0x1cb7c
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
callq 0x12cab
movq %rax, %r14
callq 0x12cb0
leaq 0xcd1b(%rip), %rsi      # 0x1cb89
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
callq 0x12ab4
leaq 0xcd2f(%rip), %rsi      # 0x1cbb9
movq %rsp, %rcx
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbd0bc(%rip)     # 0xccf5c
je 0xfebd
xorl %edi, %edi
callq 0x123cf
leaq 0xcd4e(%rip), %rsi      # 0x1cbfe
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbd094(%rip)     # 0xccf58
je 0xfef2
callq 0x122f4
movq %rax, %rdi
callq 0x123cf
movq %rax, %r14
callq 0x122fc
leaq 0xcd4b(%rip), %rsi      # 0x1cc2d
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbd05b(%rip)     # 0xccf54
je 0xff32
callq 0x122f4
movq %rax, %r14
callq 0x10b6a
movq %r14, %rdi
movq %rax, %rsi
callq 0xed2c
movq %rax, %r14
callq 0x122fc
leaq 0xcd3f(%rip), %rsi      # 0x1cc61
movq %rbx, %rdi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbc807(%rip)     # 0xcc740
je 0xff53
leaq 0xcd41(%rip), %rsi      # 0x1cc83
leaq 0xbc7f7(%rip), %rdx     # 0xcc740
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpb $0x0, 0xbc766(%rip)     # 0xcc6c0
je 0xff95
leaq 0xcd31(%rip), %rdx      # 0x1cc94
leaq 0xbc756(%rip), %rcx     # 0xcc6c0
leaq 0x100(%rsp), %r14
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x8190
leaq 0xcd32(%rip), %rsi      # 0x1ccba
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbcfc4(%rip)     # 0xccf60
je 0xffb6
leaq 0xcd31(%rip), %rsi      # 0x1ccd6
leaq 0xbcfc4(%rip), %rdx     # 0xccf70
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
cmpl $0x0, 0xbcfa7(%rip)     # 0xccf64
je 0xffd7
leaq 0xcd32(%rip), %rsi      # 0x1ccf8
leaq 0xbd0a3(%rip), %rdx     # 0xcd070
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8250
leaq 0xa7a0(%rip), %rdi      # 0x1a77e
xorl %esi, %esi
callq 0x17172
cmpq $0x3, %rax
je 0x1000b
cmpq $0x2, %rax
je 0x10000
cmpq $0x1, %rax
jne 0x10020
leaq 0xcd21(%rip), %rdi      # 0x1cd1f
jmp 0x10007
leaq 0xcd48(%rip), %rdi      # 0x1cd4f
pushq $0x2f
jmp 0x10014
leaq 0xcd6d(%rip), %rdi      # 0x1cd7f
pushq $0x2e
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x83a0
leaq 0xcd87(%rip), %rdi      # 0x1cdae
pushq $0x18
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x83a0
cmpl $0x0, 0xbcf04(%rip)     # 0xccf40
je 0x100fa
leaq 0xd9d9(%rip), %rsi      # 0x1da22
pushq $0x4
popq %rdi
callq 0x12ab9
movq %rax, %rdi
callq 0xfc2e
leaq 0xbd210(%rip), %rsi     # 0xcd270
leaq 0x600(%rsp), %r14
movl $0x4000, %edx           # imm = 0x4000
movq %r14, %rdi
callq 0xe97a
cmpb $0x0, (%r14)
je 0x1011c
leaq 0x200(%rsp), %r14
leaq 0xd994(%rip), %r15      # 0x1da22
leaq 0x600(%rsp), %r12
xorl %r13d, %r13d
movq %r14, %rdi
callq 0xed98
movq %r12, %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0xed9c
testq %rax, %rax
je 0x1011c
movq %rax, %rbp
movq %rax, %rdi
callq 0x8120
cmpq $0x23, %rax
jb 0x1011c
movl $0x400, %edx            # imm = 0x400
movq %r14, %rdi
movq %rbp, %rsi
callq 0xe97a
movq %r14, %rdi
callq 0xfb3f
movq %rbx, %rdi
leaq 0xcd02(%rip), %rsi      # 0x1cde9
leaq 0xbd082(%rip), %rdx     # 0xcd170
xorl %eax, %eax
callq 0x8250
incl %r13d
jmp 0x10099
leaq 0xcce4(%rip), %rsi      # 0x1cde5
xorl %edi, %edi
callq 0x12ab9
leaq 0xccb8(%rip), %rsi      # 0x1cdc7
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
leaq 0xccca(%rip), %rdi      # 0x1cded
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x83a0
movq %rbx, %rdi
callq 0x8100
addq $0x4608, %rsp           # imm = 0x4608
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq