mirror of
https://github.com/UOX3DevTeam/UOX3
synced 2026-08-13 12:27:04 -04:00
792 lines
23 KiB
C++
792 lines
23 KiB
C++
|
|
// cHTMLSystem.cpp: Implementierung der Klasse cHTMLSystem.
|
||
|
|
//
|
||
|
|
//////////////////////////////////////////////////////////////////////
|
||
|
|
|
||
|
|
#include "cHTMLSystem.h"
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////////////////////////
|
||
|
|
// Konstruktion/Destruktion
|
||
|
|
//////////////////////////////////////////////////////////////////////
|
||
|
|
|
||
|
|
cHTMLTemplate::cHTMLTemplate()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
cHTMLTemplate::~cHTMLTemplate()
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplate::Process
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Parses a template
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplate::Process( void )
|
||
|
|
{
|
||
|
|
|
||
|
|
// Only read the Status Page if it's not already loaded
|
||
|
|
if( !Loaded )
|
||
|
|
LoadTemplate();
|
||
|
|
|
||
|
|
// Parse the Content...
|
||
|
|
string ParsedContent = Content;
|
||
|
|
|
||
|
|
//***************************************/
|
||
|
|
// Replacing Placeholders
|
||
|
|
//***************************************/
|
||
|
|
|
||
|
|
int Pos;
|
||
|
|
|
||
|
|
// Account-Count
|
||
|
|
char AccountCount[32];
|
||
|
|
sprintf( AccountCount, "%d", Accounts->GetAccountCount() );
|
||
|
|
for( Pos = ParsedContent.find("%accounts"); Pos >= 0; Pos = ParsedContent.find( "%accounts" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 9, AccountCount );
|
||
|
|
}
|
||
|
|
|
||
|
|
// Version
|
||
|
|
string Version = VER;
|
||
|
|
#ifdef __NT__
|
||
|
|
Version += " [WIN32]";
|
||
|
|
#else
|
||
|
|
Version += " [LINUX]";
|
||
|
|
#endif
|
||
|
|
|
||
|
|
for( Pos = ParsedContent.find( "%version" ); Pos >= 0; Pos = ParsedContent.find( "%version" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 8, Version );
|
||
|
|
}
|
||
|
|
|
||
|
|
// Character Count
|
||
|
|
char CharacterCount[32];
|
||
|
|
sprintf( CharacterCount, "%d", chars.Count() );
|
||
|
|
for( Pos = ParsedContent.find( "%charcount" ); Pos >= 0; Pos = ParsedContent.find( "%charcount" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 10, CharacterCount );
|
||
|
|
}
|
||
|
|
|
||
|
|
// Item Count
|
||
|
|
char ItemCount[32];
|
||
|
|
sprintf( ItemCount, "%d", items.Count() );
|
||
|
|
for( Pos = ParsedContent.find("%itemcount"); Pos >= 0; Pos = ParsedContent.find( "%itemcount" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 10, ItemCount );
|
||
|
|
}
|
||
|
|
|
||
|
|
// Connection Count (GMs, Counselors, Player)
|
||
|
|
UI32 gm = 0, cns = 0, ccount = 0;
|
||
|
|
|
||
|
|
// Get all Network Connections
|
||
|
|
Network->PushConn();
|
||
|
|
cSocket *tSock = NULL;
|
||
|
|
for( tSock = Network->FirstSocket(); !Network->FinishedSockets(); tSock = Network->NextSocket() )
|
||
|
|
{
|
||
|
|
CChar *tChar = tSock->CurrcharObj();
|
||
|
|
if( tChar == NULL )
|
||
|
|
continue;
|
||
|
|
|
||
|
|
if( tChar->IsGM() )
|
||
|
|
gm++;
|
||
|
|
else if( tChar->IsCounselor() )
|
||
|
|
cns++;
|
||
|
|
else
|
||
|
|
ccount++;
|
||
|
|
}
|
||
|
|
Network->PopConn();
|
||
|
|
|
||
|
|
// GMs
|
||
|
|
char GMCount[32];
|
||
|
|
sprintf( GMCount, "%d", gm );
|
||
|
|
for( Pos = ParsedContent.find( "%online_gms" ); Pos >= 0; Pos = ParsedContent.find( "%online_gms" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 11, GMCount );
|
||
|
|
}
|
||
|
|
|
||
|
|
// Counselor
|
||
|
|
char CounsiCount[32];
|
||
|
|
sprintf( CounsiCount, "%d", cns );
|
||
|
|
for( Pos = ParsedContent.find( "%online_couns" ); Pos >= 0; Pos = ParsedContent.find( "%online_couns" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 13, CounsiCount );
|
||
|
|
}
|
||
|
|
|
||
|
|
// Player
|
||
|
|
char PlayerCount[32];
|
||
|
|
sprintf( PlayerCount, "%d", ccount );
|
||
|
|
for( Pos = ParsedContent.find( "%online_player" ); Pos >= 0; Pos = ParsedContent.find( "%online_player" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 14, PlayerCount );
|
||
|
|
}
|
||
|
|
|
||
|
|
// Total
|
||
|
|
char AllCount[32];
|
||
|
|
sprintf( AllCount, "%d", (ccount + gm + cns) );
|
||
|
|
for( Pos = ParsedContent.find( "%online_all" ); Pos >= 0; Pos = ParsedContent.find( "%online_all" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 11, AllCount );
|
||
|
|
}
|
||
|
|
|
||
|
|
//RealTime( time_str )
|
||
|
|
char time_str[80];
|
||
|
|
RealTime( time_str );
|
||
|
|
for( Pos = ParsedContent.find( "%time" ); Pos >= 0; Pos = ParsedContent.find( "%time" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 5, time_str );
|
||
|
|
}
|
||
|
|
|
||
|
|
// IP(s) + PORT(s)
|
||
|
|
UI16 ServerCount = (UI16)cwmWorldState->ServerData()->GetServerCount();
|
||
|
|
if( ServerCount > 0 )
|
||
|
|
{
|
||
|
|
for( UI16 i = 0; i < ServerCount; i++ )
|
||
|
|
{
|
||
|
|
physicalServer *mServ = cwmWorldState->ServerData()->GetServerEntry( i );
|
||
|
|
char ipToken[8]; // i think we'll never get higher than 2 digits, anyway...
|
||
|
|
sprintf( ipToken, "%%ip%i", i+1 );
|
||
|
|
|
||
|
|
if( mServ != NULL )
|
||
|
|
{
|
||
|
|
for( Pos = ParsedContent.find( ipToken ); Pos >= 0; Pos = ParsedContent.find( ipToken ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, strlen(ipToken), mServ->ip.c_str() );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
char portToken[10]; // i think we'll never get higher than 2 digits, anyway...
|
||
|
|
sprintf( portToken, "%%port%i", i+1 );
|
||
|
|
|
||
|
|
if( mServ != NULL )
|
||
|
|
{
|
||
|
|
for( Pos = ParsedContent.find( portToken ); Pos >= 0; Pos = ParsedContent.find( portToken ) )
|
||
|
|
{
|
||
|
|
char myPort[5];
|
||
|
|
sprintf( myPort, "%i", mServ->port );
|
||
|
|
ParsedContent.replace( Pos, strlen( portToken ), myPort );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
char serverToken[10]; // i think we'll never get higher than 2 digits, anyway...
|
||
|
|
sprintf( serverToken, "%%server%i", i+1 );
|
||
|
|
|
||
|
|
if( mServ != NULL )
|
||
|
|
{
|
||
|
|
for( Pos = ParsedContent.find( serverToken ); Pos >= 0; Pos = ParsedContent.find( serverToken ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, strlen( serverToken ), mServ->name.c_str() );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
// PLAYERLIST
|
||
|
|
for( Pos = ParsedContent.find( "%playerlist%" ); Pos >= 0; Pos = ParsedContent.find( "%playerlist%" ) )
|
||
|
|
{
|
||
|
|
UI32 SecondPos = ParsedContent.find( "%playerlist%", Pos+1 );
|
||
|
|
string myInline = ParsedContent.substr( Pos, SecondPos - Pos + 12 );
|
||
|
|
string PlayerList;
|
||
|
|
|
||
|
|
Network->PushConn();
|
||
|
|
for( tSock = Network->FirstSocket(); !Network->FinishedSockets(); tSock = Network->NextSocket() )
|
||
|
|
{
|
||
|
|
if( tSock != NULL )
|
||
|
|
{
|
||
|
|
CChar *tChar = tSock->CurrcharObj();
|
||
|
|
if( tChar != NULL )
|
||
|
|
{
|
||
|
|
string parsedInline = myInline;
|
||
|
|
parsedInline.replace( 0, 12, "" );
|
||
|
|
parsedInline.replace( parsedInline.length()-12, 12, "" );
|
||
|
|
|
||
|
|
// Tokens for the PlayerList
|
||
|
|
// %playername
|
||
|
|
// %playertitle
|
||
|
|
// %playerip
|
||
|
|
// %playeraccount
|
||
|
|
// %playerx
|
||
|
|
// %playery
|
||
|
|
// %playerz
|
||
|
|
// %playerrace
|
||
|
|
// %playerregion
|
||
|
|
|
||
|
|
// PlayerName
|
||
|
|
SI32 sPos;
|
||
|
|
for( sPos = parsedInline.find( "%playername" ); sPos >= 0; sPos = parsedInline.find( "%playername" ) )
|
||
|
|
{
|
||
|
|
parsedInline.replace( sPos, 11, tChar->GetName() );
|
||
|
|
}
|
||
|
|
|
||
|
|
// PlayerTitle
|
||
|
|
for( sPos = parsedInline.find( "%playertitle" ); sPos >= 0; sPos = parsedInline.find( "%playertitle" ) )
|
||
|
|
{
|
||
|
|
parsedInline.replace( sPos, 12, tChar->GetTitle() );
|
||
|
|
}
|
||
|
|
|
||
|
|
// PlayerIP
|
||
|
|
for( sPos = parsedInline.find( "%playerip" ); sPos >= 0; sPos = parsedInline.find( "%playerip" ) )
|
||
|
|
{
|
||
|
|
cSocket *mySock = calcSocketObjFromChar( tChar );
|
||
|
|
char ClientIP[32];
|
||
|
|
sprintf( ClientIP, "%i.%i.%i.%i", mySock->ClientIP4(), mySock->ClientIP3(), mySock->ClientIP3(), mySock->ClientIP1() );
|
||
|
|
parsedInline.replace( sPos, 9, ClientIP );
|
||
|
|
}
|
||
|
|
|
||
|
|
// PlayerAccount
|
||
|
|
for( sPos = parsedInline.find( "%playeraccount" ); sPos >= 0; sPos = parsedInline.find( "%playeraccount" ) )
|
||
|
|
{
|
||
|
|
ACTREC *toScan = tChar->GetAccountObj();
|
||
|
|
if( toScan != NULL )
|
||
|
|
parsedInline.replace( sPos, 14, toScan->lpaarHolding->Info.username );
|
||
|
|
}
|
||
|
|
|
||
|
|
// PlayerX
|
||
|
|
for( sPos = parsedInline.find( "%playerx" ); sPos >= 0; sPos = parsedInline.find( "%playerx" ) )
|
||
|
|
{
|
||
|
|
char myX[5];
|
||
|
|
sprintf( myX, "%i", tChar->GetX() );
|
||
|
|
parsedInline.replace( sPos, 8, myX );
|
||
|
|
}
|
||
|
|
|
||
|
|
// PlayerY
|
||
|
|
for( sPos = parsedInline.find( "%playery" ); sPos >= 0; sPos = parsedInline.find( "%playery" ) )
|
||
|
|
{
|
||
|
|
char myY[5];
|
||
|
|
sprintf( myY, "%i", tChar->GetY() );
|
||
|
|
parsedInline.replace( sPos, 8, myY );
|
||
|
|
}
|
||
|
|
|
||
|
|
// PlayerZ
|
||
|
|
for( sPos = parsedInline.find( "%playerz" ); sPos >= 0; sPos = parsedInline.find( "%playerz" ) )
|
||
|
|
{
|
||
|
|
char myZ[3];
|
||
|
|
sprintf( myZ, "%i", tChar->GetZ() );
|
||
|
|
parsedInline.replace( sPos, 8, myZ );
|
||
|
|
}
|
||
|
|
|
||
|
|
// PlayerRace -- needs testing
|
||
|
|
for( sPos = parsedInline.find( "%playerrace" ); sPos >= 0; sPos = parsedInline.find( "%playerrace" ) )
|
||
|
|
{
|
||
|
|
RACEID myRace = tChar->GetRace();
|
||
|
|
const char *rName = Races->Name( myRace );
|
||
|
|
UI32 raceLenName = strlen( rName );
|
||
|
|
char *myRaceName = new char[ raceLenName + 1 ];
|
||
|
|
strcpy( myRaceName, rName );
|
||
|
|
|
||
|
|
if( myRaceName != NULL )
|
||
|
|
parsedInline.replace( sPos, 11, myRaceName );
|
||
|
|
delete [] myRaceName;
|
||
|
|
}
|
||
|
|
|
||
|
|
// PlayerRegion
|
||
|
|
for( sPos = parsedInline.find( "%playerregion" ); sPos >= 0; sPos = parsedInline.find( "%playerregion" ) )
|
||
|
|
{
|
||
|
|
parsedInline.replace( sPos, 13, region[tChar->GetRegion()]->GetName() );
|
||
|
|
}
|
||
|
|
|
||
|
|
PlayerList += parsedInline;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
Network->PopConn();
|
||
|
|
|
||
|
|
ParsedContent.replace( Pos, myInline.length(), PlayerList );
|
||
|
|
}
|
||
|
|
|
||
|
|
// GuildCount
|
||
|
|
char GuildCount[32];
|
||
|
|
sprintf( GuildCount, "%d", GuildSys->NumGuilds() );
|
||
|
|
for( Pos = ParsedContent.find( "%guildcount" ); Pos >= 0; Pos = ParsedContent.find( "%guildcount" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 11, PlayerCount );
|
||
|
|
}
|
||
|
|
|
||
|
|
// GUILDLIST
|
||
|
|
for( Pos = ParsedContent.find( "%guildlist%" ); Pos >= 0; Pos = ParsedContent.find( "%guildlist%" ) )
|
||
|
|
{
|
||
|
|
UI32 SecondPos = ParsedContent.find( "%guildlist%", Pos+1 );
|
||
|
|
string myInline = ParsedContent.substr( Pos, SecondPos - Pos + 11 );
|
||
|
|
string GuildList;
|
||
|
|
|
||
|
|
|
||
|
|
for( SI16 i = 0; i < (SI16)GuildSys->NumGuilds(); i++ )
|
||
|
|
{
|
||
|
|
string parsedInline = myInline;
|
||
|
|
parsedInline.replace( 0, 11, "" );
|
||
|
|
parsedInline.replace( parsedInline.length()-11, 11, "" );
|
||
|
|
|
||
|
|
parsedInline += "Yeah it worked";
|
||
|
|
|
||
|
|
// Tokens for the GuildList
|
||
|
|
// %guildid
|
||
|
|
// %guildname
|
||
|
|
|
||
|
|
// GuildID
|
||
|
|
SI32 sPos;
|
||
|
|
CGuild *myGuild = GuildSys->Guild( i );
|
||
|
|
|
||
|
|
char GuildID[6];
|
||
|
|
sprintf( GuildID, "%d", i );
|
||
|
|
for( sPos = parsedInline.find( "%guildid" ); sPos >= 0; sPos = parsedInline.find( "%guildid" ) )
|
||
|
|
{
|
||
|
|
parsedInline.replace( sPos, 8, GuildID );
|
||
|
|
}
|
||
|
|
|
||
|
|
// GuildName
|
||
|
|
for( sPos = parsedInline.find( "%guildname" ); sPos >= 0; sPos = parsedInline.find( "%guildname" ) )
|
||
|
|
{
|
||
|
|
parsedInline.replace( sPos, 10, myGuild->Name() );
|
||
|
|
}
|
||
|
|
|
||
|
|
GuildList += parsedInline;
|
||
|
|
}
|
||
|
|
|
||
|
|
ParsedContent.replace( Pos, myInline.length(), GuildList );
|
||
|
|
}
|
||
|
|
|
||
|
|
//NPCCount
|
||
|
|
char npcs[6];
|
||
|
|
UI32 npccount = 0;
|
||
|
|
|
||
|
|
if( npccount == 0 )
|
||
|
|
{
|
||
|
|
for( UI32 a = 0; a < chars.Count(); a++ )
|
||
|
|
{
|
||
|
|
if( chars[a].isFree() )
|
||
|
|
continue;
|
||
|
|
if( chars[a].IsNpc() )
|
||
|
|
npccount++;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
sprintf(npcs, "%i", npccount);
|
||
|
|
|
||
|
|
for( Pos = ParsedContent.find( "%npcs" ); Pos >= 0; Pos = ParsedContent.find( "%npcs" ) )
|
||
|
|
{
|
||
|
|
ParsedContent.replace( Pos, 5, npcs );
|
||
|
|
}
|
||
|
|
|
||
|
|
// Performance Dump
|
||
|
|
R64 eps = 0.00000000001;
|
||
|
|
for( Pos = ParsedContent.find( "%performance" ); Pos >= 0; Pos = ParsedContent.find( "%performance" ) )
|
||
|
|
{
|
||
|
|
string performance;
|
||
|
|
ostringstream myStream( performance );
|
||
|
|
|
||
|
|
myStream << "Network code: " << (R32)((R32)networkTime/(R32)networkTimeCount) << "msec [" << networkTimeCount << " samples] <BR>";
|
||
|
|
myStream << "Timer code: " << (R32)((R32)timerTime/(R32)timerTimeCount) << "msec [" << timerTimeCount << " samples] <BR>";
|
||
|
|
myStream << "Auto code: " << (R32)((R32)autoTime/(R32)autoTimeCount) << "msec [" << autoTimeCount << " samples] <BR>";
|
||
|
|
myStream << "Loop Time: " << (R32)((R32)loopTime/(R32)loopTimeCount) << "msec [" << loopTimeCount << " samples] <BR>";
|
||
|
|
if( !( loopTime < eps || loopTimeCount < eps ) )
|
||
|
|
myStream << "Simulation Cycles: " << (1000.0*(1.0/(R32)((R32)loopTime/(R32)loopTimeCount))) << " per sec <BR>";
|
||
|
|
else
|
||
|
|
myStream << "Simulation Cycles: Greater than 10000 <BR> ";
|
||
|
|
|
||
|
|
|
||
|
|
ParsedContent.replace(Pos, 12, myStream.str());
|
||
|
|
}
|
||
|
|
|
||
|
|
// Uptime
|
||
|
|
for( Pos = ParsedContent.find( "%uptime" ); Pos >= 0; Pos = ParsedContent.find( "%uptime" ) )
|
||
|
|
{
|
||
|
|
string uptime;
|
||
|
|
|
||
|
|
char sh[3], sm[3], ss[3];
|
||
|
|
ostringstream myStream( uptime );
|
||
|
|
|
||
|
|
UI32 total, hr, min, sec;
|
||
|
|
|
||
|
|
total = (uiCurrentTime - starttime ) / CLOCKS_PER_SEC;
|
||
|
|
hr = total / 3600;
|
||
|
|
if( hr < 10 && hr <= 60 )
|
||
|
|
sprintf( sh,"0%i",hr );
|
||
|
|
else
|
||
|
|
sprintf( sh, "%i", hr);
|
||
|
|
total -= hr * 3600;
|
||
|
|
min = total / 60;
|
||
|
|
if( min < 10 && min <= 60 )
|
||
|
|
sprintf( sm, "0%i", min );
|
||
|
|
else
|
||
|
|
sprintf( sm, "%i", min );
|
||
|
|
total -= min*60;
|
||
|
|
sec = total;
|
||
|
|
if( sec < 10 && sec <= 60 )
|
||
|
|
sprintf( ss, "0%i", sec );
|
||
|
|
else
|
||
|
|
sprintf( ss, "%i", sec );
|
||
|
|
myStream << sh << ":" << sm << ":" << ss;
|
||
|
|
|
||
|
|
ParsedContent.replace(Pos, 7, myStream.str());
|
||
|
|
}
|
||
|
|
|
||
|
|
// Simulation Cycles (whatever that may be...)
|
||
|
|
for( Pos = ParsedContent.find( "%simcycles" ); Pos >= 0; Pos = ParsedContent.find( "%simcycles" ) )
|
||
|
|
{
|
||
|
|
string simcycles;
|
||
|
|
ostringstream myStream( simcycles );
|
||
|
|
|
||
|
|
if( !( loopTime < eps || loopTimeCount < eps ) )
|
||
|
|
myStream << "Simulation Cycles: " << (1000.0*(1.0/(R32)((R32)loopTime/(R32)loopTimeCount))) << " per sec <BR>";
|
||
|
|
else
|
||
|
|
myStream << "Simulation Cycles: Greater than 10000 <BR> ";
|
||
|
|
|
||
|
|
|
||
|
|
ParsedContent.replace(Pos, 10, myStream.str());
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update Time in SECONDS
|
||
|
|
for( Pos = ParsedContent.find( "%updatetime" ); Pos >= 0; Pos = ParsedContent.find( "%updatetime" ) )
|
||
|
|
{
|
||
|
|
char strUpdateTimer[32]; // Could be a big value...
|
||
|
|
sprintf( strUpdateTimer, "%i", UpdateTimer );
|
||
|
|
|
||
|
|
ParsedContent.replace( Pos, 11, strUpdateTimer );
|
||
|
|
}
|
||
|
|
|
||
|
|
//***************************************/
|
||
|
|
// End Replacing Placeholders
|
||
|
|
//***************************************/
|
||
|
|
|
||
|
|
// Print the Content out to the new file...
|
||
|
|
ofstream Output( OutputFile );
|
||
|
|
if( !Output.is_open() )
|
||
|
|
{
|
||
|
|
Console.Error( 1, "Couldn't open the template file %s for writing", OutputFile );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Output << ParsedContent;
|
||
|
|
|
||
|
|
Output.close();
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplate::Poll
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Updates the page if needed
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplate::Poll( bool Force )
|
||
|
|
{
|
||
|
|
if( ( Force ) || ( ScheduledUpdate < uiCurrentTime ) )
|
||
|
|
{
|
||
|
|
Process();
|
||
|
|
ScheduledUpdate = BuildTimeValue( (R32)UpdateTimer );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplate::LoadTemplate
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Loads the Template into memory
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplate::LoadTemplate( void )
|
||
|
|
{
|
||
|
|
Content = "";
|
||
|
|
|
||
|
|
ifstream InputFile1( InputFile );
|
||
|
|
|
||
|
|
if( !InputFile1.is_open() )
|
||
|
|
{
|
||
|
|
Console.Error( 1, "Couldn't open HTML Template File %s", InputFile );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
while( !InputFile1.eof() )
|
||
|
|
{
|
||
|
|
string Line;
|
||
|
|
getline( InputFile1, Line );
|
||
|
|
Content += Line;
|
||
|
|
}
|
||
|
|
|
||
|
|
InputFile1.close();
|
||
|
|
|
||
|
|
Loaded = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplate::UnloadTemplate
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Unloads the Template (i.e. for reloading)
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplate::UnloadTemplate( void )
|
||
|
|
{
|
||
|
|
Loaded = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplate::Load
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Loads the HTML Template from a ScriptSection
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplate::Load( ScriptSection *found )
|
||
|
|
{
|
||
|
|
Type = ETT_PERIODIC;
|
||
|
|
|
||
|
|
const char *tag = NULL;
|
||
|
|
const char *data = NULL;
|
||
|
|
|
||
|
|
for( tag = found->First(); !found->AtEnd(); tag = found->Next() )
|
||
|
|
{
|
||
|
|
data = found->GrabData();
|
||
|
|
|
||
|
|
if( !strcmp( tag, "UPDATE" ) )
|
||
|
|
{
|
||
|
|
UpdateTimer = makeNum( data );
|
||
|
|
}
|
||
|
|
else if( !strcmp( tag, "TYPE" ) )
|
||
|
|
{
|
||
|
|
if( !strcmp( data, "PERIODIC" ) )
|
||
|
|
Type = ETT_PERIODIC;
|
||
|
|
else if( !strcmp( data, "OFFLINE" ) )
|
||
|
|
Type = ETT_OFFLINE;
|
||
|
|
else if( !strcmp( data, "PLAYER" ) )
|
||
|
|
Type = ETT_PLAYER;
|
||
|
|
else if( !strcmp( data, "GUILD" ) )
|
||
|
|
Type = ETT_GUILD;
|
||
|
|
}
|
||
|
|
else if( !strcmp( tag, "INPUT" ) )
|
||
|
|
{
|
||
|
|
sprintf( InputFile, "%s", data );
|
||
|
|
}
|
||
|
|
else if( !strcmp( tag, "OUTPUT" ) )
|
||
|
|
{
|
||
|
|
sprintf( OutputFile, "%s", data );
|
||
|
|
}
|
||
|
|
else if( !strcmp( tag, "NAME" ) )
|
||
|
|
{
|
||
|
|
Name = data;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
ScheduledUpdate = 0;
|
||
|
|
Loaded = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
cHTMLTemplates::cHTMLTemplates()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
cHTMLTemplates::~cHTMLTemplates()
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::Load
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Loads the HTML Templates from the scripts
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplates::Load( void )
|
||
|
|
{
|
||
|
|
|
||
|
|
ScpList *toWalk = FileLookup->GetFiles( html_def );
|
||
|
|
if( toWalk == NULL )
|
||
|
|
return;
|
||
|
|
|
||
|
|
for( UI32 i = 0; i < toWalk->size(); i++ )
|
||
|
|
{
|
||
|
|
if( (*toWalk)[i] != NULL )
|
||
|
|
{
|
||
|
|
Script *toCheck = (*toWalk)[i];
|
||
|
|
if( toWalk == NULL )
|
||
|
|
continue;
|
||
|
|
|
||
|
|
UI32 NumEntries = toCheck->NumEntries();
|
||
|
|
if( NumEntries == 0 )
|
||
|
|
continue;
|
||
|
|
|
||
|
|
for( ScriptSection *found = toCheck->FirstEntry(); found != NULL; found = toCheck->NextEntry() )
|
||
|
|
{
|
||
|
|
cHTMLTemplate *Template = new cHTMLTemplate();
|
||
|
|
Template->Load( found );
|
||
|
|
Templates.push_back( Template );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::Unload
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Unloads all Templates
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplates::Unload( void )
|
||
|
|
{
|
||
|
|
if( Templates.size() < 1 )
|
||
|
|
return;
|
||
|
|
|
||
|
|
for( UI32 i = 0; i < Templates.size(); i++ )
|
||
|
|
{
|
||
|
|
delete( Templates[ i ] );
|
||
|
|
}
|
||
|
|
|
||
|
|
Templates.clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::Poll
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Polls the templates for updates
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplates::Poll( UI08 TemplateType )
|
||
|
|
{
|
||
|
|
if( Templates.size() < 1 )
|
||
|
|
return;
|
||
|
|
|
||
|
|
for( UI32 i = 0; i < Templates.size(); i++ )
|
||
|
|
{
|
||
|
|
if( Templates[ i ]->GetTemplateType() != TemplateType )
|
||
|
|
continue;
|
||
|
|
|
||
|
|
if( Templates[ i ] != NULL )
|
||
|
|
Templates[ i ]->Poll();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::TemplateInfoGump
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Shows an information gump about current templates
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
void cHTMLTemplates::TemplateInfoGump( cSocket *mySocket )
|
||
|
|
{
|
||
|
|
CGump InfoGump = CGump( false, false );
|
||
|
|
|
||
|
|
InfoGump.SetSerial( 1 ); // Serial for the HTML Status Callback
|
||
|
|
|
||
|
|
InfoGump.StartPage();
|
||
|
|
// Add an exit button
|
||
|
|
InfoGump.AddButton( 40, 300, (UI16)cwmWorldState->ServerData()->GetButtonCancel(), (UI16)( cwmWorldState->ServerData()->GetButtonCancel() + 1 ), 1, 0, 0 );
|
||
|
|
|
||
|
|
InfoGump.AddBackground( 0, 0, cwmWorldState->ServerData()->GetBackgroundPic(), 350, 350 );
|
||
|
|
|
||
|
|
// 10 Max Templates per page
|
||
|
|
UI32 Entries = 0; // Entries per page
|
||
|
|
UI32 CurrentPage = 0; // Page
|
||
|
|
|
||
|
|
for( UI32 i = 0; i < Templates.size(); i++ )
|
||
|
|
{
|
||
|
|
if( Entries == 0 )
|
||
|
|
{
|
||
|
|
// We should add a next button if we're not starting the first page
|
||
|
|
if( CurrentPage != 0 )
|
||
|
|
InfoGump.AddButton( 300, 250, (UI16)cwmWorldState->ServerData()->GetButtonRight(), (UI16)( cwmWorldState->ServerData()->GetButtonRight() + 1 ), 0, (UI16)( CurrentPage + 1 ), 0 );
|
||
|
|
|
||
|
|
CurrentPage = InfoGump.StartPage();
|
||
|
|
}
|
||
|
|
|
||
|
|
// If we're not on the first page add the "back" button
|
||
|
|
if( CurrentPage > 1 )
|
||
|
|
InfoGump.AddButton( 30, 250, (UI16)cwmWorldState->ServerData()->GetButtonLeft(), (UI16)( cwmWorldState->ServerData()->GetButtonLeft() + 1 ), 0, (UI16)( CurrentPage - 1 ), 0 );
|
||
|
|
|
||
|
|
Entries++;
|
||
|
|
|
||
|
|
// ~25 pixel per entry
|
||
|
|
char tmpName[256];
|
||
|
|
sprintf( tmpName, "%s (%i)", Templates[ i ]->GetName().c_str(), i );
|
||
|
|
|
||
|
|
InfoGump.AddText( 40, (UI16)( 40 + (Entries-1)*25 ), cwmWorldState->ServerData()->GetLeftTextColour(), tmpName );
|
||
|
|
|
||
|
|
if( Entries == 5 )
|
||
|
|
Entries = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
InfoGump.Send( mySocket );
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::GetName
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Returns the name of the Template
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
string cHTMLTemplate::GetName( void )
|
||
|
|
{
|
||
|
|
return Name;
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::GetOutput
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Gets the Output Filename
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
string cHTMLTemplate::GetOutput( void )
|
||
|
|
{
|
||
|
|
return OutputFile;
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::GetInput
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Gets the Input Filename
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
string cHTMLTemplate::GetInput( void )
|
||
|
|
{
|
||
|
|
return InputFile;
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::TemplateInfoGump
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Gets the next scheduled Update time
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
UI32 cHTMLTemplate::GetScheduledUpdate( void )
|
||
|
|
{
|
||
|
|
return ScheduledUpdate;
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::GetUpdateTimer
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Gets the Update timer
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
UI32 cHTMLTemplate::GetUpdateTimer( void )
|
||
|
|
{
|
||
|
|
return UpdateTimer;
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplate::GetTemplateType
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Gets the Template Type
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
UI08 cHTMLTemplate::GetTemplateType( void )
|
||
|
|
{
|
||
|
|
return Type;
|
||
|
|
}
|
||
|
|
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Function - cHTMLTemplates::Refresh
|
||
|
|
//| Programmer - Dark-Storm
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
//| Purpose - Refreshs a single template
|
||
|
|
//o---------------------------------------------------------------------------o
|
||
|
|
bool cHTMLTemplates::Refresh( UI32 TemplateID )
|
||
|
|
{
|
||
|
|
if( Templates.size() < 1 )
|
||
|
|
return false;
|
||
|
|
|
||
|
|
if( TemplateID >= Templates.size() )
|
||
|
|
return false;
|
||
|
|
|
||
|
|
if( Templates[ TemplateID ] == NULL )
|
||
|
|
return false;
|
||
|
|
|
||
|
|
Templates[ TemplateID ]->Poll( true );
|
||
|
|
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|