uox3/source/cHTMLSystem.cpp

840 lines
26 KiB
C++
Raw Normal View History

// HTML Template
2002-04-07 20:53:41 +00:00
// Code added to update when shutting down -avtotar (16/09/02)
// Slight modification on avotars fix (19/09/02)
2002-04-07 20:53:41 +00:00
Added: -JS Get/Set "vulnerable" handlers for character properties (Abaddon) -willHunger with Get/Set HungerStatus() wrappers to CChar class (can now selectively stop a character/creature from continuing to hunger) -JS Get/Set "willhunger" handlers for character properties Changed: Linux compile fixes (thanks Malketh) Hash.h warning fixed (thanks Philantrop) Fixes to getRootPack() and getPackOwner() Removed many #includes from the global scope, including them in the specific files that need them This should greatly reduce compile time and filesize, along with the need to recompile after altering most headers Removed the linux ifdefs around typedefd function declarations, this should work with gcc 3.2 Moved global loading functions into a new cFileIO() class to take them out of global scope Fixed an issue causing items to not be sent to the client (thanks Malketh) Moved some global structs into the CWorldMain class Fixed a bug causing a crash on character / item creation Moved all effects stuff into its own class to take it out of global scope Changed the variable CChar::region to CChar::regionNum to avoid conflicts with the cTownRegion region[] indexes Moved getbestskill(), isHuman(), and inDungeon() into the CChar class to remove them from global scope Took npcSimpleAttackTarget() out of global scope Rewrote restock() to make use of restockNPC() Changed the typedef'd iterator in hash.h to HASHITERATOR to kill a Linux warning Renamed cEffects::soundeffect() to PlaySound() and removed unneeded overloads Fixed a bug causing executebatch to be set with locationcount data Rewrote cEffects::bgsound() Documented sounds.cpp Misc minor cleanups / fixes Removed: sendItemsInRange() (CChar::Teleport() does the same thing) Many #includes that were not being used deathMenu() respawnnow() and moved all of its code into command_respawn() one instance of cEffects::scpSoundEffect() and renamed the other to PlaySound() 3/13/2003 Changed Fixed an issue allowing the server to not have a dictionary.ZRO (which would cause a crash when a dictionary entry was called with no language) Fixed an issue causing the server to puke when it attempted a restart Moved SpawnRandomItem() into cItem class Moved SpawnRandomMonster() into cCharHandle class Broke necro.dfn into fishing.dfn and digging.dfn Made better use of SpawnRandomItem() and SpawnRandomMonster() 3/12/2003 Added: CPOpenGump and CPSpeech packet class to remove some global vars (Note these are pretty basic classes and someone with a better understanding of how we handle sending/recieving packets could probably expand these to make better use of them) Changed: Moved many global vars into the CWorldMain() class Cleaned ResetVars() in uox3.cpp as ResetDefaults() in CWorldMain() now handles much of that Added a check to ensure text wasn't sent twice in talking(), should fix double-speech Cleaned up cmdtable.cpp removing a couple duplicate entries, etc Changed target() to only require 4 values (as the first two were always 0 and 1) Removed many unneeded typedefs and globals Went through cServerData() and noted unused server.ini entries Moved title1(), title2(), and title3() to cClick.cpp since that is their only usage, made use of MAX_TITLE to ensure we wouldn't overrun the buffers, and renamed them matching what title they were 3/11/2003 Changed: Fixed a potentially very serious bugs with how containers were being set upon loading the world Fixed possible re-adding of weight to containers and characters at load Fixed a bug causing equipped items that were not weapons to take damage in combat Minor cleanups / warning fixes / Linux compatability issues (punt) 3/7/2003 Overhauls/Additions/Major Changes Changed: Tweaks/Object Conversions/Misc Small Changes Changed: Changed CItem::Get/SetLayer() to a UI08 Fixed a bug in speech causing you to see your own text twice Fixed a nasty crash bug
2003-03-23 10:18:02 +00:00
#include "uox3.h"
#include "cHTMLSystem.h"
2002-10-25 04:57:23 +00:00
#include "cVersionClass.h"
Added: -JS Get/Set "vulnerable" handlers for character properties (Abaddon) -willHunger with Get/Set HungerStatus() wrappers to CChar class (can now selectively stop a character/creature from continuing to hunger) -JS Get/Set "willhunger" handlers for character properties Changed: Linux compile fixes (thanks Malketh) Hash.h warning fixed (thanks Philantrop) Fixes to getRootPack() and getPackOwner() Removed many #includes from the global scope, including them in the specific files that need them This should greatly reduce compile time and filesize, along with the need to recompile after altering most headers Removed the linux ifdefs around typedefd function declarations, this should work with gcc 3.2 Moved global loading functions into a new cFileIO() class to take them out of global scope Fixed an issue causing items to not be sent to the client (thanks Malketh) Moved some global structs into the CWorldMain class Fixed a bug causing a crash on character / item creation Moved all effects stuff into its own class to take it out of global scope Changed the variable CChar::region to CChar::regionNum to avoid conflicts with the cTownRegion region[] indexes Moved getbestskill(), isHuman(), and inDungeon() into the CChar class to remove them from global scope Took npcSimpleAttackTarget() out of global scope Rewrote restock() to make use of restockNPC() Changed the typedef'd iterator in hash.h to HASHITERATOR to kill a Linux warning Renamed cEffects::soundeffect() to PlaySound() and removed unneeded overloads Fixed a bug causing executebatch to be set with locationcount data Rewrote cEffects::bgsound() Documented sounds.cpp Misc minor cleanups / fixes Removed: sendItemsInRange() (CChar::Teleport() does the same thing) Many #includes that were not being used deathMenu() respawnnow() and moved all of its code into command_respawn() one instance of cEffects::scpSoundEffect() and renamed the other to PlaySound() 3/13/2003 Changed Fixed an issue allowing the server to not have a dictionary.ZRO (which would cause a crash when a dictionary entry was called with no language) Fixed an issue causing the server to puke when it attempted a restart Moved SpawnRandomItem() into cItem class Moved SpawnRandomMonster() into cCharHandle class Broke necro.dfn into fishing.dfn and digging.dfn Made better use of SpawnRandomItem() and SpawnRandomMonster() 3/12/2003 Added: CPOpenGump and CPSpeech packet class to remove some global vars (Note these are pretty basic classes and someone with a better understanding of how we handle sending/recieving packets could probably expand these to make better use of them) Changed: Moved many global vars into the CWorldMain() class Cleaned ResetVars() in uox3.cpp as ResetDefaults() in CWorldMain() now handles much of that Added a check to ensure text wasn't sent twice in talking(), should fix double-speech Cleaned up cmdtable.cpp removing a couple duplicate entries, etc Changed target() to only require 4 values (as the first two were always 0 and 1) Removed many unneeded typedefs and globals Went through cServerData() and noted unused server.ini entries Moved title1(), title2(), and title3() to cClick.cpp since that is their only usage, made use of MAX_TITLE to ensure we wouldn't overrun the buffers, and renamed them matching what title they were 3/11/2003 Changed: Fixed a potentially very serious bugs with how containers were being set upon loading the world Fixed possible re-adding of weight to containers and characters at load Fixed a bug causing equipped items that were not weapons to take damage in combat Minor cleanups / warning fixes / Linux compatability issues (punt) 3/7/2003 Overhauls/Additions/Major Changes Changed: Tweaks/Object Conversions/Misc Small Changes Changed: Changed CItem::Get/SetLayer() to a UI08 Fixed a bug in speech causing you to see your own text twice Fixed a nasty crash bug
2003-03-23 10:18:02 +00:00
#include "cGuild.h"
#include "townregion.h"
#include "cRaces.h"
#include "cServerDefinitions.h"
#include "ssection.h"
#include "gump.h"
#include "scriptc.h"
#include "packets.h"
2002-10-25 04:57:23 +00:00
extern cVersionClass CVC;
2002-04-07 20:53:41 +00:00
cHTMLTemplate::cHTMLTemplate()
{
}
cHTMLTemplate::~cHTMLTemplate()
{
}
//o---------------------------------------------------------------------------o
//| Function - cHTMLTemplate::Process
//| Programmer - Dark-Storm
//o---------------------------------------------------------------------------o
//| Purpose - Parses a template
//o---------------------------------------------------------------------------o
//o--------------------------------------------------------------------------o
//| Function - void cHTMLTemplate::Process( void )
//| Date - 1/18/2003 4:43:17 AM
//| Developers - DarkStorm / EviLDeD
//| Organization -UOX3 DevTeam
//| Status - Currently under development
//o--------------------------------------------------------------------------o
//| Description -
//o--------------------------------------------------------------------------o
//| Modifications -
//o--------------------------------------------------------------------------o
2002-04-07 20:53:41 +00:00
void cHTMLTemplate::Process( void )
{
// Only read the Status Page if it's not already loaded
if( !Loaded )
LoadTemplate();
// Parse the Content...
std::string ParsedContent = Content;
2002-04-07 20:53:41 +00:00
//***************************************/
// Replacing Placeholders
//***************************************/
int Pos;
// Account-Count
char AccountCount[32];
sprintf(AccountCount, "%d", Accounts->size());
2002-04-07 20:53:41 +00:00
for( Pos = ParsedContent.find("%accounts"); Pos >= 0; Pos = ParsedContent.find( "%accounts" ) )
{
ParsedContent.replace( Pos, 9, AccountCount );
}
// Version
std::string Version = CVC.GetVersion();
Version += "(";
2002-10-25 04:57:23 +00:00
Version += CVC.GetBuild();
Version += ")";
Changed: -Fixed a potentially very serious bugs with how containers were being set upon loading the world -Fixed possible re-adding of weight to containers and characters at load -Fixed a bug causing equipped items that were not weapons to take damage in combat -Minor cleanups / warning fixes / Linux compatability issues (punt) -Changed CItem::Get/SetLayer() to a UI08 -Fixed a bug in speech causing you to see your own text twice -Fixed a nasty crash bug caused by changing an items layer -Fixed a bug causing NPC's to always be the first attacker -Armor DEF system overhauled to match OSI system -Updated Hash Table Remove() calls to remove unrefrenced parameter "index" -Changed cSocket::Get/SetDWord() to a UI32 to fix problems checking it against INVALIDSERIAL and storing large serial numbers -Changed cSocket::AddID() to a UI32 for the same reason as above -Changed cSocket:::Get/SetWord() to a UI16 to fix possible problems storing ID's -Fixed up calcStealDiff() to match new weight system -Minor updates to CPStatsWindow to match the new Armor DEF system and Weight system -Fixed calls to getTileName() so the names container was set with MAX_NAME -Fixed up getFieldDir() using direction typedefs -Changed Get/SetMagic() to Get/SetMovable() -Cleaned up some unrefrenced params -Changed some int's to UI16's in books.cpp -WorldSave Changes: -XYZ and worldnum to Location=x,y,z,worldnum -HiDamage and LoDamage into Damage=hidamage,lodamage -Strength,st2,Dexterity,dx2,Intelligence,in2 changed to Strength=str,st2, Intelligence=int,in2, Dexterity=dex,dx2 -DWord0-3 changed to DWords=0,1,2,3 -FX1,FY1,FX2,FY2,FZ1 changed to WanderArea=FX1,FY1,FX2,FY2,FZ1 -MoreX,MoreY,MoreZ changed to MoreXYZ=morex,morey,morez -More,More2 changed to More=more,more2 -Type,Type2 changed to Type=type,type2 -Light,Rain,Heat,Cold,Snow,Lightning changed to RaceDamage=Light,Rain,Heat,Cold,Snow,Lightning -Fame,Karma,Kills changed to Reputation=fame,karma,kills -Complete rewrite to the Weight system -Weight is more permanent, removed need to recalc it constantly -Packs now show the weight of themselves and all their contents -Packs now have a weight limit (currently hardcapped to 400, should make it based on type of container and possibly scriptable) -All items use the weight value given to them in the scripts unless the entry is 0 in which case they pull weight from the MUL's -Better handling of overloaded for teleport / recall / walking -Weight will max out at 65535 stones and can not go lower than 0 stones -Items container is now set as a cBaseObject -Fixed up itemsfx() and renamed it to itemSound(), now better handles Gold sfx and where an item was dropped (ie in a pack or on the ground) -Cleaned up goldsfx() and renamed it to goldSound() -Many fixes to get/drop/wear/packItem functions -Minor fixes/cleanups in movement.cpp -Fixed a worldsave crash with tamed creatures -Pressing 0 in console reloads items as well as everything else -Made dagger usable for carve again -Fixed a horse mounting distance check -Noted (and in some cases fixed) unrefrenced variables throughout the code -Converted inscribe.gmp to inscribe.dfn and used NewMakeMenu() in favor of the old make menu system -Updated GetMagic() == 3 calls to IsLockedDown() calls (as that is all it should be used for) -Fixed up all IsLockedDown() calls, resources that are LockedDown can NOT be used, even by GM, until released -Also note, items that should be usable if locked: Skill items (looms, training dummies, etc, Recall runes) -Moved the two functions from newbie.cpp to pcmanage.cpp and removed newbie.cpp from the project -Moved action() and impaction() to effects.cpp -Moved isHuman() to npcs.cpp -Where possible made functions that were part of classes private -Made use of cCombat::getWeaponTyp
2003-03-13 09:05:58 +00:00
Version += " [";
Version += OS_STR;
Version += "]";
2002-04-07 20:53:41 +00:00
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;
2002-09-29 04:49:07 +00:00
CChar *tChar = NULL;
2002-04-07 20:53:41 +00:00
for( tSock = Network->FirstSocket(); !Network->FinishedSockets(); tSock = Network->NextSocket() )
{
2002-09-29 04:49:07 +00:00
tChar = tSock->CurrcharObj();
try
{
if( tChar == NULL )
continue;
2002-09-29 04:49:07 +00:00
if( tChar->IsGM() )
gm++;
else if( tChar->IsCounselor() )
cns++;
else
ccount++;
}
catch(...)
{
continue;
}
2002-04-07 20:53:41 +00:00
}
Network->PopConn();
// GMs
char GMCount[32];
sprintf( GMCount, "%d", gm );
for( Pos = ParsedContent.find( "%online_gms" ); Pos >= 0; Pos = ParsedContent.find( "%online_gms" ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 11, GMCount ):ParsedContent.replace( Pos, 11, "0" );
2002-04-07 20:53:41 +00:00
}
// Counselor
char CounsiCount[32];
sprintf( CounsiCount, "%d", cns );
for( Pos = ParsedContent.find( "%online_couns" ); Pos >= 0; Pos = ParsedContent.find( "%online_couns" ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 13, CounsiCount ):ParsedContent.replace( Pos, 13, "0");
2002-04-07 20:53:41 +00:00
}
// Player
char PlayerCount[32];
sprintf( PlayerCount, "%d", ccount );
for( Pos = ParsedContent.find( "%online_player" ); Pos >= 0; Pos = ParsedContent.find( "%online_player" ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 14, PlayerCount ):ParsedContent.replace( Pos, 14, "0" );
2002-04-07 20:53:41 +00:00
}
// Total
char AllCount[32];
sprintf( AllCount, "%d", (ccount + gm + cns) );
for( Pos = ParsedContent.find( "%online_all" ); Pos >= 0; Pos = ParsedContent.find( "%online_all" ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 11, AllCount ):ParsedContent.replace( Pos, 11, "0" );
2002-04-07 20:53:41 +00:00
}
//RealTime( time_str )
char time_str[80];
RealTime( time_str );
for( Pos = ParsedContent.find( "%time" ); Pos >= 0; Pos = ParsedContent.find( "%time" ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 5, time_str ):ParsedContent.replace( Pos, 5, "Down" );
2002-04-07 20:53:41 +00:00
}
// 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 ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, strlen(ipToken), mServ->getIP().c_str()):ParsedContent.replace( Pos, strlen(ipToken), "Down" );
2002-04-07 20:53:41 +00:00
}
}
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->getPort() );
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, strlen( portToken ), myPort ):ParsedContent.replace( Pos, strlen( portToken ), "NA" );
2002-04-07 20:53:41 +00:00
}
}
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 ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, strlen( serverToken ), mServ->getName().c_str() ):ParsedContent.replace( Pos, strlen( serverToken ), "Down" );
2002-04-07 20:53:41 +00:00
}
}
}
}
// PLAYERLIST
for( Pos = ParsedContent.find( "%playerlist%" ); Pos >= 0; Pos = ParsedContent.find( "%playerlist%" ) )
{
UI32 SecondPos = ParsedContent.find( "%playerlist%", Pos+1 );
std::string myInline = ParsedContent.substr( Pos, SecondPos - Pos + 12 );
std::string PlayerList;
2002-04-07 20:53:41 +00:00
Network->PushConn();
for( tSock = Network->FirstSocket(); !Network->FinishedSockets(); tSock = Network->NextSocket() )
{
try
2002-04-07 20:53:41 +00:00
{
if( tSock != NULL )
2002-04-07 20:53:41 +00:00
{
CChar *tChar = tSock->CurrcharObj();
if( tChar != NULL )
2002-04-07 20:53:41 +00:00
{
std::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" ) )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 11, tChar->GetName() ):parsedInline.replace( sPos, 11, "" );
}
// PlayerTitle
for( sPos = parsedInline.find( "%playertitle" ); sPos >= 0; sPos = parsedInline.find( "%playertitle" ) )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 12, tChar->GetTitle() ):parsedInline.replace( sPos, 12, "" );
}
// 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() );
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 9, ClientIP ):parsedInline.replace( sPos, 9, "" );
}
// PlayerAccount
for( sPos = parsedInline.find( "%playeraccount" ); sPos >= 0; sPos = parsedInline.find( "%playeraccount" ) )
{
ACCOUNTSBLOCK toScan;
toScan=tChar->GetAccount();
if( toScan.wAccountIndex!=AB_INVALID_ID)
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 14, toScan.sUsername):parsedInline.replace( sPos, 14, "" );
}
// PlayerX
for( sPos = parsedInline.find( "%playerx" ); sPos >= 0; sPos = parsedInline.find( "%playerx" ) )
{
char myX[5];
sprintf( myX, "%i", tChar->GetX() );
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 8, myX ):parsedInline.replace( sPos, 8, "" );
}
// PlayerY
for( sPos = parsedInline.find( "%playery" ); sPos >= 0; sPos = parsedInline.find( "%playery" ) )
{
char myY[5];
sprintf( myY, "%i", tChar->GetY() );
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 8, myY ):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() );
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 8, myZ ):parsedInline.replace( sPos, 8, "" );
}
// 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 )
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 11, myRaceName ):parsedInline.replace( sPos, 11, "");
delete [] myRaceName;
}
// PlayerRegion
for( sPos = parsedInline.find( "%playerregion" ); sPos >= 0; sPos = parsedInline.find( "%playerregion" ) )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 13, region[tChar->GetRegion()]->GetName() ):parsedInline.replace( sPos, 13, "");
}
PlayerList += parsedInline;
2002-04-07 20:53:41 +00:00
}
}
}
catch(...)
{
Console << "| EXCEPTION: Invalid character/socket pointer found. Ignored." << myendl;
}
2002-04-07 20:53:41 +00:00
}
Network->PopConn();
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, myInline.length(), PlayerList ):ParsedContent.replace( Pos, myInline.length(), "");
2002-04-07 20:53:41 +00:00
}
// GuildCount
char GuildCount[32];
sprintf( GuildCount, "%d", GuildSys->NumGuilds() );
for( Pos = ParsedContent.find( "%guildcount" ); Pos >= 0; Pos = ParsedContent.find( "%guildcount" ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 11, PlayerCount ):ParsedContent.replace( Pos, 11, "" );
2002-04-07 20:53:41 +00:00
}
// GUILDLIST
for( Pos = ParsedContent.find( "%guildlist%" ); Pos >= 0; Pos = ParsedContent.find( "%guildlist%" ) )
{
UI32 SecondPos = ParsedContent.find( "%guildlist%", Pos+1 );
std::string myInline = ParsedContent.substr( Pos, SecondPos - Pos + 11 );
std::string GuildList;
2002-04-07 20:53:41 +00:00
for( SI16 i = 0; i < (SI16)GuildSys->NumGuilds(); i++ )
{
std::string parsedInline = myInline;
2002-04-07 20:53:41 +00:00
parsedInline.replace( 0, 11, "" );
parsedInline.replace( parsedInline.length()-11, 11, "" );
//parsedInline += "Yeah it worked";
2002-04-07 20:53:41 +00:00
// 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" ) )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 8, GuildID ):parsedInline.replace( sPos, 8, "" );
2002-04-07 20:53:41 +00:00
}
// GuildName
for( sPos = parsedInline.find( "%guildname" ); sPos >= 0; sPos = parsedInline.find( "%guildname" ) )
{
(cwmWorldState->GetKeepRun())?parsedInline.replace( sPos, 10, myGuild->Name() ):parsedInline.replace( sPos, 10, "" );
2002-04-07 20:53:41 +00:00
}
GuildList += parsedInline;
}
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, myInline.length(), GuildList ):ParsedContent.replace( Pos, myInline.length(), "" );
2002-04-07 20:53:41 +00:00
}
//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" ) )
{
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 5, npcs ):ParsedContent.replace( Pos, 5, "0" );
2002-04-07 20:53:41 +00:00
}
// Performance Dump
R64 eps = 0.00000000001;
for( Pos = ParsedContent.find( "%performance" ); Pos >= 0; Pos = ParsedContent.find( "%performance" ) )
{
std::string performance;
std::ostringstream myStream( performance );
if(cwmWorldState->GetKeepRun())
{
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> ";
}
else
{
myStream << "Network code: 0" << "<BR>";
myStream << "Timer code: 0" << "<BR>";
myStream << "Auto code: 0" << "<BR>";
myStream << "Loop Time: 0" << "<BR>";
myStream << "Simulation Cycles: 0<BR>";
}
2002-04-07 20:53:41 +00:00
ParsedContent.replace(Pos, 12, myStream.str());
}
// Uptime
for( Pos = ParsedContent.find( "%uptime" ); Pos >= 0; Pos = ParsedContent.find( "%uptime" ) )
{
std::string uptime;
2002-04-07 20:53:41 +00:00
char sh[3], sm[3], ss[3];
std::ostringstream myStream( uptime );
2002-04-07 20:53:41 +00:00
UI32 total, hr, min, sec;
total = (cwmWorldState->GetUICurrentTime() - cwmWorldState->GetStartTime() ) / CLOCKS_PER_SEC;
2002-04-07 20:53:41 +00:00
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" ) )
{
std::string simcycles;
std::ostringstream myStream( simcycles );
2002-04-07 20:53:41 +00:00
if(cwmWorldState->GetKeepRun())
{
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> ";
}
else
{
myStream << "Simulation Cycles: 0<BR> ";
}
2002-04-07 20:53:41 +00:00
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 );
(cwmWorldState->GetKeepRun())?ParsedContent.replace( Pos, 11, strUpdateTimer ):ParsedContent.replace( Pos, 11, "0" );
2002-04-07 20:53:41 +00:00
}
//***************************************/
// End Replacing Placeholders
//***************************************/
// Print the Content out to the new file...
std::ofstream Output( OutputFile );
2002-04-07 20:53:41 +00:00
if( !Output.is_open() )
{
2003-03-04 13:53:59 +00:00
Console.Error( 1, " Couldn't open the template file %s for writing", OutputFile );
2002-04-07 20:53:41 +00:00
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 < cwmWorldState->GetUICurrentTime() ) )
2002-04-07 20:53:41 +00:00
{
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 = "";
std::ifstream InputFile1( InputFile );
2002-04-07 20:53:41 +00:00
if( !InputFile1.is_open() )
{
Console.Error( 1, "Couldn't open HTML Template File %s", InputFile );
return;
}
while( !InputFile1.eof() )
{
std::string Line;
std::getline( InputFile1, Line );
2002-04-07 20:53:41 +00:00
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 )
{
2003-03-04 13:53:59 +00:00
VECSCRIPTLIST *toWalk = FileLookup->GetFiles( html_def );
2002-04-07 20:53:41 +00:00
if( toWalk == NULL )
return;
for( UI32 i = 0; i < toWalk->size(); i++ )
{
if( (*toWalk)[i] != NULL )
{
Script *toCheck = (*toWalk)[i];
if( toWalk == NULL )
continue;
2003-03-04 13:53:59 +00:00
SI32 NumEntries = toCheck->NumEntries();
2002-04-07 20:53:41 +00:00
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
std::string cHTMLTemplate::GetName( void )
2002-04-07 20:53:41 +00:00
{
return Name;
}
//o---------------------------------------------------------------------------o
//| Function - cHTMLTemplates::GetOutput
//| Programmer - Dark-Storm
//o---------------------------------------------------------------------------o
//| Purpose - Gets the Output Filename
//o---------------------------------------------------------------------------o
std::string cHTMLTemplate::GetOutput( void )
2002-04-07 20:53:41 +00:00
{
return OutputFile;
}
//o---------------------------------------------------------------------------o
//| Function - cHTMLTemplates::GetInput
//| Programmer - Dark-Storm
//o---------------------------------------------------------------------------o
//| Purpose - Gets the Input Filename
//o---------------------------------------------------------------------------o
std::string cHTMLTemplate::GetInput( void )
2002-04-07 20:53:41 +00:00
{
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;
}