Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1:/tmp/cvs-serv2057/src
Modified Files:
basechar.cpp basechar.h books.cpp books.h dbdriver.cpp
dbdriver.h items.cpp items.h npc.cpp npc.h
persistentbroker.cpp persistentbroker.h player.cpp player.h
srvparams.cpp srvparams.h uobject.h wolf.dsp wolf.dsw
wolfpack.cpp world.cpp world.h
Removed Files:
basechar_flatstore.cpp flatstore_keys.h item_flatstore.cpp
npc_flatstore.cpp player_flatstore.cpp uobject_flatstore.cpp
Log Message:
Implemented SQLite support.
driver=sqlite
database name is the filename
Index: basechar.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.cpp,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** basechar.cpp 26 Aug 2003 03:55:13 -0000 1.34
--- basechar.cpp 26 Aug 2003 15:01:05 -0000 1.35
***************
*** 249,253 ****
addStrField( "name", orgName_ );
addStrField( "title", title_ );
! addField( "creationdate", creationDate_.toString() );
addField( "body", bodyID_ );
addField( "orgbody", orgBodyID_ );
--- 249,253 ----
addStrField( "name", orgName_ );
addStrField( "title", title_ );
! addStrField( "creationdate", creationDate_.toString() );
addField( "body", bodyID_ );
addField( "orgbody", orgBodyID_ );
Index: basechar.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** basechar.h 21 Aug 2003 01:02:41 -0000 1.23
--- basechar.h 26 Aug 2003 15:01:05 -0000 1.24
***************
*** 82,88 ****
void load( char **, ushort& );
void save();
- void save( FlatStore::OutputFile*, bool first = false ) throw();
- bool load( unsigned char chunkGroup, unsigned char chunkType, FlatStore::InputFile* ) throw();
- bool postload() throw();
bool del();
--- 82,85 ----
Index: books.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/books.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** books.cpp 21 Aug 2003 01:02:41 -0000 1.41
--- books.cpp 26 Aug 2003 15:01:05 -0000 1.42
***************
*** 39,46 ****
#include "globals.h"
- // Flatstore
- #include "flatstore_keys.h"
- #include "flatstore/flatstore.h"
-
#include <qregexp.h>
#include <qsqlcursor.h>
--- 39,42 ----
***************
*** 62,66 ****
UObjectFactory::instance()->registerType( "cBook", productCreator );
- UObjectFactory::instance()->registerType( QString::number( CHUNK_BOOK ), productCreator );
}
--- 58,61 ----
***************
*** 120,216 ****
BOOK_PAGES, // unsigned short + count * utf8
};
-
- void cBook::save( FlatStore::OutputFile *output, bool first ) throw()
- {
- cItem::save( output, first );
- return;
-
- if( first )
- output->startObject( serial_, CHUNK_BOOK );
-
- cItem::save( output );
-
- output->startChunkGroup( CHUNK_BOOK );
-
- if( predefined_ )
- output->startChunk( BOOK_PREDEFINED );
-
- if( readonly_ )
- output->startChunk( BOOK_READONLY );
-
- if( !title_.isNull() && !title_.isEmpty() )
- output->chunkData( BOOK_TITLE, (const char*)title_.utf8().data() );
-
- if( !author_.isNull() && !author_.isEmpty() )
- output->chunkData( BOOK_AUTHOR, (const char*)author_.utf8().data() );
-
- if( !section_.isNull() && !section_.isEmpty() )
- output->chunkData( BOOK_SECTION, (const char*)section_.utf8().data() );
-
- // Write pages
- output->chunkData( BOOK_PAGES, (unsigned short)pages_ );
-
- unsigned int i;
- for( i = 0; i < pages_; ++i )
- {
- if( i >= content_.count() )
- output->writeString( "" );
- else
- output->writeString( content_[i].utf8().data() );
- }
-
- if( first )
- output->finishObject();
- }
-
- bool cBook::load( unsigned char chunkGroup, unsigned char chunkType, FlatStore::InputFile *input ) throw()
- {
- // if( chunkGroup != CHUNK_BOOK )
- return cItem::load( chunkGroup, chunkType, input );
- /*
- unsigned int i;
-
- switch( chunkType )
- {
- case BOOK_PREDEFINED:
- predefined_ = true;
- break;
-
- case BOOK_READONLY:
- readonly_ = true;
- break;
-
- case BOOK_TITLE:
- title_ = QString::fromUtf8( input->readString() );
- break;
-
- case BOOK_AUTHOR:
- author_ = QString::fromUtf8( input->readString() );
- break;
-
- case BOOK_SECTION:
- section_ = QString::fromUtf8( input->readString() );
- break;
-
- case BOOK_PAGES:
- input->readUShort( pages_ );
- content_.clear();
-
- for( i = 0; i < pages_; ++i )
- content_.push_back( QString::fromUtf8( input->readString() ) );
-
- break;
-
- default:
- return false;
- };
-
- return true;*/
- }
-
- bool cBook::postload() throw()
- {
- return cItem::postload();
- }
void cBook::save()
--- 115,118 ----
Index: books.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/books.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** books.h 21 Aug 2003 05:04:35 -0000 1.27
--- books.h 26 Aug 2003 15:01:05 -0000 1.28
***************
*** 63,71 ****
virtual void flagUnchanged() { cBook::changed_ = false; cItem::flagUnchanged(); }
- // FlatStore
- void save( FlatStore::OutputFile*, bool first = false ) throw();
- bool load( unsigned char chunkGroup, unsigned char chunkType, FlatStore::InputFile* ) throw();
- bool postload() throw();
-
// setters/getters
QString title( void ) const;
--- 63,66 ----
Index: dbdriver.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/dbdriver.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** dbdriver.cpp 9 May 2003 05:11:33 -0000 1.16
--- dbdriver.cpp 26 Aug 2003 15:01:05 -0000 1.17
***************
*** 44,47 ****
--- 44,48 ----
#include <errmsg.h>
#include <stdlib.h>
+ #include "sqlite/sqlite.h"
/*****************************************************************************
***************
*** 64,68 ****
cDBDriver::~cDBDriver()
{
! close();
}
--- 65,69 ----
cDBDriver::~cDBDriver()
{
! //close();
}
***************
*** 78,88 ****
if ( !connection )
throw QString("mysql_init(): insufficient memory to allocate a new object");
- connection->reconnect = 1;
! if ( !mysql_real_connect(connection, _host.latin1(), _username.latin1(), _password.latin1(), _dbname.latin1(), 0, 0, CLIENT_COMPRESS ) )
{ // Named pipes are acctually slower :(
! throw QString( "Connection to DB failed: %1" ).arg( mysql_error( connection ) );
}
! connections[ id ] = connection;
return true;
--- 79,90 ----
if ( !connection )
throw QString("mysql_init(): insufficient memory to allocate a new object");
! ( (MYSQL*)connection )->reconnect = 1;
!
! if ( !mysql_real_connect((MYSQL*)connection, _host.latin1(), _username.latin1(), _password.latin1(), _dbname.latin1(), 0, 0, CLIENT_COMPRESS ) )
{ // Named pipes are acctually slower :(
! throw QString( "Connection to DB failed: %1" ).arg( mysql_error( (MYSQL*)connection ) );
}
! connections[ id ] = (MYSQL*)connection;
return true;
***************
*** 94,98 ****
void cDBDriver::close()
{
! mysql_close( connection );
}
--- 96,100 ----
void cDBDriver::close()
{
! mysql_close( (MYSQL*)connection );
}
***************
*** 103,107 ****
cDBResult cDBDriver::query( const QString &query )
{
! MYSQL *mysql = connection;
if( !mysql )
--- 105,109 ----
cDBResult cDBDriver::query( const QString &query )
{
! MYSQL *mysql = (MYSQL*)connection;
if( !mysql )
***************
*** 121,139 ****
Returns true if executed successfully.
*/
! bool cDBDriver::exec( const QString &query ) const
{
if( !connection )
throw QString( "Not connected to mysql server. Unable to execute query." );
! bool ok = !mysql_query( connection, query.latin1() );
return ok;
}
! void cDBDriver::lockTable( const QString& table ) const
{
exec( QString("LOCK TABLES %1 WRITE;").arg(table) );
}
! void cDBDriver::unlockTable( const QString& table ) const
{
exec( QString("UNLOCK TABLES") );
--- 123,141 ----
Returns true if executed successfully.
*/
! bool cDBDriver::exec( const QString &query )
{
if( !connection )
throw QString( "Not connected to mysql server. Unable to execute query." );
! bool ok = !mysql_query( (MYSQL*)connection, query.latin1() );
return ok;
}
! void cDBDriver::lockTable( const QString& table )
{
exec( QString("LOCK TABLES %1 WRITE;").arg(table) );
}
! void cDBDriver::unlockTable( const QString& table )
{
exec( QString("UNLOCK TABLES") );
***************
*** 143,147 ****
QString cDBDriver::error()
{
! const char *error = mysql_error( connection );
if( error != 0 )
--- 145,149 ----
QString cDBDriver::error()
{
! const char *error = mysql_error( (MYSQL*)connection );
if( error != 0 )
***************
*** 178,183 ****
return false;
! _row = mysql_fetch_row( _result );
! return ( _row != 0 );
}
--- 180,195 ----
return false;
! if( mysql_type )
! {
! _row = mysql_fetch_row( (st_mysql_res*)_result );
! return ( _row != 0 );
! }
! else
! {
! int count;
! const char **columns;
!
! return ( sqlite_step( (sqlite_vm*)_result, &count, (const char***)&_row, &columns ) == SQLITE_ROW );
! }
}
***************
*** 185,189 ****
void cDBResult::free()
{
! mysql_free_result( _result );
_result = 0;
_row = 0;
--- 197,222 ----
void cDBResult::free()
{
! if( mysql_type )
! {
! mysql_free_result( (st_mysql_res*)_result );
! }
! else
! {
! char *error;
! if( sqlite_finalize( (sqlite_vm*)_result, &error ) != SQLITE_OK )
! {
! if( error )
! {
! QString err( error );
! sqlite_freemem( error );
! throw err;
! }
! else
! {
! throw QString( "Unknown SQLite error while finalizing query." );
! }
! }
! }
!
_result = 0;
_row = 0;
***************
*** 213,215 ****
--- 246,331 ----
return _row[offset];
+ }
+
+ /*****************************************************************************
+ cSQLiteDriver member functions
+ *****************************************************************************/
+
+ bool cSQLiteDriver::open( int id )
+ {
+ char *error = NULL;
+
+ close();
+
+ connection = sqlite_open( _dbname.latin1(), 0, &error );
+
+ if( !connection )
+ {
+ if( error )
+ {
+ QString err( error );
+ sqlite_freemem( error );
+ throw err;
+ }
+ else
+ {
+ throw QString( "Unknown SQLite error while opening database." );
+ }
+ }
+
+ return true;
+ }
+
+ void cSQLiteDriver::close()
+ {
+ if( connection != 0 )
+ {
+ sqlite_close( (sqlite*)connection );
+ connection = 0;
+ }
+ }
+
+ bool cSQLiteDriver::exec( const QString &query )
+ {
+ char *error;
+
+ if( sqlite_exec( (sqlite*)connection, query.latin1(), NULL, NULL, &error ) != SQLITE_OK )
+ {
+ if( error )
+ {
+ QString err( QString( error ) + " (" + query + ")" );
+ sqlite_freemem( error );
+ throw err;
+ }
+ else
+ {
+ throw QString( "Unknown SQLite error while executing: %1" ).arg( query );
+ }
+ }
+
+ return true;
+ }
+
+ cDBResult cSQLiteDriver::query( const QString &query )
+ {
+ char *error = NULL;
+ sqlite_vm *result;
+
+
+ // Compile a VM and pass it to cSQLiteResult
+ if( sqlite_compile( (sqlite*)connection, query.latin1(), NULL, &result, &error ) != SQLITE_OK )
+ {
+ if( error )
+ {
+ QString err( QString( error ) + " (" + query + ")" );
+ sqlite_freemem( error );
+ throw err;
+ }
+ else
+ {
+ throw QString( "Unknown SQLite error while querying: %1" ).arg( query );
+ }
+ }
+
+ return cDBResult( result, connection, false );
}
Index: dbdriver.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/dbdriver.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** dbdriver.h 30 Apr 2003 05:54:31 -0000 1.9
--- dbdriver.h 26 Aug 2003 15:01:05 -0000 1.10
***************
*** 35,38 ****
--- 35,40 ----
struct st_mysql;
struct st_mysql_res;
+ struct sqlite;
+ struct sqlite_vm;
#include <qstring.h>
***************
*** 41,51 ****
class cDBResult;
class cDBDriver
{
friend class cDBResult;
! private:
std::map< int, st_mysql* > connections;
! st_mysql *connection;
QString _host, _dbname, _username, _password;
QString lasterror_;
--- 43,55 ----
class cDBResult;
+ class cSQLiteResult;
class cDBDriver
{
friend class cDBResult;
! protected:
std::map< int, st_mysql* > connections;
! void *connection;
!
QString _host, _dbname, _username, _password;
QString lasterror_;
***************
*** 57,67 ****
virtual ~cDBDriver();
! bool open( int id = CONN_MAIN );
! void close();
! bool exec( const QString &query ) const; // Just execute some SQL code, no return!
! cDBResult query( const QString &query ); // Executes a query
! void lockTable( const QString& table ) const;
! void unlockTable( const QString& table ) const;
! QString error(); // Returns an error (if there is one), uses the current connection
// Setters + Getters
--- 61,71 ----
virtual ~cDBDriver();
! virtual bool open( int id = CONN_MAIN );
! virtual void close();
! virtual bool exec( const QString &query ); // Just execute some SQL code, no return!
! virtual cDBResult query( const QString &query ); // Executes a query
! virtual void lockTable( const QString& table );
! virtual void unlockTable( const QString& table );
! virtual QString error(); // Returns an error (if there is one), uses the current connection
// Setters + Getters
***************
*** 77,89 ****
};
class cDBResult
{
! private:
char **_row;
! st_mysql_res *_result;
! st_mysql *_connection; // Connection occupied by this query
public:
! cDBResult(): _row( 0 ), _result( 0 ), _connection( 0 ) {} // Standard Constructor
! cDBResult( st_mysql_res *result, st_mysql *connection ): _row( 0 ), _result( result ), _connection( connection ) {}; // MySQL Constructor
virtual ~cDBResult() {}
--- 81,111 ----
};
+ class cSQLiteDriver : public cDBDriver
+ {
+ public:
+ cSQLiteDriver() {}
+ virtual ~cSQLiteDriver() {}
+
+ bool open( int id = CONN_MAIN );
+ void close();
+
+ void lockTable( const QString &table ) {}
+ void unlockTable( const QString &table ) {}
+ QString error() { return QString::null; }
+
+ bool exec( const QString &query );
+ cDBResult query( const QString &query );
+ };
+
class cDBResult
{
! public:
char **_row;
! void *_result;
! void *_connection; // Connection occupied by this query
! bool mysql_type;
public:
! cDBResult(): _row( 0 ), _result( 0 ), _connection( 0 ), mysql_type( true ) {} // Standard Constructor
! cDBResult( void *result, void *connection, bool mysql_type = true ): _row( 0 ), _result( result ), _connection( connection ) { this->mysql_type = mysql_type; }; // MySQL Constructor
virtual ~cDBResult() {}
Index: items.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.cpp,v
retrieving revision 1.334
retrieving revision 1.335
diff -C2 -d -r1.334 -r1.335
*** items.cpp 23 Aug 2003 15:20:29 -0000 1.334
--- items.cpp 26 Aug 2003 15:01:05 -0000 1.335
***************
*** 2002,2005 ****
--- 2002,2019 ----
}
+ static cUObject* productCreator()
+ {
+ return new cItem;
+ }
+
+ void cItem::registerInFactory()
+ {
+ QStringList fields, tables, conditions;
+ buildSqlString( fields, tables, conditions ); // Build our SQL string
+ QString sqlString = QString( "SELECT /*! STRAIGHT_JOIN SQL_SMALL_RESULT */ uobjectmap.serial,uobjectmap.type,%1 FROM uobjectmap,%2 WHERE uobjectmap.type = 'cItem' AND %3" ).arg( fields.join( "," ) ).arg( tables.join( "," ) ).arg( conditions.join( " AND " ) );
+ UObjectFactory::instance()->registerType("cItem", productCreator);
+ UObjectFactory::instance()->registerSqlQuery( "cItem", sqlString );
+ }
+
void cItem::load( char **result, UINT16 &offset )
{
Index: items.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.h,v
retrieving revision 1.169
retrieving revision 1.170
diff -C2 -d -r1.169 -r1.170
*** items.h 26 Aug 2003 03:55:13 -0000 1.169
--- items.h 26 Aug 2003 15:01:05 -0000 1.170
***************
*** 101,107 ****
void load( char **, UINT16& );
void save();
- void save( FlatStore::OutputFile*, bool first = false ) throw();
- bool load( unsigned char chunkGroup, unsigned char chunkType, FlatStore::InputFile* ) throw();
- bool postload() throw();
bool del();
--- 101,104 ----
Index: npc.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/npc.cpp,v
retrieving revision 1.31
retrieving revision 1.32
diff -C2 -d -r1.31 -r1.32
*** npc.cpp 21 Aug 2003 01:02:42 -0000 1.31
--- npc.cpp 26 Aug 2003 15:01:05 -0000 1.32
***************
*** 94,97 ****
--- 94,106 ----
}
+ void cNPC::registerInFactory()
+ {
+ QStringList fields, tables, conditions;
+ buildSqlString( fields, tables, conditions ); // Build our SQL string
+ QString sqlString = QString( "SELECT /*! STRAIGHT_JOIN SQL_SMALL_RESULT */ uobjectmap.serial,uobjectmap.type,%1 FROM uobjectmap,%2 WHERE uobjectmap.type = 'cNPC' AND %3" ).arg( fields.join( "," ) ).arg( tables.join( "," ) ).arg( conditions.join( " AND " ) );
+ UObjectFactory::instance()->registerType( "cNPC", productCreator );
+ UObjectFactory::instance()->registerSqlQuery( "cNPC", sqlString );
+ }
+
void cNPC::buildSqlString( QStringList &fields, QStringList &tables, QStringList &conditions )
{
Index: npc.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/npc.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** npc.h 21 Aug 2003 05:04:35 -0000 1.19
--- npc.h 26 Aug 2003 15:01:05 -0000 1.20
***************
*** 83,89 ****
void load( char **, UINT16& );
void save();
- void save( FlatStore::OutputFile*, bool first = false ) throw();
- bool load( unsigned char chunkGroup, unsigned char chunkType, FlatStore::InputFile* ) throw();
- bool postload() throw();
bool del();
--- 83,86 ----
Index: persistentbroker.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentbroker.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** persistentbroker.cpp 11 May 2003 16:03:32 -0000 1.13
--- persistentbroker.cpp 26 Aug 2003 15:01:05 -0000 1.14
***************
*** 52,56 ****
bool PersistentBroker::openDriver( const QString& driver )
{
! connection = new cDBDriver();
if ( !connection )
return false;
--- 52,67 ----
bool PersistentBroker::openDriver( const QString& driver )
{
! if( connection != 0 )
! {
! connection->close();
! delete connection;
! connection = 0;
! }
!
! if( driver == "sqlite" )
! connection = new cSQLiteDriver();
! else
! connection = new cDBDriver;
!
if ( !connection )
return false;
***************
*** 75,78 ****
--- 86,95 ----
}
+ void PersistentBroker::disconnect()
+ {
+ if( connection )
+ connection->close();
+ }
+
bool PersistentBroker::saveObject( PersistentObject* object )
{
***************
*** 109,112 ****
--- 126,132 ----
bool PersistentBroker::executeQuery( const QString& query )
{
+ if( !connection )
+ throw QString( "PersistentBroker not connected to database." );
+
bool result = connection->exec(query);
if( !result )
***************
*** 129,133 ****
{
if( !connection )
! return cDBResult( 0, 0 );
return connection->query( query );
--- 149,153 ----
{
if( !connection )
! throw QString( "PersistentBroker not connected to database." );
return connection->query( query );
Index: persistentbroker.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentbroker.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** persistentbroker.h 5 May 2003 11:59:13 -0000 1.16
--- persistentbroker.h 26 Aug 2003 15:01:05 -0000 1.17
***************
*** 57,61 ****
--- 57,64 ----
~PersistentBroker();
bool openDriver( const QString& driver );
+
bool connect( const QString& host, const QString& db, const QString& username, const QString& password );
+ void disconnect();
+
bool executeQuery( const QString& query );
cDBResult query( const QString& query );
***************
*** 78,82 ****
inline QString __escapeReservedCharacters( const QString& d )
{
! return QString(d).replace( QRegExp("'"), "\\'" );
}
--- 81,86 ----
inline QString __escapeReservedCharacters( const QString& d )
{
! //return QString(d).replace( QRegExp("'"), "\\'" );
! return QString(d).replace( QRegExp("'"), "''" );
}
***************
*** 141,146 ****
#endif
! #define initSave QStringList conditions; QStringList fields; QString table;
! #define clearFields conditions.clear(); fields.clear();
#define setTable( value ) table = value;
--- 145,150 ----
#endif
! #define initSave QStringList conditions, fields, values; QString table;
! #define clearFields conditions.clear(); fields.clear(); values.clear();
#define setTable( value ) table = value;
***************
*** 148,163 ****
// for inserting we use the faster VALUES() method
! #define addField( name, value ) fields.push_back( QString( "`%1` = '%2'" ).arg( name ).arg( value ) );
! #define addStrField( name, value ) fields.push_back( QString( "`%1` = '%2'" ).arg( name ).arg( __escapeReservedCharacters( value.isNull() ? QString( "" ) : value ) ) );
#define addCondition( name, value ) conditions.push_back( QString( "`%1` = '%2'" ).arg( name ).arg( value ) );
#define saveFields \
if( isPersistent ) \
! { \
! persistentBroker->executeQuery( QString( "UPDATE `%1` SET %2 WHERE %3" ).arg( table ).arg( fields.join(", ") ).arg( conditions.join(" AND ") ) ); \
! } \
else \
! { \
! persistentBroker->executeQuery( QString( "INSERT INTO `%1` SET %2" ).arg( table ).arg( fields.join( ", " ) ) ); \
! }
#endif // __PERSISTENTBROKER_H__
--- 152,163 ----
// for inserting we use the faster VALUES() method
! #define addField( name, value ) fields.push_back( name ); values.push_back( QString::number( value ) );
! #define addStrField( name, value ) fields.push_back( name ); values.push_back( "'" + ( value.isNull() ? QString( "" ) : __escapeReservedCharacters( value ) ) + "'" );
#define addCondition( name, value ) conditions.push_back( QString( "`%1` = '%2'" ).arg( name ).arg( value ) );
#define saveFields \
if( isPersistent ) \
! persistentBroker->executeQuery( QString( "UPDATE %1 (%2) VALUES(%3) WHERE %4" ).arg( table ).arg( fields.join( "," ) ).arg( values.join( "," ) ).arg( conditions.join( " AND " ) ) ); \
else \
! persistentBroker->executeQuery( QString( "INSERT INTO %1 (%2) VALUES(%3)" ).arg( table ).arg( fields.join( "," ) ).arg( values.join( "," ) ) );
#endif // __PERSISTENTBROKER_H__
Index: player.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/player.cpp,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -d -r1.24 -r1.25
*** player.cpp 21 Aug 2003 01:02:42 -0000 1.24
--- player.cpp 26 Aug 2003 15:01:05 -0000 1.25
***************
*** 87,90 ****
--- 87,99 ----
}
+ void cPlayer::registerInFactory()
+ {
+ QStringList fields, tables, conditions;
+ buildSqlString( fields, tables, conditions ); // Build our SQL string
+ QString sqlString = QString( "SELECT /*! STRAIGHT_JOIN SQL_SMALL_RESULT */ uobjectmap.serial,uobjectmap.type,%1 FROM uobjectmap,%2 WHERE uobjectmap.type = 'cPlayer' AND %3" ).arg( fields.join( "," ) ).arg( tables.join( "," ) ).arg( conditions.join( " AND " ) );
+ UObjectFactory::instance()->registerType( "cPlayer", productCreator );
+ UObjectFactory::instance()->registerSqlQuery( "cPlayer", sqlString );
+ }
+
void cPlayer::buildSqlString( QStringList &fields, QStringList &tables, QStringList &conditions )
{
Index: player.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/player.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** player.h 21 Aug 2003 05:04:35 -0000 1.16
--- player.h 26 Aug 2003 15:01:05 -0000 1.17
***************
*** 62,68 ****
void load( char **, UINT16& );
void save();
- void save( FlatStore::OutputFile*, bool first = false ) throw();
- bool load( unsigned char chunkGroup, unsigned char chunkType, FlatStore::InputFile* ) throw();
- bool postload() throw();
bool del();
--- 62,65 ----
Index: srvparams.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/srvparams.cpp,v
retrieving revision 1.84
retrieving revision 1.85
diff -C2 -d -r1.84 -r1.85
*** srvparams.cpp 21 Aug 2003 05:04:35 -0000 1.84
--- srvparams.cpp 26 Aug 2003 15:01:05 -0000 1.85
***************
*** 119,127 ****
databaseUsername_ = getString("Database", "username", "", true);
databaseHost_ = getString("Database", "host", "", true);
! databaseName_ = getString("Database", "name", "", true);
!
! // Remote Admin
! ra_port_ = getNumber("Remote Admin", "Port", 2594, true);
! EnableRA_ = getBool("Remote Admin", "Enable", false, true);
// Repsys
--- 119,124 ----
databaseUsername_ = getString("Database", "username", "", true);
databaseHost_ = getString("Database", "host", "", true);
! databaseHost_ = getString("Database", "driver", "sqlite", true);
! databaseName_ = getString("Database", "name", "world.db", true);
// Repsys
***************
*** 272,281 ****
walkDisturbsCast_ = getBool( "Magic", "Walking Disturbs Casting", true, true );
precasting_ = getBool( "Magic", "Precasting", true, true );
-
- // Worldsave
- saveModule_ = getString( "Worldsaves", "Saver", "sql", true );
- loadModule_ = getString( "Worldsaves", "Loader", "sql", true );
- savePrefix_ = getString( "Worldsaves", "Prefix", "", true );
- savePath_ = getString( "Worldsaves", "Path", "", true );
// Path Finding
--- 269,272 ----
Index: srvparams.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/srvparams.h,v
retrieving revision 1.53
retrieving revision 1.54
diff -C2 -d -r1.53 -r1.54
*** srvparams.h 21 Aug 2003 05:04:35 -0000 1.53
--- srvparams.h 26 Aug 2003 15:01:05 -0000 1.54
***************
*** 145,148 ****
--- 145,149 ----
unsigned int beggingTime_;
unsigned char season_;
+ QString databaseDriver_;
QString databaseName_;
QString databaseUsername_;
***************
*** 158,165 ****
QString accountsArchiver_;
bool categoryTagAddMenu_;
- QString saveModule_;
- QString loadModule_;
- QString savePath_;
- QString savePrefix_;
double npcMoveTime_;
double tamedNpcMoveTime_;
--- 159,162 ----
***************
*** 171,178 ****
unsigned int animalWildFleeRange_;
- // Remote Admin
- unsigned int ra_port_;
- bool EnableRA_;
-
// Regenerate
unsigned int hitpointrate_;
--- 168,171 ----
***************
*** 350,353 ****
--- 343,347 ----
// Persistency Module
+ QString databaseDriver() const;
QString databaseHost() const;
QString databasePassword() const;
***************
*** 355,362 ****
QString databaseName() const;
- // Remote Admin
- unsigned int ra_port() const;
- bool EnableRA() const;
-
// Regenerate
unsigned int hitpointrate() const;
--- 349,352 ----
***************
*** 422,431 ****
bool enableGame() const;
- // Worldsave
- QString savePath() const;
- QString saveModule() const;
- QString loadModule() const;
- QString savePrefix() const;
-
// Path Finding
int pathfindMaxSteps() const;
--- 412,415 ----
***************
*** 942,955 ****
}
- inline unsigned int cSrvParams::ra_port() const
- {
- return ra_port_;
- }
-
- inline bool cSrvParams::EnableRA() const
- {
- return EnableRA_;
- }
-
inline long int cSrvParams::murderdecay() const
{
--- 926,929 ----
***************
*** 1092,1095 ****
--- 1066,1074 ----
}
+ inline QString cSrvParams::databaseDriver() const
+ {
+ return databaseDriver_;
+ }
+
inline QString cSrvParams::databaseHost() const
{
***************
*** 1140,1163 ****
{
return categoryTagAddMenu_;
- }
-
- inline QString cSrvParams::saveModule() const
- {
- return saveModule_;
- }
-
- inline QString cSrvParams::loadModule() const
- {
- return loadModule_;
- }
-
- inline QString cSrvParams::savePrefix() const
- {
- return savePrefix_;
- }
-
- inline QString cSrvParams::savePath() const
- {
- return savePath_;
}
--- 1119,1122 ----
Index: uobject.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/uobject.h,v
retrieving revision 1.71
retrieving revision 1.72
diff -C2 -d -r1.71 -r1.72
*** uobject.h 22 Aug 2003 16:57:09 -0000 1.71
--- uobject.h 26 Aug 2003 15:01:05 -0000 1.72
***************
*** 57,66 ****
class cItem;
- namespace FlatStore
- {
- class OutputFile;
- class InputFile;
- };
-
struct stError;
--- 57,60 ----
***************
*** 110,116 ****
void save();
bool del();
- virtual void save( FlatStore::OutputFile*, bool first = false ) throw();
- virtual bool load( unsigned char chunkGroup, unsigned char chunkType, FlatStore::InputFile* ) throw();
- virtual bool postload() throw();
QString eventList( void ) const; // Returns the list of events
--- 104,107 ----
Index: wolf.dsp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/wolf.dsp,v
retrieving revision 1.204
retrieving revision 1.205
diff -C2 -d -r1.204 -r1.205
*** wolf.dsp 23 Aug 2003 01:03:31 -0000 1.204
--- wolf.dsp 26 Aug 2003 15:01:06 -0000 1.205
***************
*** 1,23 ****
# Microsoft Developer Studio Project File - Name="wolf" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
! # ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=wolf - Win32 Debug
! !MESSAGE This is not a valid makefile. To build this project using NMAKE,
! !MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "wolf.mak".
!MESSAGE
! !MESSAGE You can specify a configuration when running NMAKE
! !MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "wolf.mak" CFG="wolf - Win32 Debug"
!MESSAGE
! !MESSAGE Possible choices for configuration are:
!MESSAGE
! !MESSAGE "wolf - Win32 Release" (based on "Win32 (x86) Console Application")
! !MESSAGE "wolf - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
--- 1,23 ----
# Microsoft Developer Studio Project File - Name="wolf" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
! # ** NICHT BEARBEITEN **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=wolf - Win32 Debug
! !MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
! !MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
!MESSAGE
!MESSAGE NMAKE /f "wolf.mak".
!MESSAGE
! !MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
! !MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
!MESSAGE
!MESSAGE NMAKE /f "wolf.mak" CFG="wolf - Win32 Debug"
!MESSAGE
! !MESSAGE Für die Konfiguration stehen zur Auswahl:
!MESSAGE
! !MESSAGE "wolf - Win32 Release" (basierend auf "Win32 (x86) Console Application")
! !MESSAGE "wolf - Win32 Debug" (basierend auf "Win32 (x86) Console Application")
!MESSAGE
***************
*** 26,30 ****
# PROP Scc_ProjName "wolf"
# PROP Scc_LocalPath "."
! CPP=xicl6.exe
RSC=rc.exe
--- 26,30 ----
# PROP Scc_ProjName "wolf"
# PROP Scc_LocalPath "."
! CPP=cl.exe
RSC=rc.exe
***************
*** 50,54 ****
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
! LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib $(QTDIR)\lib\qt-mt312.lib libmysql.lib flatstore.lib /nologo /subsystem:console /map /machine:I386 /nodefaultlib:"libcmt MSVCRTD" /out:"D:\wolfpack\wolfpack.exe" /libpath:"lib\ZThread\lib" /libpath:"lib\Python\lib" /libpath:"lib\bugreport\lib" /libpath:"flatstore\Release" /opt:ref /opt:nowin98
--- 50,54 ----
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
! LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib $(QTDIR)\lib\qt-mt312.lib libmysql.lib flatstore.lib /nologo /subsystem:console /map /machine:I386 /nodefaultlib:"libcmt MSVCRTD" /out:"D:\wolfpack\wolfpack.exe" /libpath:"lib\ZThread\lib" /libpath:"lib\Python\lib" /libpath:"lib\bugreport\lib" /libpath:"flatstore\Release" /opt:ref /opt:nowin98
***************
*** 75,81 ****
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
! LINK32=xilink6.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
! # ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib $(QTDIR)\lib\qt-mt320.lib libmysql.lib flatstore.lib /nologo /version:12.9 /subsystem:console /map /debug /machine:I386 /out:"..\Wolfpack.exe" /pdbtype:sept /libpath:"lib\bugreport\lib" /libpath:"flatstore\Debug"
# SUBTRACT LINK32 /pdb:none
--- 75,81 ----
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
! LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
! # ADD LINK32 kernel32.lib user32.lib advapi32.lib ws2_32.lib $(QTDIR)\lib\qt-mt312.lib libmysql.lib flatstore.lib /nologo /version:12.9 /subsystem:console /map /debug /machine:I386 /out:"..\Wolfpack.exe" /pdbtype:sept /libpath:"lib\bugreport\lib" /libpath:"flatstore\Debug"
# SUBTRACT LINK32 /pdb:none
***************
*** 1617,1620 ****
--- 1617,1776 ----
SOURCE=.\moc_wptargetrequests.cpp
+ # End Source File
+ # End Group
+ # Begin Group "SQLite"
+
+ # PROP Default_Filter ""
+ # Begin Source File
+
+ SOURCE=.\sqlite\attach.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\auth.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\btree.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\btree.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\btree_rb.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\build.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\config.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\copy.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\delete.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\expr.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\func.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\hash.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\hash.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\insert.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\main.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\opcodes.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\opcodes.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\os.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\os.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\pager.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\pager.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\parse.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\parse.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\pragma.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\printf.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\random.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\select.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\sqlite.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\sqliteInt.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\table.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\tokenize.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\trigger.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\update.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\util.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\vacuum.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\vdbe.c
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\vdbe.h
+ # End Source File
+ # Begin Source File
+
+ SOURCE=.\sqlite\where.c
# End Source File
# End Group
Index: wolf.dsw
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/wolf.dsw,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** wolf.dsw 23 Aug 2003 01:03:31 -0000 1.40
--- wolf.dsw 26 Aug 2003 15:01:06 -0000 1.41
***************
*** 1,16 ****
Microsoft Developer Studio Workspace File, Format Version 6.00
! # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
!
! ###############################################################################
!
! Project: "flatstore"=.\flatstore\flatstore.dsp - Package Owner=<4>
!
! Package=<5>
! {{{
! }}}
!
! Package=<4>
! {{{
! }}}
###############################################################################
--- 1,4 ----
Microsoft Developer Studio Workspace File, Format Version 6.00
! # WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELÖSCHT WERDEN!
###############################################################################
Index: wolfpack.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/wolfpack.cpp,v
retrieving revision 1.437
retrieving revision 1.438
diff -C2 -d -r1.437 -r1.438
*** wolfpack.cpp 23 Aug 2003 15:20:29 -0000 1.437
--- wolfpack.cpp 26 Aug 2003 15:01:06 -0000 1.438
***************
*** 710,730 ****
// Try to open our driver
! if( !persistentBroker->openDriver( "mysql" ) )
{
exit( -1 );
- }
-
- // Don't connect if everything is empty
- if( !SrvParams->databaseHost().isEmpty() || !SrvParams->databaseName().isEmpty() || !SrvParams->databaseUsername().isEmpty() || !SrvParams->databasePassword().isEmpty() )
- {
- try
- {
- persistentBroker->connect( SrvParams->databaseHost(), SrvParams->databaseName(), SrvParams->databaseUsername(), SrvParams->databasePassword() );
- }
- catch( QString &e )
- {
- clConsole.log( LOG_FATAL, QString( "An error occured while connecting to the database: %1\n" ).arg( e ) );
- exit( -1 );
- }
}
--- 710,716 ----
// Try to open our driver
! if( !persistentBroker->openDriver( SrvParams->databaseDriver() ) )
{
exit( -1 );
}
Index: world.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/world.cpp,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** world.cpp 21 Aug 2003 05:04:35 -0000 1.26
--- world.cpp 26 Aug 2003 15:01:06 -0000 1.27
***************
*** 45,48 ****
--- 45,49 ----
#include "player.h"
#include "npc.h"
+ #include "sqlite/sqlite.h"
// Postprocessing stuff, can be deleted later on
***************
*** 60,67 ****
#include "python/tempeffect.h"
- // FlatStore Includes
- #include "flatstore_keys.h"
- #include "flatstore/flatstore.h"
-
// Library Includes
#include <list>
--- 61,64 ----
***************
*** 107,111 ****
pendingObjects.clear();
-
}
};
--- 104,107 ----
***************
*** 182,190 ****
}
! /*!
! Load a World using the SQL database
! */
! void cWorld::loadSql()
{
ISerialization* archive = cPluginFactory::serializationArchiver( "xml" );
--- 178,195 ----
}
! void cWorld::load()
{
+ clConsole.send( "Loading World...\n" );
+
+ try
+ {
+ persistentBroker->connect( SrvParams->databaseHost(), SrvParams->databaseName(), SrvParams->databaseUsername(), SrvParams->databasePassword() );
+ }
+ catch( QString &e )
+ {
+ clConsole.log( LOG_FATAL, QString( "An error occured while connecting to the database: %1\n" ).arg( e ) );
+ return;
+ }
+
ISerialization* archive = cPluginFactory::serializationArchiver( "xml" );
***************
*** 437,538 ****
deleteItems.clear();
}
- }
-
- void cWorld::loadFlatstore( const QString &prefix )
- {
- FlatStore::InputFile input;
-
- input.startRead( QString( "%1world.fsd" ).arg( prefix ).latin1() );
-
- unsigned int serial;
- unsigned short objectType;
-
- while( input.readObject( objectType, serial ) )
- {
- // Create a new object based on the object-type
- unsigned char group, chunk;
- cUObject *object = 0;
-
- // Get an object
- object = UObjectFactory::instance()->createObject( QString::number( objectType ) );
-
- if( !object )
- {
- clConsole.log( LOG_ERROR, QString( "Invalid object type encountered: %1" ).arg( objectType ) );
- continue;
- }
-
- object->setSerial( serial ); // This autoregisters the object too
-
- while( input.readChunk( group, chunk ) )
- {
- if( !object->load( group, chunk, &input ) )
- {
- clConsole.log( LOG_ERROR, QString( "Invalid chunk key found in worldfile: %1 (Group: %2)." ).arg( chunk ).arg( group ) );
-
- unregisterObject( object );
- delete object;
-
- break; // Problem about this is that most likely the whole object is corrupted until we have a world.fsh file
- }
- }
- }
! // Postprocessing (Items first)
! cItemIterator i_iter;
! for( P_ITEM pItem = i_iter.first(); pItem; pItem = i_iter.next() )
! {
! if( !pItem->postload() )
! quickdelete( pItem );
! }
!
! cCharIterator c_iter;
!
! for( P_CHAR pChar = c_iter.first(); pChar; pChar = c_iter.next() )
! {
! pChar->postload();
! // I think we could delete characters the normal way here
! // But it seems like characters never get deleted during postprocess
! }
! input.finishRead();
}
! void cWorld::load( QString basepath, QString prefix, QString module )
{
! clConsole.send( "Loading World..." );
!
! if( module == QString::null )
! module = SrvParams->loadModule();
!
! if( prefix == QString::null )
! prefix = SrvParams->savePrefix();
!
! if( basepath == QString::null )
! basepath = SrvParams->savePath();
!
! prefix.prepend( basepath );
! if( module == "sql" )
! loadSql();
! else if( module == "flatstore" )
! loadFlatstore( prefix );
! else
{
! clConsole.ChangeColor( WPC_RED );
! clConsole.send( " Failed\n" );
! clConsole.ChangeColor( WPC_NORMAL );
!
! throw QString( "Unknown worldsave module: %1" ).arg( module );
}
! clConsole.send("World Loading ");
! clConsole.ChangeColor( WPC_GREEN );
! clConsole.send( "Completed\n" );
! clConsole.ChangeColor( WPC_NORMAL );
! }
! void cWorld::saveSql()
! {
SrvParams->flush();
--- 442,471 ----
deleteItems.clear();
}
! persistentBroker->disconnect();
! clConsole.send("World Loading ");
! clConsole.ChangeColor( WPC_GREEN );
! clConsole.send( "Completed\n" );
! clConsole.ChangeColor( WPC_NORMAL );
}
! void cWorld::save()
{
! clConsole.send( "Saving World..." );
! try
{
! persistentBroker->connect( SrvParams->databaseHost(), SrvParams->databaseName(), SrvParams->databaseUsername(), SrvParams->databasePassword() );
! }
! catch( QString &e )
! {
! clConsole.log( LOG_FATAL, QString( "An error occured while connecting to the database: %1\n" ).arg( e ) );
! return;
}
! unsigned int startTime = getNormalizedTime();
! // Try to Benchmark
SrvParams->flush();
***************
*** 577,669 ****
uiCurrentTime = getNormalizedTime();
! }
!
! void cWorld::saveFlatstore( const QString &prefix )
! {
! persistentBroker->clearDeleteQueue(); // prevents us from accidently not freeing memory
!
! FlatStore::OutputFile output;
! std::list< cUObject* >::const_iterator delIt;
!
! output.startOutput( QString( prefix + "world.fsd" ).latin1() );
!
! // Save Characters
! CharMap::const_iterator char_it;
! for( char_it = p->chars.begin(); char_it != p->chars.end(); ++char_it )
! {
! P_CHAR pChar = char_it->second;
! try
! {
! pChar->save( &output, true );
! }
! catch( ... )
! {
! clConsole.ChangeColor( WPC_RED );
! clConsole.send( " Failed\n" );
! clConsole.ChangeColor( WPC_NORMAL );
!
! clConsole.log( LOG_ERROR, QString( "Couldn't save character: 0x%1" ).arg( pChar->serial(), 0, 16 ) );
!
! clConsole.send( "Continuing...");
! }
! }
!
! // Save Items
! ItemMap::const_iterator item_it;
! for( item_it = p->items.begin(); item_it != p->items.end(); ++item_it )
! {
! P_ITEM pItem = item_it->second;
!
! try
! {
! pItem->save( &output, true );
! }
! catch( ... )
! {
! clConsole.ChangeColor( WPC_RED );
! clConsole.send( " Failed\n" );
! clConsole.ChangeColor( WPC_NORMAL );
!
! clConsole.log( LOG_ERROR, QString( "Couldn't save item: 0x%1" ).arg( pItem->serial(), 0, 16 ) );
!
! clConsole.send( "Continuing...");
! }
! }
!
! for( delIt = p->pendingObjects.begin(); delIt != p->pendingObjects.end(); ++delIt )
! // Now we can finally delete pending objects
! delete *delIt;
!
! p->pendingObjects.clear();
!
! output.finishOutput();
! }
!
! void cWorld::save( QString basepath, QString prefix, QString module )
! {
! if( module == QString::null )
! module = SrvParams->saveModule();
!
! if( prefix == QString::null )
! prefix = SrvParams->savePrefix();
!
! if( basepath == QString::null )
! basepath = SrvParams->savePath();
!
! prefix.prepend( basepath );
!
! clConsole.send( "Saving World..." );
!
! unsigned int startTime = getNormalizedTime();
!
! // Try to Benchmark
! if( module == "sql" )
! saveSql();
! else if( module == "flatstore" )
! saveFlatstore( prefix );
!
clConsole.ChangeColor( WPC_GREEN );
clConsole.send( " Done" );
clConsole.ChangeColor( WPC_NORMAL );
clConsole.send( QString( " [%1ms]\n" ).arg( getNormalizedTime() - startTime ) );
--- 510,519 ----
uiCurrentTime = getNormalizedTime();
!
clConsole.ChangeColor( WPC_GREEN );
clConsole.send( " Done" );
clConsole.ChangeColor( WPC_NORMAL );
+
+ persistentBroker->disconnect();
clConsole.send( QString( " [%1ms]\n" ).arg( getNormalizedTime() - startTime ) );
Index: world.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/world.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** world.h 11 May 2003 21:30:21 -0000 1.3
--- world.h 26 Aug 2003 15:01:06 -0000 1.4
***************
*** 75,84 ****
SERIAL _lastCharSerial, _lastItemSerial;
- void loadFlatstore( const QString &prefix );
- void loadSql();
-
- void saveFlatstore( const QString &prefix );
- void saveSql();
-
public:
// Constructor/Destructor
--- 75,78 ----
***************
*** 87,92 ****
// WorldLoader interface
! void load( QString basepath = QString::null, QString prefix = QString::null, QString module = QString::null );
! void save( QString basepath = QString::null, QString prefix = QString::null, QString module = QString::null );
// Book-keeping functions
--- 81,86 ----
// WorldLoader interface
! void load();
! void save();
// Book-keeping functions
--- basechar_flatstore.cpp DELETED ---
--- flatstore_keys.h DELETED ---
--- item_flatstore.cpp DELETED ---
--- npc_flatstore.cpp DELETED ---
--- player_flatstore.cpp DELETED ---
--- uobject_flatstore.cpp DELETED ---
|