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
|
2006-04-25 17:11:35 +00:00
|
|
|
// Copyright (C) 2003-2004,2006 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
|
2003-10-24 16:59:18 +00:00
|
|
|
|
2006-10-26 00:48:00 +00:00
|
|
|
|
2003-10-24 16:59:18 +00:00
|
|
|
#include "CommPSQLSocket.h"
|
|
|
|
|
|
|
|
|
|
#include "common/Database.h"
|
|
|
|
|
#include "common/log.h"
|
2003-10-27 01:59:53 +00:00
|
|
|
#include "common/debug.h"
|
2006-04-25 17:11:35 +00:00
|
|
|
#include "common/globals.h"
|
2003-10-27 01:59:53 +00:00
|
|
|
|
2014-01-31 11:17:48 +01:00
|
|
|
#include <boost/asio.hpp>
|
2003-10-24 16:59:18 +00:00
|
|
|
|
2014-01-31 11:17:48 +01:00
|
|
|
#include <iostream>
|
2003-10-24 21:24:26 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
static const bool debug_flag = false;
|
|
|
|
|
|
2014-02-01 21:18:11 +01:00
|
|
|
/// Interval between database vacuum jobs.
|
|
|
|
|
const int CommPSQLSocket::vacFreq = 25 * 60;
|
|
|
|
|
/// Interval between database reindex jobs.
|
|
|
|
|
const int CommPSQLSocket::reindexFreq = 30 * 60;
|
|
|
|
|
|
|
|
|
|
|
2004-08-27 Al Riddoch <alriddoch@zepler.org>
* common/BaseWorld.h, server/CommSocket.h, server/CommIdleSocket.h:
Make constructors of some base classes protected.
* server/Account.cpp: Note a possible bug in the character
creation code.
* server/CommIdleSocket.cpp, server/CommIdleSocket.h,
server/CommListener.cpp, server/CommListener.h,
server/CommLocalClient.cpp, server/CommMetaClient.cpp,
server/CommMetaClient.h, server/CommPSQLSocket.cpp,
server/CommPSQLSocket.h, server/CommRemoteClient.cpp,
server/CommSocket.cpp, server/CommSocket.h,
server/CommUnixListener.cpp, server/CommUnixListener.h:
Clean up the Comm classes for consistancy and readability.
2004-08-28 00:58:01 +00:00
|
|
|
/// \brief Constructor for PostgreSQL socket polling object.
|
|
|
|
|
///
|
|
|
|
|
/// @param db Reference to the low level database management object.
|
2014-01-31 11:17:48 +01:00
|
|
|
CommPSQLSocket::CommPSQLSocket(boost::asio::io_service& io_service, Database & db) :
|
|
|
|
|
m_io_service(io_service), m_socket(new boost::asio::ip::tcp::socket(io_service)),
|
|
|
|
|
m_vacuumTimer(io_service), m_reindexTimer(io_service), m_reconnectTimer(io_service),
|
|
|
|
|
m_db(db), m_vacuumFull(false)
|
2003-10-24 16:59:18 +00:00
|
|
|
{
|
|
|
|
|
// This assumes the database connection is already sorted, which I think
|
|
|
|
|
// is okay
|
|
|
|
|
PGconn * con = m_db.getConnection();
|
|
|
|
|
assert(con != 0);
|
|
|
|
|
|
|
|
|
|
if (PQsetnonblocking(con, 1) == -1) {
|
|
|
|
|
log(ERROR, "Unable to put database connection in non-blocking mode.");
|
|
|
|
|
}
|
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
|
|
|
|
2014-01-31 11:17:48 +01:00
|
|
|
//wrap the postgres socket in our tcp socket
|
|
|
|
|
int fd = PQsocket(con);
|
|
|
|
|
if (fd >= 0) {
|
|
|
|
|
m_socket->assign(boost::asio::ip::tcp::v4(), fd);
|
2006-04-25 17:11:35 +00:00
|
|
|
}
|
2014-01-31 11:17:48 +01:00
|
|
|
vacuum();
|
|
|
|
|
reindex();
|
|
|
|
|
do_read();
|
2003-10-24 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-31 11:17:48 +01:00
|
|
|
void CommPSQLSocket::tryReConnect()
|
2003-10-24 16:59:18 +00:00
|
|
|
{
|
2014-02-03 22:00:46 +01:00
|
|
|
m_reconnectTimer.expires_from_now(boost::posix_time::seconds(2));
|
2014-01-31 11:17:48 +01:00
|
|
|
m_reconnectTimer.async_wait([this](boost::system::error_code ec) {
|
|
|
|
|
if (!ec) {
|
|
|
|
|
if (m_db.initConnection() == 0) {
|
|
|
|
|
log(NOTICE, "Database connection re-established");
|
|
|
|
|
PGconn * con = m_db.getConnection();
|
|
|
|
|
if (PQsetnonblocking(con, 1) == -1) {
|
|
|
|
|
log(ERROR, "Unable to put database connection in non-blocking mode.");
|
|
|
|
|
}
|
|
|
|
|
int fd = PQsocket(con);
|
|
|
|
|
if (fd >= 0) {
|
|
|
|
|
m_socket = new boost::asio::ip::tcp::socket(m_io_service);
|
|
|
|
|
m_socket->assign(boost::asio::ip::tcp::v4(), fd);
|
|
|
|
|
do_read();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this->tryReConnect();
|
|
|
|
|
});
|
2003-10-24 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-31 11:17:48 +01:00
|
|
|
|
|
|
|
|
CommPSQLSocket::~CommPSQLSocket()
|
2003-10-24 16:59:18 +00:00
|
|
|
{
|
2014-02-04 15:56:26 +01:00
|
|
|
m_db.shutdownConnection();
|
2014-01-31 11:17:48 +01:00
|
|
|
delete m_socket;
|
2003-10-24 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-31 11:17:48 +01:00
|
|
|
void CommPSQLSocket::do_read()
|
2003-10-24 16:59:18 +00:00
|
|
|
{
|
2014-01-31 11:17:48 +01:00
|
|
|
//only use asio to poll for data available; use the PG* functions
|
|
|
|
|
//to do the actual reading
|
|
|
|
|
m_socket->async_read_some(boost::asio::null_buffers(),
|
|
|
|
|
[this](boost::system::error_code ec, std::size_t length)
|
|
|
|
|
{
|
|
|
|
|
if (!ec)
|
|
|
|
|
{
|
|
|
|
|
int result = this->read();
|
|
|
|
|
if (result == 0) {
|
|
|
|
|
this->dispatch();
|
|
|
|
|
this->do_read();
|
|
|
|
|
} else {
|
|
|
|
|
delete m_socket;
|
|
|
|
|
m_socket = nullptr;
|
|
|
|
|
this->tryReConnect();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
delete m_socket;
|
|
|
|
|
m_socket = nullptr;
|
|
|
|
|
this->tryReConnect();
|
|
|
|
|
}
|
|
|
|
|
});
|
2003-10-24 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
2004-10-03 Al Riddoch <alriddoch@zepler.org>
* server/CommClient.cpp, server/CommClient.h, server/CommListener.cpp,
server/CommListener.h, server/CommMetaClient.cpp,
server/CommMetaClient.h, server/CommPSQLSocket.cpp,
server/CommPSQLSocket.h, server/CommServer.cpp, server/CommSocket.h,
server/CommUnixListener.cpp, server/CommUnixListener.h:
Use int for returning error status.
2004-10-03 01:16:10 +00:00
|
|
|
int CommPSQLSocket::read()
|
2003-10-24 16:59:18 +00:00
|
|
|
{
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "CommPSQLSocket::read()" << std::endl << std::flush;);
|
2003-10-24 16:59:18 +00:00
|
|
|
PGconn * con = m_db.getConnection();
|
|
|
|
|
assert(con != 0);
|
|
|
|
|
|
2014-01-31 11:17:48 +01:00
|
|
|
if (PQstatus(con) != CONNECTION_OK) {
|
|
|
|
|
log(ERROR, "Database connection closed.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-24 16:59:18 +00:00
|
|
|
if (PQconsumeInput(con) == 0) {
|
|
|
|
|
log(ERROR, "Error reading from database connection.");
|
|
|
|
|
m_db.reportError();
|
2004-11-16 21:37:08 +00:00
|
|
|
|
|
|
|
|
log(ERROR, "Connection to RDBMS lost.");
|
|
|
|
|
return 1;
|
2003-10-24 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
2003-10-24 21:18:28 +00:00
|
|
|
PGresult * res;
|
2003-10-24 23:50:12 +00:00
|
|
|
while (PQisBusy(con) == 0) {
|
|
|
|
|
if ((res = PQgetResult(con)) != 0) {
|
|
|
|
|
m_db.queryResult(PQresultStatus(res));
|
|
|
|
|
PQclear(res);
|
|
|
|
|
} else {
|
|
|
|
|
m_db.queryComplete();
|
2004-10-03 Al Riddoch <alriddoch@zepler.org>
* server/CommClient.cpp, server/CommClient.h, server/CommListener.cpp,
server/CommListener.h, server/CommMetaClient.cpp,
server/CommMetaClient.h, server/CommPSQLSocket.cpp,
server/CommPSQLSocket.h, server/CommServer.cpp, server/CommSocket.h,
server/CommUnixListener.cpp, server/CommUnixListener.h:
Use int for returning error status.
2004-10-03 01:16:10 +00:00
|
|
|
return 0;
|
2003-10-24 23:50:12 +00:00
|
|
|
}
|
2003-10-24 21:18:28 +00:00
|
|
|
};
|
2003-10-24 16:59:18 +00:00
|
|
|
|
2004-10-03 Al Riddoch <alriddoch@zepler.org>
* server/CommClient.cpp, server/CommClient.h, server/CommListener.cpp,
server/CommListener.h, server/CommMetaClient.cpp,
server/CommMetaClient.h, server/CommPSQLSocket.cpp,
server/CommPSQLSocket.h, server/CommServer.cpp, server/CommSocket.h,
server/CommUnixListener.cpp, server/CommUnixListener.h:
Use int for returning error status.
2004-10-03 01:16:10 +00:00
|
|
|
return 0;
|
2003-10-24 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommPSQLSocket::dispatch()
|
|
|
|
|
{
|
2003-10-27 12:04:53 +00:00
|
|
|
debug(std::cout << "CommPSQLSocket::dispatch()"
|
|
|
|
|
<< std::endl << std::flush;);
|
2003-10-24 16:59:18 +00:00
|
|
|
|
2003-10-27 01:59:53 +00:00
|
|
|
if (m_db.queryInProgress()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_db.launchNewQuery();
|
2003-10-24 16:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
2014-01-31 11:17:48 +01:00
|
|
|
void CommPSQLSocket::vacuum()
|
2003-10-24 16:59:18 +00:00
|
|
|
{
|
2014-01-31 11:17:48 +01:00
|
|
|
if (m_socket && m_socket->is_open()) {
|
2003-10-28 00:18:18 +00:00
|
|
|
if (m_vacuumFull) {
|
|
|
|
|
m_db.runMaintainance(Database::MAINTAIN_VACUUM |
|
2003-10-29 Al Riddoch <alriddoch@zepler.org>
* common/const.cpp, common/const.h, common/random.h,
physics/BBox.h, physics/Collision.cpp, physics/Collision.h,
physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Python_API.cpp,
tests/collisiontest.cpp: Update variables relating to geometry
from double to float as this is the type used internall by
WFMath.
* physics/Vector3D.cpp, physics/Quaternion.cpp, physics/Quaternion.h:
Remove legacy code.
* server/CommPSQLSocket.cpp: Reformatting.
2003-10-29 01:39:09 +00:00
|
|
|
Database::MAINTAIN_VACUUM_FULL);
|
2003-10-28 00:18:18 +00:00
|
|
|
} else {
|
|
|
|
|
m_db.runMaintainance(Database::MAINTAIN_VACUUM |
|
2003-10-29 Al Riddoch <alriddoch@zepler.org>
* common/const.cpp, common/const.h, common/random.h,
physics/BBox.h, physics/Collision.cpp, physics/Collision.h,
physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.h,
rulesets/Movement.cpp, rulesets/Plant.cpp, rulesets/Python_API.cpp,
tests/collisiontest.cpp: Update variables relating to geometry
from double to float as this is the type used internall by
WFMath.
* physics/Vector3D.cpp, physics/Quaternion.cpp, physics/Quaternion.h:
Remove legacy code.
* server/CommPSQLSocket.cpp: Reformatting.
2003-10-29 01:39:09 +00:00
|
|
|
Database::MAINTAIN_VACUUM_ANALYZE);
|
2003-10-28 00:18:18 +00:00
|
|
|
}
|
|
|
|
|
m_vacuumFull = !m_vacuumFull;
|
|
|
|
|
}
|
2014-01-31 11:17:48 +01:00
|
|
|
|
2014-02-03 22:00:46 +01:00
|
|
|
m_vacuumTimer.expires_from_now(boost::posix_time::seconds(vacFreq));
|
2014-01-31 11:17:48 +01:00
|
|
|
m_vacuumTimer.async_wait([this](boost::system::error_code ec) {
|
|
|
|
|
if (!ec) {
|
|
|
|
|
this->vacuum();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CommPSQLSocket::reindex()
|
|
|
|
|
{
|
|
|
|
|
if (m_socket && m_socket->is_open()) {
|
2003-10-28 00:18:18 +00:00
|
|
|
m_db.runMaintainance(Database::MAINTAIN_REINDEX);
|
|
|
|
|
}
|
2014-02-03 22:00:46 +01:00
|
|
|
m_reindexTimer.expires_from_now(boost::posix_time::seconds(reindexFreq));
|
2014-01-31 11:17:48 +01:00
|
|
|
m_reindexTimer.async_wait([this](boost::system::error_code ec) {
|
|
|
|
|
if (!ec) {
|
|
|
|
|
this->reindex();
|
|
|
|
|
}
|
|
|
|
|
});
|
2003-10-24 16:59:18 +00:00
|
|
|
}
|