Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32435
Modified Files:
customtags.h timers.cpp timers.h wolfpack.vcproj world.cpp
world.h
Log Message:
Binary saves almost completed.
Index: world.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/world.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** world.h 10 Aug 2004 03:15:57 -0000 1.18
--- world.h 16 Aug 2004 18:18:03 -0000 1.19
***************
*** 35,38 ****
--- 35,39 ----
// Library Includes
#include <qvaluevector.h>
+ #include <qmap.h>
#include "server.h"
***************
*** 78,81 ****
--- 79,83 ----
unsigned int _playerCount, _npcCount;
void loadTag( cBufferedReader& reader, unsigned int version );
+ QMap<QString, QString> options;
public:
***************
*** 90,95 ****
// For the "settings" table
! void getOption( const QString& name, QString& value, const QString fallback, bool newconnection = true );
! void setOption( const QString& name, const QString& value, bool newconnection = true );
// Book-keeping functions
--- 92,97 ----
// For the "settings" table
! void getOption( const QString& name, QString& value, const QString fallback );
! void setOption( const QString& name, const QString& value );
// Book-keeping functions
Index: customtags.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/customtags.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** customtags.h 10 Aug 2004 03:15:56 -0000 1.32
--- customtags.h 16 Aug 2004 18:18:03 -0000 1.33
***************
*** 54,59 ****
static const cVariant null;
! enum Type
! {
Invalid = 0,
String,
--- 54,58 ----
static const cVariant null;
! enum Type {
Invalid = 0,
String,
Index: wolfpack.vcproj
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/wolfpack.vcproj,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** wolfpack.vcproj 15 Aug 2004 02:17:39 -0000 1.41
--- wolfpack.vcproj 16 Aug 2004 18:18:03 -0000 1.42
***************
*** 81,87 ****
Optimization="3"
GlobalOptimizations="TRUE"
! InlineFunctionExpansion="1"
! EnableIntrinsicFunctions="FALSE"
! FavorSizeOrSpeed="2"
OptimizeForProcessor="0"
OptimizeForWindowsApplication="TRUE"
--- 81,87 ----
Optimization="3"
GlobalOptimizations="TRUE"
! InlineFunctionExpansion="2"
! EnableIntrinsicFunctions="TRUE"
! FavorSizeOrSpeed="1"
OptimizeForProcessor="0"
OptimizeForWindowsApplication="TRUE"
***************
*** 89,96 ****
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;QT_THREAD_SUPPORT;QT_LITE_COMPONENT;QT_DLL;QT_NO_STL;QT_NO_COMPRESS;CRASHHANDLER;MYSQL_DRIVER"
StringPooling="TRUE"
! MinimalRebuild="FALSE"
BasicRuntimeChecks="0"
RuntimeLibrary="2"
! StructMemberAlignment="3"
BufferSecurityCheck="FALSE"
EnableFunctionLevelLinking="FALSE"
--- 89,96 ----
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;QT_THREAD_SUPPORT;QT_LITE_COMPONENT;QT_DLL;QT_NO_STL;QT_NO_COMPRESS;CRASHHANDLER;MYSQL_DRIVER"
StringPooling="TRUE"
! MinimalRebuild="TRUE"
BasicRuntimeChecks="0"
RuntimeLibrary="2"
! StructMemberAlignment="0"
BufferSecurityCheck="FALSE"
EnableFunctionLevelLinking="FALSE"
Index: timers.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/timers.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** timers.cpp 13 Aug 2004 08:55:26 -0000 1.9
--- timers.cpp 16 Aug 2004 18:18:03 -0000 1.10
***************
*** 386,393 ****
effect = new cPythonEffect;
}
- else if ( objectId == "cDelayedHideChar" )
- {
- effect = new cDelayedHideChar;
- }
else
{
--- 386,389 ----
***************
*** 436,468 ****
}
-
- // cDelayedHideChar
- cDelayedHideChar::cDelayedHideChar( SERIAL serial )
- {
- if ( !isCharSerial( serial ) || !FindCharBySerial( serial ) )
- {
- destSer = INVALID_SERIAL;
- return;
- }
-
- destSer = serial;
- setSerializable( true );
- }
-
- cDelayedHideChar::cDelayedHideChar()
- {
- setSerializable( true );
- }
-
- void cDelayedHideChar::Expire()
- {
- P_PLAYER pc = dynamic_cast<P_PLAYER>( FindCharBySerial( destSer ) );
- if ( !pc || pc->socket() ) // break if the char has relogged in the meantime
- return;
-
- pc->setHidden( 1 );
- pc->resend( true );
- }
-
cDelayedOnCreateCall::cDelayedOnCreateCall( cUObject* obj, const QString& definition ) :
obj_(obj), def_(definition)
--- 432,435 ----
***************
*** 509,510 ****
--- 476,518 ----
}
}
+
+ void cTimer::load(cBufferedReader &reader, unsigned int version) {
+ serializable = true;
+ expiretime = Server::instance()->time() + reader.readInt();
+ dispellable = reader.readBool();
+ sourSer = reader.readInt();
+ destSer = reader.readInt();
+ }
+
+ void cTimer::save(cBufferedWriter &writer, unsigned int version) {
+ writer.writeInt(expiretime - Server::instance()->time());
+ writer.writeBool(dispellable);
+ writer.writeInt(sourSer);
+ writer.writeInt(destSer);
+ }
+
+ void cTimers::save(cBufferedWriter &writer) {
+ std::vector<cTimer*>::iterator it;
+ for (it = teffects.begin(); it != teffects.end(); ++it) {
+ if ((*it)->isSerializable()) {
+ writer.writeByte(0xFC);
+ writer.writeAscii((*it)->objectID().latin1());
+ (*it)->save(writer, writer.version());
+ }
+ }
+ }
+
+ void cTimers::load(cBufferedReader &reader) {
+ QCString objectId = reader.readAscii();
+
+ cTimer *timer = 0;
+
+ if (objectId == "cPythonEffect") {
+ timer = new cPythonEffect;
+ } else {
+ throw QString("Unknown TempEffect Type: %1").arg(objectId);
+ }
+
+ timer->load(reader, reader.version());
+ insert(timer);
+ }
Index: world.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/world.cpp,v
retrieving revision 1.113
retrieving revision 1.114
diff -C2 -d -r1.113 -r1.114
*** world.cpp 16 Aug 2004 14:58:59 -0000 1.113
--- world.cpp 16 Aug 2004 18:18:03 -0000 1.114
***************
*** 466,469 ****
--- 466,479 ----
// Special Type for Tags
}
+ else if ( type == 0xFB )
+ {
+ QString name = reader.readUtf8();
+ QString value = reader.readUtf8();
+ setOption(name, value);
+ }
+ else if ( type == 0xFC )
+ {
+ Timers::instance()->load(reader);
+ }
else if ( type == 0xFD )
{
***************
*** 521,525 ****
if ( !strcmp( tableInfo[i].name, "settings" ) )
{
! setOption( "db_version", WP_DATABASE_VERSION, false );
}
}
--- 531,535 ----
if ( !strcmp( tableInfo[i].name, "settings" ) )
{
! setOption("db_version", WP_DATABASE_VERSION);
}
}
***************
*** 583,586 ****
--- 593,603 ----
Timers::instance()->load();
+ // Load Options
+ cDBResult oresult = PersistentBroker::instance()->query("SELECT option,value FROM settings;");
+ while (oresult.fetchrow()) {
+ setOption(oresult.getString(0), oresult.getString(1));
+ }
+ oresult.free();
+
// It's not possible to use cItemIterator during postprocessing because it skips lingering items
ItemMap::iterator iter;
***************
*** 734,740 ****
cSpawnRegion *region = SpawnRegions::instance()->region( spawnregion );
cUObject *object = findObject( serial );
! if ( object && region )
{
! object->setSpawnregion( region );
}
}
--- 751,757 ----
cSpawnRegion *region = SpawnRegions::instance()->region( spawnregion );
cUObject *object = findObject( serial );
! if (object && region)
{
! object->setSpawnregion(region);
}
}
***************
*** 747,751 ****
QString db_time;
QString default_time = Config::instance()->getString( "General", "UO Time", "", true );
! getOption( "worldtime", db_time, default_time, false );
UoTime::instance()->setMinutes( db_time.toInt() );
--- 764,768 ----
QString db_time;
QString default_time = Config::instance()->getString( "General", "UO Time", "", true );
! getOption( "worldtime", db_time, default_time );
UoTime::instance()->setMinutes( db_time.toInt() );
***************
*** 757,764 ****
}
! void cWorld::save()
! {
Console::instance()->send( "Saving World..." );
- Timing::instance()->setLastWorldsave( getNormalizedTime() );
// Send a nice status gump to all sockets if enabled
--- 774,782 ----
}
! void cWorld::save() {
! // Broadcast a message to all connected clients
! Network::instance()->broadcast(tr("Worldsave Initialized"));
!
Console::instance()->send( "Saving World..." );
// Send a nice status gump to all sockets if enabled
***************
*** 789,795 ****
}
try
{
! unsigned int startTime = getNormalizedTime();
if (Config::instance()->databaseDriver() == "binary") {
--- 807,816 ----
}
+ unsigned int startTime = getNormalizedTime();
+
try
{
! // Save the Current Time
! setOption("worldtime", QString::number( UoTime::instance()->getMinutes() ));
if (Config::instance()->databaseDriver() == "binary") {
***************
*** 820,823 ****
--- 841,855 ----
}
+ // Write Temporary Effects
+ Timers::instance()->save(writer);
+
+ // Write Options
+ QMap<QString, QString>::iterator oit;
+ for (oit = options.begin(); oit != options.end(); ++oit) {
+ writer.writeByte(0xFB);
+ writer.writeUtf8(oit.key());
+ writer.writeUtf8(oit.data());
+ }
+
writer.writeByte( 0xFF ); // Terminator Type
writer.close();
***************
*** 889,903 ****
Guilds::instance()->save();
! PersistentBroker::instance()->commitTransaction();
! // Save the Current Time
! setOption( "worldtime", QString::number( UoTime::instance()->getMinutes() ), false );
! // Save the accounts
! Accounts::instance()->save();
PersistentBroker::instance()->disconnect();
}
Server::instance()->refreshTime();
--- 921,943 ----
Guilds::instance()->save();
! PersistentBroker::instance()->commitTransaction();
! // Write Options
! PersistentBroker::instance()->executeQuery("DELETE FROM settings;");
! QMap<QString, QString>::iterator oit;
! for (oit = options.begin(); oit != options.end(); ++oit) {
! QString sql = QString("INSERT INTO settings VALUES('%1','%2');")
! .arg(PersistentBroker::instance()->quoteString(oit.key()))
! .arg(PersistentBroker::instance()->quoteString(oit.data()));
! PersistentBroker::instance()->executeQuery(sql);
! }
PersistentBroker::instance()->disconnect();
}
+ // Save the accounts
+ Accounts::instance()->save();
+
Server::instance()->refreshTime();
***************
*** 919,922 ****
--- 959,965 ----
}
+ // Broadcast a message to all connected clients
+ Network::instance()->broadcast(tr("Worldsave Completed In %1ms").arg(Server::instance()->time() - startTime));
+
if ( fancy )
{
***************
*** 929,932 ****
--- 972,977 ----
}
}
+
+ Timing::instance()->setLastWorldsave( getNormalizedTime() );
}
***************
*** 934,973 ****
* Gets a value from the settings table and returns the value
*/
! void cWorld::getOption( const QString& name, QString& value, const QString fallback, bool newconnection )
{
! if ( newconnection )
! {
! if ( !PersistentBroker::instance()->openDriver( Config::instance()->databaseDriver() ) )
! {
! Console::instance()->log( LOG_ERROR, QString( "Unknown Worldsave Database Driver '%1', check your wolfpack.xml" ).arg( Config::instance()->databaseDriver() ) );
! return;
! }
!
! try
! {
! PersistentBroker::instance()->connect( Config::instance()->databaseHost(), Config::instance()->databaseName(), Config::instance()->databaseUsername(), Config::instance()->databasePassword() );
! }
! catch ( QString& e )
! {
! Console::instance()->log( LOG_ERROR, QString( "Couldn't open the database: %1\n" ).arg( e ) );
! return;
! }
! }
!
! cDBResult res = PersistentBroker::instance()->query( QString( "SELECT option,value FROM settings WHERE option='%1' LIMIT 1;" ).arg( PersistentBroker::instance()->quoteString( name ) ) );
!
! if ( !res.fetchrow() )
! {
value = fallback;
! }
! else
! {
! value = res.getString( 1 );
! }
! res.free();
!
! if ( newconnection )
! {
! PersistentBroker::instance()->disconnect();
}
}
--- 979,989 ----
* Gets a value from the settings table and returns the value
*/
! void cWorld::getOption( const QString& name, QString& value, const QString fallback )
{
! QMap<QString, QString>::iterator it = options.find(name);
! if (it == options.end()) {
value = fallback;
! } else {
! value = it.data();
}
}
***************
*** 976,1012 ****
* Sets a value in the settings table.
*/
! void cWorld::setOption( const QString& name, const QString& value, bool newconnection )
{
! if ( newconnection )
! {
! if ( !PersistentBroker::instance()->openDriver( Config::instance()->databaseDriver() ) )
! {
! Console::instance()->log( LOG_ERROR, QString( "Unknown Worldsave Database Driver '%1', check your wolfpack.xml" ).arg( Config::instance()->databaseDriver() ) );
! return;
! }
!
! try
! {
! if ( !PersistentBroker::instance()->driver() )
! {
! PersistentBroker::instance()->connect( Config::instance()->databaseHost(), Config::instance()->databaseName(), Config::instance()->databaseUsername(), Config::instance()->databasePassword() );
! }
! }
! catch ( QString& e )
! {
! Console::instance()->log( LOG_ERROR, QString( "Couldn't open the database: %1\n" ).arg( e ) );
! return;
! }
! }
!
! // check if the option already exists
! PersistentBroker::instance()->addToDeleteQueue( "settings", QString( "option = '%1'" ).arg( name ) );
!
! PersistentBroker::instance()->executeQuery( QString( "REPLACE INTO settings VALUES( '%1', '%2' );" ).arg( PersistentBroker::instance()->quoteString( name ), PersistentBroker::instance()->quoteString( value ) ) );
!
! if ( newconnection )
! {
! PersistentBroker::instance()->disconnect();
! }
}
--- 992,998 ----
* Sets a value in the settings table.
*/
! void cWorld::setOption( const QString& name, const QString& value )
{
! options.insert(name, value, true);
}
Index: timers.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/timers.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** timers.h 12 Aug 2004 03:02:51 -0000 1.5
--- timers.h 16 Aug 2004 18:18:03 -0000 1.6
***************
*** 41,44 ****
--- 41,46 ----
class cScriptTimer;
class cTimers;
+ class cBufferedReader;
+ class cBufferedWriter;
// Wolfpack includes
***************
*** 84,88 ****
bool loadItem( unsigned int id, const QString& key, P_ITEM& item );
! public:
// cTimer() { serializable = true; }
cTimer( cTimer* left_ = NULL, cTimer* right_ = NULL, cTimer* father_ = NULL, cTimer* son_ = NULL, int rank_ = 0, bool marker_ = false )
--- 86,92 ----
bool loadItem( unsigned int id, const QString& key, P_ITEM& item );
! virtual void load(cBufferedReader &reader, unsigned int version);
! virtual void save(cBufferedWriter &writer, unsigned int version);
!
// cTimer() { serializable = true; }
cTimer( cTimer* left_ = NULL, cTimer* right_ = NULL, cTimer* father_ = NULL, cTimer* son_ = NULL, int rank_ = 0, bool marker_ = false )
***************
*** 149,164 ****
};
- class cDelayedHideChar : public cTimer
- {
- public:
- cDelayedHideChar( SERIAL serial );
- cDelayedHideChar();
- void Expire();
- QString objectID() const
- {
- return "cDelayedHideChar";
- }
- };
-
class cDelayedOnCreateCall : public cTimer
{
--- 153,156 ----
***************
*** 192,195 ****
--- 184,189 ----
void load();
void save();
+ void save(cBufferedWriter &writer);
+ void load(cBufferedReader &reader);
void check();
|