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
|
2004-11-29 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp,
common/BaseWorld.h, common/Burn.h, common/Chop.h, common/Cut.h,
common/Database.cpp, common/Database.h, common/Eat.h,
common/Generic.h, common/Load.h, common/Nourish.h,
common/OOGThing.cpp, common/OOGThing.h, common/Save.h,
common/Setup.h, common/Tick.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/inheritance.cpp, common/inheritance.h,
common/log.cpp, common/log.h, common/op_switch.h, common/random.h,
common/serialno.h, common/system.cpp, common/system.h,
common/type_utils.h, common/types.h, common/utility.cpp,
common/utility.h: Update copyright dates in files as appropriate.
2004-11-29 21:42:00 +00:00
|
|
|
// Copyright (C) 2000-2004 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
|
2001-04-10 19:05:14 +00:00
|
|
|
|
2006-10-26 00:48:00 +00:00
|
|
|
|
2005-03-28 18:49:54 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-04-10 19:05:14 +00:00
|
|
|
#include "globals.h"
|
2007-04-28 15:21:17 +00:00
|
|
|
|
|
|
|
|
#include "const.h"
|
2004-06-15 18:06:59 +00:00
|
|
|
#include "log.h"
|
2007-03-20 14:50:39 +00:00
|
|
|
#include "compose.hpp"
|
2010-08-19 18:04:53 +01:00
|
|
|
#include "system.h"
|
2001-04-10 19:05:14 +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
|
|
|
|
2007-04-28 16:45:13 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2007-03-20 14:50:39 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
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>
|
2014-01-20 23:07:22 +01:00
|
|
|
#include <memory>
|
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
|
|
|
|
2009-09-17 02:24:48 +01:00
|
|
|
#ifdef HAVE_IO_H
|
|
|
|
|
#include <io.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-10-03 13:55:54 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2013-11-13 20:55:34 +01:00
|
|
|
const char * const CYPHESIS = "cyphesis";
|
|
|
|
|
const char * const SLAVE = "slave";
|
2007-12-05 21:27:33 +00:00
|
|
|
|
2013-11-15 21:14:47 +01:00
|
|
|
static const char * const DEFAULT_RULESET = "deeds";
|
2013-11-13 20:55:34 +01:00
|
|
|
static const char * const DEFAULT_INSTANCE = "cyphesis";
|
2007-04-28 20:13:08 +00:00
|
|
|
|
2001-04-10 19:05:14 +00:00
|
|
|
varconf::Config * global_conf = NULL;
|
2007-12-04 19:18:17 +00:00
|
|
|
std::string instance(DEFAULT_INSTANCE);
|
2015-05-28 21:22:11 +02:00
|
|
|
std::string bin_directory(BINDIR);
|
2005-03-28 18:49:54 +00:00
|
|
|
std::string share_directory(DATADIR);
|
|
|
|
|
std::string etc_directory(SYSCONFDIR);
|
|
|
|
|
std::string var_directory(LOCALSTATEDIR);
|
2012-01-19 19:34:20 +00:00
|
|
|
std::string ruleset_name(DEFAULT_RULESET);
|
2013-05-14 15:04:47 -04:00
|
|
|
std::string server_uuid("");
|
|
|
|
|
std::string server_key("");
|
2013-08-21 20:53:40 +02:00
|
|
|
|
2001-10-06 16:52:02 +00:00
|
|
|
bool exit_flag = false;
|
2013-08-21 20:53:40 +02:00
|
|
|
bool exit_flag_soft = false;
|
|
|
|
|
bool exit_soft_enabled = false;
|
2001-10-06 16:52:02 +00:00
|
|
|
bool daemon_flag = false;
|
2007-02-20 00:52:41 +00:00
|
|
|
bool database_flag = true;
|
2009-05-07 13:49:51 +01:00
|
|
|
int timeoffset = SPM * MPH * 9; // Morning
|
2004-12-13 12:22:35 +00:00
|
|
|
int client_port_num = 6767;
|
2008-11-09 06:19:40 +00:00
|
|
|
int dynamic_port_start = 6800;
|
|
|
|
|
int dynamic_port_end = 6899;
|
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
|
|
|
|
2013-11-13 20:55:34 +01:00
|
|
|
static const char * const FALLBACK_LOCALSTATEDIR = "/var";
|
2007-04-28 16:45:13 +00:00
|
|
|
|
|
|
|
|
static const int S = USAGE_SERVER;
|
|
|
|
|
static const int C = USAGE_CLIENT;
|
|
|
|
|
static const int M = USAGE_CYCMD;
|
|
|
|
|
static const int D = USAGE_DBASE;
|
2009-02-09 05:32:44 +00:00
|
|
|
static const int P = USAGE_CYPYTHON;
|
2013-07-27 22:23:09 +02:00
|
|
|
static const int A = USAGE_AICLIENT;
|
2007-04-28 16:45:13 +00:00
|
|
|
|
2009-08-24 14:16:39 +01:00
|
|
|
/// \brief Structure for holding data about varconf options
|
2007-04-28 16:45:13 +00:00
|
|
|
typedef struct {
|
2007-04-28 20:13:08 +00:00
|
|
|
const char * section;
|
|
|
|
|
const char * option;
|
|
|
|
|
const char * value;
|
2007-04-28 16:45:13 +00:00
|
|
|
const char * dflt;
|
|
|
|
|
const char * description;
|
|
|
|
|
int flags;
|
|
|
|
|
} usage_data;
|
|
|
|
|
|
|
|
|
|
static const usage_data usage[] = {
|
2013-07-27 22:23:09 +02:00
|
|
|
{ "", "help", "", "", "Display usage information and exit", S|C|M|D|A },
|
|
|
|
|
{ "", "version", "", "", "Display the version information and exit", S|C|M|D|A },
|
2007-12-05 01:21:11 +00:00
|
|
|
{ "", "instance", "<short_name>", "\"cyphesis\"", "Unique short name for the server instance", S|C|M|D },
|
2009-11-25 17:54:44 +00:00
|
|
|
{ "", "interactive", "", "", "Run in interactive mode, giving a Python prompt", C },
|
2015-07-15 11:29:31 +02:00
|
|
|
{ CYPHESIS, "dynamicpaths", "true|false", "false", "Enables dynamic paths, calculated from the current executable", S|D|C|M|A },
|
2007-12-05 21:27:33 +00:00
|
|
|
{ CYPHESIS, "directory", "<directory>", "", "Directory where server data and scripts can be found", S|C },
|
|
|
|
|
{ CYPHESIS, "confdir", "<directory>", "", "Directory where server config can be found", S|C|M|D },
|
2015-05-28 21:22:11 +02:00
|
|
|
{ CYPHESIS, "bindir", "<directory>", "", "Directory where Cyphesis binaries can be found", S|C|M|D },
|
2007-12-05 21:27:33 +00:00
|
|
|
{ CYPHESIS, "vardir", "<directory>", "", "Directory where temporary files can be stored", S|C|M },
|
|
|
|
|
{ CYPHESIS, "ruleset", "<name>", DEFAULT_RULESET, "Ruleset name", S|C|D },
|
|
|
|
|
{ CYPHESIS, "servername", "<name>", "<hostname>", "Published name of the server", S|C },
|
|
|
|
|
{ CYPHESIS, "tcpport", "<portnumber>", "6767", "Network listen port for client connections", S|C|M },
|
2008-11-10 14:01:34 +00:00
|
|
|
{ CYPHESIS, "dynamic_port_start", "<portnumber>", "6800", "Lowest port to try and used for dyanmic ports", S },
|
|
|
|
|
{ CYPHESIS, "dynamic_port_end", "<portnumber>", "6899", "Highest port to try and used for dyanmic ports", S },
|
2007-12-05 21:27:33 +00:00
|
|
|
{ CYPHESIS, "usedatabase", "true|false", "true", "Flag to control whether to use a database for persistent storage", S },
|
|
|
|
|
{ CYPHESIS, "daemon", "true|false", "false", "Flag to control running the server in daemon mode", S },
|
|
|
|
|
{ CYPHESIS, "nice", "<level>", "1", "Reduce the priority level of the server", S },
|
|
|
|
|
{ CYPHESIS, "useaiclient", "true|false", "false", "Flag to control whether AI is to be driven by a client", S },
|
|
|
|
|
{ CYPHESIS, "dbserver", "<hostname>", "", "Hostname for the PostgreSQL RDBMS", S|D },
|
|
|
|
|
{ CYPHESIS, "dbname", "<name>", "\"cyphesis\"", "Name of the database to use", S|D },
|
|
|
|
|
{ CYPHESIS, "dbuser", "<dbusername>", "<username>", "Database user name for access", S|D },
|
|
|
|
|
{ CYPHESIS, "dbpasswd", "<dbusername>", "", "Database password for access", S|D },
|
|
|
|
|
{ SLAVE, "tcpport", "<portnumber>", "6768", "Network listen port for client connections to the AI slave server", M },
|
|
|
|
|
{ SLAVE, "server", "<hostname>", "localhost", "Master server to connect the slave to", M },
|
2007-04-28 16:45:13 +00:00
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
|
};
|
2007-03-20 14:50:39 +00:00
|
|
|
|
|
|
|
|
static int check_tmp_path(const std::string & dir)
|
|
|
|
|
{
|
2007-05-07 22:45:15 +00:00
|
|
|
std::string tmp_directory = dir + "/tmp";
|
2007-03-20 14:50:39 +00:00
|
|
|
struct stat tmp_stat;
|
|
|
|
|
|
|
|
|
|
if (::stat(tmp_directory.c_str(), &tmp_stat) != 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!S_ISDIR(tmp_stat.st_mode)) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-07 22:53:13 +00:00
|
|
|
if (::access(tmp_directory.c_str(), W_OK) != 0) {
|
2007-05-07 22:45:15 +00:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-20 14:50:39 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-06 02:46:32 +00:00
|
|
|
static int force_simple_name(const std::string & in, std::string & out)
|
|
|
|
|
{
|
|
|
|
|
out = std::string(in.size(), ' ');
|
|
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < in.size(); ++i) {
|
|
|
|
|
int c = in[i];
|
|
|
|
|
if (islower(c) || isdigit(c)) {
|
|
|
|
|
out[i] = c;
|
|
|
|
|
} else if (isalpha(c)) {
|
|
|
|
|
out[i] = ::tolower(c);
|
|
|
|
|
} else if (isspace(c) || c == '_') {
|
|
|
|
|
out[i] = '_';
|
|
|
|
|
} else {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-11-05 04:11:38 +00:00
|
|
|
template <typename T>
|
|
|
|
|
int readConfigItem(const std::string & section, const std::string & key, T & storage)
|
|
|
|
|
{
|
|
|
|
|
if (global_conf->findItem(section, key)) {
|
|
|
|
|
storage = global_conf->getItem(section, key);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
int readConfigItem<std::string>(const std::string & section, const std::string & key, std::string & storage)
|
|
|
|
|
{
|
|
|
|
|
if (global_conf->findItem(section, key)) {
|
|
|
|
|
storage = global_conf->getItem(section, key).as_string();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-09 01:27:08 +01:00
|
|
|
template int readConfigItem<bool>(const std::string & section, const std::string & key, bool & storage);
|
2014-04-28 18:45:55 +02:00
|
|
|
template int readConfigItem<int>(const std::string & section, const std::string & key, int & storage);
|
2009-04-09 01:27:08 +01:00
|
|
|
|
2009-08-24 14:16:39 +01:00
|
|
|
/// \brief Base class for handling varconf options declared inline.
|
2009-04-08 00:16:35 +01:00
|
|
|
class Option {
|
|
|
|
|
protected:
|
2014-01-20 23:07:22 +01:00
|
|
|
const std::string m_value;
|
|
|
|
|
const std::string m_description;
|
2009-04-08 00:16:35 +01:00
|
|
|
|
|
|
|
|
Option(const std::string & val, const std::string & descr);
|
|
|
|
|
public:
|
|
|
|
|
virtual ~Option() = 0;
|
|
|
|
|
|
2014-01-20 23:07:22 +01:00
|
|
|
const std::string & value() const { return m_value; }
|
|
|
|
|
const std::string & description() const { return m_description; }
|
2009-04-08 00:16:35 +01:00
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
virtual void read(varconf::Variable var) = 0;
|
|
|
|
|
|
|
|
|
|
virtual const std::string repr() const = 0;
|
2009-04-08 00:16:35 +01:00
|
|
|
|
|
|
|
|
virtual size_t size() const = 0;
|
2009-04-08 15:50:02 +01:00
|
|
|
|
|
|
|
|
virtual void missing() { }
|
|
|
|
|
|
|
|
|
|
virtual void postProcess() { }
|
2009-04-08 00:16:35 +01:00
|
|
|
};
|
|
|
|
|
|
2009-08-24 14:16:39 +01:00
|
|
|
/// \brief Basic varconf option which does not require any processing
|
2009-04-08 00:16:35 +01:00
|
|
|
class DumbOption : public Option {
|
|
|
|
|
protected:
|
2014-01-20 23:07:22 +01:00
|
|
|
const std::string m_default;
|
2009-04-08 00:16:35 +01:00
|
|
|
public:
|
|
|
|
|
DumbOption(const std::string & val, const std::string & descr,
|
|
|
|
|
const std::string & deflt);
|
|
|
|
|
|
|
|
|
|
virtual ~DumbOption() { }
|
2009-04-08 02:03:14 +01:00
|
|
|
|
|
|
|
|
virtual void read(varconf::Variable var) { }
|
2009-04-08 00:16:35 +01:00
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
virtual const std::string repr() const;
|
|
|
|
|
|
|
|
|
|
virtual size_t size() const;
|
|
|
|
|
};
|
|
|
|
|
|
2009-08-24 14:16:39 +01:00
|
|
|
/// \brief Basic varconf option declared as a variable inline
|
2009-04-08 02:03:14 +01:00
|
|
|
template<typename ValueT>
|
|
|
|
|
class StaticOption : public Option {
|
|
|
|
|
protected:
|
|
|
|
|
ValueT & m_data;
|
|
|
|
|
const ValueT m_default;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
StaticOption(const std::string & val,
|
|
|
|
|
const std::string & descr,
|
|
|
|
|
ValueT & data) :
|
|
|
|
|
Option(val, descr), m_data(data), m_default(data) { }
|
|
|
|
|
|
|
|
|
|
virtual void read(varconf::Variable var);
|
|
|
|
|
|
|
|
|
|
virtual const std::string repr() const;
|
2009-04-08 00:16:35 +01:00
|
|
|
|
|
|
|
|
virtual size_t size() const;
|
2009-04-08 02:03:14 +01:00
|
|
|
|
2009-04-08 00:16:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Option::Option(const std::string & val, const std::string & descr) :
|
|
|
|
|
m_value(val), m_description(descr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
Option::~Option()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-08 00:16:35 +01:00
|
|
|
DumbOption::DumbOption(const std::string & val,
|
|
|
|
|
const std::string & descr,
|
|
|
|
|
const std::string & deflt) :
|
|
|
|
|
Option(val, descr), m_default(deflt)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
const std::string DumbOption::repr() const
|
2009-04-08 00:16:35 +01:00
|
|
|
{
|
|
|
|
|
return m_default;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t DumbOption::size() const
|
|
|
|
|
{
|
|
|
|
|
return m_default.size();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-08 21:22:19 +01:00
|
|
|
template<>
|
|
|
|
|
void StaticOption<std::string>::read(varconf::Variable var)
|
|
|
|
|
{
|
|
|
|
|
m_data = var.as_string();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
template<typename ValueT>
|
|
|
|
|
void StaticOption<ValueT>::read(varconf::Variable var)
|
|
|
|
|
{
|
|
|
|
|
m_data = var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename ValueT>
|
|
|
|
|
const std::string StaticOption<ValueT>::repr() const
|
2009-04-08 00:16:35 +01:00
|
|
|
{
|
2009-04-08 02:03:14 +01:00
|
|
|
return String::compose("%1", m_default);
|
2009-04-08 00:16:35 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
template<typename ValueT>
|
|
|
|
|
size_t StaticOption<ValueT>::size() const
|
|
|
|
|
{
|
|
|
|
|
return String::compose("%1", m_default).size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template class StaticOption<int>;
|
|
|
|
|
|
2009-08-24 14:16:39 +01:00
|
|
|
/// \brief Handle the processing required for a unix socket option
|
2009-04-08 21:22:19 +01:00
|
|
|
class UnixSockOption : public StaticOption<std::string>
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
const char * const m_format;
|
|
|
|
|
public:
|
|
|
|
|
UnixSockOption(const std::string & val,
|
|
|
|
|
const std::string & descr,
|
|
|
|
|
std::string & data,
|
|
|
|
|
const char * format) :
|
|
|
|
|
StaticOption<std::string>(val, descr, data), m_format(format) { }
|
|
|
|
|
|
|
|
|
|
virtual void missing();
|
|
|
|
|
|
|
|
|
|
virtual void postProcess();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void UnixSockOption::missing()
|
|
|
|
|
{
|
|
|
|
|
m_data = String::compose(m_format, instance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnixSockOption::postProcess()
|
|
|
|
|
{
|
|
|
|
|
if (m_data.find('/') != 0) {
|
|
|
|
|
m_data = String::compose("%1/tmp/%2",
|
|
|
|
|
var_directory,
|
|
|
|
|
m_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-20 23:07:22 +01:00
|
|
|
typedef std::map<std::string, std::unique_ptr<Option> > OptionMap;
|
2009-04-08 00:16:35 +01:00
|
|
|
typedef std::map<std::string, OptionMap> SectionMap;
|
2007-11-14 22:40:17 +00:00
|
|
|
|
2009-08-24 14:16:39 +01:00
|
|
|
/// \brief Singleton to manage all information about varconf options.
|
2009-04-07 23:17:49 +01:00
|
|
|
class Options {
|
|
|
|
|
protected:
|
2009-04-08 00:16:35 +01:00
|
|
|
SectionMap m_sectionMap;
|
2009-04-07 23:17:49 +01:00
|
|
|
|
|
|
|
|
static Options * m_instance;
|
|
|
|
|
|
|
|
|
|
explicit Options();
|
|
|
|
|
public:
|
|
|
|
|
static Options * instance() {
|
|
|
|
|
if (m_instance == 0) {
|
|
|
|
|
m_instance = new Options;
|
|
|
|
|
}
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-08 00:16:35 +01:00
|
|
|
const SectionMap & sectionMap() const {
|
|
|
|
|
return m_sectionMap;
|
2009-04-07 23:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int check_config(varconf::Config &, int usage_groups = USAGE_SERVER|
|
|
|
|
|
USAGE_CLIENT|
|
|
|
|
|
USAGE_CYCMD|
|
|
|
|
|
USAGE_DBASE) const;
|
|
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
void addOption(const std::string & section,
|
|
|
|
|
const std::string & setting,
|
|
|
|
|
Option *);
|
2009-04-07 23:17:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Options * Options::m_instance = 0;
|
2007-11-14 22:40:17 +00:00
|
|
|
|
2009-04-07 23:17:49 +01:00
|
|
|
Options::Options()
|
|
|
|
|
{
|
2007-11-14 22:40:17 +00:00
|
|
|
const usage_data * ud = &usage[0];
|
|
|
|
|
for (; ud->section != 0; ++ud) {
|
2009-04-08 00:16:35 +01:00
|
|
|
m_sectionMap[ud->section].insert(std::make_pair(ud->option,
|
2014-01-20 23:07:22 +01:00
|
|
|
std::unique_ptr<Option>(new DumbOption(ud->value, ud->description, ud->dflt))));
|
2007-11-14 22:40:17 +00:00
|
|
|
}
|
2009-04-07 23:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Options::check_config(varconf::Config & config,
|
|
|
|
|
int usage_groups) const
|
|
|
|
|
{
|
2009-04-08 00:16:35 +01:00
|
|
|
SectionMap::const_iterator I = m_sectionMap.begin();
|
|
|
|
|
SectionMap::const_iterator Iend = m_sectionMap.end();
|
2007-11-14 22:40:17 +00:00
|
|
|
for (; I != Iend; ++I) {
|
|
|
|
|
const std::string & section_name = I->first;
|
2009-04-08 00:16:35 +01:00
|
|
|
const OptionMap & section_help = I->second;
|
2007-11-14 22:40:17 +00:00
|
|
|
const varconf::sec_map & section = config.getSection(section_name);
|
|
|
|
|
|
|
|
|
|
varconf::sec_map::const_iterator J = section.begin();
|
|
|
|
|
varconf::sec_map::const_iterator Jend = section.end();
|
|
|
|
|
for (; J != Jend; ++J) {
|
|
|
|
|
const std::string & option_name = J->first;
|
2009-04-09 01:27:08 +01:00
|
|
|
if (section_help.find(J->first) == section_help.end() &&
|
|
|
|
|
J->second->scope() == varconf::INSTANCE) {
|
2007-11-14 22:40:17 +00:00
|
|
|
log(WARNING, String::compose("Invalid option -- %1:%2",
|
|
|
|
|
section_name, option_name));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
void Options::addOption(const std::string & section,
|
|
|
|
|
const std::string & setting,
|
|
|
|
|
Option * option)
|
2009-04-07 23:17:49 +01:00
|
|
|
{
|
2009-04-08 21:22:19 +01:00
|
|
|
OptionMap & config_section = m_sectionMap[section];
|
|
|
|
|
if (config_section.find(setting) != config_section.end()) {
|
|
|
|
|
log(ERROR, String::compose("Config option %1:%2 already defined",
|
|
|
|
|
section, setting));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-01-20 23:07:22 +01:00
|
|
|
m_sectionMap[section].insert(std::make_pair(setting, std::unique_ptr<Option>(option)));
|
2009-04-07 23:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int_config_register::int_config_register(int & var,
|
|
|
|
|
const char * section,
|
|
|
|
|
const char * setting,
|
|
|
|
|
const char * help)
|
|
|
|
|
{
|
2009-04-08 02:03:14 +01:00
|
|
|
Options::instance()->addOption(section, setting,
|
|
|
|
|
new StaticOption<int>("<foo>", help, var));
|
2009-04-07 23:17:49 +01:00
|
|
|
}
|
|
|
|
|
|
2009-04-08 21:49:52 +01:00
|
|
|
bool_config_register::bool_config_register(bool & var,
|
|
|
|
|
const char * section,
|
|
|
|
|
const char * setting,
|
|
|
|
|
const char * help)
|
|
|
|
|
{
|
|
|
|
|
Options::instance()->addOption(section, setting,
|
|
|
|
|
new StaticOption<bool>("<foo>", help, var));
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-08 21:22:19 +01:00
|
|
|
string_config_register::string_config_register(std::string & var,
|
|
|
|
|
const char * section,
|
|
|
|
|
const char * setting,
|
|
|
|
|
const char * help)
|
|
|
|
|
{
|
|
|
|
|
Options::instance()->addOption(section, setting,
|
|
|
|
|
new StaticOption<std::string>("<foo>", help, var));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unixsock_config_register::unixsock_config_register(std::string & var,
|
|
|
|
|
const char * section,
|
|
|
|
|
const char * setting,
|
|
|
|
|
const char * help,
|
|
|
|
|
const char * format)
|
|
|
|
|
{
|
|
|
|
|
Options::instance()->addOption(section, setting,
|
2009-12-03 18:33:36 +00:00
|
|
|
new UnixSockOption("<filename>", help, var, format));
|
2009-04-08 21:22:19 +01:00
|
|
|
}
|
|
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
void readInstanceConfiguration(const std::string & section);
|
|
|
|
|
|
2007-11-14 22:40:17 +00:00
|
|
|
int loadConfig(int argc, char ** argv, int usage)
|
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
|
|
|
{
|
|
|
|
|
global_conf = varconf::Config::inst();
|
|
|
|
|
|
2007-04-24 12:59:26 +00:00
|
|
|
global_conf->setParameterLookup('h', "help");
|
|
|
|
|
global_conf->setParameterLookup('?', "help");
|
|
|
|
|
|
2007-04-28 15:21:17 +00:00
|
|
|
global_conf->setParameterLookup('v', "version");
|
2009-11-25 17:54:44 +00:00
|
|
|
global_conf->setParameterLookup('i', "interactive");
|
2007-04-28 15:21:17 +00:00
|
|
|
|
2007-11-14 22:40:17 +00:00
|
|
|
// Check the commmand line config doesn't contain any unknown or
|
|
|
|
|
// inappropriate options.
|
|
|
|
|
varconf::Config test_cmdline;
|
|
|
|
|
test_cmdline.getCmdline(argc, argv);
|
2009-04-07 23:17:49 +01:00
|
|
|
Options::instance()->check_config(test_cmdline, usage);
|
2007-11-14 22:40:17 +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
|
|
|
// See if the user has set the install directory on the command line
|
2006-01-04 15:06:46 +00:00
|
|
|
bool home_dir_config = false;
|
|
|
|
|
char * home = getenv("HOME");
|
|
|
|
|
|
|
|
|
|
// Read in only the users settings, and the commandline settings.
|
|
|
|
|
if (home != NULL) {
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
home_dir_config = global_conf->readFromFile(std::string(home) + "/.cyphesis.vconf");
|
|
|
|
|
}
|
2006-01-04 15:06:46 +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
|
|
|
global_conf->getCmdline(argc, argv);
|
2006-01-04 15:06:46 +00:00
|
|
|
|
2007-04-28 15:21:17 +00:00
|
|
|
if (global_conf->findItem("", "version")) {
|
|
|
|
|
return CONFIG_VERSION;
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-24 12:59:26 +00:00
|
|
|
if (global_conf->findItem("", "help")) {
|
2007-04-28 15:21:17 +00:00
|
|
|
return CONFIG_HELP;
|
2007-04-24 12:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
2015-07-15 11:29:31 +02:00
|
|
|
bool dynamicPaths = false;
|
|
|
|
|
readConfigItem("cyphesis", "dynamicpaths", dynamicPaths);
|
|
|
|
|
if (dynamicPaths) {
|
|
|
|
|
log(INFO, "Dynamic paths are now enabled. All paths will be calculated relative to the current executable.");
|
|
|
|
|
getinstallprefix();
|
|
|
|
|
}
|
2010-08-19 18:04:53 +01:00
|
|
|
|
2006-01-04 15:06:46 +00:00
|
|
|
// Check if the config directory has been overriden at this point, as if
|
|
|
|
|
// it has, that will affect loading the main config.
|
2007-11-14 22:40:17 +00:00
|
|
|
readConfigItem("cyphesis", "confdir", etc_directory);
|
2006-01-04 15:06:46 +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
|
|
|
// Load up the rest of the system config file, and then ensure that
|
|
|
|
|
// settings are overridden in the users config file, and the command line
|
2002-04-25 Al Riddoch <alriddoch@zepler.org>
* rulesets/Entity.cpp, rulesets/Entity.h, rulesets/Character.cpp,
rulesets/Character.h, rulesets/Thing.cpp, rulesets/Food.cpp:
Renamed weight member as mass, and use this name in Atlas,
as this is a better convention, and has already been adopted in
stage.
* Switched python code to using mass instead of weight, as it is
a more accurate term.
* common/globals.cpp, common/globals.h, tools/cyloadrules.cpp:
Put admin modifiable config in etc instead of share directory.
* Don't build cycmd if readline is not available. Untested, and
probably nasty.
2002-04-26 08:08:48 +00:00
|
|
|
bool main_config = global_conf->readFromFile(etc_directory +
|
2006-01-04 15:06:46 +00:00
|
|
|
"/cyphesis/cyphesis.vconf",
|
|
|
|
|
varconf::GLOBAL);
|
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 (!main_config) {
|
2007-10-01 04:57:15 +00:00
|
|
|
log(ERROR, String::compose("Unable to read main config file \"%1\"",
|
2007-07-29 Al Riddoch <alriddoch@zepler.org>
* common/log.cpp, common/log.h: Switch to taking a C++ string reference
rather than a char *, as it is not really an optimisation, and it
makes the code simpler to read and write.
* client/BaseClient.cpp, client/ClientConnection.cpp,
common/AtlasFileLoader.cpp, common/BaseEntity.cpp,
common/Database.cpp, common/globals.cpp, common/id.cpp,
common/inheritance.cpp, common/log.cpp, common/log.h,
rulesets/Character.cpp, rulesets/Creator.cpp, rulesets/Entity.cpp,
rulesets/MemMap.cpp, rulesets/Motion.cpp, rulesets/Pedestrian.cpp,
rulesets/Py_Object.cpp, rulesets/Py_RootEntity.cpp,
rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp,
rulesets/Python_API.cpp, rulesets/Thing.cpp, server/Account.cpp,
server/Admin.cpp, server/ArithmeticFactory.cpp,
server/CommClient.cpp, server/CommListener.cpp,
server/CommMDNSPublisher.cpp, server/CommServer.cpp,
server/Connection.cpp, server/EntityFactory.cpp,
server/Persistance.cpp, server/Restoration.cpp,
server/ScriptFactory.cpp, server/TaskFactory.cpp,
server/WorldRouter.cpp, server/server.cpp: Convert over to using
new API correctly.
* data/mason.xml: Add biomass and transient to fircone, making its
script obsolete:
2007-07-29 03:33:33 +00:00
|
|
|
etc_directory +
|
|
|
|
|
"/cyphesis/cyphesis.vconf"));
|
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 (home_dir_config) {
|
2004-06-15 18:06:59 +00:00
|
|
|
log(INFO, "Try removing .cyphesis.vconf from your home directory as it may specify an invalid installation directory, and then restart cyphesis.");
|
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
|
|
|
} else {
|
2004-06-15 18:06:59 +00:00
|
|
|
log(INFO, "Please ensure that cyphesis has been installed correctly.");
|
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 (home_dir_config) {
|
|
|
|
|
global_conf->readFromFile(std::string(home) + "/.cyphesis.vconf");
|
|
|
|
|
}
|
2007-11-14 22:40:17 +00:00
|
|
|
|
2004-10-03 13:55:54 +00:00
|
|
|
int optind = global_conf->getCmdline(argc, argv);
|
|
|
|
|
|
2009-04-07 23:17:49 +01:00
|
|
|
Options::instance()->check_config(*global_conf);
|
2007-11-14 22:40:17 +00:00
|
|
|
|
2004-10-03 13:55:54 +00:00
|
|
|
assert(optind > 0);
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
|
2007-12-06 02:46:32 +00:00
|
|
|
std::string raw_instance;
|
|
|
|
|
|
|
|
|
|
if (readConfigItem("", "instance", raw_instance) == 0) {
|
|
|
|
|
if (force_simple_name(raw_instance, instance) != 0) {
|
|
|
|
|
log(ERROR, "Invalid instance name.");
|
|
|
|
|
return CONFIG_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (raw_instance != instance) {
|
|
|
|
|
log(INFO, String::compose("Using instance name \"%1\".", instance));
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-12-04 19:18:17 +00:00
|
|
|
|
|
|
|
|
readConfigItem("cyphesis", "dynamic_port_start", dynamic_port_start);
|
|
|
|
|
readConfigItem("cyphesis", "dynamic_port_end", dynamic_port_end);
|
|
|
|
|
|
2009-04-08 02:03:14 +01:00
|
|
|
Options * options = Options::instance();
|
|
|
|
|
|
|
|
|
|
SectionMap::const_iterator I = options->sectionMap().begin();
|
|
|
|
|
SectionMap::const_iterator Iend = options->sectionMap().end();
|
|
|
|
|
OptionMap::const_iterator J;
|
|
|
|
|
OptionMap::const_iterator Jend;
|
|
|
|
|
for (; I != Iend; ++I) {
|
|
|
|
|
J = I->second.begin();
|
|
|
|
|
Jend = I->second.end();
|
|
|
|
|
for (; J != Jend; ++J) {
|
|
|
|
|
if (global_conf->findItem(I->first, J->first)) {
|
|
|
|
|
J->second->read(global_conf->getItem(I->first, J->first));
|
2009-04-08 15:50:02 +01:00
|
|
|
} else {
|
|
|
|
|
J->second->missing();
|
2009-04-08 02:03:14 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
readInstanceConfiguration(instance);
|
|
|
|
|
|
2009-12-12 21:03:09 +00:00
|
|
|
I = options->sectionMap().begin();
|
|
|
|
|
for (; I != Iend; ++I) {
|
|
|
|
|
J = I->second.begin();
|
|
|
|
|
Jend = I->second.end();
|
|
|
|
|
for (; J != Jend; ++J) {
|
|
|
|
|
J->second->postProcess();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
return optind;
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-05 17:33:19 +00:00
|
|
|
void updateUserConfiguration()
|
|
|
|
|
{
|
|
|
|
|
char * home = getenv("HOME");
|
|
|
|
|
|
|
|
|
|
// Write out any changes that have been overriden at user scope. It
|
|
|
|
|
// may be a good idea to do this at shutdown.
|
|
|
|
|
if (home != NULL) {
|
|
|
|
|
global_conf->writeToFile(std::string(home) + "/.cyphesis.vconf", varconf::USER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
void readInstanceConfiguration(const std::string & section)
|
|
|
|
|
{
|
2002-01-28 Al Riddoch <alriddoch@zepler.org>
* client/ClientConnection.cpp, client/CommClient.h,
common/globals.cpp, common/globals.h, server/server.cpp,
tools/cycmd.cpp:
Make the TCP port number a global config setting, and
ensure it is used everwhere, so it can be overriden, and all
clients and tools will use it. Modify behavoir so that any
settings overridden on the command line are made semi-permanent
in the users home directory, making it easier for users to run
two versions on one machine at the same time.
* common/Database.cpp, common/Database.h: Remove obsolete iterator
code. Add a method to clear a given database table.
* server/Persistance.h, tools/cyloadrules.cpp:
Automate loading of the ruleset given in the config file, and
the rulesets it depends on, ensuring that the rules table
is cleared first.
2002-01-28 11:40:10 +00:00
|
|
|
// Config is now loaded. Now set the values of some globals.
|
|
|
|
|
|
2015-05-28 21:22:11 +02:00
|
|
|
readConfigItem(section, "bindir", bin_directory);
|
|
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
readConfigItem(section, "directory", share_directory);
|
2006-01-04 15:06:46 +00:00
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
readConfigItem(section, "confdir", etc_directory);
|
2006-01-04 15:06:46 +00:00
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
readConfigItem(section, "vardir", var_directory);
|
2006-01-04 15:06:46 +00:00
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
readConfigItem(section, "daemon", daemon_flag);
|
2002-01-27 13:22:33 +00:00
|
|
|
|
2007-12-04 19:18:17 +00:00
|
|
|
if (readConfigItem(section, "tcpport", client_port_num) != 0) {
|
|
|
|
|
if (section != DEFAULT_INSTANCE) {
|
|
|
|
|
client_port_num = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-28 Al Riddoch <alriddoch@zepler.org>
* client/ClientConnection.cpp, client/CommClient.h,
common/globals.cpp, common/globals.h, server/server.cpp,
tools/cycmd.cpp:
Make the TCP port number a global config setting, and
ensure it is used everwhere, so it can be overriden, and all
clients and tools will use it. Modify behavoir so that any
settings overridden on the command line are made semi-permanent
in the users home directory, making it easier for users to run
two versions on one machine at the same time.
* common/Database.cpp, common/Database.h: Remove obsolete iterator
code. Add a method to clear a given database table.
* server/Persistance.h, tools/cyloadrules.cpp:
Automate loading of the ruleset given in the config file, and
the rulesets it depends on, ensuring that the rules table
is cleared first.
2002-01-28 11:40:10 +00:00
|
|
|
|
2007-06-19 13:19:57 +00:00
|
|
|
// Load up the ruleset.
|
2012-01-19 19:34:20 +00:00
|
|
|
if (readConfigItem(section, "ruleset", ruleset_name)) {
|
2007-12-05 17:33:19 +00:00
|
|
|
if (section == DEFAULT_INSTANCE) {
|
|
|
|
|
log(ERROR, String::compose("No ruleset specified in config. "
|
|
|
|
|
"Using \"%1\" rules.", DEFAULT_RULESET));
|
|
|
|
|
} else {
|
|
|
|
|
log(INFO, String::compose("Auto configuring new instance \"%1\" "
|
|
|
|
|
"to use ruleset \"%2\".",
|
2012-01-19 19:34:20 +00:00
|
|
|
instance, ruleset_name));
|
|
|
|
|
global_conf->setItem(section,
|
|
|
|
|
"ruleset",
|
|
|
|
|
ruleset_name,
|
|
|
|
|
varconf::USER);
|
2007-12-05 17:33:19 +00:00
|
|
|
}
|
2007-03-19 16:21:47 +00:00
|
|
|
}
|
|
|
|
|
|
2007-03-20 14:50:39 +00:00
|
|
|
if (check_tmp_path(var_directory) != 0) {
|
|
|
|
|
if (var_directory != "/usr/var") {
|
|
|
|
|
// Binreloc enabled builds installed system wide have localstatedir
|
|
|
|
|
// set to something that is never writable, so must always fall
|
|
|
|
|
// back to /var/tmp, so we should not display the message.
|
|
|
|
|
log(WARNING,
|
|
|
|
|
String::compose("No temporary directory found at \"%1/tmp\"",
|
2007-07-29 Al Riddoch <alriddoch@zepler.org>
* common/log.cpp, common/log.h: Switch to taking a C++ string reference
rather than a char *, as it is not really an optimisation, and it
makes the code simpler to read and write.
* client/BaseClient.cpp, client/ClientConnection.cpp,
common/AtlasFileLoader.cpp, common/BaseEntity.cpp,
common/Database.cpp, common/globals.cpp, common/id.cpp,
common/inheritance.cpp, common/log.cpp, common/log.h,
rulesets/Character.cpp, rulesets/Creator.cpp, rulesets/Entity.cpp,
rulesets/MemMap.cpp, rulesets/Motion.cpp, rulesets/Pedestrian.cpp,
rulesets/Py_Object.cpp, rulesets/Py_RootEntity.cpp,
rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp,
rulesets/Python_API.cpp, rulesets/Thing.cpp, server/Account.cpp,
server/Admin.cpp, server/ArithmeticFactory.cpp,
server/CommClient.cpp, server/CommListener.cpp,
server/CommMDNSPublisher.cpp, server/CommServer.cpp,
server/Connection.cpp, server/EntityFactory.cpp,
server/Persistance.cpp, server/Restoration.cpp,
server/ScriptFactory.cpp, server/TaskFactory.cpp,
server/WorldRouter.cpp, server/server.cpp: Convert over to using
new API correctly.
* data/mason.xml: Add biomass and transient to fircone, making its
script obsolete:
2007-07-29 03:33:33 +00:00
|
|
|
var_directory));
|
2007-03-20 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
if (check_tmp_path(FALLBACK_LOCALSTATEDIR) != 0) {
|
2007-07-29 Al Riddoch <alriddoch@zepler.org>
* common/log.cpp, common/log.h: Switch to taking a C++ string reference
rather than a char *, as it is not really an optimisation, and it
makes the code simpler to read and write.
* client/BaseClient.cpp, client/ClientConnection.cpp,
common/AtlasFileLoader.cpp, common/BaseEntity.cpp,
common/Database.cpp, common/globals.cpp, common/id.cpp,
common/inheritance.cpp, common/log.cpp, common/log.h,
rulesets/Character.cpp, rulesets/Creator.cpp, rulesets/Entity.cpp,
rulesets/MemMap.cpp, rulesets/Motion.cpp, rulesets/Pedestrian.cpp,
rulesets/Py_Object.cpp, rulesets/Py_RootEntity.cpp,
rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp,
rulesets/Python_API.cpp, rulesets/Thing.cpp, server/Account.cpp,
server/Admin.cpp, server/ArithmeticFactory.cpp,
server/CommClient.cpp, server/CommListener.cpp,
server/CommMDNSPublisher.cpp, server/CommServer.cpp,
server/Connection.cpp, server/EntityFactory.cpp,
server/Persistance.cpp, server/Restoration.cpp,
server/ScriptFactory.cpp, server/TaskFactory.cpp,
server/WorldRouter.cpp, server/server.cpp: Convert over to using
new API correctly.
* data/mason.xml: Add biomass and transient to fircone, making its
script obsolete:
2007-07-29 03:33:33 +00:00
|
|
|
log(CRITICAL, String::compose("No temporary directory available "
|
|
|
|
|
"at \"%1/tmp\" or \"%2/tmp\".",
|
|
|
|
|
var_directory,
|
|
|
|
|
FALLBACK_LOCALSTATEDIR));
|
2007-03-20 14:50:39 +00:00
|
|
|
} else {
|
|
|
|
|
if (var_directory != "/usr/var") {
|
|
|
|
|
log(NOTICE,
|
|
|
|
|
String::compose("Using \"%1/tmp\" as temporary directory",
|
2007-07-29 Al Riddoch <alriddoch@zepler.org>
* common/log.cpp, common/log.h: Switch to taking a C++ string reference
rather than a char *, as it is not really an optimisation, and it
makes the code simpler to read and write.
* client/BaseClient.cpp, client/ClientConnection.cpp,
common/AtlasFileLoader.cpp, common/BaseEntity.cpp,
common/Database.cpp, common/globals.cpp, common/id.cpp,
common/inheritance.cpp, common/log.cpp, common/log.h,
rulesets/Character.cpp, rulesets/Creator.cpp, rulesets/Entity.cpp,
rulesets/MemMap.cpp, rulesets/Motion.cpp, rulesets/Pedestrian.cpp,
rulesets/Py_Object.cpp, rulesets/Py_RootEntity.cpp,
rulesets/PythonMindScript.cpp, rulesets/PythonThingScript.cpp,
rulesets/Python_API.cpp, rulesets/Thing.cpp, server/Account.cpp,
server/Admin.cpp, server/ArithmeticFactory.cpp,
server/CommClient.cpp, server/CommListener.cpp,
server/CommMDNSPublisher.cpp, server/CommServer.cpp,
server/Connection.cpp, server/EntityFactory.cpp,
server/Persistance.cpp, server/Restoration.cpp,
server/ScriptFactory.cpp, server/TaskFactory.cpp,
server/WorldRouter.cpp, server/server.cpp: Convert over to using
new API correctly.
* data/mason.xml: Add biomass and transient to fircone, making its
script obsolete:
2007-07-29 03:33:33 +00:00
|
|
|
FALLBACK_LOCALSTATEDIR));
|
2007-03-20 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
var_directory = FALLBACK_LOCALSTATEDIR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-13 Al Riddoch <alriddoch@zepler.org>
* client/client.cpp, server/server.cpp, common/globals.cpp,
common/globals.h, tools/cycmd.cpp, tools/cydbload.cpp,
tools/cypasswd.cpp: Move code for handling loading of config
from the command line, user config and global config, into
globals.cpp, and make use of it in all tools.
* tools/cycmd.cpp: Fix objtype on server set commands.
* common/Database.cpp, common/Database.h: Implemented new database
interface to PostgreSQL to replace inadequate db3 code.
* common/database.cpp, common/database.h: Old code removed from the
build.
* common/accountbase.h, server/Admin.cpp, server/Persistance.cpp,
server/server.cpp, tools/cydbload.cpp: Fixed for minor changes
in the low level database API.
* common/globals.h, common/globals.cpp, rulesets/EntityFactory.cpp,
server/Admin.cpp, server/CommServer.cpp,
Remove varconf header from globals.h, and put in .cpp files
where it belongs.
2002-01-13 17:24:53 +00:00
|
|
|
}
|
2007-04-28 15:21:17 +00:00
|
|
|
|
|
|
|
|
void reportVersion(const char * prgname)
|
|
|
|
|
{
|
|
|
|
|
std::cout << prgname << " (cyphesis) " << consts::version
|
|
|
|
|
<< " (WorldForge)" << std::endl << std::flush;
|
|
|
|
|
}
|
2007-04-28 16:45:13 +00:00
|
|
|
|
2007-11-14 22:40:17 +00:00
|
|
|
void showUsage(const char * prgname, int usage_flags, const char * extras)
|
2007-04-28 16:45:13 +00:00
|
|
|
{
|
2013-11-13 21:51:52 +01:00
|
|
|
//Create a lookup table of the commands and flags in "usage"
|
|
|
|
|
std::map<std::string, int> default_commands_flags;
|
|
|
|
|
|
|
|
|
|
const usage_data * ud = &usage[0];
|
|
|
|
|
for (; ud->section != 0; ++ud) {
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << ud->section << ":" << ud->option;
|
|
|
|
|
default_commands_flags[ss.str()] = ud->flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Check if the section and option is allowed given the usage_flag
|
|
|
|
|
auto isAllowed = [&](const std::string& section, const std::string& option) {
|
|
|
|
|
auto I = default_commands_flags.find(section + ":" + option);
|
|
|
|
|
if (I == default_commands_flags.end()) {
|
|
|
|
|
//If it can't be found in "usage" it's defined for the specific command and is allowed
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return ((I->second & usage_flags) != 0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-04-29 13:32:27 +00:00
|
|
|
std::cout << "Usage: " << prgname << " [options]";
|
|
|
|
|
if (extras != 0) {
|
|
|
|
|
std::cout << " " << extras;
|
|
|
|
|
}
|
|
|
|
|
std::cout << std::endl;
|
2007-04-28 16:45:13 +00:00
|
|
|
std::cout << "Options:" << std::endl;
|
|
|
|
|
|
|
|
|
|
size_t column_width = 0;
|
|
|
|
|
|
2009-04-08 00:16:35 +01:00
|
|
|
Options * options = Options::instance();
|
|
|
|
|
|
|
|
|
|
SectionMap::const_iterator I = options->sectionMap().begin();
|
|
|
|
|
SectionMap::const_iterator Iend = options->sectionMap().end();
|
|
|
|
|
OptionMap::const_iterator J;
|
|
|
|
|
OptionMap::const_iterator Jend;
|
|
|
|
|
for (; I != Iend; ++I) {
|
|
|
|
|
J = I->second.begin();
|
|
|
|
|
Jend = I->second.end();
|
|
|
|
|
for (; J != Jend; ++J) {
|
2013-11-13 21:51:52 +01:00
|
|
|
if (isAllowed(I->first, J->first)) {
|
|
|
|
|
column_width = std::max(column_width, I->first.size() + J->first.size() + J->second->value().size() + 2);
|
|
|
|
|
}
|
2009-04-08 00:16:35 +01:00
|
|
|
}
|
2007-04-28 16:45:13 +00:00
|
|
|
}
|
|
|
|
|
|
2007-12-13 00:21:48 +00:00
|
|
|
std::cout << " --help, -h Display usage information and exit"
|
2007-05-02 00:14:38 +00:00
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
|
|
std::cout << " --version, -v Display the version information and exit"
|
|
|
|
|
<< std::endl << std::endl;
|
|
|
|
|
|
2009-04-08 00:16:35 +01:00
|
|
|
I = options->sectionMap().begin();
|
|
|
|
|
for (; I != Iend; ++I) {
|
|
|
|
|
J = I->second.begin();
|
|
|
|
|
Jend = I->second.end();
|
|
|
|
|
for (; J != Jend; ++J) {
|
2013-11-13 21:51:52 +01:00
|
|
|
if (isAllowed(I->first, J->first)) {
|
|
|
|
|
if (I->first.size() != 0) {
|
|
|
|
|
std::cout << " --" << I->first << ":" << J->first;
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << " --" << J->first;
|
|
|
|
|
}
|
2014-01-20 23:07:22 +01:00
|
|
|
const Option * opt = J->second.get();
|
2009-04-08 00:16:35 +01:00
|
|
|
if (opt->value().size() != 0) {
|
2013-11-13 21:51:52 +01:00
|
|
|
std::cout << "=" << opt->value();
|
|
|
|
|
}
|
|
|
|
|
if (opt->size() != 0) {
|
|
|
|
|
size_t len = I->first.size() + 1 + J->first.size();
|
|
|
|
|
if (opt->value().size() != 0) {
|
|
|
|
|
len += (opt->value().size() + 1);
|
|
|
|
|
}
|
|
|
|
|
std::cout << std::string(column_width - len + 2, ' ')
|
|
|
|
|
<< "= " << opt->repr();
|
2009-04-08 00:16:35 +01:00
|
|
|
}
|
2013-11-13 21:51:52 +01:00
|
|
|
std::cout << std::endl;
|
|
|
|
|
std::cout << " " << opt->description() << std::endl;
|
2007-04-28 20:13:08 +00:00
|
|
|
}
|
2007-04-28 16:45:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
std::cout << std::flush;
|
|
|
|
|
}
|