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
|
|
|
|
2018-05-19 21:47:24 +02:00
|
|
|
#include <Atlas/Codecs/Packed.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
|
|
|
|
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
|
|
|
|
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>
|
|
|
|
|
|
2003-10-30 00:03:54 +00:00
|
|
|
#include <cassert>
|
2018-05-19 21:47:24 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2003-10-30 00:03:54 +00:00
|
|
|
|
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
|
|
|
|
2018-05-19 21:47:24 +02:00
|
|
|
typedef Atlas::Codecs::Packed Serialiser;
|
2003-01-11 18:21:31 +00:00
|
|
|
|
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
|
|
|
|
2018-05-16 11:21:07 +02:00
|
|
|
template<> Database* Singleton<Database>::ms_Singleton = nullptr;
|
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
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
Database::Database() : 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
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-30 19:31:27 +01:00
|
|
|
Database::~Database() = default;
|
2011-09-28 23:15:46 +01:00
|
|
|
|
2002-11-24 02:51:54 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
2016-03-18 20:00:48 +01:00
|
|
|
Serialiser codec(str, str, m_d);
|
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();
|
|
|
|
|
|
2018-01-28 21:23:18 +01:00
|
|
|
codec.poll(true);
|
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()) {
|
2018-05-16 21:48:18 +02:00
|
|
|
log(WARNING, "Database entry does not appear to be decodable");
|
|
|
|
|
return -1;
|
2003-01-05 19:55:52 +00:00
|
|
|
}
|
2018-05-16 21:48:18 +02:00
|
|
|
|
|
|
|
|
o = m_d.get();
|
2011-09-29 12:15:43 +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
|
|
|
}
|
|
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult Database::selectRelation(const std::string & name,
|
2003-01-05 19:55:52 +00:00
|
|
|
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::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
|
|
|
}
|
|
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult Database::selectSimpleRowBy(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 & 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
|
|
|
|
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
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult Database::selectEntities(const std::string & loc)
|
2008-11-17 01:36:24 +00:00
|
|
|
{
|
|
|
|
|
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-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 ");
|
2018-10-30 19:50:09 +01:00
|
|
|
for (auto& tuple : tuples) {
|
2008-08-23 17:53:43 +00:00
|
|
|
if (first) {
|
2018-10-30 19:50:09 +01:00
|
|
|
query += compose("(%1, '%2', '%3')", id, tuple.first, tuple.second);
|
2008-08-23 17:53:43 +00:00
|
|
|
first = 0;
|
|
|
|
|
} else {
|
2018-10-30 19:50:09 +01:00
|
|
|
query += compose(", (%1, '%2', '%3')", id, tuple.first, tuple.second);
|
2008-08-23 17:53:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return scheduleCommand(query);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult Database::selectProperties(const std::string & id)
|
2008-11-17 01:36:24 +00:00
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
2018-05-16 21:48:18 +02:00
|
|
|
auto I = tuples.begin();
|
|
|
|
|
auto Iend = tuples.end();
|
2008-08-24 23:01:32 +00:00
|
|
|
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
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult Database::selectThoughts(const std::string & loc)
|
2013-04-06 18:26:38 +02:00
|
|
|
{
|
|
|
|
|
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)"
|
2018-05-19 21:47:24 +02:00
|
|
|
" VALUES (%1, '%2')", id, boost::replace_all_copy(thought, "'", "''"));
|
2013-04-06 18:26:38 +02:00
|
|
|
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;
|
2018-01-30 16:54:49 +01:00
|
|
|
createquery += " (id integer REFERENCES entities NOT nullptr";
|
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];
|
2018-01-30 16:54:49 +01:00
|
|
|
createquery += " integer NOT nullptr";
|
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
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult::DatabaseResult(DatabaseResult&& dr) noexcept
|
|
|
|
|
: m_worker(std::move(dr.m_worker))
|
2003-10-27 01:59:53 +00:00
|
|
|
{
|
|
|
|
|
|
2003-10-24 23:50:12 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult::const_iterator::const_iterator(std::unique_ptr<DatabaseResult::const_iterator_worker>&& worker, const DatabaseResult::DatabaseResultWorker& dr)
|
|
|
|
|
: m_worker(std::move(worker)),
|
|
|
|
|
m_dr(dr)
|
2003-10-27 18:01:03 +00:00
|
|
|
{
|
2018-05-19 21:47:24 +02:00
|
|
|
|
2004-09-14 16:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult::const_iterator::const_iterator(const_iterator&& ci) noexcept
|
|
|
|
|
: m_worker(std::move(ci.m_worker)),
|
|
|
|
|
m_dr(ci.m_dr)
|
|
|
|
|
{}
|
2004-09-14 16:39:30 +00:00
|
|
|
|
|
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
DatabaseResult::const_iterator& DatabaseResult::const_iterator::operator++()
|
2004-09-14 16:39:30 +00:00
|
|
|
{
|
2018-05-19 21:47:24 +02:00
|
|
|
m_worker->operator++();
|
|
|
|
|
|
2018-05-16 21:48:18 +02:00
|
|
|
return *this;
|
2004-09-14 16:39:30 +00:00
|
|
|
}
|