Rest of the changes for 0.99.6-RC1

Misc cleanup and standardization of style and naming conventions in code and scripts
Added missing code for showing race in paperdoll based on ini setting
Players can no longer use Polymorph spell while incognitoed, or while under effect of tribal paint
Players can no longer use Incognito spell while polymorphed, or while under the effects of tribal paint
Facial hair is now removed from players who are under the effects of Incognito spell that changes their gender for female
This commit is contained in:
Xoduz 2022-10-24 18:39:33 +08:00
parent 27af43b422
commit 37a76083de
409 changed files with 59540 additions and 44718 deletions

View file

@ -15,12 +15,12 @@
#include "osunique.hpp"
cHTMLTemplates *HTMLTemplates;
cHTMLTemplate::cHTMLTemplate() : UpdateTimer( 60 ), Loaded( false ), Type( ETT_INVALIDTEMPLATE ), ScheduledUpdate( 0 )
cHTMLTemplate::cHTMLTemplate() : updateTimer( 60 ), loaded( false ), type( ETT_INVALIDTEMPLATE ), scheduledUpdate( 0 )
{
Name = "";
Content = "";
OutputFile.reserve( MAX_PATH );
InputFile.reserve( MAX_PATH );
name = "";
content = "";
outputFile.reserve( MAX_PATH );
inputFile.reserve( MAX_PATH );
}
cHTMLTemplate::~cHTMLTemplate()
@ -40,17 +40,17 @@ std::string GetUptime( void )
std::string builtString = "";
if( ho < 10 )
{
builtString += std::string("0");
builtString += std::string( "0" );
}
builtString += oldstrutil::number( ho ) + ":";
if( mi < 10 )
{
builtString += std::string("0");
builtString += std::string( "0" );
}
builtString += oldstrutil::number( mi ) + std::string(":");
if( se < 10 )
{
builtString += std::string("0");
builtString += std::string( "0" );
}
builtString += oldstrutil::number( se );
return builtString;
@ -59,43 +59,47 @@ std::string GetUptime( void )
bool CountNPCFunctor( CBaseObject *a, UI32 &b, void *extraData )
{
bool retVal = true;
if( ValidateObject( a ) )
if( ValidateObject( a ))
{
CChar *j = static_cast< CChar * >(a);
CChar *j = static_cast< CChar * >( a );
if( j->IsNpc() )
{
++b;
}
}
return retVal;
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void cHTMLTemplate::Process( void )
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::Process()
//| Date - 1/18/2003 4:43:17 AM
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Purpose -
//|
//| Changes - 08062003 - For the record this is some of the
//| most fucked up shit I have EVER SEEN!! Written to truely
//| handle multiple Templates.
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
void cHTMLTemplate::Process( void )
{
// Need to check to see if the server is actually running, of so we do not want to process the offline template.
if(cwmWorldState->GetKeepRun() && this->GetTemplateType() == ETT_OFFLINE )
if( cwmWorldState->GetKeepRun() && this->GetTemplateType() == ETT_OFFLINE )
return;
// Only read the Status Page if it's not already loaded
if( !Loaded )
if( !loaded )
{
LoadTemplate();
}
// Parse the Content...
std::string ParsedContent = Content;
std::string ParsedContent = content;
// Replacing Placeholders
// Account-Count
std::string AccountCount = oldstrutil::number( (Accounts->size()) );
size_t Pos = ParsedContent.find( "%accounts" );
std::string AccountCount = oldstrutil::number(( Accounts->size() ));
size_t Pos = ParsedContent.find( "%accounts" );
while( Pos != std::string::npos )
{
ParsedContent.replace( Pos, 9, AccountCount );
@ -117,8 +121,8 @@ void cHTMLTemplate::Process( void )
Pos = ParsedContent.find( "%version" );
}
// Character Count
std::string CharacterCount = oldstrutil::number( ObjectFactory::getSingleton().CountOfObjects( OT_CHAR ) );
Pos = ParsedContent.find( "%charcount" );
std::string CharacterCount = oldstrutil::number( ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR ));
Pos = ParsedContent.find( "%charcount" );
while( Pos != std::string::npos )
{
ParsedContent.replace( Pos, 10, CharacterCount );
@ -126,8 +130,8 @@ void cHTMLTemplate::Process( void )
}
// Item Count
std::string ItemCount = oldstrutil::number( ObjectFactory::getSingleton().CountOfObjects( OT_ITEM ) );
Pos = ParsedContent.find( "%itemcount" );
std::string ItemCount = oldstrutil::number( ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM ));
Pos = ParsedContent.find( "%itemcount" );
while( Pos != std::string::npos )
{
ParsedContent.replace( Pos, 10, ItemCount );
@ -163,37 +167,37 @@ void cHTMLTemplate::Process( void )
// GMs
std::string GMCount = oldstrutil::number( gm );
Pos = ParsedContent.find( "%online_gms" );
Pos = ParsedContent.find( "%online_gms" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 11, GMCount ):ParsedContent.replace( Pos, 11, "0" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 11, GMCount ) : ParsedContent.replace( Pos, 11, "0" );
Pos = ParsedContent.find( "%online_gms" );
}
// Counselor
std::string CounsiCount = oldstrutil::number( cns );
Pos = ParsedContent.find( "%online_couns" );
Pos = ParsedContent.find( "%online_couns" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 13, CounsiCount ):ParsedContent.replace( Pos, 13, "0");
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 13, CounsiCount ) : ParsedContent.replace( Pos, 13, "0" );
Pos = ParsedContent.find( "%online_couns" );
}
// Player
std::string PlayerCount = oldstrutil::number( ccount );
Pos = ParsedContent.find( "%online_player" );
Pos = ParsedContent.find( "%online_player" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 14, PlayerCount ):ParsedContent.replace( Pos, 14, "0" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 14, PlayerCount ) : ParsedContent.replace( Pos, 14, "0" );
Pos = ParsedContent.find( "%online_player" );
}
// Total
std::string AllCount = oldstrutil::number( (ccount + gm + cns) );
Pos = ParsedContent.find( "%online_all" );
std::string AllCount = oldstrutil::number(( ccount + gm + cns ));
Pos = ParsedContent.find( "%online_all" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 11, AllCount ):ParsedContent.replace( Pos, 11, "0" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 11, AllCount ) : ParsedContent.replace( Pos, 11, "0" );
Pos = ParsedContent.find( "%online_all" );
}
@ -203,7 +207,7 @@ void cHTMLTemplate::Process( void )
Pos = ParsedContent.find( "%time" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 5, time_str ):ParsedContent.replace( Pos, 5, "Down" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 5, time_str ) : ParsedContent.replace( Pos, 5, "Down" );
Pos = ParsedContent.find( "%time" );
}
@ -212,7 +216,7 @@ void cHTMLTemplate::Process( void )
Pos = ParsedContent.find( "%24time" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 7, time_str ):ParsedContent.replace( Pos, 7, "Down" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 7, time_str ) : ParsedContent.replace( Pos, 7, "Down" );
Pos = ParsedContent.find( "%24time" );
}
@ -220,12 +224,12 @@ void cHTMLTemplate::Process( void )
time_t currTime;
time( &currTime );
struct tm dtime;
currTime = mktime( mgmtime(&dtime, &currTime ) );
currTime = mktime( mgmtime( &dtime, &currTime ));
std::string timestamp = oldstrutil::number( currTime );
Pos = ParsedContent.find( "%tstamp" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 7, timestamp ):ParsedContent.replace( Pos, 7, "Down" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 7, timestamp ) : ParsedContent.replace( Pos, 7, "Down" );
Pos = ParsedContent.find( "%tstamp" );
}
@ -255,14 +259,15 @@ void cHTMLTemplate::Process( void )
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 11, oldstrutil::number( serverPort )) : ParsedContent.replace( Pos, 11, "127.0.0.1" );
Pos = ParsedContent.find( "%serverport" );
}
// PLAYERLIST
// Playerlist
Pos = ParsedContent.find( "%playerlist%" );
while( Pos != std::string::npos )
{
size_t SecondPos = ParsedContent.find( "%playerlist%", Pos+1 );
size_t SecondPos = ParsedContent.find( "%playerlist%", Pos + 1 );
if( SecondPos == std::string::npos ) // there's no closing part!
break;
std::string myInline = ParsedContent.substr( Pos, SecondPos - Pos + 12 );
std::string myInline = ParsedContent.substr( Pos, SecondPos - Pos + 12 );
std::string PlayerList;
{
for( auto &tSock : Network->connClients )
@ -280,7 +285,7 @@ void cHTMLTemplate::Process( void )
std::string parsedInline = myInline;
parsedInline.replace( 0, 12, "" );
parsedInline.replace( parsedInline.length()-12, 12, "" );
parsedInline.replace( parsedInline.length() - 12, 12, "" );
// Tokens for the PlayerList
// %playername
@ -297,7 +302,7 @@ void cHTMLTemplate::Process( void )
size_t sPos = parsedInline.find( "%playername" );
while( sPos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 11, tChar->GetName() ):parsedInline.replace( sPos, 11, "" );
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 11, tChar->GetName() ) : parsedInline.replace( sPos, 11, "" );
sPos = parsedInline.find( "%playername" );
}
@ -310,7 +315,7 @@ void cHTMLTemplate::Process( void )
sPos = parsedInline.find( "%playertitle" );
while( sPos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 12, tChar->GetTitle() ):parsedInline.replace( sPos, 12, "" );
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 12, tChar->GetTitle() ) : parsedInline.replace( sPos, 12, "" );
sPos = parsedInline.find( "%playertitle" );
}
@ -320,8 +325,8 @@ void cHTMLTemplate::Process( void )
{
CSocket *mySock = tChar->GetSocket();
auto ClientIP = oldstrutil::format("%i.%i.%i.%i", mySock->ClientIP4(), mySock->ClientIP3(), mySock->ClientIP3(), mySock->ClientIP1() );
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 9, ClientIP ):parsedInline.replace( sPos, 9, "" );
auto ClientIP = oldstrutil::format( "%i.%i.%i.%i", mySock->ClientIP4(), mySock->ClientIP3(), mySock->ClientIP3(), mySock->ClientIP1() );
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 9, ClientIP ):parsedInline.replace( sPos, 9, "" );
sPos = parsedInline.find( "%playerip" );
}
@ -329,9 +334,11 @@ void cHTMLTemplate::Process( void )
sPos = parsedInline.find( "%playeraccount" );
while( sPos != std::string::npos )
{
CAccountBlock& toScan = tChar->GetAccount();
CAccountBlock_st& toScan = tChar->GetAccount();
if( toScan.wAccountIndex != AB_INVALID_ID )
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 14, toScan.sUsername):parsedInline.replace( sPos, 14, "" );
{
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 14, toScan.sUsername) : parsedInline.replace( sPos, 14, "" );
}
sPos = parsedInline.find( "%playeraccount" );
}
@ -340,7 +347,7 @@ void cHTMLTemplate::Process( void )
while( sPos != std::string::npos )
{
std::string myX = oldstrutil::number( tChar->GetX() );
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 8, myX ):parsedInline.replace( sPos, 8, "" );
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 8, myX ) : parsedInline.replace( sPos, 8, "" );
sPos = parsedInline.find( "%playerx" );
}
@ -349,7 +356,7 @@ void cHTMLTemplate::Process( void )
while( sPos != std::string::npos )
{
std::string myY = oldstrutil::number( tChar->GetY() );
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 8, myY ):parsedInline.replace( sPos, 8, "" );
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 8, myY ) : parsedInline.replace( sPos, 8, "" );
sPos = parsedInline.find( "%playery" );
}
@ -358,7 +365,7 @@ void cHTMLTemplate::Process( void )
while( sPos != std::string::npos )
{
std::string myZ = oldstrutil::number( tChar->GetZ() );
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 8, myZ ):parsedInline.replace( sPos, 8, "" );
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 8, myZ ) : parsedInline.replace( sPos, 8, "" );
sPos = parsedInline.find( "%playerz" );
}
@ -371,7 +378,9 @@ void cHTMLTemplate::Process( void )
size_t raceLenName = rName.length();
if( raceLenName > 0 )
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 11, rName ):parsedInline.replace( sPos, 11, "");
{
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 11, rName ) : parsedInline.replace( sPos, 11, "");
}
sPos = parsedInline.find( "%playerrace" );
}
@ -379,7 +388,7 @@ void cHTMLTemplate::Process( void )
sPos = parsedInline.find( "%playerregion" );
while( sPos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 13, tChar->GetRegion()->GetName() ):parsedInline.replace( sPos, 13, "");
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 13, tChar->GetRegion()->GetName() ) : parsedInline.replace( sPos, 13, "" );
sPos = parsedInline.find( "%playerregion" );
}
@ -394,16 +403,16 @@ void cHTMLTemplate::Process( void )
}
}
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, myInline.length(), PlayerList ):ParsedContent.replace( Pos, myInline.length(), "");
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, myInline.length(), PlayerList ) : ParsedContent.replace( Pos, myInline.length(), "");
Pos = ParsedContent.find( "%playerlist%" );
}
// GuildCount
std::string GuildCount = oldstrutil::number( (SI32)GuildSys->NumGuilds() );
Pos = ParsedContent.find( "%guildcount" );
std::string GuildCount = oldstrutil::number( static_cast<SI32>( GuildSys->NumGuilds() ));
Pos = ParsedContent.find( "%guildcount" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 11, GuildCount ):ParsedContent.replace( Pos, 11, "" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 11, GuildCount ) : ParsedContent.replace( Pos, 11, "" );
Pos = ParsedContent.find( "%guildcount" );
}
@ -411,32 +420,32 @@ void cHTMLTemplate::Process( void )
Pos = ParsedContent.find( "%guildlist%" );
while( Pos != std::string::npos )
{
size_t SecondPos = ParsedContent.find( "%guildlist%", Pos+1 );
size_t SecondPos = ParsedContent.find( "%guildlist%", Pos + 1 );
if( SecondPos == std::string::npos ) // can't find closing
break;
std::string myInline = ParsedContent.substr( Pos, SecondPos - Pos + 11 );
std::string myInline = ParsedContent.substr( Pos, SecondPos - Pos + 11 );
std::string GuildList;
for( SI16 i = 0; i < (SI16)GuildSys->NumGuilds(); ++i )
for( SI16 i = 0; i < static_cast<SI16>( GuildSys->NumGuilds() ); ++i )
{
std::string parsedInline = myInline;
parsedInline.replace( 0, 11, "" );
parsedInline.replace( parsedInline.length()-11, 11, "" );
parsedInline.replace( parsedInline.length() - 11, 11, "" );
// Tokens for the GuildList
// %guildid
// %guildname
// %guildmembercount
// GuildID
// GuildId
size_t sPos;
CGuild *myGuild = GuildSys->Guild( i );
std::string GuildID = oldstrutil::number( i );
sPos = parsedInline.find( "%guildid" );
std::string GuildId = oldstrutil::number( i );
sPos = parsedInline.find( "%guildid" );
while( sPos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 8, GuildID ):parsedInline.replace( sPos, 8, "" );
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 8, GuildId ) : parsedInline.replace( sPos, 8, "" );
sPos = parsedInline.find( "%guildid" );
}
@ -444,7 +453,7 @@ void cHTMLTemplate::Process( void )
sPos = parsedInline.find( "%guildname" );
while( sPos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 10, myGuild->Name() ):parsedInline.replace( sPos, 10, "" );
( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 10, myGuild->Name() ) : parsedInline.replace( sPos, 10, "" );
sPos = parsedInline.find( "%guildname" );
}
@ -459,21 +468,21 @@ void cHTMLTemplate::Process( void )
GuildList += parsedInline;
}
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, myInline.length(), GuildList ):ParsedContent.replace( Pos, myInline.length(), "" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, myInline.length(), GuildList ) : ParsedContent.replace( Pos, myInline.length(), "" );
Pos = ParsedContent.find( "%guildlist%" );
}
//NPCCount
UI32 npccount = 0;
UI32 b = 0;
ObjectFactory::getSingleton().IterateOver( OT_CHAR, b, nullptr, &CountNPCFunctor );
npccount = b;
UI32 b = 0;
ObjectFactory::GetSingleton().IterateOver( OT_CHAR, b, nullptr, &CountNPCFunctor );
npccount = b;
std::string npcs = oldstrutil::number( npccount );
Pos = ParsedContent.find( "%npcs" );
std::string npcs = oldstrutil::number( npccount );
Pos = ParsedContent.find( "%npcs" );
while( Pos != std::string::npos )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 5, npcs ):ParsedContent.replace( Pos, 5, "0" );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 5, npcs ) : ParsedContent.replace( Pos, 5, "0" );
Pos = ParsedContent.find( "%npcs" );
}
@ -490,14 +499,18 @@ void cHTMLTemplate::Process( void )
UI32 timerTimeCount = cwmWorldState->ServerProfile()->TimerTimeCount();
UI32 autoTimeCount = cwmWorldState->ServerProfile()->AutoTimeCount();
UI32 loopTimeCount = cwmWorldState->ServerProfile()->LoopTimeCount();
myStream << "Network code: " << (R32)((R32)cwmWorldState->ServerProfile()->NetworkTime()/(R32)networkTimeCount) << "msec [" << networkTimeCount << " samples] <BR>";
myStream << "Timer code: " << (R32)((R32)cwmWorldState->ServerProfile()->TimerTime()/(R32)timerTimeCount) << "msec [" << timerTimeCount << " samples] <BR>";
myStream << "Auto code: " << (R32)((R32)cwmWorldState->ServerProfile()->AutoTime()/(R32)autoTimeCount) << "msec [" << autoTimeCount << " samples] <BR>";
myStream << "Loop Time: " << (R32)((R32)cwmWorldState->ServerProfile()->LoopTime()/(R32)loopTimeCount) << "msec [" << loopTimeCount << " samples] <BR>";
if( !( cwmWorldState->ServerProfile()->LoopTime() < eps || loopTimeCount < eps ) )
myStream << "Simulation Cycles: " << (1000.0*(1.0/(R32)((R32)cwmWorldState->ServerProfile()->LoopTime()/(R32)loopTimeCount))) << " per sec <BR>";
myStream << "Network code: " << static_cast<R32>( static_cast<R32>( cwmWorldState->ServerProfile()->NetworkTime() ) / static_cast<R32>( networkTimeCount )) << "msec [" << networkTimeCount << " samples] <BR>";
myStream << "Timer code: " << static_cast<R32>( static_cast<R32>( cwmWorldState->ServerProfile()->TimerTime() ) / static_cast<R32>( timerTimeCount )) << "msec [" << timerTimeCount << " samples] <BR>";
myStream << "Auto code: " << static_cast<R32>( static_cast<R32>( cwmWorldState->ServerProfile()->AutoTime() ) / static_cast<R32>( autoTimeCount )) << "msec [" << autoTimeCount << " samples] <BR>";
myStream << "Loop Time: " << static_cast<R32>( static_cast<R32>( cwmWorldState->ServerProfile()->LoopTime() ) / static_cast<R32>( loopTimeCount )) << "msec [" << loopTimeCount << " samples] <BR>";
if( !( cwmWorldState->ServerProfile()->LoopTime() < eps || loopTimeCount < eps ))
{
myStream << "Simulation Cycles: " << ( 1000.0 * ( 1.0 / static_cast<R32>( static_cast<R32>( cwmWorldState->ServerProfile()->LoopTime() ) / static_cast<R32>( loopTimeCount )))) << " per sec <BR>";
}
else
{
myStream << "Simulation Cycles: Greater than 10000 <BR> ";
}
}
else
{
@ -529,10 +542,14 @@ void cHTMLTemplate::Process( void )
if( cwmWorldState->GetKeepRun() )
{
if( !( cwmWorldState->ServerProfile()->LoopTime() < eps || cwmWorldState->ServerProfile()->LoopTimeCount() < eps ) )
myStream << "Simulation Cycles: " << (1000.0*(1.0/(R32)((R32)cwmWorldState->ServerProfile()->LoopTime()/(R32)cwmWorldState->ServerProfile()->LoopTimeCount()))) << " per sec <BR>";
if( !( cwmWorldState->ServerProfile()->LoopTime() < eps || cwmWorldState->ServerProfile()->LoopTimeCount() < eps ))
{
myStream << "Simulation Cycles: " << ( 1000.0 * ( 1.0 / static_cast<R32>( static_cast<R32>( cwmWorldState->ServerProfile()->LoopTime() ) / static_cast<R32>( cwmWorldState->ServerProfile()->LoopTimeCount() )))) << " per sec <BR>";
}
else
{
myStream << "Simulation Cycles: Greater than 10000 <BR> ";
}
}
else
{
@ -546,8 +563,8 @@ void cHTMLTemplate::Process( void )
Pos = ParsedContent.find( "%updatetime" );
while( Pos != std::string::npos )
{
std::string strUpdateTimer = oldstrutil::number( UpdateTimer );
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 11, strUpdateTimer ):ParsedContent.replace( Pos, 11, "0" );
std::string strUpdateTimer = oldstrutil::number( updateTimer );
( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 11, strUpdateTimer ) : ParsedContent.replace( Pos, 11, "0" );
Pos = ParsedContent.find( "%updatetime" );
}
@ -555,47 +572,49 @@ void cHTMLTemplate::Process( void )
// Print the Content out to the new file...
std::ofstream Output;
Output.open( OutputFile.c_str(), std::ios::out );
Output.open( outputFile.c_str(), std::ios::out );
if( Output.is_open() )
{
Output << ParsedContent;
Output.close();
}
else
Console.error( oldstrutil::format(" Couldn't open the template file %s for writing", OutputFile.c_str()) );
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void Poll( void )
//o-----------------------------------------------------------------------------------------------o
//| Purpose - Updates the page if needed
//o-----------------------------------------------------------------------------------------------o
void cHTMLTemplate::Poll( void )
{
if( ScheduledUpdate < cwmWorldState->GetUICurrentTime() || !cwmWorldState->GetKeepRun() )
{
Process();
ScheduledUpdate = BuildTimeValue( (R32)UpdateTimer );
Console.Error( oldstrutil::format( " Couldn't open the template file %s for writing", outputFile.c_str() ));
}
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void LoadTemplate( void )
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::Poll()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Updates the page if needed
//o------------------------------------------------------------------------------------------------o
void cHTMLTemplate::Poll( void )
{
if( scheduledUpdate < cwmWorldState->GetUICurrentTime() || !cwmWorldState->GetKeepRun() )
{
Process();
scheduledUpdate = BuildTimeValue( static_cast<R32>( updateTimer ));
}
}
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::LoadTemplate()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Loads the Template into memory
//|
//| Changes - 08062003 - Updated this member function to actually handle
//| loading the different templates for use later.
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
void cHTMLTemplate::LoadTemplate( void )
{
Content = "";
content = "";
std::ifstream InputFile1( InputFile.c_str() );
std::ifstream InputFile1( inputFile.c_str() );
if( !InputFile1.is_open() )
{
Console.error( oldstrutil::format("Couldn't open HTML Template File %s", InputFile.c_str()) );
Console.Error( oldstrutil::format( "Couldn't open HTML Template File %s", inputFile.c_str() ));
return;
}
@ -603,79 +622,90 @@ void cHTMLTemplate::LoadTemplate( void )
{
std::string Line;
std::getline( InputFile1, Line );
Content += Line;
content += Line;
}
InputFile1.close();
Loaded = true;
loaded = true;
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void UnloadTemplate( void )
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::UnloadTemplate()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Unloads the Template (i.e. for reloading)
//|
//| Changes - 08062003 - Updated to properly unload a template
//| and to unload the correect template, instead of just the
//| status template.
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
void cHTMLTemplate::UnloadTemplate( void )
{
Content="";
Loaded = false;
content = "";
loaded = false;
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void Load( ScriptSection *found )
//o-----------------------------------------------------------------------------------------------o
//| Purpose - Loads the HTML Template from a ScriptSection
//o-----------------------------------------------------------------------------------------------o
void cHTMLTemplate::Load( ScriptSection *found )
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::Load( CScriptSection *found )
//o------------------------------------------------------------------------------------------------o
//| Purpose - Loads the HTML Template from a CScriptSection
//o------------------------------------------------------------------------------------------------o
void cHTMLTemplate::Load( CScriptSection *found )
{
for (const auto &sec : found->collection()){
for( const auto &sec : found->collection() )
{
auto tag = sec->tag;
auto data = sec->data ;
auto data = sec->data;
auto UTag = oldstrutil::upper( tag );
if( UTag == "UPDATE" ) {
UpdateTimer = static_cast<UI32>(std::stoul(data, nullptr, 0));
if( UTag == "UPDATE" )
{
updateTimer = static_cast<UI32>( std::stoul( data, nullptr, 0 ));
}
else if( UTag == "TYPE" ) {
else if( UTag == "TYPE" )
{
auto UData = oldstrutil::upper( data );
if( UData == "STATUS" ) {
Type = ETT_ONLINE;
if( UData == "STATUS" )
{
type = ETT_ONLINE;
}
else if( UData == "OFFLINE" ) {
Type = ETT_OFFLINE;
else if( UData == "OFFLINE" )
{
type = ETT_OFFLINE;
}
else if( UData == "PLAYER" ) {
Type = ETT_PLAYER;
else if( UData == "PLAYER" )
{
type = ETT_PLAYER;
}
else if( UData == "GUILD" ) {
Type = ETT_GUILD;
else if( UData == "GUILD" )
{
type = ETT_GUILD;
}
else if( UData == "GMSTATUS" ) {
Type = ETT_GMSTATUS;
else if( UData == "GMSTATUS" )
{
type = ETT_GMSTATUS;
}
}
else if( UTag == "INPUT" ) {
else if( UTag == "INPUT" )
{
auto fullPath = cwmWorldState->ServerData()->Directory( CSDDP_DEFS ) + "html/" + data;
//LOOKATME
InputFile = oldstrutil::trim(fullPath).substr( 0, MAX_PATH - 1 );
inputFile = oldstrutil::trim( fullPath ).substr( 0, MAX_PATH - 1 );
}
else if( UTag == "OUTPUT" ) {
else if( UTag == "OUTPUT" )
{
auto fullPath = cwmWorldState->ServerData()->Directory( CSDDP_HTML ) + data;
//LOOKATME
OutputFile = oldstrutil::trim(fullPath).substr( 0, MAX_PATH - 1 );
outputFile = oldstrutil::trim( fullPath ).substr( 0, MAX_PATH - 1 );
}
else if( UTag == "NAME" ){
Name = data;
else if( UTag == "NAME" )
{
name = data;
}
}
ScheduledUpdate = 0;
Loaded = false;
scheduledUpdate = 0;
loaded = false;
}
@ -684,17 +714,22 @@ cHTMLTemplates::~cHTMLTemplates()
Unload();
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void Load( void )
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplates::Load()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Loads the HTML Templates from the scripts
//o-----------------------------------------------------------------------------------------------o
auto cHTMLTemplates::Load()->void {
for (auto &toCheck : FileLookup->ScriptListings[html_def]){
if(toCheck) {
//o------------------------------------------------------------------------------------------------o
auto cHTMLTemplates::Load() -> void
{
for( auto &toCheck : FileLookup->ScriptListings[html_def] )
{
if( toCheck )
{
size_t NumEntries = toCheck->NumEntries();
if( NumEntries != 0 ){
for (const auto &[entryName, found]: toCheck->collection()){
if( NumEntries != 0 )
{
for( const auto &[entryName, found]: toCheck->collection() )
{
cHTMLTemplate *Template = new cHTMLTemplate();
Template->Load( found );
Templates.push_back( Template );
@ -704,11 +739,11 @@ auto cHTMLTemplates::Load()->void {
}
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void Unload( void )
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplates::Unload()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Unloads all Templates
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
void cHTMLTemplates::Unload( void )
{
if( Templates.empty() )
@ -722,30 +757,32 @@ void cHTMLTemplates::Unload( void )
Templates.clear();
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void Poll( ETemplateType nTemplateID )
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplates::Poll()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Polls the templates for updates
//o-----------------------------------------------------------------------------------------------o
void cHTMLTemplates::Poll( ETemplateType nTemplateID )
//o------------------------------------------------------------------------------------------------o
void cHTMLTemplates::Poll( ETemplateType nTemplateId )
{
std::vector< cHTMLTemplate* >::const_iterator tIter;
std::vector<cHTMLTemplate *>::const_iterator tIter;
for( tIter = Templates.begin(); tIter != Templates.end(); ++tIter )
{
cHTMLTemplate *toPoll = (*tIter);
cHTMLTemplate *toPoll = ( *tIter );
if( toPoll != nullptr )
{
if( nTemplateID == -1 || toPoll->GetTemplateType() == nTemplateID )
if( nTemplateId == -1 || toPoll->GetTemplateType() == nTemplateId )
{
toPoll->Poll();
}
}
}
}
//o-----------------------------------------------------------------------------------------------o
//| Function - void TemplateInfoGump( CSocket *mySocket )
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplates::TemplateInfoGump()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Shows an information gump about current templates
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
void cHTMLTemplates::TemplateInfoGump( CSocket *mySocket )
{
CGump InfoGump = CGump( false, false );
@ -768,85 +805,91 @@ void cHTMLTemplates::TemplateInfoGump( CSocket *mySocket )
{
// We should add a next button if we're not starting the first page
if( CurrentPage != 0 )
{
InfoGump.AddButton( 300, 250, cwmWorldState->ServerData()->ButtonRight(), static_cast<UI16>( cwmWorldState->ServerData()->ButtonRight() + 1 ), 0, static_cast<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, cwmWorldState->ServerData()->ButtonLeft(), static_cast<UI16>( cwmWorldState->ServerData()->ButtonLeft() + 1 ), 0, static_cast<UI16>( CurrentPage - 1 ), 0 );
}
++Entries;
// ~25 pixel per entry
InfoGump.AddText( 40, static_cast<UI16>( 40 + (Entries-1)*25 ), cwmWorldState->ServerData()->LeftTextColour(), oldstrutil::format( "%s (%i)", Templates[ i ]->GetName().c_str(), i ) );
InfoGump.AddText( 40, static_cast<UI16>( 40 + ( Entries - 1 ) * 25 ), cwmWorldState->ServerData()->LeftTextColour(), oldstrutil::format( "%s (%i)", Templates[ i ]->GetName().c_str(), i ));
if( Entries == 5 )
{
Entries = 0;
}
}
InfoGump.Send( mySocket );
}
//o-----------------------------------------------------------------------------------------------o
//| Function - std::string GetName( void ) const
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::GetName()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Returns the name of the Template
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
std::string cHTMLTemplate::GetName( void ) const
{
return Name;
return name;
}
//o-----------------------------------------------------------------------------------------------o
//| Function - std::string GetOutput( void ) const
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::GetOutput()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets the Output Filename
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
std::string cHTMLTemplate::GetOutput( void ) const
{
return OutputFile;
return outputFile;
}
//o-----------------------------------------------------------------------------------------------o
//| Function - std::string GetInput( void ) const
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::GetInput()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets the Input Filename
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
std::string cHTMLTemplate::GetInput( void ) const
{
return InputFile;
return inputFile;
}
//o-----------------------------------------------------------------------------------------------o
//| Function - UI32 GetScheduledUpdate( void ) const
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::GetScheduledUpdate()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets the next scheduled Update time
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
UI32 cHTMLTemplate::GetScheduledUpdate( void ) const
{
return ScheduledUpdate;
return scheduledUpdate;
}
//o-----------------------------------------------------------------------------------------------o
//| Function - UI32 GetUpdateTimer( void ) const
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::GetUpdateTimer()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets the Update timer
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
UI32 cHTMLTemplate::GetUpdateTimer( void ) const
{
return UpdateTimer;
return updateTimer;
}
//o-----------------------------------------------------------------------------------------------o
//| Function - ETemplateType GetTemplateType( void ) const
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
//| Function - cHTMLTemplate::GetTemplateType()
//o------------------------------------------------------------------------------------------------o
//| Purpose - Gets the Template Type
//o-----------------------------------------------------------------------------------------------o
//o------------------------------------------------------------------------------------------------o
ETemplateType cHTMLTemplate::GetTemplateType( void ) const
{
return Type;
return type;
}