2006-01-19 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientAccount.cpp, aiclient/ClientAccount.h,
aiclient/ClientConnection.cpp, aiclient/ClientConnection.h,
aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp,
client/BaseClient.h, client/CharacterClient.cpp,
client/CharacterClient.h, client/ClientConnection.cpp,
client/ClientConnection.h, client/CreatorClient.cpp,
client/CreatorClient.h, client/ObserverClient.cpp,
client/ObserverClient.h, client/Py_CreatorClient.cpp,
client/Py_CreatorClient.h, client/client.cpp,
client/define_world.cpp, client/define_world.h, common/Add.h,
common/Affect.h, common/AtlasFileLoader.cpp,
common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp,
common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h,
common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp,
common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h,
common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h,
common/Eat.h, common/FormattedXMLWriter.cpp,
common/FormattedXMLWriter.h, common/Generic.h, common/Load.h,
common/Monitor.h, common/Mow.h, common/Nourish.h,
common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp,
common/Property.h, common/Property_impl.h, common/Save.h,
common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h,
common/Use.h, common/Wield.h, common/accountbase.cpp,
common/accountbase.h, common/const.cpp, common/const.h,
common/custom.cpp, common/debug.h, common/globals.cpp,
common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp,
common/inheritance.h, common/inheritance_impl.h, common/log.cpp,
common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h,
common/operations.cpp, common/operations.h, common/random.h,
common/refno.h, common/serialno.cpp, common/serialno.h,
common/system.cpp, common/system.h, common/terrain_utils.cpp,
common/terrain_utils.h, common/type_utils.h, common/types.h,
common/utility.cpp, common/utility.h, modules/DateTime.cpp,
modules/DateTime.h, modules/Location.cpp, modules/Location.h,
modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp,
physics/BBox.h, physics/Collision.cpp, physics/Collision.h,
physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp,
physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp,
rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h,
rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h,
rulesets/BaseMind.cpp, rulesets/BaseMind.h,
rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h,
rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp,
rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h,
rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp,
rulesets/Entity.h, rulesets/EntityProperties.cpp,
rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h,
rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp,
rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h,
rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp,
rulesets/MemMap.h, rulesets/MemMap_methods.h,
rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h,
rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp,
rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h,
rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp,
rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h,
rulesets/Py_Location.cpp, rulesets/Py_Location.h,
rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp,
rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h,
rulesets/Py_Operation.cpp, rulesets/Py_Operation.h,
rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp,
rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h,
rulesets/Py_Property.cpp, rulesets/Py_Property.h,
rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h,
rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h,
rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h,
rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp,
rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp,
rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h,
rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h,
rulesets/PythonArithmeticScript.cpp,
rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp,
rulesets/PythonMindScript.h, rulesets/PythonScript.cpp,
rulesets/PythonScript.h, rulesets/PythonThingScript.cpp,
rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp,
rulesets/PythonWrapper.h, rulesets/Python_API.cpp,
rulesets/Python_API.h, rulesets/Python_Script_Utils.h,
rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp,
rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h,
rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h,
rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp,
rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h,
rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h,
rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp,
rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h,
rulesets/attributes.h, server/Account.cpp, server/Account.h,
server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp,
server/ArithmeticFactory.h, server/CommClient.cpp,
server/CommClient.h, server/CommIdleSocket.cpp,
server/CommIdleSocket.h, server/CommListener.cpp,
server/CommListener.h, server/CommLocalClient.cpp,
server/CommLocalClient.h, server/CommMDNSPublisher.cpp,
server/CommMDNSPublisher.h, server/CommMaster.cpp,
server/CommMaster.h, server/CommMetaClient.cpp,
server/CommMetaClient.h, server/CommPSQLSocket.cpp,
server/CommPSQLSocket.h, server/CommPeer.cpp,
server/CommPeer.h, server/CommPeerListener.cpp,
server/CommPeerListener.h, server/CommRemoteClient.cpp,
server/CommRemoteClient.h, server/CommServer.cpp,
server/CommServer.h, server/CommSlaveClient.cpp,
server/CommSlaveClient.h, server/CommSlaveListener.cpp,
server/CommSlaveListener.h, server/CommSocket.cpp,
server/CommSocket.h, server/CommUnixListener.cpp,
server/CommUnixListener.h, server/Connection.cpp,
server/Connection.h, server/Connection_methods.h,
server/EntityFactory.cpp, server/EntityFactory.h,
server/ExternalMind.cpp, server/ExternalMind.h,
server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h,
server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h,
server/Persistance.cpp, server/Persistance.h,
server/PersistantThingFactory.cpp, server/PersistantThingFactory.h,
server/PersistantThingFactory_impl.h, server/Persistor.cpp,
server/Persistor.h, server/Persistor_impl.h,
server/Player.cpp, server/Player.h, server/Restoration.cpp,
server/Restoration.h, server/Restorer.cpp, server/Restorer.h,
server/Restorer_impl.h, server/ScriptFactory.cpp,
server/ScriptFactory.h, server/ServerRouting.cpp,
server/ServerRouting.h, server/ServerRouting_methods.h,
server/SlaveClientConnection.cpp, server/SlaveClientConnection.h,
server/TaskFactory.cpp, server/TaskFactory.h,
server/TrustedConnection.cpp, server/TrustedConnection.h,
server/WorldRouter.cpp, server/WorldRouter.h,
server/server.cpp, server/server.h, server/slave.cpp,
tests/Areatest.cpp, tests/BaseEntitytest.cpp,
tests/Charactertest.cpp, tests/Containertest.cpp,
tests/Creatortest.cpp, tests/EntityExerciser.h,
tests/EntityFactorytest.cpp, tests/Entitytest.cpp,
tests/Foodtest.cpp, tests/IGEntityExerciser.h,
tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp,
tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp,
tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h,
tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp,
tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp,
tests/distancetest.cpp, tests/emergencetest.cpp,
tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp,
tests/systemtest.cpp, tests/transformtest.cpp,
tests/type_utilstest.cpp, tests/utilitytest.cpp,
tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp,
tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp,
tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp,
tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp,
tools/cywatchdog.cpp: Replace the copyright and license statements
with new versions that include disclaimer of warranty, and
permit distribution under later versions of the GPL.
2006-01-19 02:17:06 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
2007-12-05 22:43:46 +00:00
|
|
|
// Copyright (C) 2000-2007 Alistair Riddoch
|
2006-01-19 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientAccount.cpp, aiclient/ClientAccount.h,
aiclient/ClientConnection.cpp, aiclient/ClientConnection.h,
aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp,
client/BaseClient.h, client/CharacterClient.cpp,
client/CharacterClient.h, client/ClientConnection.cpp,
client/ClientConnection.h, client/CreatorClient.cpp,
client/CreatorClient.h, client/ObserverClient.cpp,
client/ObserverClient.h, client/Py_CreatorClient.cpp,
client/Py_CreatorClient.h, client/client.cpp,
client/define_world.cpp, client/define_world.h, common/Add.h,
common/Affect.h, common/AtlasFileLoader.cpp,
common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp,
common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h,
common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp,
common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h,
common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h,
common/Eat.h, common/FormattedXMLWriter.cpp,
common/FormattedXMLWriter.h, common/Generic.h, common/Load.h,
common/Monitor.h, common/Mow.h, common/Nourish.h,
common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp,
common/Property.h, common/Property_impl.h, common/Save.h,
common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h,
common/Use.h, common/Wield.h, common/accountbase.cpp,
common/accountbase.h, common/const.cpp, common/const.h,
common/custom.cpp, common/debug.h, common/globals.cpp,
common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp,
common/inheritance.h, common/inheritance_impl.h, common/log.cpp,
common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h,
common/operations.cpp, common/operations.h, common/random.h,
common/refno.h, common/serialno.cpp, common/serialno.h,
common/system.cpp, common/system.h, common/terrain_utils.cpp,
common/terrain_utils.h, common/type_utils.h, common/types.h,
common/utility.cpp, common/utility.h, modules/DateTime.cpp,
modules/DateTime.h, modules/Location.cpp, modules/Location.h,
modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp,
physics/BBox.h, physics/Collision.cpp, physics/Collision.h,
physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp,
physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp,
rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h,
rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h,
rulesets/BaseMind.cpp, rulesets/BaseMind.h,
rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h,
rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp,
rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h,
rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp,
rulesets/Entity.h, rulesets/EntityProperties.cpp,
rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h,
rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp,
rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h,
rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp,
rulesets/MemMap.h, rulesets/MemMap_methods.h,
rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h,
rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp,
rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h,
rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp,
rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h,
rulesets/Py_Location.cpp, rulesets/Py_Location.h,
rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp,
rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h,
rulesets/Py_Operation.cpp, rulesets/Py_Operation.h,
rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp,
rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h,
rulesets/Py_Property.cpp, rulesets/Py_Property.h,
rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h,
rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h,
rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h,
rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp,
rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp,
rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h,
rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h,
rulesets/PythonArithmeticScript.cpp,
rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp,
rulesets/PythonMindScript.h, rulesets/PythonScript.cpp,
rulesets/PythonScript.h, rulesets/PythonThingScript.cpp,
rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp,
rulesets/PythonWrapper.h, rulesets/Python_API.cpp,
rulesets/Python_API.h, rulesets/Python_Script_Utils.h,
rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp,
rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h,
rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h,
rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp,
rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h,
rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h,
rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp,
rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h,
rulesets/attributes.h, server/Account.cpp, server/Account.h,
server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp,
server/ArithmeticFactory.h, server/CommClient.cpp,
server/CommClient.h, server/CommIdleSocket.cpp,
server/CommIdleSocket.h, server/CommListener.cpp,
server/CommListener.h, server/CommLocalClient.cpp,
server/CommLocalClient.h, server/CommMDNSPublisher.cpp,
server/CommMDNSPublisher.h, server/CommMaster.cpp,
server/CommMaster.h, server/CommMetaClient.cpp,
server/CommMetaClient.h, server/CommPSQLSocket.cpp,
server/CommPSQLSocket.h, server/CommPeer.cpp,
server/CommPeer.h, server/CommPeerListener.cpp,
server/CommPeerListener.h, server/CommRemoteClient.cpp,
server/CommRemoteClient.h, server/CommServer.cpp,
server/CommServer.h, server/CommSlaveClient.cpp,
server/CommSlaveClient.h, server/CommSlaveListener.cpp,
server/CommSlaveListener.h, server/CommSocket.cpp,
server/CommSocket.h, server/CommUnixListener.cpp,
server/CommUnixListener.h, server/Connection.cpp,
server/Connection.h, server/Connection_methods.h,
server/EntityFactory.cpp, server/EntityFactory.h,
server/ExternalMind.cpp, server/ExternalMind.h,
server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h,
server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h,
server/Persistance.cpp, server/Persistance.h,
server/PersistantThingFactory.cpp, server/PersistantThingFactory.h,
server/PersistantThingFactory_impl.h, server/Persistor.cpp,
server/Persistor.h, server/Persistor_impl.h,
server/Player.cpp, server/Player.h, server/Restoration.cpp,
server/Restoration.h, server/Restorer.cpp, server/Restorer.h,
server/Restorer_impl.h, server/ScriptFactory.cpp,
server/ScriptFactory.h, server/ServerRouting.cpp,
server/ServerRouting.h, server/ServerRouting_methods.h,
server/SlaveClientConnection.cpp, server/SlaveClientConnection.h,
server/TaskFactory.cpp, server/TaskFactory.h,
server/TrustedConnection.cpp, server/TrustedConnection.h,
server/WorldRouter.cpp, server/WorldRouter.h,
server/server.cpp, server/server.h, server/slave.cpp,
tests/Areatest.cpp, tests/BaseEntitytest.cpp,
tests/Charactertest.cpp, tests/Containertest.cpp,
tests/Creatortest.cpp, tests/EntityExerciser.h,
tests/EntityFactorytest.cpp, tests/Entitytest.cpp,
tests/Foodtest.cpp, tests/IGEntityExerciser.h,
tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp,
tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp,
tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h,
tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp,
tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp,
tests/distancetest.cpp, tests/emergencetest.cpp,
tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp,
tests/systemtest.cpp, tests/transformtest.cpp,
tests/type_utilstest.cpp, tests/utilitytest.cpp,
tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp,
tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp,
tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp,
tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp,
tools/cywatchdog.cpp: Replace the copyright and license statements
with new versions that include disclaimer of warranty, and
permit distribution under later versions of the GPL.
2006-01-19 02:17:06 +00:00
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2006-10-26 00:48:00 +00:00
|
|
|
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
#include "Database.h"
|
|
|
|
|
|
2005-11-12 01:40:37 +00:00
|
|
|
#include "id.h"
|
2002-07-14 21:04:50 +00:00
|
|
|
#include "log.h"
|
2002-04-12 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp,
common/Database.cpp, common/accountbase.h, modules/WorldTime.h,
rulesets/Py_World.cpp, server/Admin.cpp, server/Persistance.cpp,
server/Persistance.h:
Clean up includes.
* rulesets/Entity.cpp, rulesets/Entity.h: Write improved way of
handling immutable object attributes.
* server/EntityFactory.cpp, server/Player.cpp, server/Player.h:
Implement a character_types attribute on the player account,
by adding "playable" tag to rules database, and setting
up a set of character types when rules are read from database.
2002-04-12 21:54:44 +00:00
|
|
|
#include "debug.h"
|
|
|
|
|
#include "globals.h"
|
2005-09-13 01:01:58 +00:00
|
|
|
#include "compose.hpp"
|
2008-09-03 23:36:50 +00:00
|
|
|
#include "const.h"
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2005-08-27 14:52:12 +00:00
|
|
|
#include <Atlas/Message/MEncoder.h>
|
|
|
|
|
#include <Atlas/Message/Element.h>
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
#include <Atlas/Codecs/XML.h>
|
|
|
|
|
|
2006-01-04 15:06:46 +00:00
|
|
|
#include <varconf/config.h>
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2004-11-16 12:27:27 +00:00
|
|
|
#include <sstream>
|
2002-04-12 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp,
common/Database.cpp, common/accountbase.h, modules/WorldTime.h,
rulesets/Py_World.cpp, server/Admin.cpp, server/Persistance.cpp,
server/Persistance.h:
Clean up includes.
* rulesets/Entity.cpp, rulesets/Entity.h: Write improved way of
handling immutable object attributes.
* server/EntityFactory.cpp, server/Player.cpp, server/Player.h:
Implement a character_types attribute on the player account,
by adding "playable" tag to rules database, and setting
up a set of character types when rules are read from database.
2002-04-12 21:54:44 +00:00
|
|
|
|
2008-04-28 Al Riddoch <alriddoch@googlemail.com>
* common/Database.cpp, common/globals.cpp, common/id.cpp,
common/log.cpp, modules/DateTime.cpp, rulesets/Container.h,
rulesets/Statistics.h, server/CommListener.cpp,
server/CommServer.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp:
Add includes required for recent compilers which include less
stuff implicitly in standard headers.
2008-04-28 17:26:08 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
2003-10-30 00:03:54 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2003-08-07 23:03:26 +00:00
|
|
|
using Atlas::Message::Element;
|
2004-08-07 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.h,
common/Database.cpp, common/Database.h, common/FormattedXMLWriter.cpp,
common/FormattedXMLWriter.h, common/accountbase.cpp,
common/accountbase.h, common/custom.cpp, common/inheritance.cpp,
common/inheritance.h, common/operations.h, common/type_utils.h,
common/utility.cpp, common/utility.h, modules/Location.cpp,
modules/Location.h, rulesets/Area.cpp, rulesets/Area.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Creator.cpp, rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/Entity_getLocation.h, rulesets/Food.cpp, rulesets/Line.cpp,
rulesets/Line.h, rulesets/MemMap.cpp, rulesets/MemMap.h,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp, rulesets/Plant.h,
rulesets/Py_Mind.cpp, rulesets/Py_Object.cpp, rulesets/Py_Object.h,
rulesets/Py_Operation.cpp, rulesets/Py_Thing.cpp,
rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Stackable.h,
rulesets/Thing.cpp, rulesets/World.cpp, rulesets/World.h,
server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/CommClient.cpp, server/CommClient.h,
server/CommListener.cpp, server/CommListener.h,
server/CommLocalClient.cpp, server/CommLocalClient.h,
server/CommMetaClient.h, server/CommPSQLSocket.h,
server/CommRemoteClient.cpp, server/CommRemoteClient.h,
server/CommServer.cpp, server/CommServer.h, server/CommSocket.cpp,
server/CommSocket.h, server/CommUnixListener.cpp,
server/CommUnixListener.h, server/Connection.cpp,
server/Connection.h, server/EntityFactory.cpp,
server/EntityFactory.h, server/Lobby.cpp, server/Lobby.h,
server/Persistance.cpp, server/Persistance.h,
server/PersistantThingFactory.h, server/Persistor.cpp,
server/Player.cpp, server/Player.h, server/Restorer.h,
server/Restorer_impl.h, server/ServerRouting.cpp,
server/ServerRouting.h, server/TrustedConnection.cpp,
server/TrustedConnection.h, server/WorldRouter.cpp,
server/WorldRouter.h: Convert code to using Atlas Message
typedefs as found in Atlas-C++ 0.6 to aid conversion later.
2004-08-16 14:26:47 +00:00
|
|
|
using Atlas::Message::MapType;
|
2007-12-07 17:42:58 +00:00
|
|
|
using Atlas::Objects::Root;
|
2008-11-16 23:25:34 +00:00
|
|
|
using String::compose;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
|
2003-01-11 18:21:31 +00:00
|
|
|
typedef Atlas::Codecs::XML Serialiser;
|
|
|
|
|
|
2003-10-27 12:04:53 +00:00
|
|
|
static const bool debug_flag = false;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
|
|
|
|
Database * Database::m_instance = NULL;
|
|
|
|
|
|
2012-01-30 15:14:05 +00:00
|
|
|
static void databaseNotice(void *, const char * message)
|
2004-10-04 13:10:01 +00:00
|
|
|
{
|
2009-10-19 20:06:39 +01:00
|
|
|
log(NOTICE, "Notice from database:");
|
|
|
|
|
log_formatted(NOTICE, message);
|
2004-10-04 13:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2003-05-04 18:31:38 +00:00
|
|
|
Database::Database() : m_rule_db("rules"),
|
2003-10-24 23:50:12 +00:00
|
|
|
m_queryInProgress(false),
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
m_connection(NULL)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:15:46 +01:00
|
|
|
Database::~Database()
|
|
|
|
|
{
|
2011-09-28 23:19:21 +01:00
|
|
|
if (pendingQueries.size() != 0) {
|
|
|
|
|
log(ERROR, compose("Database delete with %1 queries pending",
|
|
|
|
|
pendingQueries.size()));
|
|
|
|
|
|
|
|
|
|
}
|
2011-09-28 23:15:46 +01:00
|
|
|
}
|
|
|
|
|
|
2002-11-24 02:51:54 +00:00
|
|
|
bool Database::tuplesOk()
|
|
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2002-11-24 02:51:54 +00:00
|
|
|
bool status = false;
|
|
|
|
|
|
|
|
|
|
PGresult * res;
|
|
|
|
|
while ((res = PQgetResult(m_connection)) != NULL) {
|
2002-12-10 23:38:15 +00:00
|
|
|
if (PQresultStatus(res) == PGRES_TUPLES_OK) {
|
|
|
|
|
status = true;
|
|
|
|
|
}
|
2003-07-21 09:37:58 +00:00
|
|
|
PQclear(res);
|
2002-11-24 02:51:54 +00:00
|
|
|
};
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 22:32:39 +01:00
|
|
|
int Database::commandOk()
|
2002-11-24 02:51:54 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2011-09-28 22:32:39 +01:00
|
|
|
int status = -1;
|
2002-11-24 02:51:54 +00:00
|
|
|
|
|
|
|
|
PGresult * res;
|
|
|
|
|
while ((res = PQgetResult(m_connection)) != NULL) {
|
2002-12-10 23:38:15 +00:00
|
|
|
if (PQresultStatus(res) == PGRES_COMMAND_OK) {
|
2011-09-28 22:32:39 +01:00
|
|
|
status = 0;
|
2004-07-12 10:58:20 +00:00
|
|
|
} else {
|
|
|
|
|
reportError();
|
2002-12-10 23:38:15 +00:00
|
|
|
}
|
2003-07-21 09:37:58 +00:00
|
|
|
PQclear(res);
|
2002-11-24 02:51:54 +00:00
|
|
|
};
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-05 23:40:05 +00:00
|
|
|
int Database::createInstanceDatabase()
|
|
|
|
|
{
|
|
|
|
|
assert(::instance != CYPHESIS);
|
|
|
|
|
|
|
|
|
|
std::string error_message;
|
|
|
|
|
|
|
|
|
|
if (connect(CYPHESIS, error_message) != 0) {
|
2008-11-16 23:45:51 +00:00
|
|
|
log(ERROR, compose("Connection to master database failed: \n%1",
|
|
|
|
|
error_message));
|
2007-12-05 23:40:05 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string dbname;
|
|
|
|
|
if (::instance == CYPHESIS) {
|
|
|
|
|
dbname = CYPHESIS;
|
|
|
|
|
} else {
|
2008-11-16 23:45:51 +00:00
|
|
|
dbname = compose("%1_%2", CYPHESIS, ::instance);
|
2007-12-05 23:40:05 +00:00
|
|
|
}
|
|
|
|
|
readConfigItem(::instance, "dbname", dbname);
|
|
|
|
|
|
2011-09-28 22:46:32 +01:00
|
|
|
if (runCommandQuery(compose("CREATE DATABASE %1", dbname)) != 0) {
|
2007-12-05 23:40:05 +00:00
|
|
|
shutdownConnection();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shutdownConnection();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Database::connect(const std::string & context, std::string & error_msg)
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
{
|
|
|
|
|
std::stringstream conninfos;
|
2007-11-05 19:35:32 +00:00
|
|
|
|
|
|
|
|
std::string db_server;
|
2007-12-05 23:54:22 +00:00
|
|
|
if (readConfigItem(context, "dbserver", db_server) == 0) {
|
2004-06-03 17:34:58 +00:00
|
|
|
if (db_server.empty()) {
|
2007-11-05 19:35:32 +00:00
|
|
|
log(WARNING, "Empty database hostname specified in config file. "
|
|
|
|
|
"Using none.");
|
2004-06-03 17:34:58 +00:00
|
|
|
} else {
|
2007-11-05 19:35:32 +00:00
|
|
|
conninfos << "host=" << db_server << " ";
|
2004-06-03 17:34:58 +00:00
|
|
|
}
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-05 22:43:46 +00:00
|
|
|
std::string dbname;
|
2007-12-05 23:54:22 +00:00
|
|
|
if (context == CYPHESIS) {
|
2007-12-05 22:43:46 +00:00
|
|
|
dbname = CYPHESIS;
|
|
|
|
|
} else {
|
2008-11-16 23:45:51 +00:00
|
|
|
dbname = compose("%1_%2", CYPHESIS, ::instance);
|
2007-12-05 22:43:46 +00:00
|
|
|
}
|
2007-12-05 23:54:22 +00:00
|
|
|
readConfigItem(context, "dbname", dbname);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
conninfos << "dbname=" << dbname << " ";
|
|
|
|
|
|
2007-11-05 19:35:32 +00:00
|
|
|
std::string db_user;
|
2007-12-05 23:54:22 +00:00
|
|
|
if (readConfigItem(context, "dbuser", db_user) == 0) {
|
2004-06-03 17:34:58 +00:00
|
|
|
if (db_user.empty()) {
|
2007-11-05 19:35:32 +00:00
|
|
|
log(WARNING, "Empty username specified in config file. "
|
|
|
|
|
"Using current user.");
|
2004-06-03 17:34:58 +00:00
|
|
|
} else {
|
|
|
|
|
conninfos << "user=" << db_user << " ";
|
|
|
|
|
}
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2007-11-05 19:35:32 +00:00
|
|
|
std::string db_passwd;
|
2007-12-05 23:54:22 +00:00
|
|
|
if (readConfigItem(context, "dbpasswd", db_passwd) == 0) {
|
2007-11-05 19:35:32 +00:00
|
|
|
conninfos << "password=" << db_passwd << " ";
|
2002-03-03 00:48:28 +00:00
|
|
|
}
|
|
|
|
|
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
const std::string cinfo = conninfos.str();
|
|
|
|
|
|
2002-11-24 02:51:54 +00:00
|
|
|
m_connection = PQconnectdb(cinfo.c_str());
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2005-09-13 01:01:58 +00:00
|
|
|
if (m_connection == NULL) {
|
2007-12-05 23:40:05 +00:00
|
|
|
error_msg = "Unknown error";
|
2005-09-13 01:01:58 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PQstatus(m_connection) != CONNECTION_OK) {
|
2007-12-05 23:40:05 +00:00
|
|
|
error_msg = PQerrorMessage(m_connection);
|
|
|
|
|
PQfinish(m_connection);
|
|
|
|
|
m_connection = 0;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Database::initConnection()
|
|
|
|
|
{
|
|
|
|
|
std::string error_message;
|
|
|
|
|
|
|
|
|
|
if (connect(::instance, error_message) != 0) {
|
2009-10-19 20:01:38 +01:00
|
|
|
log(ERROR, "Connection to database failed:");
|
|
|
|
|
log_formatted(ERROR, error_message);
|
2004-10-03 01:50:49 +00:00
|
|
|
return -1;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-04 13:10:01 +00:00
|
|
|
PQsetNoticeProcessor(m_connection, databaseNotice, 0);
|
|
|
|
|
|
2004-10-03 01:50:49 +00:00
|
|
|
return 0;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-28 22:54:35 +01:00
|
|
|
int Database::initRule(bool createTables)
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
int status = 0;
|
2004-03-08 14:36:44 +00:00
|
|
|
clearPendingQuery();
|
2008-11-16 23:45:51 +00:00
|
|
|
status = PQsendQuery(m_connection, "SELECT * FROM rules WHERE "
|
|
|
|
|
"id = 'test' AND contents = 'test'");
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
if (!status) {
|
2002-12-10 23:38:15 +00:00
|
|
|
reportError();
|
2011-09-28 22:54:35 +01:00
|
|
|
return -1;
|
2002-11-24 02:51:54 +00:00
|
|
|
}
|
2004-07-12 10:58:20 +00:00
|
|
|
|
2002-11-24 02:51:54 +00:00
|
|
|
if (!tuplesOk()) {
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
debug(std::cout << "Rule table does not exist"
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
if (createTables) {
|
2008-11-16 23:45:51 +00:00
|
|
|
std::string query = compose("CREATE TABLE rules ( "
|
|
|
|
|
"id varchar(%1) PRIMARY KEY, "
|
|
|
|
|
"ruleset varchar(%1), "
|
|
|
|
|
"contents text ) "
|
|
|
|
|
"WITHOUT OIDS", consts::id_len);
|
2008-11-13 03:27:17 +00:00
|
|
|
status = PQsendQuery(m_connection, query.c_str());
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
if (!status) {
|
2002-12-10 23:38:15 +00:00
|
|
|
reportError();
|
2011-09-28 22:54:35 +01:00
|
|
|
return -1;
|
2002-12-10 23:38:15 +00:00
|
|
|
}
|
2011-09-28 22:32:39 +01:00
|
|
|
if (commandOk() != 0) {
|
2002-07-14 21:04:50 +00:00
|
|
|
log(ERROR, "Error creating rules table in database");
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
reportError();
|
2011-09-28 22:54:35 +01:00
|
|
|
return -1;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
}
|
2003-10-28 00:18:18 +00:00
|
|
|
allTables.insert("rules");
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
} else {
|
2002-07-14 21:04:50 +00:00
|
|
|
log(ERROR, "Server table does not exist in database");
|
2011-09-28 22:54:35 +01:00
|
|
|
return -1;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-10-28 00:18:18 +00:00
|
|
|
allTables.insert("rules");
|
2011-09-28 22:54:35 +01:00
|
|
|
return 0;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
void Database::shutdownConnection()
|
|
|
|
|
{
|
2007-12-06 02:49:32 +00:00
|
|
|
if (m_connection != 0) {
|
|
|
|
|
PQfinish(m_connection);
|
|
|
|
|
m_connection = 0;
|
|
|
|
|
}
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Database * Database::instance()
|
|
|
|
|
{
|
|
|
|
|
if (m_instance == NULL) {
|
|
|
|
|
m_instance = new Database();
|
|
|
|
|
}
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-06 08:11:23 +00:00
|
|
|
void Database::cleanup()
|
|
|
|
|
{
|
2012-05-14 14:45:32 +01:00
|
|
|
delete m_instance;
|
2006-12-06 08:11:23 +00:00
|
|
|
|
|
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:01:12 +01:00
|
|
|
int Database::decodeObject(const std::string & data,
|
|
|
|
|
Root &o)
|
2007-12-07 17:42:58 +00:00
|
|
|
{
|
|
|
|
|
if (data.empty()) {
|
2011-09-28 23:01:12 +01:00
|
|
|
return 0;
|
2007-12-07 17:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::stringstream str(data, std::ios::in);
|
|
|
|
|
|
|
|
|
|
Serialiser codec(str, m_od);
|
|
|
|
|
Atlas::Message::Encoder enc(codec);
|
|
|
|
|
|
|
|
|
|
// Clear the decoder
|
2011-09-28 22:56:59 +01:00
|
|
|
m_od.get();
|
2007-12-07 17:42:58 +00:00
|
|
|
|
|
|
|
|
codec.poll();
|
|
|
|
|
|
|
|
|
|
if (!m_od.check()) {
|
|
|
|
|
log(WARNING, "Database entry does not appear to be decodable");
|
2011-09-28 23:01:12 +01:00
|
|
|
return -1;
|
2007-12-07 17:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
o = m_od.get();
|
2011-09-28 23:01:12 +01:00
|
|
|
return 0;
|
2007-12-07 17:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:13:13 +01:00
|
|
|
int Database::decodeMessage(const std::string & data,
|
|
|
|
|
MapType &o)
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
{
|
2003-01-12 03:21:54 +00:00
|
|
|
if (data.empty()) {
|
2011-09-28 23:13:13 +01:00
|
|
|
return 0;
|
2003-01-12 03:21:54 +00:00
|
|
|
}
|
|
|
|
|
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
std::stringstream str(data, std::ios::in);
|
|
|
|
|
|
2005-08-27 14:52:12 +00:00
|
|
|
Serialiser codec(str, m_d);
|
|
|
|
|
Atlas::Message::Encoder enc(codec);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
|
|
|
|
// Clear the decoder
|
|
|
|
|
m_d.get();
|
|
|
|
|
|
2003-08-07 23:03:26 +00:00
|
|
|
codec.poll();
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
|
|
|
|
if (!m_d.check()) {
|
2002-07-14 21:04:50 +00:00
|
|
|
log(WARNING, "Database entry does not appear to be decodable");
|
2011-09-28 23:13:13 +01:00
|
|
|
return -1;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
2004-07-12 10:58:20 +00:00
|
|
|
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
o = m_d.get();
|
2011-09-28 23:13:13 +01:00
|
|
|
return 0;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:22:18 +01:00
|
|
|
int Database::encodeObject(const MapType & o,
|
|
|
|
|
std::string & data)
|
2003-01-11 18:21:31 +00:00
|
|
|
{
|
|
|
|
|
std::stringstream str;
|
|
|
|
|
|
2005-08-27 14:52:12 +00:00
|
|
|
Serialiser codec(str, m_d);
|
|
|
|
|
Atlas::Message::Encoder enc(codec);
|
2003-01-11 18:21:31 +00:00
|
|
|
|
2003-08-07 23:03:26 +00:00
|
|
|
codec.streamBegin();
|
2005-08-27 14:52:12 +00:00
|
|
|
enc.streamMessageElement(o);
|
2003-08-07 23:03:26 +00:00
|
|
|
codec.streamEnd();
|
2003-01-11 18:21:31 +00:00
|
|
|
|
2008-09-02 18:31:18 +00:00
|
|
|
std::string raw = str.str();
|
|
|
|
|
char safe[raw.size() * 2 + 1];
|
2008-09-27 15:36:31 +00:00
|
|
|
int errcode;
|
2008-09-02 18:31:18 +00:00
|
|
|
|
2008-09-27 15:36:31 +00:00
|
|
|
PQescapeStringConn(m_connection, safe, raw.c_str(), raw.size(), &errcode);
|
|
|
|
|
|
|
|
|
|
if (errcode != 0) {
|
|
|
|
|
std::cerr << "ERROR: " << errcode << std::endl << std::flush;
|
|
|
|
|
}
|
2008-09-02 18:31:18 +00:00
|
|
|
|
|
|
|
|
data = safe;
|
|
|
|
|
|
2011-09-28 23:22:18 +01:00
|
|
|
return 0;
|
2003-01-11 18:21:31 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:28:47 +01:00
|
|
|
int Database::getObject(const std::string & table,
|
|
|
|
|
const std::string & key,
|
|
|
|
|
MapType & o)
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2002-11-24 02:51:54 +00:00
|
|
|
debug(std::cout << "Database::getObject() " << table << "." << key
|
|
|
|
|
<< std::endl << std::flush;);
|
2004-10-02 01:12:02 +00:00
|
|
|
std::string query = std::string("SELECT * FROM ") + table + " WHERE id = '" + key + "'";
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
clearPendingQuery();
|
2002-11-24 02:51:54 +00:00
|
|
|
int status = PQsendQuery(m_connection, query.c_str());
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
if (!status) {
|
2002-12-10 23:38:15 +00:00
|
|
|
reportError();
|
2011-09-28 23:28:47 +01:00
|
|
|
return -1;
|
2002-11-24 02:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PGresult * res;
|
|
|
|
|
if ((res = PQgetResult(m_connection)) == NULL) {
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
debug(std::cout << "Error accessing " << key << " in " << table
|
2002-03-06 19:40:55 +00:00
|
|
|
<< " table" << std::endl << std::flush;);
|
2011-09-28 23:28:47 +01:00
|
|
|
return -1;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
2007-07-30 Al Riddoch <alriddoch@zepler.org>
* client/Py_CreatorClient.cpp, common/Database.cpp,
common/accountbase.cpp, common/system.cpp, rulesets/Character.cpp,
rulesets/Motion.cpp, rulesets/Plant.cpp, rulesets/Py_Location.cpp,
rulesets/Py_Mind.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Point3D.cpp, rulesets/Py_Statistics.cpp,
rulesets/Py_Task.cpp, rulesets/Py_TerrainProperty.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Vector3D.cpp,
rulesets/Py_WorldTime.cpp, rulesets/Python_API.cpp,
rulesets/TerrainProperty.cpp, server/Admin.cpp,
server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/WorldRouter.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp:
Remove unnecessary () from conditional expressions, where operator
binding is clear.
2007-07-30 18:12:50 +00:00
|
|
|
if (PQntuples(res) < 1 || PQnfields(res) < 2) {
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
debug(std::cout << "No entry for " << key << " in " << table
|
|
|
|
|
<< " table" << std::endl << std::flush;);
|
2003-07-21 09:37:58 +00:00
|
|
|
PQclear(res);
|
|
|
|
|
while ((res = PQgetResult(m_connection)) != NULL) {
|
|
|
|
|
PQclear(res);
|
|
|
|
|
}
|
2011-09-28 23:28:47 +01:00
|
|
|
return -1;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
2002-11-24 02:51:54 +00:00
|
|
|
const char * data = PQgetvalue(res, 0, 1);
|
2002-03-06 19:40:55 +00:00
|
|
|
debug(std::cout << "Got record " << key << " from database, value " << data
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
<< std::endl << std::flush;);
|
2002-11-24 02:51:54 +00:00
|
|
|
|
2011-09-28 23:13:13 +01:00
|
|
|
int ret = decodeMessage(data, o);
|
2003-07-21 09:37:58 +00:00
|
|
|
PQclear(res);
|
2002-11-24 02:51:54 +00:00
|
|
|
|
2003-07-21 09:37:58 +00:00
|
|
|
while ((res = PQgetResult(m_connection)) != NULL) {
|
|
|
|
|
PQclear(res);
|
2002-11-24 02:51:54 +00:00
|
|
|
log(ERROR, "Extra database result to simple query.");
|
|
|
|
|
};
|
|
|
|
|
|
2011-09-28 23:28:47 +01:00
|
|
|
return ret;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:28:47 +01:00
|
|
|
int Database::putObject(const std::string & table,
|
|
|
|
|
const std::string & key,
|
|
|
|
|
const MapType & o,
|
|
|
|
|
const StringVector & c)
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
{
|
2002-11-24 02:51:54 +00:00
|
|
|
debug(std::cout << "Database::putObject() " << table << "." << key
|
|
|
|
|
<< std::endl << std::flush;);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
std::stringstream str;
|
|
|
|
|
|
2005-08-27 14:52:12 +00:00
|
|
|
Serialiser codec(str, m_d);
|
|
|
|
|
Atlas::Message::Encoder enc(codec);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2003-08-07 23:03:26 +00:00
|
|
|
codec.streamBegin();
|
2005-08-27 14:52:12 +00:00
|
|
|
enc.streamMessageElement(o);
|
2003-08-07 23:03:26 +00:00
|
|
|
codec.streamEnd();
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2007-07-29 Al Riddoch <alriddoch@zepler.org>
* common/log.cpp, common/log.h, common/BaseEntity.cpp,
common/BaseEntity.h: Switch to taking a C++ string reference rather
than a char *, for the rest of the logging and error related
calls.
* common/Database.cpp, common/log.cpp, common/log.h,
rulesets/PythonMindScript.cpp, server/Account.cpp,
server/Admin.cpp, server/Connection.cpp, server/Player.cpp,
tools/cyisoload.cpp: Convert over to using the new API correctly.
2007-07-29 12:22:58 +00:00
|
|
|
debug(std::cout << "Encoded to: " << str.str() << " "
|
2002-03-06 19:40:55 +00:00
|
|
|
<< str.str().size() << std::endl << std::flush;);
|
2004-07-12 10:58:20 +00:00
|
|
|
std::string query = std::string("INSERT INTO ") + table + " VALUES ('" + key;
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
StringVector::const_iterator Iend = c.end();
|
|
|
|
|
for (StringVector::const_iterator I = c.begin(); I != Iend; ++I) {
|
2004-07-12 10:58:20 +00:00
|
|
|
query += "', '";
|
|
|
|
|
query += *I;
|
|
|
|
|
}
|
|
|
|
|
query += "', '";
|
|
|
|
|
query += str.str();
|
2004-10-02 01:12:02 +00:00
|
|
|
query += "')";
|
2011-09-29 12:11:15 +01:00
|
|
|
return scheduleCommand(query);
|
2002-03-03 02:37:35 +00:00
|
|
|
}
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2011-09-28 23:28:47 +01:00
|
|
|
int Database::updateObject(const std::string & table,
|
|
|
|
|
const std::string & key,
|
|
|
|
|
const MapType & o)
|
2002-03-03 02:37:35 +00:00
|
|
|
{
|
2002-11-24 02:51:54 +00:00
|
|
|
debug(std::cout << "Database::updateObject() " << table << "." << key
|
|
|
|
|
<< std::endl << std::flush;);
|
2002-03-03 02:37:35 +00:00
|
|
|
std::stringstream str;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2005-08-27 14:52:12 +00:00
|
|
|
Serialiser codec(str, m_d);
|
|
|
|
|
Atlas::Message::Encoder enc(codec);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2003-08-07 23:03:26 +00:00
|
|
|
codec.streamBegin();
|
2005-08-27 14:52:12 +00:00
|
|
|
enc.streamMessageElement(o);
|
2003-08-07 23:03:26 +00:00
|
|
|
codec.streamEnd();
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2002-07-14 16:10:17 +00:00
|
|
|
std::string query = std::string("UPDATE ") + table + " SET contents = '" +
|
2004-10-02 01:12:02 +00:00
|
|
|
str.str() + "' WHERE id='" + key + "'";
|
2011-09-29 12:11:15 +01:00
|
|
|
return scheduleCommand(query);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:28:47 +01:00
|
|
|
int Database::delObject(const std::string & table, const std::string & key)
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
{
|
|
|
|
|
#if 0
|
|
|
|
|
Dbt key, data;
|
|
|
|
|
|
|
|
|
|
key.set_data((void*)keystr);
|
|
|
|
|
key.set_size(strlen(keystr) + 1);
|
|
|
|
|
|
|
|
|
|
int err;
|
|
|
|
|
if ((err = db.del(NULL, &key, 0)) != 0) {
|
|
|
|
|
debug(cout << "db.del.ERROR! " << err << endl << flush;);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
#endif
|
2011-09-28 23:28:47 +01:00
|
|
|
return 0;
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-22 11:25:24 +00:00
|
|
|
bool Database::hasKey(const std::string & table, const std::string & key)
|
|
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2004-07-22 11:25:24 +00:00
|
|
|
std::string query = std::string("SELECT id FROM ") + table +
|
2004-10-02 01:12:02 +00:00
|
|
|
" WHERE id='" + key + "'";
|
2004-07-22 11:25:24 +00:00
|
|
|
|
|
|
|
|
clearPendingQuery();
|
|
|
|
|
int status = PQsendQuery(m_connection, query.c_str());
|
|
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
|
reportError();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PGresult * res;
|
|
|
|
|
bool ret = false;
|
|
|
|
|
if ((res = PQgetResult(m_connection)) == NULL) {
|
|
|
|
|
debug(std::cout << "Error accessing " << table
|
|
|
|
|
<< " table" << std::endl << std::flush;);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
int results = PQntuples(res);
|
|
|
|
|
if (results > 0) {
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
PQclear(res);
|
|
|
|
|
while ((res = PQgetResult(m_connection)) != NULL) {
|
|
|
|
|
PQclear(res);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:12:00 +01:00
|
|
|
int Database::getTable(const std::string & table,
|
|
|
|
|
std::map<std::string, Root> & contents)
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
{
|
2006-12-31 15:56:35 +00:00
|
|
|
if (m_connection == 0) {
|
|
|
|
|
log(CRITICAL, "Database connection is down. This is okay during tests");
|
2011-09-29 10:12:00 +01:00
|
|
|
return -1;
|
2006-12-31 15:56:35 +00:00
|
|
|
}
|
2006-12-06 08:11:23 +00:00
|
|
|
|
2004-10-02 01:12:02 +00:00
|
|
|
std::string query = std::string("SELECT * FROM ") + table;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
clearPendingQuery();
|
2002-11-24 02:51:54 +00:00
|
|
|
int status = PQsendQuery(m_connection, query.c_str());
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
|
|
|
|
|
if (!status) {
|
2002-11-24 02:51:54 +00:00
|
|
|
reportError();
|
2011-09-29 10:12:00 +01:00
|
|
|
return -1;
|
2002-11-24 02:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PGresult * res;
|
|
|
|
|
if ((res = PQgetResult(m_connection)) == NULL) {
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
debug(std::cout << "Error accessing " << table
|
2002-03-06 19:40:55 +00:00
|
|
|
<< " table" << std::endl << std::flush;);
|
2011-09-29 10:12:00 +01:00
|
|
|
return -1;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
}
|
2002-11-24 02:51:54 +00:00
|
|
|
int results = PQntuples(res);
|
2007-07-30 Al Riddoch <alriddoch@zepler.org>
* client/Py_CreatorClient.cpp, common/Database.cpp,
common/accountbase.cpp, common/system.cpp, rulesets/Character.cpp,
rulesets/Motion.cpp, rulesets/Plant.cpp, rulesets/Py_Location.cpp,
rulesets/Py_Mind.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Point3D.cpp, rulesets/Py_Statistics.cpp,
rulesets/Py_Task.cpp, rulesets/Py_TerrainProperty.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Vector3D.cpp,
rulesets/Py_WorldTime.cpp, rulesets/Python_API.cpp,
rulesets/TerrainProperty.cpp, server/Admin.cpp,
server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/WorldRouter.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp:
Remove unnecessary () from conditional expressions, where operator
binding is clear.
2007-07-30 18:12:50 +00:00
|
|
|
if (results < 1 || PQnfields(res) < 2) {
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
debug(std::cout << "No entries in " << table
|
|
|
|
|
<< " table" << std::endl << std::flush;);
|
2003-07-21 09:37:58 +00:00
|
|
|
PQclear(res);
|
|
|
|
|
while ((res = PQgetResult(m_connection)) != NULL) {
|
|
|
|
|
PQclear(res);
|
|
|
|
|
}
|
2011-09-29 10:12:00 +01:00
|
|
|
return -1;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
}
|
2004-07-12 10:58:20 +00:00
|
|
|
int id_column = PQfnumber(res, "id"),
|
|
|
|
|
contents_column = PQfnumber(res, "contents");
|
|
|
|
|
|
|
|
|
|
if (id_column == -1 || contents_column == -1) {
|
|
|
|
|
log(ERROR, "Could not find 'id' and 'contents' columns in database result");
|
2011-09-29 10:12:00 +01:00
|
|
|
return -1;
|
2004-07-12 10:58:20 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-07 17:42:58 +00:00
|
|
|
Root t;
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
for(int i = 0; i < results; ++i) {
|
2004-07-12 10:58:20 +00:00
|
|
|
const char * key = PQgetvalue(res, i, id_column);
|
|
|
|
|
const char * data = PQgetvalue(res, i, contents_column);
|
2002-03-06 19:40:55 +00:00
|
|
|
debug(std::cout << "Got record " << key << " from database, value "
|
|
|
|
|
<< data << std::endl << std::flush;);
|
2004-07-12 10:58:20 +00:00
|
|
|
|
2011-09-28 23:01:12 +01:00
|
|
|
if (decodeObject(data, t) == 0) {
|
2007-12-07 17:42:58 +00:00
|
|
|
contents[key] = t;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
}
|
2004-07-12 10:58:20 +00:00
|
|
|
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
}
|
2003-07-21 09:37:58 +00:00
|
|
|
PQclear(res);
|
2002-11-24 02:51:54 +00:00
|
|
|
|
|
|
|
|
while ((res = PQgetResult(m_connection)) != NULL) {
|
2003-07-21 09:37:58 +00:00
|
|
|
PQclear(res);
|
2002-11-24 02:51:54 +00:00
|
|
|
log(ERROR, "Extra database result to simple query.");
|
|
|
|
|
};
|
|
|
|
|
|
2011-09-29 10:12:00 +01:00
|
|
|
return 0;
|
2002-01-27 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/Database.h,
server/Persistance.cpp, server/Persistance.h:
Add a new table to store rulesets, so they can be persisted, and
edited online. The new ruleset format integrates information
about the class hierarchy, scripting and default attributes.
Added low level method to fetch an entire database table as an
Atlas map.
* tools/cyloadrules.cpp: New tool to load rulesets in new xml
format into database table.
* server/EntityFactory.cpp, server/EntityFactory.h:
New re-written Entity Factory, to support new rules database
table, and better class definition capabilities.
* rulesets/EntityFactory.cpp, rulesets/EntityFactory.h:
Removed from build.
* client/CommClient.cpp: Redundant include removed.
* rulesets/ThingFactory.h: Add storage to factory for script
info and default attributes.
* server/WorldRouter.cpp: Switch to using new EntityFactory.
* server/server.cpp: Removed old ruleset loading code, and now
simply load the ruleset names from the config file.
* tools/cycmd.cpp: Exit correctly if connection fails.
2002-01-27 00:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:31:41 +01:00
|
|
|
int Database::clearTable(const std::string & table)
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
{
|
2004-10-02 01:12:02 +00:00
|
|
|
std::string query = std::string("DELETE FROM ") + table;
|
2011-09-29 12:11:15 +01:00
|
|
|
return scheduleCommand(query);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
2002-01-28 Al Riddoch <alriddoch@zepler.org>
* client/ClientConnection.cpp, client/CommClient.h,
common/globals.cpp, common/globals.h, server/server.cpp,
tools/cycmd.cpp:
Make the TCP port number a global config setting, and
ensure it is used everwhere, so it can be overriden, and all
clients and tools will use it. Modify behavoir so that any
settings overridden on the command line are made semi-permanent
in the users home directory, making it easier for users to run
two versions on one machine at the same time.
* common/Database.cpp, common/Database.h: Remove obsolete iterator
code. Add a method to clear a given database table.
* server/Persistance.h, tools/cyloadrules.cpp:
Automate loading of the ruleset given in the config file, and
the rulesets it depends on, ensuring that the rules table
is cleared first.
2002-01-28 11:40:10 +00:00
|
|
|
void Database::reportError()
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2004-10-04 13:10:01 +00:00
|
|
|
char * message = PQerrorMessage(m_connection);
|
|
|
|
|
assert(message != NULL);
|
|
|
|
|
|
|
|
|
|
if (strlen(message) < 2) {
|
|
|
|
|
log(WARNING, "Zero length database error message");
|
|
|
|
|
}
|
|
|
|
|
std::string msg = std::string("DATABASE: ") + message;
|
|
|
|
|
msg = msg.substr(0, msg.size() - 1);
|
2007-07-29 Al Riddoch <alriddoch@zepler.org>
* common/log.cpp, common/log.h: Switch to taking a C++ string reference
rather than a char *, as it is not really an optimisation, and it
makes the code simpler to read and write.
* client/BaseClient.cpp, client/ClientConnection.cpp,
common/AtlasFileLoader.cpp, common/BaseEntity.cpp,
common/Database.cpp, common/globals.cpp, common/id.cpp,
common/inheritance.cpp, common/log.cpp, common/log.h,
rulesets/Character.cpp, rulesets/Creator.cpp, rulesets/Entity.cpp,
rulesets/MemMap.cpp, rulesets/Motion.cpp, rulesets/Pedestrian.cpp,
rulesets/Py_Object.cpp, rulesets/Py_RootEntity.cpp,
rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp,
rulesets/Python_API.cpp, rulesets/Thing.cpp, server/Account.cpp,
server/Admin.cpp, server/ArithmeticFactory.cpp,
server/CommClient.cpp, server/CommListener.cpp,
server/CommMDNSPublisher.cpp, server/CommServer.cpp,
server/Connection.cpp, server/EntityFactory.cpp,
server/Persistance.cpp, server/Restoration.cpp,
server/ScriptFactory.cpp, server/TaskFactory.cpp,
server/WorldRouter.cpp, server/server.cpp: Convert over to using
new API correctly.
* data/mason.xml: Add biomass and transient to fircone, making its
script obsolete:
2007-07-29 03:33:33 +00:00
|
|
|
log(ERROR, msg);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
2002-11-25 15:41:04 +00:00
|
|
|
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
const DatabaseResult Database::runSimpleSelectQuery(const std::string & query)
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
debug(std::cout << "QUERY: " << query << std::endl << std::flush;);
|
2003-10-27 01:59:53 +00:00
|
|
|
clearPendingQuery();
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
int status = PQsendQuery(m_connection, query.c_str());
|
|
|
|
|
if (!status) {
|
2005-01-13 00:38:41 +00:00
|
|
|
log(ERROR, "runSimpleSelectQuery(): Database query error.");
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
reportError();
|
|
|
|
|
return DatabaseResult(0);
|
|
|
|
|
}
|
|
|
|
|
debug(std::cout << "done" << std::endl << std::flush;);
|
|
|
|
|
PGresult * res;
|
|
|
|
|
if ((res = PQgetResult(m_connection)) == NULL) {
|
|
|
|
|
log(ERROR, "Error selecting.");
|
|
|
|
|
reportError();
|
|
|
|
|
debug(std::cout << "Row query didn't work"
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
return DatabaseResult(0);
|
|
|
|
|
}
|
|
|
|
|
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
|
|
|
|
|
log(ERROR, "Error selecting row.");
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "QUERY: " << query << std::endl << std::flush;);
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
reportError();
|
2003-07-21 09:37:58 +00:00
|
|
|
PQclear(res);
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
res = 0;
|
|
|
|
|
}
|
2003-07-21 09:37:58 +00:00
|
|
|
PGresult * nres;
|
|
|
|
|
while ((nres = PQgetResult(m_connection)) != NULL) {
|
|
|
|
|
PQclear(nres);
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
log(ERROR, "Extra database result to simple query.");
|
|
|
|
|
};
|
|
|
|
|
return DatabaseResult(res);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 22:46:32 +01:00
|
|
|
int Database::runCommandQuery(const std::string & query)
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
clearPendingQuery();
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
int status = PQsendQuery(m_connection, query.c_str());
|
|
|
|
|
if (!status) {
|
2005-01-13 00:38:41 +00:00
|
|
|
log(ERROR, "runCommandQuery(): Database query error.");
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
reportError();
|
2011-09-28 22:46:32 +01:00
|
|
|
return -1;
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
2011-09-28 22:32:39 +01:00
|
|
|
if (commandOk() != 0) {
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
log(ERROR, "Error running command query row.");
|
2007-07-29 Al Riddoch <alriddoch@zepler.org>
* common/log.cpp, common/log.h, common/BaseEntity.cpp,
common/BaseEntity.h: Switch to taking a C++ string reference rather
than a char *, for the rest of the logging and error related
calls.
* common/Database.cpp, common/log.cpp, common/log.h,
rulesets/PythonMindScript.cpp, server/Account.cpp,
server/Admin.cpp, server/Connection.cpp, server/Player.cpp,
tools/cyisoload.cpp: Convert over to using the new API correctly.
2007-07-29 12:22:58 +00:00
|
|
|
log(NOTICE, query);
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
reportError();
|
|
|
|
|
debug(std::cout << "Row query didn't work"
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
} else {
|
|
|
|
|
debug(std::cout << "Query worked" << std::endl << std::flush;);
|
2011-09-28 22:46:32 +01:00
|
|
|
return 0;
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
2011-09-28 22:46:32 +01:00
|
|
|
return -1;
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:15:43 +01:00
|
|
|
int Database::registerRelation(std::string & tablename,
|
|
|
|
|
const std::string & sourcetable,
|
|
|
|
|
const std::string & targettable,
|
|
|
|
|
RelationType kind)
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2004-07-14 18:31:07 +00:00
|
|
|
tablename = sourcetable + "_" + targettable;
|
|
|
|
|
|
2008-11-16 23:25:34 +00:00
|
|
|
std::string query = compose("SELECT * FROM %1 WHERE source = 0 "
|
|
|
|
|
"AND target = 0", tablename);
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
|
|
|
|
|
debug(std::cout << "QUERY: " << query << std::endl << std::flush;);
|
2004-03-08 14:36:44 +00:00
|
|
|
clearPendingQuery();
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
int status = PQsendQuery(m_connection, query.c_str());
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
if (!status) {
|
2005-01-13 00:38:41 +00:00
|
|
|
log(ERROR, "registerRelation(): Database query error.");
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
reportError();
|
2011-09-29 12:15:43 +01:00
|
|
|
return -1;
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
}
|
|
|
|
|
if (!tuplesOk()) {
|
|
|
|
|
debug(reportError(););
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
debug(std::cout << "Table does not yet exist"
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
} else {
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
debug(std::cout << "Table exists" << std::endl << std::flush;);
|
2004-07-14 18:31:07 +00:00
|
|
|
allTables.insert(tablename);
|
2011-09-29 12:15:43 +01:00
|
|
|
return 0;
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
}
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
|
2008-11-16 23:25:34 +00:00
|
|
|
query = "CREATE TABLE ";
|
|
|
|
|
query += tablename;
|
|
|
|
|
if (kind == OneToOne || kind == ManyToOne) {
|
|
|
|
|
query += " (source integer UNIQUE REFERENCES ";
|
|
|
|
|
} else {
|
|
|
|
|
query += " (source integer REFERENCES ";
|
|
|
|
|
}
|
|
|
|
|
query += sourcetable;
|
|
|
|
|
if (kind == OneToOne || kind == OneToMany) {
|
|
|
|
|
query += " (id), target integer UNIQUE REFERENCES ";
|
|
|
|
|
} else {
|
|
|
|
|
query += " (id), target integer REFERENCES ";
|
|
|
|
|
}
|
|
|
|
|
query += targettable;
|
|
|
|
|
query += " (id) ON DELETE CASCADE ) WITHOUT OIDS";
|
|
|
|
|
|
|
|
|
|
debug(std::cout << "CREATE QUERY: " << query
|
2004-07-16 16:15:11 +00:00
|
|
|
<< std::endl << std::flush;);
|
2011-09-28 22:46:32 +01:00
|
|
|
if (runCommandQuery(query) != 0) {
|
2011-09-29 12:15:43 +01:00
|
|
|
return -1;
|
2003-01-05 19:55:52 +00:00
|
|
|
}
|
2004-07-14 18:31:07 +00:00
|
|
|
allTables.insert(tablename);
|
|
|
|
|
#if 0
|
2007-07-30 Al Riddoch <alriddoch@zepler.org>
* client/Py_CreatorClient.cpp, common/Database.cpp,
common/accountbase.cpp, common/system.cpp, rulesets/Character.cpp,
rulesets/Motion.cpp, rulesets/Plant.cpp, rulesets/Py_Location.cpp,
rulesets/Py_Mind.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Point3D.cpp, rulesets/Py_Statistics.cpp,
rulesets/Py_Task.cpp, rulesets/Py_TerrainProperty.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Vector3D.cpp,
rulesets/Py_WorldTime.cpp, rulesets/Python_API.cpp,
rulesets/TerrainProperty.cpp, server/Admin.cpp,
server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/WorldRouter.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp:
Remove unnecessary () from conditional expressions, where operator
binding is clear.
2007-07-30 18:12:50 +00:00
|
|
|
if (kind == ManyToOne || kind == OneToOne) {
|
2003-01-05 19:55:52 +00:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
std::string indexQuery = "CREATE INDEX ";
|
2004-07-14 18:31:07 +00:00
|
|
|
indexQuery += tablename;
|
|
|
|
|
indexQuery += "_source_idx ON ";
|
|
|
|
|
indexQuery += tablename;
|
2004-10-02 01:12:02 +00:00
|
|
|
indexQuery += " (source)";
|
2011-09-28 22:46:32 +01:00
|
|
|
return runCommandQuery(indexQuery) == 0;
|
2003-01-05 19:55:52 +00:00
|
|
|
}
|
2004-07-14 18:31:07 +00:00
|
|
|
#else
|
2011-09-29 12:15:43 +01:00
|
|
|
return 0;
|
2004-07-14 18:31:07 +00:00
|
|
|
#endif
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-05 19:55:52 +00:00
|
|
|
const DatabaseResult Database::selectRelation(const std::string & name,
|
|
|
|
|
const std::string & id)
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
{
|
2004-07-14 18:31:07 +00:00
|
|
|
std::string query = "SELECT target FROM ";
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
query += name;
|
2004-07-14 18:31:07 +00:00
|
|
|
query += " WHERE source = ";
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
query += id;
|
|
|
|
|
|
|
|
|
|
debug(std::cout << "Selecting on id = " << id << " ... " << std::flush;);
|
|
|
|
|
|
|
|
|
|
return runSimpleSelectQuery(query);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::createRelationRow(const std::string & name,
|
|
|
|
|
const std::string & id,
|
|
|
|
|
const std::string & other)
|
2003-01-05 19:55:52 +00:00
|
|
|
{
|
|
|
|
|
std::string query = "INSERT INTO ";
|
|
|
|
|
query += name;
|
2004-07-14 18:31:07 +00:00
|
|
|
query += " (source, target) VALUES (";
|
2003-01-05 19:55:52 +00:00
|
|
|
query += id;
|
|
|
|
|
query += ", ";
|
|
|
|
|
query += other;
|
2004-10-02 01:12:02 +00:00
|
|
|
query += ")";
|
2003-01-05 19:55:52 +00:00
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
return scheduleCommand(query);
|
2003-01-05 19:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::removeRelationRow(const std::string & name,
|
|
|
|
|
const std::string & id)
|
2003-01-12 15:06:09 +00:00
|
|
|
{
|
|
|
|
|
std::string query = "DELETE FROM ";
|
|
|
|
|
query += name;
|
2004-09-14 16:39:30 +00:00
|
|
|
query += " WHERE source = ";
|
2003-01-12 15:06:09 +00:00
|
|
|
query += id;
|
|
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
return scheduleCommand(query);
|
2003-01-12 15:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::removeRelationRowByOther(const std::string & name,
|
|
|
|
|
const std::string & other)
|
2003-01-12 15:06:09 +00:00
|
|
|
{
|
|
|
|
|
std::string query = "DELETE FROM ";
|
|
|
|
|
query += name;
|
2004-09-14 16:39:30 +00:00
|
|
|
query += " WHERE target = ";
|
2003-01-12 15:06:09 +00:00
|
|
|
query += other;
|
|
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
return scheduleCommand(query);
|
2003-01-12 15:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:15:43 +01:00
|
|
|
int Database::registerSimpleTable(const std::string & name,
|
|
|
|
|
const MapType & row)
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
if (row.empty()) {
|
|
|
|
|
log(ERROR, "Attempt to create empty database table");
|
|
|
|
|
}
|
|
|
|
|
// Check whether the table exists
|
|
|
|
|
std::string query = "SELECT * FROM ";
|
|
|
|
|
std::string createquery = "CREATE TABLE ";
|
|
|
|
|
query += name;
|
|
|
|
|
createquery += name;
|
|
|
|
|
query += " WHERE id = 0";
|
|
|
|
|
createquery += " (id integer UNIQUE PRIMARY KEY";
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
MapType::const_iterator Iend = row.end();
|
|
|
|
|
for (MapType::const_iterator I = row.begin(); I != Iend; ++I) {
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
query += " AND ";
|
|
|
|
|
createquery += ", ";
|
|
|
|
|
const std::string & column = I->first;
|
|
|
|
|
query += column;
|
|
|
|
|
createquery += column;
|
2004-08-07 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.h,
common/Database.cpp, common/Database.h, common/FormattedXMLWriter.cpp,
common/FormattedXMLWriter.h, common/accountbase.cpp,
common/accountbase.h, common/custom.cpp, common/inheritance.cpp,
common/inheritance.h, common/operations.h, common/type_utils.h,
common/utility.cpp, common/utility.h, modules/Location.cpp,
modules/Location.h, rulesets/Area.cpp, rulesets/Area.h,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Character.h,
rulesets/Creator.cpp, rulesets/Entity.cpp, rulesets/Entity.h,
rulesets/Entity_getLocation.h, rulesets/Food.cpp, rulesets/Line.cpp,
rulesets/Line.h, rulesets/MemMap.cpp, rulesets/MemMap.h,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp, rulesets/Plant.h,
rulesets/Py_Mind.cpp, rulesets/Py_Object.cpp, rulesets/Py_Object.h,
rulesets/Py_Operation.cpp, rulesets/Py_Thing.cpp,
rulesets/Python_API.cpp, rulesets/Stackable.cpp, rulesets/Stackable.h,
rulesets/Thing.cpp, rulesets/World.cpp, rulesets/World.h,
server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/CommClient.cpp, server/CommClient.h,
server/CommListener.cpp, server/CommListener.h,
server/CommLocalClient.cpp, server/CommLocalClient.h,
server/CommMetaClient.h, server/CommPSQLSocket.h,
server/CommRemoteClient.cpp, server/CommRemoteClient.h,
server/CommServer.cpp, server/CommServer.h, server/CommSocket.cpp,
server/CommSocket.h, server/CommUnixListener.cpp,
server/CommUnixListener.h, server/Connection.cpp,
server/Connection.h, server/EntityFactory.cpp,
server/EntityFactory.h, server/Lobby.cpp, server/Lobby.h,
server/Persistance.cpp, server/Persistance.h,
server/PersistantThingFactory.h, server/Persistor.cpp,
server/Player.cpp, server/Player.h, server/Restorer.h,
server/Restorer_impl.h, server/ServerRouting.cpp,
server/ServerRouting.h, server/TrustedConnection.cpp,
server/TrustedConnection.h, server/WorldRouter.cpp,
server/WorldRouter.h: Convert code to using Atlas Message
typedefs as found in Atlas-C++ 0.6 to aid conversion later.
2004-08-16 14:26:47 +00:00
|
|
|
const Element & type = I->second;
|
2003-08-07 23:03:26 +00:00
|
|
|
if (type.isString()) {
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
query += " LIKE 'foo'";
|
2012-01-30 15:14:05 +00:00
|
|
|
std::size_t size = type.String().size();
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
if (size == 0) {
|
|
|
|
|
createquery += " text";
|
|
|
|
|
} else {
|
|
|
|
|
char buf[32];
|
2012-11-12 22:00:33 +00:00
|
|
|
snprintf(buf, 32, "%zd", size);
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
createquery += " varchar(";
|
|
|
|
|
createquery += buf;
|
|
|
|
|
createquery += ")";
|
|
|
|
|
}
|
2003-08-07 23:03:26 +00:00
|
|
|
} else if (type.isInt()) {
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
query += " = 1";
|
|
|
|
|
createquery += " integer";
|
2003-08-07 23:03:26 +00:00
|
|
|
} else if (type.isFloat()) {
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
query += " = 1.0";
|
|
|
|
|
createquery += " float";
|
|
|
|
|
} else {
|
2004-09-07 10:09:02 +00:00
|
|
|
log(ERROR, "Illegal column type in database simple row");
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
debug(std::cout << "QUERY: " << query << std::endl << std::flush;);
|
2004-03-08 14:36:44 +00:00
|
|
|
clearPendingQuery();
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
int status = PQsendQuery(m_connection, query.c_str());
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
if (!status) {
|
2005-01-13 00:38:41 +00:00
|
|
|
log(ERROR, "registerSimpleTable(): Database query error.");
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
reportError();
|
2011-09-29 12:15:43 +01:00
|
|
|
return -1;
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
}
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
if (!tuplesOk()) {
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
debug(reportError(););
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
debug(std::cout << "Table does not yet exist"
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
} else {
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
debug(std::cout << "Table exists" << std::endl << std::flush;);
|
2003-10-28 00:18:18 +00:00
|
|
|
allTables.insert(name);
|
2011-09-29 12:15:43 +01:00
|
|
|
return 0;
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-02 01:12:02 +00:00
|
|
|
createquery += ") WITHOUT OIDS";
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
debug(std::cout << "CREATE QUERY: " << createquery
|
|
|
|
|
<< std::endl << std::flush;);
|
2011-09-28 22:46:32 +01:00
|
|
|
int ret = runCommandQuery(createquery);
|
|
|
|
|
if (ret == 0) {
|
2003-10-28 00:18:18 +00:00
|
|
|
allTables.insert(name);
|
|
|
|
|
}
|
2011-09-29 12:15:43 +01:00
|
|
|
return ret;
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DatabaseResult Database::selectSimpleRow(const std::string & id,
|
|
|
|
|
const std::string & name)
|
|
|
|
|
{
|
|
|
|
|
std::string query = "SELECT * FROM ";
|
|
|
|
|
query += name;
|
|
|
|
|
query += " WHERE id = ";
|
|
|
|
|
query += id;
|
|
|
|
|
|
|
|
|
|
debug(std::cout << "Selecting on id = " << id << " ... " << std::flush;);
|
|
|
|
|
|
|
|
|
|
return runSimpleSelectQuery(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DatabaseResult Database::selectSimpleRowBy(const std::string & name,
|
|
|
|
|
const std::string & column,
|
|
|
|
|
const std::string & value)
|
|
|
|
|
{
|
|
|
|
|
std::string query = "SELECT * FROM ";
|
|
|
|
|
query += name;
|
|
|
|
|
query += " WHERE ";
|
|
|
|
|
query += column;
|
|
|
|
|
query += " = ";
|
|
|
|
|
query += value;
|
|
|
|
|
|
|
|
|
|
debug(std::cout << "Selecting on " << column << " = " << value
|
|
|
|
|
<< " ... " << std::flush;);
|
|
|
|
|
|
|
|
|
|
return runSimpleSelectQuery(query);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::createSimpleRow(const std::string & name,
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
const std::string & id,
|
|
|
|
|
const std::string & columns,
|
|
|
|
|
const std::string & values)
|
|
|
|
|
{
|
|
|
|
|
std::string query = "INSERT INTO ";
|
|
|
|
|
query += name;
|
|
|
|
|
query += " ( id, ";
|
|
|
|
|
query += columns;
|
|
|
|
|
query += " ) VALUES ( ";
|
|
|
|
|
query += id;
|
|
|
|
|
query += ", ";
|
|
|
|
|
query += values;
|
2004-10-02 01:12:02 +00:00
|
|
|
query += ")";
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
return scheduleCommand(query);
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::updateSimpleRow(const std::string & name,
|
|
|
|
|
const std::string & key,
|
|
|
|
|
const std::string & value,
|
|
|
|
|
const std::string & columns)
|
2003-08-24 23:56:15 +00:00
|
|
|
{
|
2003-10-27 01:59:53 +00:00
|
|
|
std::string query = "UPDATE ";
|
|
|
|
|
query += name;
|
|
|
|
|
query += " SET ";
|
|
|
|
|
query += columns;
|
|
|
|
|
query += " WHERE ";
|
|
|
|
|
query += key;
|
|
|
|
|
query += "='";
|
|
|
|
|
query += value;
|
2004-10-02 01:12:02 +00:00
|
|
|
query += "'";
|
2003-10-27 01:59:53 +00:00
|
|
|
|
|
|
|
|
return scheduleCommand(query);
|
2003-08-24 23:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-19 21:43:14 +00:00
|
|
|
int Database::registerEntityIdGenerator()
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2004-03-08 14:36:44 +00:00
|
|
|
clearPendingQuery();
|
2004-10-02 01:12:02 +00:00
|
|
|
int status = PQsendQuery(m_connection, "SELECT * FROM entity_ent_id_seq");
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
if (!status) {
|
2005-01-13 00:38:41 +00:00
|
|
|
log(ERROR, "registerEntityIdGenerator(): Database query error.");
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
reportError();
|
2008-08-19 21:43:14 +00:00
|
|
|
return -1;
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
|
|
|
|
if (!tuplesOk()) {
|
|
|
|
|
debug(reportError(););
|
|
|
|
|
debug(std::cout << "Sequence does not yet exist"
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
} else {
|
|
|
|
|
debug(std::cout << "Sequence exists" << std::endl << std::flush;);
|
2008-08-19 21:43:14 +00:00
|
|
|
return 0;
|
2003-01-03 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.h, server/Persistor.h: Make inheritance of
SigC::Object virtual, although multiple inheritance is not planned.
* common/Database.cpp, common/Database.h: Remove legacy account
table, and add support for generic non-inherited tables for OOG
data.
* common/Database.cpp, common/Database.h: Add general methods for
running queries and reporting errors, and cut down duplicated
code elsewhere by using them.
* common/accountbase.cpp, common/accountbase.h: Remove code
that used old account table, and replace with stubs. New
account yet to be written.
* server/Account.cpp, server/Account.h, server/Admin.cpp,
server/Admin.h, server/Player.cpp, server/Player.h:
Allow an id to be specified when creating an account.
* server/Persistance.cpp: Re-write account persistance methods
to use new table.
* server/Restoration.cpp: Clarify debug output.
2003-01-03 17:14:28 +00:00
|
|
|
}
|
2011-09-28 22:46:32 +01:00
|
|
|
return runCommandQuery("CREATE SEQUENCE entity_ent_id_seq");
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
2005-11-12 01:40:37 +00:00
|
|
|
long Database::newId(std::string & id)
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
{
|
2006-12-06 08:11:23 +00:00
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
clearPendingQuery();
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
int status = PQsendQuery(m_connection,
|
2004-10-02 01:12:02 +00:00
|
|
|
"SELECT nextval('entity_ent_id_seq')");
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
if (!status) {
|
2005-01-13 00:38:41 +00:00
|
|
|
log(ERROR, "newId(): Database query error.");
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
reportError();
|
2005-11-12 01:40:37 +00:00
|
|
|
return -1;
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
}
|
|
|
|
|
PGresult * res;
|
|
|
|
|
if ((res = PQgetResult(m_connection)) == NULL) {
|
|
|
|
|
log(ERROR, "Error getting new ID.");
|
|
|
|
|
reportError();
|
2005-11-12 01:40:37 +00:00
|
|
|
return -1;
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
}
|
2003-07-21 09:37:58 +00:00
|
|
|
const char * cid = PQgetvalue(res, 0, 0);
|
|
|
|
|
id = cid;
|
|
|
|
|
PQclear(res);
|
|
|
|
|
while ((res = PQgetResult(m_connection)) != NULL) {
|
|
|
|
|
PQclear(res);
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
log(ERROR, "Extra database result to simple query.");
|
|
|
|
|
};
|
2006-05-06 Al Riddoch <alriddoch@zepler.org>
* common/Database.cpp, common/newid.cpp, server/server.cpp:
Modify new ID checks so that code still runs when database is
unavailable, and events requiring new IDs fail cleanly.
* server/Connection.cpp: Report a failure to create a player
account if no ID available.
* rulesets/BaseMind.cpp: When processing appearance ops, handle
stamp more efficiently, report an error if ID is missing
from argument.
* server/IdlePSQLConnector.cpp, server/IdlePSQLConnector.h:
Implement re-connecting to the Database if connection is lost.
* rulesets/Character.cpp, rulesets/Entity.cpp, rulesets/Thing.cpp:
Ensure STAMP is present on appearance op args.
* server/CommListener.cpp, server/CommListener.h,
server/CommPeerListener.cpp, server/CommPeerListener.h,
server/CommSlaveListener.cpp, server/CommSlaveListener.h,
server/CommUnixListener.cpp, server/CommUnixListener.h:
Add a return value to method for creating new client socket
objects, and use it to return failure if no ID is available
from the database for a new object.
* rulesets/Py_Point3D.cpp, rulesets/Py_Vector3D.cpp,
rulesets/Python_API.cpp: Add "new" method for class wrappers, and
call the in place constructor from new rather than init. Re-write
internal function for creating new instances so it uses the "new"
method.
* rulesets/Py_Statistics.cpp: Remove some obsolete code inadvertedly
copied from another file. Comment out some unused code to get rid
of a warning.
* server/CommPSQLSocket.cpp: Clear the database connection from
destructor.
* tests/python_class.cpp: A new test for experimenting with new
Python wrappers.
2006-05-06 21:36:57 +00:00
|
|
|
if (id.empty()) {
|
|
|
|
|
log(ERROR, "Unknown error getting ID from database.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2005-11-23 11:55:08 +00:00
|
|
|
return forceIntegerId(id);
|
2002-12-28 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, rulesets/Character.cpp,
rulesets/Food.cpp, rulesets/Thing.cpp, rulesets/World.cpp:
Add arg to error method specifying where the error should go. Use
this arg to ensure that errors don't get broadcast.
* common/Database.cpp, common/Database.h, common/const.cpp,
server/Persistor.cpp, server/Restoration.cpp,
server/WorldRouter.cpp
Change id and loc column in entity tables to integer for
performance. Add id generator sequence to database
* common/Database.cpp, common/Database.h, server/Persistance.cpp,
server/Persistance.h: Remove old legacy world, mind and server
tables as they are no longer used.
* common/BaseEntity.cpp, common/Load.h, common/Save.h,
common/custom.cpp, common/op_switch.h, common/operations.cpp,
common/operations.h, common/types.h, rulesets/BaseMind.cpp,
rulesets/BaseMind.h, rulesets/Character.cpp, rulesets/Character.h,
server/Admin.cpp, server/Admin.h, server/server.cpp,
tools/cycmd.cpp: Remove Load and Save ops.
* rulesets/Area.cpp, rulesets/Character.cpp, rulesets/Line.cpp,
rulesets/Plant.cpp: Fix != to |= when setting update flags.
* server/CommMetaClient.cpp, server/CommMetaClient.h,
server/CommServer.cpp, server/CommServer.h, server/server.cpp:
Add mechanism for sockets to be called whenever the server
is idle, so that they do period things. Use this mechanis,
to handle sending periodic packets to the metaserver, removing
special case code from CommServer.
2002-12-28 21:52:32 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-19 21:43:14 +00:00
|
|
|
int Database::registerEntityTable(const std::map<std::string, int> & chunks)
|
|
|
|
|
{
|
|
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
|
|
|
|
clearPendingQuery();
|
|
|
|
|
int status = PQsendQuery(m_connection, "SELECT * FROM entities");
|
|
|
|
|
if (!status) {
|
|
|
|
|
log(ERROR, "registerEntityIdGenerator(): Database query error.");
|
|
|
|
|
reportError();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (!tuplesOk()) {
|
|
|
|
|
debug(reportError(););
|
|
|
|
|
debug(std::cout << "Table does not yet exist"
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
} else {
|
2008-11-10 03:04:33 +00:00
|
|
|
allTables.insert("entities");
|
2008-09-08 17:45:36 +00:00
|
|
|
// FIXME Flush out the whole state of the databases, to ensure they
|
|
|
|
|
// don't clog up while we are testing.
|
2008-11-18 02:36:51 +00:00
|
|
|
// runCommandQuery("DELETE FROM properties");
|
|
|
|
|
// runCommandQuery(compose("DELETE FROM entities WHERE id!=%1",
|
|
|
|
|
// consts::rootWorldIntId));
|
2008-08-19 21:43:14 +00:00
|
|
|
debug(std::cout << "Table exists" << std::endl << std::flush;);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2008-11-16 23:45:51 +00:00
|
|
|
std::string query = compose("CREATE TABLE entities ("
|
|
|
|
|
"id integer UNIQUE PRIMARY KEY, "
|
|
|
|
|
"loc integer, "
|
|
|
|
|
"type varchar(%1), "
|
|
|
|
|
"seq integer", consts::id_len);
|
2008-08-19 21:43:14 +00:00
|
|
|
std::map<std::string, int>::const_iterator I = chunks.begin();
|
|
|
|
|
std::map<std::string, int>::const_iterator Iend = chunks.end();
|
|
|
|
|
for (; I != Iend; ++I) {
|
2008-11-16 23:45:51 +00:00
|
|
|
query += compose(", %1 varchar(1024)", I->first);
|
2008-08-19 21:43:14 +00:00
|
|
|
}
|
2008-08-19 22:07:16 +00:00
|
|
|
query += ")";
|
2011-09-28 22:46:32 +01:00
|
|
|
if (runCommandQuery(query) != 0) {
|
2008-09-03 23:36:50 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
2008-11-04 00:26:04 +00:00
|
|
|
allTables.insert("entities");
|
2008-11-16 23:45:51 +00:00
|
|
|
query = compose("INSERT INTO entities VALUES (%1, null, 'world')",
|
|
|
|
|
consts::rootWorldIntId);
|
2011-09-28 22:46:32 +01:00
|
|
|
if (runCommandQuery(query) != 0) {
|
2008-09-03 23:36:50 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2008-08-19 21:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-23 17:53:43 +00:00
|
|
|
int Database::insertEntity(const std::string & id,
|
|
|
|
|
const std::string & loc,
|
|
|
|
|
const std::string & type,
|
2008-08-28 09:43:50 +00:00
|
|
|
int seq,
|
|
|
|
|
const std::string & value)
|
2008-08-23 17:53:43 +00:00
|
|
|
{
|
2008-11-16 23:45:51 +00:00
|
|
|
std::string query = compose("INSERT INTO entities VALUES "
|
|
|
|
|
"(%1, %2, '%3', %4, '%5')",
|
|
|
|
|
id, loc, type, seq, value);
|
2008-08-23 17:53:43 +00:00
|
|
|
return scheduleCommand(query);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-28 09:43:50 +00:00
|
|
|
int Database::updateEntity(const std::string & id,
|
|
|
|
|
int seq,
|
2013-06-15 22:46:52 +02:00
|
|
|
const std::string & location_data,
|
|
|
|
|
const std::string & location_entity_id)
|
|
|
|
|
{
|
|
|
|
|
std::string query = compose("UPDATE entities SET seq = %1, location = '%2',"
|
|
|
|
|
" loc = '%3'"
|
|
|
|
|
" WHERE id = %4", seq, location_data,
|
|
|
|
|
location_entity_id, id);
|
|
|
|
|
return scheduleCommand(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Database::updateEntityWithoutLoc(const std::string & id,
|
|
|
|
|
int seq,
|
|
|
|
|
const std::string & location_data)
|
2008-08-23 17:53:43 +00:00
|
|
|
{
|
2008-11-16 23:45:51 +00:00
|
|
|
std::string query = compose("UPDATE entities SET seq = %1, location = '%2'"
|
2013-06-15 22:46:52 +02:00
|
|
|
" WHERE id = %3", seq, location_data, id);
|
2008-08-23 17:53:43 +00:00
|
|
|
return scheduleCommand(query);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 22:46:52 +02:00
|
|
|
|
2008-11-17 01:36:24 +00:00
|
|
|
const DatabaseResult Database::selectEntities(const std::string & loc)
|
|
|
|
|
{
|
|
|
|
|
std::string query = compose("SELECT id, type, seq, location FROM entities"
|
|
|
|
|
" WHERE loc = %1", loc);
|
|
|
|
|
|
2008-11-18 02:36:51 +00:00
|
|
|
debug(std::cout << "Selecting on loc = " << loc << " ... " << std::flush;);
|
2008-11-17 01:36:24 +00:00
|
|
|
|
|
|
|
|
return runSimpleSelectQuery(query);
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-04 09:33:16 +00:00
|
|
|
int Database::dropEntity(long id)
|
|
|
|
|
{
|
2008-11-16 23:45:51 +00:00
|
|
|
std::string query = compose("DELETE FROM properties WHERE id = '%1'", id);
|
2008-09-04 09:33:16 +00:00
|
|
|
|
|
|
|
|
scheduleCommand(query);
|
|
|
|
|
|
2008-11-16 23:45:51 +00:00
|
|
|
query = compose("DELETE FROM entities WHERE id = %1", id);
|
2008-09-04 09:33:16 +00:00
|
|
|
|
|
|
|
|
scheduleCommand(query);
|
|
|
|
|
|
2013-04-06 18:26:38 +02:00
|
|
|
query = compose("DELETE FROM thoughts WHERE id = %1", id);
|
|
|
|
|
|
|
|
|
|
scheduleCommand(query);
|
|
|
|
|
|
2008-09-04 09:33:16 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-19 23:45:43 +00:00
|
|
|
int Database::registerPropertyTable()
|
|
|
|
|
{
|
|
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
|
|
|
|
clearPendingQuery();
|
|
|
|
|
int status = PQsendQuery(m_connection, "SELECT * FROM properties");
|
|
|
|
|
if (!status) {
|
|
|
|
|
log(ERROR, "registerPropertyIdGenerator(): Database query error.");
|
|
|
|
|
reportError();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (!tuplesOk()) {
|
|
|
|
|
debug(reportError(););
|
|
|
|
|
debug(std::cout << "Table does not yet exist"
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
} else {
|
2008-11-10 03:04:33 +00:00
|
|
|
allTables.insert("properties");
|
2008-08-19 23:45:43 +00:00
|
|
|
debug(std::cout << "Table exists" << std::endl << std::flush;);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2008-11-04 00:26:04 +00:00
|
|
|
allTables.insert("properties");
|
2008-11-16 23:45:51 +00:00
|
|
|
std::string query = compose("CREATE TABLE properties ("
|
|
|
|
|
"id integer REFERENCES entities "
|
|
|
|
|
"ON DELETE CASCADE, "
|
|
|
|
|
"name varchar(%1), "
|
|
|
|
|
"value text)", consts::id_len);
|
2011-09-28 22:46:32 +01:00
|
|
|
if (runCommandQuery(query) != 0) {
|
2008-11-04 00:26:04 +00:00
|
|
|
reportError();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
query = "CREATE INDEX property_names on properties (name)";
|
2011-09-28 22:46:32 +01:00
|
|
|
if (runCommandQuery(query) != 0) {
|
2008-11-04 00:26:04 +00:00
|
|
|
reportError();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2008-08-19 23:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
2008-08-23 17:53:43 +00:00
|
|
|
int Database::insertProperties(const std::string & id,
|
|
|
|
|
const KeyValues & tuples)
|
|
|
|
|
{
|
|
|
|
|
int first = 1;
|
|
|
|
|
std::string query("INSERT INTO properties VALUES ");
|
|
|
|
|
KeyValues::const_iterator I = tuples.begin();
|
|
|
|
|
KeyValues::const_iterator Iend = tuples.end();
|
|
|
|
|
for (; I != Iend; ++I) {
|
|
|
|
|
if (first) {
|
2008-11-16 23:45:51 +00:00
|
|
|
query += compose("(%1, '%2', '%3')", id, I->first, I->second);
|
2008-08-23 17:53:43 +00:00
|
|
|
first = 0;
|
|
|
|
|
} else {
|
2008-11-16 23:45:51 +00:00
|
|
|
query += compose(", (%1, '%2', '%3')", id, I->first, I->second);
|
2008-08-23 17:53:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return scheduleCommand(query);
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-17 01:36:24 +00:00
|
|
|
const DatabaseResult Database::selectProperties(const std::string & id)
|
|
|
|
|
{
|
|
|
|
|
std::string query = compose("SELECT name, value FROM properties"
|
|
|
|
|
" WHERE id = %1", id);
|
|
|
|
|
|
2008-11-18 02:36:51 +00:00
|
|
|
debug(std::cout << "Selecting on id = " << id << " ... "
|
|
|
|
|
<< std::endl << std::flush;);
|
2008-11-17 01:36:24 +00:00
|
|
|
|
|
|
|
|
return runSimpleSelectQuery(query);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-23 17:53:43 +00:00
|
|
|
int Database::updateProperties(const std::string & id,
|
|
|
|
|
const KeyValues & tuples)
|
|
|
|
|
{
|
2008-08-24 23:01:32 +00:00
|
|
|
KeyValues::const_iterator I = tuples.begin();
|
|
|
|
|
KeyValues::const_iterator Iend = tuples.end();
|
|
|
|
|
for (; I != Iend; ++I) {
|
2008-11-16 23:45:51 +00:00
|
|
|
std::string query = compose("UPDATE properties SET value = '%3' WHERE"
|
|
|
|
|
" id=%1 AND name='%2'",
|
|
|
|
|
id, I->first, I->second);
|
2008-08-24 23:01:32 +00:00
|
|
|
scheduleCommand(query);
|
|
|
|
|
}
|
2008-08-24 21:58:11 +00:00
|
|
|
return 0;
|
2008-08-23 17:53:43 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-06 18:26:38 +02:00
|
|
|
int Database::registerThoughtsTable()
|
|
|
|
|
{
|
|
|
|
|
assert(m_connection != 0);
|
|
|
|
|
|
|
|
|
|
clearPendingQuery();
|
|
|
|
|
int status = PQsendQuery(m_connection, "SELECT * FROM thoughts");
|
|
|
|
|
if (!status) {
|
|
|
|
|
log(ERROR, "registerThoughtsTable(): Database query error.");
|
|
|
|
|
reportError();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (!tuplesOk()) {
|
|
|
|
|
debug(reportError(););
|
|
|
|
|
debug(std::cout << "Table does not yet exist"
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
} else {
|
|
|
|
|
allTables.insert("thoughts");
|
|
|
|
|
debug(std::cout << "Table exists" << std::endl << std::flush;);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
allTables.insert("properties");
|
|
|
|
|
std::string query = "CREATE TABLE thoughts ("
|
|
|
|
|
"id integer REFERENCES entities "
|
|
|
|
|
"ON DELETE CASCADE, "
|
|
|
|
|
"thought text)";
|
|
|
|
|
if (runCommandQuery(query) != 0) {
|
|
|
|
|
reportError();
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DatabaseResult Database::selectThoughts(const std::string & loc)
|
|
|
|
|
{
|
|
|
|
|
std::string query = compose("SELECT thought FROM thoughts"
|
|
|
|
|
" WHERE id = %1", loc);
|
|
|
|
|
|
|
|
|
|
debug(std::cout << "Selecting on id = " << loc << " ... "
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
|
|
|
|
|
return runSimpleSelectQuery(query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Database::replaceThoughts(const std::string & id,
|
|
|
|
|
const std::vector<std::string>& thoughts)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
std::string deleteQuery = compose("DELETE FROM thoughts WHERE id=%1", id);
|
|
|
|
|
scheduleCommand(deleteQuery);
|
|
|
|
|
|
|
|
|
|
for (auto& thought : thoughts) {
|
|
|
|
|
std::string insertQuery = compose("INSERT INTO thoughts (id, thought)"
|
|
|
|
|
" VALUES (%1, '%2')", id, thought);
|
|
|
|
|
scheduleCommand(insertQuery);
|
|
|
|
|
}
|
2013-06-15 22:47:18 +02:00
|
|
|
return 0;
|
2013-04-06 18:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
2007-12-21 16:42:35 +00:00
|
|
|
#if 0
|
2004-09-06 22:18:32 +00:00
|
|
|
// Interface for tables for sparse sequences or arrays of data. Terrain
|
|
|
|
|
// control points and other spatial data.
|
|
|
|
|
|
2004-09-07 17:22:35 +00:00
|
|
|
static const char * array_axes[] = { "i", "j", "k", "l", "m" };
|
2004-09-07 10:09:02 +00:00
|
|
|
|
|
|
|
|
bool Database::registerArrayTable(const std::string & name,
|
|
|
|
|
unsigned int dimension,
|
|
|
|
|
const MapType & row)
|
2004-09-06 22:18:32 +00:00
|
|
|
{
|
2006-12-31 15:56:35 +00:00
|
|
|
if (m_connection == 0) {
|
|
|
|
|
log(CRITICAL, "Database connection is down. This is okay during tests");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-06 08:11:23 +00:00
|
|
|
|
2004-09-07 17:22:35 +00:00
|
|
|
assert(dimension <= 5);
|
2004-09-07 10:09:02 +00:00
|
|
|
|
|
|
|
|
if (row.empty()) {
|
|
|
|
|
log(ERROR, "Attempt to create empty array table");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string query("SELECT * from ");
|
|
|
|
|
std::string createquery("CREATE TABLE ");
|
2004-09-27 10:33:12 +00:00
|
|
|
std::string indexquery("CREATE UNIQUE INDEX ");
|
2004-09-07 10:09:02 +00:00
|
|
|
|
|
|
|
|
query += name;
|
|
|
|
|
query += " WHERE id = 0";
|
|
|
|
|
|
|
|
|
|
createquery += name;
|
2008-11-17 00:40:21 +00:00
|
|
|
createquery += " (id integer REFERENCES entities NOT NULL";
|
2004-09-27 10:33:12 +00:00
|
|
|
|
|
|
|
|
indexquery += name;
|
|
|
|
|
indexquery += "_point_idx on ";
|
|
|
|
|
indexquery += name;
|
|
|
|
|
indexquery += " (id";
|
2004-09-07 10:09:02 +00:00
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < dimension; ++i) {
|
|
|
|
|
query += " AND ";
|
|
|
|
|
query += array_axes[i];
|
|
|
|
|
query += " = 0";
|
|
|
|
|
|
|
|
|
|
createquery += ", ";
|
|
|
|
|
createquery += array_axes[i];
|
2004-09-07 17:22:35 +00:00
|
|
|
createquery += " integer NOT NULL";
|
2004-09-27 10:33:12 +00:00
|
|
|
|
|
|
|
|
indexquery += ", ";
|
|
|
|
|
indexquery += array_axes[i];
|
2004-09-07 10:09:02 +00:00
|
|
|
}
|
|
|
|
|
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
MapType::const_iterator Iend = row.end();
|
|
|
|
|
for (MapType::const_iterator I = row.begin(); I != Iend; ++I) {
|
2004-09-07 10:09:02 +00:00
|
|
|
const std::string & column = I->first;
|
|
|
|
|
|
|
|
|
|
query += " AND ";
|
|
|
|
|
query += column;
|
|
|
|
|
|
|
|
|
|
createquery += ", ";
|
|
|
|
|
createquery += column;
|
|
|
|
|
|
|
|
|
|
const Element & type = I->second;
|
|
|
|
|
|
|
|
|
|
if (type.isString()) {
|
|
|
|
|
query += " LIKE 'foo'";
|
2005-08-30 Al Riddoch <alriddoch@zepler.org>
* common/AtlasFileLoader.cpp, common/Database.cpp,
common/FormattedXMLWriter.cpp, common/Property.cpp,
common/accountbase.cpp, rulesets/Character.cpp,
rulesets/Entity_getLocation.h, rulesets/MemMap.cpp,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp,
rulesets/Py_Object.cpp, rulesets/Thing.cpp,
server/Admin.cpp, server/Connection.cpp, server/EntityFactory.cpp,
server/WorldRouter.cpp, tools/AdminClient.cpp, tools/cycmd.cpp,
tools/cyconvertrules.cpp: After an Element has been checked
with isFoo(), it is more efficient to get its value using Foo()
rather than asFoo() which repeats the check.
2005-08-30 20:43:19 +00:00
|
|
|
int size = type.String().size();
|
2004-09-07 10:09:02 +00:00
|
|
|
if (size == 0) {
|
|
|
|
|
createquery += " text";
|
|
|
|
|
} else {
|
|
|
|
|
char buf[32];
|
|
|
|
|
snprintf(buf, 32, "%d", size);
|
|
|
|
|
createquery += " varchar(";
|
|
|
|
|
createquery += buf;
|
|
|
|
|
createquery += ")";
|
|
|
|
|
}
|
|
|
|
|
} else if (type.isInt()) {
|
|
|
|
|
query += " = 1";
|
|
|
|
|
createquery += " integer";
|
|
|
|
|
} else if (type.isFloat()) {
|
|
|
|
|
query += " = 1.0";
|
|
|
|
|
createquery += " float";
|
|
|
|
|
} else {
|
|
|
|
|
log(ERROR, "Illegal column type in database array row");
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-10-02 01:12:02 +00:00
|
|
|
|
2004-09-25 00:06:39 +00:00
|
|
|
debug(std::cout << "QUERY: " << query << std::endl << std::flush;);
|
2004-09-07 10:09:02 +00:00
|
|
|
clearPendingQuery();
|
|
|
|
|
int status = PQsendQuery(m_connection, query.c_str());
|
|
|
|
|
if (!status) {
|
2005-01-13 00:38:41 +00:00
|
|
|
log(ERROR, "registerArrayTable(): Database query error.");
|
2004-09-07 10:09:02 +00:00
|
|
|
reportError();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!tuplesOk()) {
|
|
|
|
|
debug(reportError(););
|
|
|
|
|
debug(std::cout << "Table does not yet exist"
|
|
|
|
|
<< std::endl << std::flush;);
|
|
|
|
|
} else {
|
|
|
|
|
debug(std::cout << "Table exists" << std::endl << std::flush;);
|
|
|
|
|
allTables.insert(name);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-10-02 01:12:02 +00:00
|
|
|
createquery += ") WITHOUT OIDS";
|
2004-09-07 10:09:02 +00:00
|
|
|
debug(std::cout << "CREATE QUERY: " << createquery
|
|
|
|
|
<< std::endl << std::flush;);
|
2011-09-28 22:46:32 +01:00
|
|
|
int ret = runCommandQuery(createquery);
|
|
|
|
|
if (ret != 0) {
|
2004-09-27 10:33:12 +00:00
|
|
|
return false;
|
2004-09-07 10:09:02 +00:00
|
|
|
}
|
2004-10-02 01:12:02 +00:00
|
|
|
indexquery += ")";
|
2004-09-28 00:47:18 +00:00
|
|
|
debug(std::cout << "INDEX QUERY: " << indexquery
|
|
|
|
|
<< std::endl << std::flush;);
|
2004-09-27 10:33:12 +00:00
|
|
|
ret = runCommandQuery(indexquery);
|
2011-09-28 22:46:32 +01:00
|
|
|
if (ret != 0) {
|
2004-09-27 10:33:12 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
allTables.insert(name);
|
|
|
|
|
return true;
|
2004-09-06 22:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-14 16:39:30 +00:00
|
|
|
const DatabaseResult Database::selectArrayRows(const std::string & name,
|
|
|
|
|
const std::string & id)
|
|
|
|
|
{
|
|
|
|
|
std::string query("SELECT * FROM ");
|
|
|
|
|
query += name;
|
|
|
|
|
query += " WHERE id = ";
|
|
|
|
|
query += id;
|
|
|
|
|
|
2004-09-25 00:06:39 +00:00
|
|
|
debug(std::cout << "ARRAY QUERY: " << query << std::endl << std::flush;);
|
2004-09-14 16:39:30 +00:00
|
|
|
|
|
|
|
|
return runSimpleSelectQuery(query);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::createArrayRow(const std::string & name,
|
|
|
|
|
const std::string & id,
|
|
|
|
|
const std::vector<int> & key,
|
|
|
|
|
const MapType & data)
|
2004-09-06 22:18:32 +00:00
|
|
|
{
|
2004-09-07 17:22:35 +00:00
|
|
|
assert(key.size() > 0);
|
|
|
|
|
assert(key.size() <= 5);
|
|
|
|
|
assert(!data.empty());
|
|
|
|
|
|
|
|
|
|
std::stringstream query;
|
|
|
|
|
query << "INSERT INTO " << name << " ( id";
|
|
|
|
|
for (unsigned int i = 0; i < key.size(); ++i) {
|
|
|
|
|
query << ", " << array_axes[i];
|
|
|
|
|
}
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
MapType::const_iterator Iend = data.end();
|
|
|
|
|
for (MapType::const_iterator I = data.begin(); I != Iend; ++I) {
|
2004-09-07 17:22:35 +00:00
|
|
|
query << ", " << I->first;
|
|
|
|
|
}
|
|
|
|
|
query << " ) VALUES ( " << id;
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
std::vector<int>::const_iterator Jend = key.end();
|
|
|
|
|
for (std::vector<int>::const_iterator J = key.begin(); J != Jend; ++J) {
|
|
|
|
|
query << ", " << *J;
|
2004-09-07 17:22:35 +00:00
|
|
|
}
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
// We assume data has not been modified, so Iend is still valid
|
|
|
|
|
for (MapType::const_iterator I = data.begin(); I != Iend; ++I) {
|
2004-09-07 17:22:35 +00:00
|
|
|
const Element & e = I->second;
|
|
|
|
|
switch (e.getType()) {
|
|
|
|
|
case Element::TYPE_INT:
|
2005-08-30 Al Riddoch <alriddoch@zepler.org>
* common/AtlasFileLoader.cpp, common/Database.cpp,
common/FormattedXMLWriter.cpp, common/Property.cpp,
common/accountbase.cpp, rulesets/Character.cpp,
rulesets/Entity_getLocation.h, rulesets/MemMap.cpp,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp,
rulesets/Py_Object.cpp, rulesets/Thing.cpp,
server/Admin.cpp, server/Connection.cpp, server/EntityFactory.cpp,
server/WorldRouter.cpp, tools/AdminClient.cpp, tools/cycmd.cpp,
tools/cyconvertrules.cpp: After an Element has been checked
with isFoo(), it is more efficient to get its value using Foo()
rather than asFoo() which repeats the check.
2005-08-30 20:43:19 +00:00
|
|
|
query << ", " << e.Int();
|
2004-09-07 17:22:35 +00:00
|
|
|
break;
|
|
|
|
|
case Element::TYPE_FLOAT:
|
2005-08-30 Al Riddoch <alriddoch@zepler.org>
* common/AtlasFileLoader.cpp, common/Database.cpp,
common/FormattedXMLWriter.cpp, common/Property.cpp,
common/accountbase.cpp, rulesets/Character.cpp,
rulesets/Entity_getLocation.h, rulesets/MemMap.cpp,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp,
rulesets/Py_Object.cpp, rulesets/Thing.cpp,
server/Admin.cpp, server/Connection.cpp, server/EntityFactory.cpp,
server/WorldRouter.cpp, tools/AdminClient.cpp, tools/cycmd.cpp,
tools/cyconvertrules.cpp: After an Element has been checked
with isFoo(), it is more efficient to get its value using Foo()
rather than asFoo() which repeats the check.
2005-08-30 20:43:19 +00:00
|
|
|
query << ", " << e.Float();
|
2004-09-07 17:22:35 +00:00
|
|
|
break;
|
|
|
|
|
case Element::TYPE_STRING:
|
2005-08-30 Al Riddoch <alriddoch@zepler.org>
* common/AtlasFileLoader.cpp, common/Database.cpp,
common/FormattedXMLWriter.cpp, common/Property.cpp,
common/accountbase.cpp, rulesets/Character.cpp,
rulesets/Entity_getLocation.h, rulesets/MemMap.cpp,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp,
rulesets/Py_Object.cpp, rulesets/Thing.cpp,
server/Admin.cpp, server/Connection.cpp, server/EntityFactory.cpp,
server/WorldRouter.cpp, tools/AdminClient.cpp, tools/cycmd.cpp,
tools/cyconvertrules.cpp: After an Element has been checked
with isFoo(), it is more efficient to get its value using Foo()
rather than asFoo() which repeats the check.
2005-08-30 20:43:19 +00:00
|
|
|
query << ", " << e.String();
|
2004-09-07 17:22:35 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
log(ERROR, "Bad type constructing array database row for insert");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-10-02 01:12:02 +00:00
|
|
|
query << ")";
|
2004-09-07 17:22:35 +00:00
|
|
|
|
|
|
|
|
std::string qstr = query.str();
|
2004-09-28 00:47:18 +00:00
|
|
|
debug(std::cout << "QUery: " << qstr << std::endl << std::flush;);
|
2004-09-07 17:22:35 +00:00
|
|
|
return scheduleCommand(qstr);
|
2004-09-06 22:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::updateArrayRow(const std::string & name,
|
|
|
|
|
const std::string & id,
|
|
|
|
|
const std::vector<int> & key,
|
|
|
|
|
const Atlas::Message::MapType & data)
|
2004-09-06 22:18:32 +00:00
|
|
|
{
|
2004-09-17 17:19:55 +00:00
|
|
|
assert(key.size() > 0);
|
|
|
|
|
assert(key.size() <= 5);
|
|
|
|
|
assert(!data.empty());
|
|
|
|
|
|
|
|
|
|
std::stringstream query;
|
|
|
|
|
|
|
|
|
|
query << "UPDATE " << name << " SET ";
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
MapType::const_iterator Iend = data.end();
|
|
|
|
|
for (MapType::const_iterator I = data.begin(); I != Iend; ++I) {
|
2004-09-17 17:19:55 +00:00
|
|
|
if (I != data.begin()) {
|
|
|
|
|
query << ", ";
|
|
|
|
|
}
|
|
|
|
|
query << I->first << " = ";
|
|
|
|
|
const Element & e = I->second;
|
|
|
|
|
switch (e.getType()) {
|
|
|
|
|
case Element::TYPE_INT:
|
2005-08-30 Al Riddoch <alriddoch@zepler.org>
* common/AtlasFileLoader.cpp, common/Database.cpp,
common/FormattedXMLWriter.cpp, common/Property.cpp,
common/accountbase.cpp, rulesets/Character.cpp,
rulesets/Entity_getLocation.h, rulesets/MemMap.cpp,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp,
rulesets/Py_Object.cpp, rulesets/Thing.cpp,
server/Admin.cpp, server/Connection.cpp, server/EntityFactory.cpp,
server/WorldRouter.cpp, tools/AdminClient.cpp, tools/cycmd.cpp,
tools/cyconvertrules.cpp: After an Element has been checked
with isFoo(), it is more efficient to get its value using Foo()
rather than asFoo() which repeats the check.
2005-08-30 20:43:19 +00:00
|
|
|
query << e.Int();
|
2004-09-17 17:19:55 +00:00
|
|
|
break;
|
|
|
|
|
case Element::TYPE_FLOAT:
|
2005-08-30 Al Riddoch <alriddoch@zepler.org>
* common/AtlasFileLoader.cpp, common/Database.cpp,
common/FormattedXMLWriter.cpp, common/Property.cpp,
common/accountbase.cpp, rulesets/Character.cpp,
rulesets/Entity_getLocation.h, rulesets/MemMap.cpp,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp,
rulesets/Py_Object.cpp, rulesets/Thing.cpp,
server/Admin.cpp, server/Connection.cpp, server/EntityFactory.cpp,
server/WorldRouter.cpp, tools/AdminClient.cpp, tools/cycmd.cpp,
tools/cyconvertrules.cpp: After an Element has been checked
with isFoo(), it is more efficient to get its value using Foo()
rather than asFoo() which repeats the check.
2005-08-30 20:43:19 +00:00
|
|
|
query << e.Float();
|
2004-09-17 17:19:55 +00:00
|
|
|
break;
|
|
|
|
|
case Element::TYPE_STRING:
|
2005-08-30 Al Riddoch <alriddoch@zepler.org>
* common/AtlasFileLoader.cpp, common/Database.cpp,
common/FormattedXMLWriter.cpp, common/Property.cpp,
common/accountbase.cpp, rulesets/Character.cpp,
rulesets/Entity_getLocation.h, rulesets/MemMap.cpp,
rulesets/Pedestrian.cpp, rulesets/Plant.cpp,
rulesets/Py_Object.cpp, rulesets/Thing.cpp,
server/Admin.cpp, server/Connection.cpp, server/EntityFactory.cpp,
server/WorldRouter.cpp, tools/AdminClient.cpp, tools/cycmd.cpp,
tools/cyconvertrules.cpp: After an Element has been checked
with isFoo(), it is more efficient to get its value using Foo()
rather than asFoo() which repeats the check.
2005-08-30 20:43:19 +00:00
|
|
|
query << "'" << e.String() << "'";
|
2004-09-17 17:19:55 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
log(ERROR, "Bad type constructing array database row for update");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
query << " WHERE id='" << id << "'";
|
|
|
|
|
for (unsigned int i = 0; i < key.size(); ++i) {
|
|
|
|
|
query << " AND " << array_axes[i] << " = " << key[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string qstr = query.str();
|
2004-09-28 00:47:18 +00:00
|
|
|
debug(std::cout << "QUery: " << qstr << std::endl << std::flush;);
|
2004-09-17 17:19:55 +00:00
|
|
|
return scheduleCommand(qstr);
|
2004-09-06 22:18:32 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::removeArrayRow(const std::string & name,
|
|
|
|
|
const std::string & id,
|
|
|
|
|
const std::vector<int> & key)
|
2004-09-06 22:18:32 +00:00
|
|
|
{
|
2004-09-14 16:39:30 +00:00
|
|
|
/// Not sure we need this one yet, so lets no bother for now ;)
|
2011-09-29 12:11:15 +01:00
|
|
|
return -1;
|
2004-09-06 22:18:32 +00:00
|
|
|
}
|
2007-12-21 16:42:35 +00:00
|
|
|
#endif // 0
|
2004-09-06 22:18:32 +00:00
|
|
|
|
|
|
|
|
// General functions for handling queries at the low level.
|
|
|
|
|
|
2003-10-24 23:50:12 +00:00
|
|
|
void Database::queryResult(ExecStatusType status)
|
|
|
|
|
{
|
|
|
|
|
if (!m_queryInProgress || pendingQueries.empty()) {
|
|
|
|
|
log(ERROR, "Got database result when no query was pending.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DatabaseQuery & q = pendingQueries.front();
|
|
|
|
|
if (q.second == PGRES_EMPTY_QUERY) {
|
|
|
|
|
log(ERROR, "Got database result which is already done.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (q.second == status) {
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "Query status ok" << std::endl << std::flush;);
|
2003-10-24 23:50:12 +00:00
|
|
|
// Mark this query as done
|
|
|
|
|
q.second = PGRES_EMPTY_QUERY;
|
2003-10-27 01:59:53 +00:00
|
|
|
} else {
|
|
|
|
|
log(ERROR, "Database error from async query");
|
2004-09-28 00:47:18 +00:00
|
|
|
std::cerr << "Query error in : " << q.first << std::endl << std::flush;
|
2003-10-27 01:59:53 +00:00
|
|
|
reportError();
|
|
|
|
|
q.second = PGRES_EMPTY_QUERY;
|
2003-10-24 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Database::queryComplete()
|
|
|
|
|
{
|
|
|
|
|
if (!m_queryInProgress || pendingQueries.empty()) {
|
|
|
|
|
log(ERROR, "Got database query complete when no query was pending");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DatabaseQuery & q = pendingQueries.front();
|
|
|
|
|
if (q.second != PGRES_EMPTY_QUERY) {
|
2003-10-27 01:59:53 +00:00
|
|
|
abort();
|
2003-10-24 23:50:12 +00:00
|
|
|
log(ERROR, "Got database query complete when query was not done");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "Query complete" << std::endl << std::flush;);
|
2003-10-24 23:50:12 +00:00
|
|
|
pendingQueries.pop_front();
|
|
|
|
|
m_queryInProgress = false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 22:36:41 +01:00
|
|
|
int Database::launchNewQuery()
|
2003-10-24 23:50:12 +00:00
|
|
|
{
|
2008-11-13 01:26:16 +00:00
|
|
|
if (m_connection == 0) {
|
|
|
|
|
log(ERROR, "Can't launch new query while database is offline.");
|
2011-09-28 22:36:41 +01:00
|
|
|
return -1;
|
2008-11-13 01:26:16 +00:00
|
|
|
}
|
2003-10-24 23:50:12 +00:00
|
|
|
if (m_queryInProgress) {
|
|
|
|
|
log(ERROR, "Launching new query when query is in progress");
|
2011-09-28 22:36:41 +01:00
|
|
|
return -1;
|
2003-10-24 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
if (pendingQueries.empty()) {
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "No queries to launch" << std::endl << std::flush;);
|
2011-09-28 22:36:41 +01:00
|
|
|
return -1;
|
2003-10-24 23:50:12 +00:00
|
|
|
}
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << pendingQueries.size() << " queries pending"
|
|
|
|
|
<< std::endl << std::flush;);
|
2003-10-24 23:50:12 +00:00
|
|
|
DatabaseQuery & q = pendingQueries.front();
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "Launching async query: " << q.first
|
|
|
|
|
<< std::endl << std::flush;);
|
2003-10-24 23:50:12 +00:00
|
|
|
int status = PQsendQuery(m_connection, q.first.c_str());
|
|
|
|
|
if (!status) {
|
|
|
|
|
log(ERROR, "Database query error when launching.");
|
|
|
|
|
reportError();
|
2011-09-28 22:36:41 +01:00
|
|
|
return -1;
|
2003-10-24 23:50:12 +00:00
|
|
|
} else {
|
2003-10-27 01:59:53 +00:00
|
|
|
m_queryInProgress = true;
|
2003-10-24 23:50:12 +00:00
|
|
|
PQflush(m_connection);
|
2011-09-28 22:36:41 +01:00
|
|
|
return 0;
|
2003-10-24 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::scheduleCommand(const std::string & query)
|
2003-10-24 23:50:12 +00:00
|
|
|
{
|
|
|
|
|
pendingQueries.push_back(std::make_pair(query, PGRES_COMMAND_OK));
|
2003-10-27 01:59:53 +00:00
|
|
|
if (!m_queryInProgress) {
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "Query: " << query << " launched"
|
|
|
|
|
<< std::endl << std::flush;);
|
2011-09-29 12:11:15 +01:00
|
|
|
return launchNewQuery();
|
2003-10-27 01:59:53 +00:00
|
|
|
} else {
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "Query: " << query << " scheduled"
|
|
|
|
|
<< std::endl << std::flush;);
|
2011-09-29 12:11:15 +01:00
|
|
|
return 0;
|
2003-10-27 01:59:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 22:32:39 +01:00
|
|
|
int Database::clearPendingQuery()
|
2003-10-27 01:59:53 +00:00
|
|
|
{
|
|
|
|
|
if (!m_queryInProgress) {
|
2011-09-28 22:32:39 +01:00
|
|
|
return 0;
|
2003-10-27 01:59:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(!pendingQueries.empty());
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "Clearing a pending query" << std::endl << std::flush;);
|
2003-10-27 01:59:53 +00:00
|
|
|
|
|
|
|
|
DatabaseQuery & q = pendingQueries.front();
|
|
|
|
|
if (q.second == PGRES_COMMAND_OK) {
|
|
|
|
|
m_queryInProgress = false;
|
|
|
|
|
pendingQueries.pop_front();
|
|
|
|
|
return commandOk();
|
|
|
|
|
} else {
|
|
|
|
|
log(ERROR, "Pending query wants unknown status");
|
2011-09-28 22:32:39 +01:00
|
|
|
return -1;
|
2003-10-27 01:59:53 +00:00
|
|
|
}
|
2003-10-24 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-28 22:25:58 +01:00
|
|
|
int Database::runMaintainance(int command)
|
2003-10-27 18:01:03 +00:00
|
|
|
{
|
2008-11-17 00:40:21 +00:00
|
|
|
// VACUUM and REINDEX tables from a common store
|
2003-10-28 00:18:18 +00:00
|
|
|
if ((command & MAINTAIN_REINDEX) == MAINTAIN_REINDEX) {
|
|
|
|
|
std::string query("REINDEX TABLE ");
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
TableSet::const_iterator Iend = allTables.end();
|
|
|
|
|
for (TableSet::const_iterator I = allTables.begin(); I != Iend; ++I) {
|
2003-10-28 00:18:18 +00:00
|
|
|
scheduleCommand(query + *I);
|
2003-10-27 18:01:03 +00:00
|
|
|
}
|
2003-10-28 00:18:18 +00:00
|
|
|
}
|
|
|
|
|
if ((command & MAINTAIN_VACUUM) == MAINTAIN_VACUUM) {
|
|
|
|
|
std::string query("VACUUM ");
|
|
|
|
|
if ((command & MAINTAIN_VACUUM_ANALYZE) == MAINTAIN_VACUUM_ANALYZE) {
|
|
|
|
|
query += "ANALYZE ";
|
|
|
|
|
}
|
|
|
|
|
if ((command & MAINTAIN_VACUUM_FULL) == MAINTAIN_VACUUM_FULL) {
|
|
|
|
|
query += "FULL ";
|
|
|
|
|
}
|
2004-11-06 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientConnection.cpp, client/BaseClient.cpp,
client/CharacterClient.cpp, client/ClientConnection.cpp,
common/Database.cpp, common/FormattedXMLWriter.cpp,
common/inheritance.cpp, common/refno.h, common/terrain_utils.cpp,
common/type_utils.h, common/utility.cpp, modules/WorldTime.cpp,
modules/WorldTime.h, physics/Collision.cpp, rulesets/Area.cpp,
rulesets/BaseMind.cpp, rulesets/Character.cpp, rulesets/Entity.cpp,
rulesets/Line.cpp, rulesets/MemMap.cpp, rulesets/MemMap_methods.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Py_Map.cpp,
rulesets/Py_Object.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Oplist.cpp, rulesets/PythonMindScript.cpp,
rulesets/PythonThingScript.cpp, rulesets/Python_API.cpp,
rulesets/Stackable.cpp, rulesets/TerrainProperty.cpp,
rulesets/Thing.cpp, rulesets/World.cpp, server/Account.cpp,
server/CommClient.cpp, server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/Lobby.cpp, server/Persistance.cpp,
server/Player.cpp, server/Restoration.cpp, server/ServerRouting.cpp,
server/WorldRouter.cpp, tests/EntityExerciser.h,
tests/IGEntityExerciser.h, tests/inheritancetest.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cydbload.cpp,
tools/cyloadrules.cpp:
Tweak for loops to avoid creating a temporary iterator each
iteration.
* tests/type_utilstest.cpp: New test for function which does
list conversions.
2004-11-06 20:36:03 +00:00
|
|
|
TableSet::const_iterator Iend = allTables.end();
|
|
|
|
|
for(TableSet::const_iterator I = allTables.begin(); I != Iend; ++I) {
|
2003-10-28 00:18:18 +00:00
|
|
|
scheduleCommand(query + *I);
|
2003-10-27 18:01:03 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-09-28 22:25:58 +01:00
|
|
|
return 0;
|
2003-10-27 18:01:03 +00:00
|
|
|
}
|
|
|
|
|
|
2002-12-23 00:01:59 +00:00
|
|
|
const char * DatabaseResult::field(const char * column, int row) const
|
2002-12-21 17:11:05 +00:00
|
|
|
{
|
2013-09-12 22:12:49 +02:00
|
|
|
int col_num = PQfnumber(m_res.get(), column);
|
2002-12-21 17:11:05 +00:00
|
|
|
if (col_num == -1) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2013-09-12 22:12:49 +02:00
|
|
|
return PQgetvalue(m_res.get(), row, col_num);
|
2002-12-21 17:11:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * DatabaseResult::const_iterator::column(const char * column) const
|
|
|
|
|
{
|
2013-09-12 22:12:49 +02:00
|
|
|
int col_num = PQfnumber(m_dr.m_res.get(), column);
|
2002-12-21 17:11:05 +00:00
|
|
|
if (col_num == -1) {
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2013-09-12 22:12:49 +02:00
|
|
|
return PQgetvalue(m_dr.m_res.get(), m_row, col_num);
|
2002-12-21 17:11:05 +00:00
|
|
|
}
|
2004-09-14 16:39:30 +00:00
|
|
|
|
|
|
|
|
void DatabaseResult::const_iterator::readColumn(const char * column,
|
|
|
|
|
int & val) const
|
|
|
|
|
{
|
2013-09-12 22:12:49 +02:00
|
|
|
int col_num = PQfnumber(m_dr.m_res.get(), column);
|
2004-09-14 16:39:30 +00:00
|
|
|
if (col_num == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-09-12 22:12:49 +02:00
|
|
|
const char * v = PQgetvalue(m_dr.m_res.get(), m_row, col_num);
|
2004-09-14 16:39:30 +00:00
|
|
|
val = strtol(v, 0, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DatabaseResult::const_iterator::readColumn(const char * column,
|
|
|
|
|
float & val) const
|
|
|
|
|
{
|
2013-09-12 22:12:49 +02:00
|
|
|
int col_num = PQfnumber(m_dr.m_res.get(), column);
|
2004-09-14 16:39:30 +00:00
|
|
|
if (col_num == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-09-12 22:12:49 +02:00
|
|
|
const char * v = PQgetvalue(m_dr.m_res.get(), m_row, col_num);
|
2004-09-14 16:39:30 +00:00
|
|
|
val = strtof(v, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DatabaseResult::const_iterator::readColumn(const char * column,
|
|
|
|
|
double & val) const
|
|
|
|
|
{
|
2013-09-12 22:12:49 +02:00
|
|
|
int col_num = PQfnumber(m_dr.m_res.get(), column);
|
2004-09-14 16:39:30 +00:00
|
|
|
if (col_num == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-09-12 22:12:49 +02:00
|
|
|
const char * v = PQgetvalue(m_dr.m_res.get(), m_row, col_num);
|
2004-09-14 16:39:30 +00:00
|
|
|
val = strtod(v, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DatabaseResult::const_iterator::readColumn(const char * column,
|
|
|
|
|
std::string & val) const
|
|
|
|
|
{
|
2013-09-12 22:12:49 +02:00
|
|
|
int col_num = PQfnumber(m_dr.m_res.get(), column);
|
2004-09-14 16:39:30 +00:00
|
|
|
if (col_num == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-09-12 22:12:49 +02:00
|
|
|
const char * v = PQgetvalue(m_dr.m_res.get(), m_row, col_num);
|
2004-09-14 16:39:30 +00:00
|
|
|
val = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DatabaseResult::const_iterator::readColumn(const char * column,
|
|
|
|
|
MapType & val) const
|
|
|
|
|
{
|
2013-09-12 22:12:49 +02:00
|
|
|
int col_num = PQfnumber(m_dr.m_res.get(), column);
|
2004-09-14 16:39:30 +00:00
|
|
|
if (col_num == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-09-12 22:12:49 +02:00
|
|
|
const char * v = PQgetvalue(m_dr.m_res.get(), m_row, col_num);
|
2007-12-07 17:42:58 +00:00
|
|
|
Database::instance()->decodeMessage(v, val);
|
2004-09-14 16:39:30 +00:00
|
|
|
}
|