Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1:/tmp/cvs-serv6052
Modified Files:
accounts.cpp dbdriver.cpp dbdriver.h persistentbroker.cpp
persistentbroker.h wolf.dsp world.cpp
Log Message:
Implemented a rudimentary db autocreation.
This is subject to change later but will solve some issues for now.
Index: accounts.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/accounts.cpp,v
retrieving revision 1.66
retrieving revision 1.67
diff -C2 -d -r1.66 -r1.67
*** accounts.cpp 11 Sep 2003 12:22:24 -0000 1.66
--- accounts.cpp 12 Sep 2003 20:02:44 -0000 1.67
***************
*** 42,45 ****
--- 42,56 ----
#include "world.h"
+ // DB AutoCreation
+ const char *createSql = "CREATE TABLE accounts (\
+ login varchar(255) NOT NULL default '',\
+ password varchar(255) NOT NULL default '',\
+ flags int NOT NULL default '0',\
+ acl varchar(255) NOT NULL default 'player',\
+ lastlogin int NOT NULL default '',\
+ blockuntil int NOT NULL default '',\
+ PRIMARY KEY (login)\
+ );";
+
/*****************************************************************************
cAccount member functions
***************
*** 289,292 ****
--- 300,308 ----
connected = true;
+ if( !persistentBroker->tableExists( "accounts" ) )
+ {
+ persistentBroker->executeQuery( createSql );
+ }
+
persistentBroker->executeQuery( "BEGIN;" );
***************
*** 334,337 ****
--- 350,358 ----
try
{
+ if( !persistentBroker->tableExists( "accounts" ) )
+ {
+ persistentBroker->executeQuery( createSql );
+ }
+
persistentBroker->connect( SrvParams->accountsHost(), SrvParams->accountsName(), SrvParams->accountsUsername(), SrvParams->accountsPassword() );
Index: dbdriver.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/dbdriver.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** dbdriver.cpp 3 Sep 2003 20:58:17 -0000 1.22
--- dbdriver.cpp 12 Sep 2003 20:02:44 -0000 1.23
***************
*** 241,244 ****
--- 241,255 ----
}
+ bool cSQLiteDriver::tableExists( const QString &table )
+ {
+ cDBResult result = query( QString( "PRAGMA table_info('%1');" ).arg( table ) );
+
+ bool res = result.fetchrow(); // Every table has at least one field
+
+ result.free();
+
+ return res;
+ }
+
/*****************************************************************************
cMySQLDriver member functions
***************
*** 333,336 ****
--- 344,355 ----
connection = connections[ id ];
}
+ }
+
+ /*!
+ No checking done for MySQL yet.
+ */
+ bool cMySQLDriver::tableExists( const QString &table )
+ {
+ return true;
}
Index: dbdriver.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/dbdriver.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** dbdriver.h 2 Sep 2003 01:07:44 -0000 1.13
--- dbdriver.h 12 Sep 2003 20:02:44 -0000 1.14
***************
*** 70,73 ****
--- 70,74 ----
virtual void unlockTable( const QString& table );
virtual QString error(); // Returns an error (if there is one), uses the current connection
+ virtual bool tableExists( const QString &table ) = 0;
// Setters + Getters
***************
*** 96,99 ****
--- 97,101 ----
void lockTable( const QString &table ) {}
void unlockTable( const QString &table ) {}
+ bool tableExists( const QString &table );
QString error() { return QString::null; }
***************
*** 116,119 ****
--- 118,122 ----
void lockTable( const QString& table );
void unlockTable( const QString& table );
+ bool tableExists( const QString &table );
QString error();
void setActiveConnection( int id );
Index: persistentbroker.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentbroker.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** persistentbroker.cpp 9 Sep 2003 23:09:30 -0000 1.27
--- persistentbroker.cpp 12 Sep 2003 20:02:44 -0000 1.28
***************
*** 152,160 ****
if( !result )
{
! qWarning( query );
! Console::instance()->ChangeColor( WPC_RED );
! Console::instance()->send( "ERROR" );
! Console::instance()->ChangeColor( WPC_NORMAL );
! Console::instance()->send( ":" + connection->error() + "\n" );
}
return result;
--- 152,156 ----
if( !result )
{
! Console::instance()->log( LOG_ERROR, connection->error() );
}
return result;
***************
*** 232,234 ****
--- 228,235 ----
if( sqlite )
executeQuery( "ROLLBACK;" );
+ }
+
+ bool PersistentBroker::tableExists( const QString &table )
+ {
+ return connection->tableExists( table );
}
Index: persistentbroker.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/persistentbroker.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** persistentbroker.h 9 Sep 2003 23:09:30 -0000 1.23
--- persistentbroker.h 12 Sep 2003 20:02:44 -0000 1.24
***************
*** 78,81 ****
--- 78,82 ----
void lockTable( const QString& table ) const;
void unlockTable( const QString& table ) const;
+ bool tableExists( const QString& table );
bool saveObject( PersistentObject* );
Index: wolf.dsp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/wolf.dsp,v
retrieving revision 1.229
retrieving revision 1.230
diff -C2 -d -r1.229 -r1.230
*** wolf.dsp 12 Sep 2003 15:39:55 -0000 1.229
--- wolf.dsp 12 Sep 2003 20:02:44 -0000 1.230
***************
*** 239,246 ****
# Begin Source File
- SOURCE=.\pfactory.cpp
- # End Source File
- # Begin Source File
-
SOURCE=.\player.cpp
# End Source File
--- 239,242 ----
***************
*** 697,704 ****
SOURCE=.\persistentobject.h
# PROP Ignore_Default_Tool 1
- # End Source File
- # Begin Source File
-
- SOURCE=.\pfactory.h
# End Source File
# Begin Source File
--- 693,696 ----
Index: world.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/world.cpp,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** world.cpp 12 Sep 2003 15:39:56 -0000 1.44
--- world.cpp 12 Sep 2003 20:02:44 -0000 1.45
***************
*** 30,34 ****
// Wolfpack Includes
- #include "pfactory.h"
#include "world.h"
#include "console.h"
--- 30,33 ----
***************
*** 78,81 ****
--- 77,330 ----
#endif
+ // This is used for autocreating the tables
+ struct {
+ const char *name;
+ const char *create;
+ } tableInfo[] =
+ {
+ { "boats", "CREATE TABLE boats ( \
+ serial int(11) NOT NULL default '0', \
+ autosail tinyint(1) NOT NULL default '0', \
+ boatdir tinyint(1) NOT NULL default '0', \
+ itemserial1 int(11) NOT NULL default '-1', \
+ itemserial2 int(11) NOT NULL default '-1', \
+ itemserial3 int(11) NOT NULL default '-1', \
+ itemserial4 int(11) NOT NULL default '-1', \
+ multi1 smallint(6) default '0', \
+ multi2 smallint(6) default '0', \
+ multi3 smallint(6) default '0', \
+ multi4 smallint(6) default '0', \
+ PRIMARY KEY (serial) \
+ );" },
+
+ { "boats_itemids", "CREATE TABLE boats_itemids ( \
+ serial int(11) NOT NULL default '0', \
+ a tinyint(1) NOT NULL default '0', \
+ b tinyint(1) NOT NULL default '0', \
+ id smallint(6) default '0', \
+ PRIMARY KEY (serial) \
+ );" },
+
+ { "boats_itemoffsets", "CREATE TABLE boats_itemoffsets (\
+ serial int(11) NOT NULL default '0',\
+ a tinyint(1) NOT NULL default '0',\
+ b tinyint(1) NOT NULL default '0',\
+ c tinyint(1) NOT NULL default '0',\
+ offset smallint(6) default '0',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "characters", "CREATE TABLE characters (\
+ serial int(11) NOT NULL default '0',\
+ name varchar(255) default NULL,\
+ title varchar(255) default NULL,\
+ creationdate varchar(255) default NULL,\
+ body smallint(5) NOT NULL default '0',\
+ orgbody smallint(5) NOT NULL default '0',\
+ skin smallint(5) NOT NULL default '0',\
+ orgskin smallint(5) NOT NULL default '0',\
+ saycolor smallint(5) NOT NULL default '0',\
+ emotecolor smallint(5) NOT NULL default '0',\
+ strength smallint(6) NOT NULL default '0',\
+ strengthmod smallint(6) NOT NULL default '0',\
+ dexterity smallint(6) NOT NULL default '0',\
+ dexteritymod smallint(6) NOT NULL default '0',\
+ intelligence smallint(6) NOT NULL default '0',\
+ intelligencemod smallint(6) NOT NULL default '0',\
+ maxhitpoints smallint(6) NOT NULL default '0',\
+ hitpoints smallint(6) NOT NULL default '0',\
+ maxstamina smallint(6) NOT NULL default '0',\
+ stamina smallint(6) NOT NULL default '0',\
+ maxmana smallint(6) default NULL,\
+ mana smallint(6) default NULL,\
+ karma int(11) NOT NULL default '0',\
+ fame int(11) NOT NULL default '0',\
+ kills int(10) NOT NULL default '0',\
+ deaths int(10) NOT NULL default '0',\
+ def int(10) NOT NULL default '0',\
+ hunger int(11) NOT NULL default '0',\
+ poison int(11) NOT NULL default '0',\
+ poisoned int(10) NOT NULL default '0',\
+ murderertime int(11) NOT NULL default '0',\
+ criminaltime int(11) NOT NULL default '0',\
+ nutriment int(10) NOT NULL default '0',\
+ gender tinyint(1) NOT NULL default '0',\
+ propertyflags int(11) NOT NULL default '0',\
+ attacker int(11) NOT NULL default '-1',\
+ combattarget int(11) NOT NULL default '-1',\
+ murderer int(11) NOT NULL default '-1',\
+ guarding int(11) NOT NULL default '-1',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "corpses", "CREATE TABLE corpses (\
+ serial int(11) NOT NULL default '0',\
+ bodyid smallint(6) NOT NULL default '0',\
+ hairstyle smallint(6) NOT NULL default '0',\
+ haircolor smallint(6) NOT NULL default '0',\
+ beardstyle smallint(6) NOT NULL default '0',\
+ beardcolor smallint(6) NOT NULL default '0',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "corpses_equipment", "CREATE TABLE corpses_equipment (\
+ serial int(11) NOT NULL default '0',\
+ layer tinyint(3) NOT NULL default '0',\
+ item int(11) NOT NULL default '-1', \
+ PRIMARY KEY (serial,layer)\
+ );" },
+
+ { "houses", "CREATE TABLE houses (\
+ serial int(11) NOT NULL default '0',\
+ nokey tinyint(1) NOT NULL default '0',\
+ charpos_x smallint(6) NOT NULL default '0',\
+ charpos_y smallint(6) NOT NULL default '0',\
+ charpos_z smallint(6) NOT NULL default '0',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "items", "CREATE TABLE items (\
+ serial int(11) NOT NULL default '0',\
+ id smallint(5) NOT NULL default '0',\
+ color smallint(5) NOT NULL default '0',\
+ cont int(11) NOT NULL default '-1',\
+ layer tinyint(3) NOT NULL default '0',\
+ type smallint(5) NOT NULL default '0',\
+ type2 smallint(5) NOT NULL default '0',\
+ amount smallint(5) NOT NULL default '0',\
+ decaytime int(10) NOT NULL default '0',\
+ def int(10) NOT NULL default '0',\
+ hidamage smallint(6) NOT NULL default '0',\
+ lodamage smallint(6) NOT NULL default '0',\
+ time_unused int(10) NOT NULL default '0',\
+ weight int(11) NOT NULL default '0',\
+ hp smallint(6) NOT NULL default '0',\
+ maxhp smallint(6) NOT NULL default '0',\
+ speed int(11) NOT NULL default '0',\
+ poisoned int(10) NOT NULL default '0',\
+ magic tinyint(3) NOT NULL default '0',\
+ owner int(11) NOT NULL default '-1',\
+ visible tinyint(3) NOT NULL default '0',\
+ spawn int(11) NOT NULL default '-1',\
+ priv tinyint(3) NOT NULL default '0',\
+ sellprice int(11) NOT NULL default '0',\
+ buyprice int(11) NOT NULL default '0',\
+ restock smallint(5) NOT NULL default '0',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "multis", "CREATE TABLE multis (\
+ serial int(11) NOT NULL default '0',\
+ coowner int(11) NOT NULL default '-1',\
+ deedsection varchar(255) NOT NULL default '',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "multis_bans", "CREATE TABLE multis_bans (\
+ serial int(11) NOT NULL default '0',\
+ ban int(11) NOT NULL default '-1',\
+ PRIMARY KEY (serial,ban)\
+ );" },
+
+ { "multis_friends", "CREATE TABLE multis_friends (\
+ serial int(11) NOT NULL default '0',\
+ friend int(11) NOT NULL default '-1',\
+ PRIMARY KEY (serial,friend)\
+ );" },
+
+ { "npcs", "CREATE TABLE npcs (\
+ serial int(11) NOT NULL default '0',\
+ mindamage smallint(6) NOT NULL default '0',\
+ maxdamage smallint(6) NOT NULL default '0',\
+ tamingminskill smallint(6) NOT NULL default '0',\
+ summontime int(11) NOT NULL default '0',\
+ additionalflags int(11) NOT NULL default '0',\
+ owner int(11) NOT NULL default '-1',\
+ carve varchar(255) default NULL,\
+ spawnregion varchar(255) default NULL,\
+ stablemaster int(11) NOT NULL default '-1',\
+ lootlist varchar(255) default NULL,\
+ ai varchar(255) default NULL,\
+ wandertype smallint(3) NOT NULL default '0',\
+ wanderx1 smallint(6) NOT NULL default '0',\
+ wanderx2 smallint(6) NOT NULL default '0',\
+ wandery1 smallint(6) NOT NULL default '0',\
+ wandery2 smallint(6) NOT NULL default '0',\
+ wanderradius smallint(6) NOT NULL default '0',\
+ fleeat smallint(3) NOT NULL default '10',\
+ spellslow int(11) NOT NULL default '0',\
+ spellshigh int(11) NOT NULL default '0',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "players", "CREATE TABLE players (\
+ serial int(11) NOT NULL default '0',\
+ account varchar(255) default NULL,\
+ additionalflags int(10) NOT NULL default '0',\
+ visualrange tinyint(3) NOT NULL default '0',\
+ profile longtext,\
+ fixedlight tinyint(3) NOT NULL default '0',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "skills", "CREATE TABLE skills (\
+ serial int(11) NOT NULL default '0',\
+ skill tinyint(3) NOT NULL default '0',\
+ value smallint(6) NOT NULL default '0',\
+ locktype tinyint(4) default '0',\
+ cap smallint(6) default '0',\
+ PRIMARY KEY (serial,skill)\
+ );" },
+
+ { "tags", "CREATE TABLE tags (\
+ serial int(11) NOT NULL default '0',\
+ name varchar(64) NOT NULL default '',\
+ type varchar(6) NOT NULL default '',\
+ value longtext NOT NULL,\
+ PRIMARY KEY (serial,name)\
+ );" },
+
+ { "uobject", "CREATE TABLE uobject (\
+ name varchar(255) default NULL,\
+ serial int(11) NOT NULL default '0',\
+ multis int(11) NOT NULL default '-1',\
+ direction char(1) NOT NULL default '0',\
+ pos_x smallint(6) NOT NULL default '0',\
+ pos_y smallint(6) NOT NULL default '0',\
+ pos_z smallint(6) NOT NULL default '0',\
+ pos_map tinyint(4) NOT NULL default '0', \
+ events varchar(255) default NULL,\
+ bindmenu varchar(255) default NULL,\
+ havetags tinyint(1) NOT NULL default '0',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "uobjectmap", "CREATE TABLE uobjectmap (\
+ serial int(11) NOT NULL default '0',\
+ type varchar(80) NOT NULL default '',\
+ PRIMARY KEY (serial)\
+ );" },
+
+ { "effects", "CREATE TABLE effects (\
+ id int NOT NULL,\
+ objectid varchar(64) NOT NULL,\
+ expiretime int NOT NULL,\
+ dispellable tinyint NOT NULL default '0',\
+ source int NOT NULL default '-1',\
+ destination int NOT NULL default '-1',\
+ PRIMARY KEY (id)\
+ );" },
+
+ { "effects_properties", "CREATE TABLE effects_properties (\
+ id int NOT NULL,\
+ key varchar(64) NOT NULL,\
+ type varchar(64) NOT NULL,\
+ value text NOT NULL,\
+ PRIMARY KEY (id,key)\
+ );" },
+
+ { NULL, NULL }
+ };
+
/*****************************************************************************
cWorldPrivate member functions
***************
*** 193,196 ****
--- 442,455 ----
register unsigned int i = 0;
+ while( tableInfo[i].name )
+ {
+ if( !persistentBroker->tableExists( tableInfo[i].name ) )
+ {
+ persistentBroker->executeQuery( tableInfo[i].create );
+ }
+
+ ++i;
+ }
+
QStringList types = UObjectFactory::instance()->objectTypes();
***************
*** 428,431 ****
--- 687,702 ----
Console::instance()->log( LOG_ERROR, QString( "Couldn't open the database: %1\n" ).arg( e ) );
return;
+ }
+
+ unsigned int i = 0;
+
+ while( tableInfo[i].name )
+ {
+ if( !persistentBroker->tableExists( tableInfo[i].name ) )
+ {
+ persistentBroker->executeQuery( tableInfo[i].create );
+ }
+
+ ++i;
}
|