2010-07-29 16:14:24 +01:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2010 Alistair Riddoch
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-07-29 16:14:24 +01:00
|
|
|
#include "server/StorageManager.h"
|
2020-06-23 00:12:33 +02:00
|
|
|
#include "server/Persistence.h"
|
2010-07-29 16:14:24 +01:00
|
|
|
|
2020-04-13 11:17:52 +02:00
|
|
|
#include "rules/simulation/WorldRouter.h"
|
2010-07-29 17:08:56 +01:00
|
|
|
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/simulation/Entity.h"
|
2020-03-25 23:50:00 +01:00
|
|
|
#include "server/MindProperty.h"
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2020-07-15 00:10:14 +02:00
|
|
|
#include "common/Property_impl.h"
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../DatabaseNull.h"
|
2021-06-20 15:40:33 +02:00
|
|
|
#include "../TestPropertyManager.h"
|
2011-10-31 12:47:56 +01:00
|
|
|
|
2010-07-29 16:14:24 +01:00
|
|
|
#include <cassert>
|
2018-08-04 01:12:45 +02:00
|
|
|
#include <server/EntityBuilder.h>
|
|
|
|
|
|
2013-08-22 14:20:33 +02:00
|
|
|
using Atlas::Message::Element;
|
2010-07-29 16:14:24 +01:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
struct TestStorageManager : public StorageManager
|
2010-07-29 22:30:27 +01:00
|
|
|
{
|
2021-06-20 15:40:33 +02:00
|
|
|
TestStorageManager(WorldRouter& w, Database& db, EntityBuilder& eb, PropertyManager& propertyManager) : StorageManager(w, db, eb, propertyManager)
|
2021-05-27 17:38:58 +02:00
|
|
|
{}
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
|
|
|
|
|
void test_entityInserted(LocatedEntity& e)
|
|
|
|
|
{
|
2010-07-29 22:30:27 +01:00
|
|
|
entityInserted(e);
|
|
|
|
|
}
|
2021-05-27 17:38:58 +02:00
|
|
|
|
|
|
|
|
void test_entityUpdated(LocatedEntity& e)
|
|
|
|
|
{
|
2010-07-29 22:30:27 +01:00
|
|
|
entityUpdated(e);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
void test_encodeProperty(PropertyBase& p, std::string& s)
|
|
|
|
|
{
|
2010-07-29 22:30:27 +01:00
|
|
|
encodeProperty(p, s);
|
|
|
|
|
}
|
2021-05-27 17:38:58 +02:00
|
|
|
|
|
|
|
|
void test_restoreProperties(LocatedEntity& e)
|
|
|
|
|
{
|
2014-09-06 20:44:53 +02:00
|
|
|
restorePropertiesRecursively(e);
|
2010-07-29 22:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
void test_insertEntity(LocatedEntity& e)
|
|
|
|
|
{
|
2010-07-29 22:30:27 +01:00
|
|
|
insertEntity(e);
|
|
|
|
|
}
|
2021-05-27 17:38:58 +02:00
|
|
|
|
|
|
|
|
void test_updateEntity(LocatedEntity& e)
|
|
|
|
|
{
|
2010-07-29 22:30:27 +01:00
|
|
|
updateEntity(e);
|
|
|
|
|
}
|
2021-05-27 17:38:58 +02:00
|
|
|
|
|
|
|
|
void test_restoreChildren(LocatedEntity& e)
|
|
|
|
|
{
|
2010-07-29 22:30:27 +01:00
|
|
|
restoreChildren(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-29 16:14:24 +01:00
|
|
|
int main()
|
|
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
EntityBuilder eb;
|
2018-05-19 21:47:24 +02:00
|
|
|
DatabaseNull database;
|
|
|
|
|
Persistence persistence(database);
|
2021-06-20 15:40:33 +02:00
|
|
|
TestPropertyManager propertyManager;
|
2018-05-19 21:47:24 +02:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<LocatedEntity> le(new Entity(0));
|
2018-07-24 21:18:50 +02:00
|
|
|
|
2010-07-29 17:08:56 +01:00
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 17:08:56 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
StorageManager store(world, database, eb, propertyManager);
|
2010-07-29 17:08:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 17:08:56 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
StorageManager store(world, database, eb, propertyManager);
|
2010-07-29 22:19:14 +01:00
|
|
|
|
2018-07-24 21:18:50 +02:00
|
|
|
store.initWorld(le);
|
2010-07-29 22:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:19:14 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
StorageManager store(world, database, eb, propertyManager);
|
2010-07-29 22:19:14 +01:00
|
|
|
|
2018-07-24 21:18:50 +02:00
|
|
|
store.restoreWorld(le);
|
2010-07-29 22:19:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:19:14 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
StorageManager store(world, database, eb, propertyManager);
|
2010-07-29 22:19:14 +01:00
|
|
|
|
|
|
|
|
store.tick();
|
2010-07-29 17:08:56 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-29 22:30:27 +01:00
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
TestStorageManager store(world, database, eb, propertyManager);
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e1(new Entity(1));
|
2021-05-27 17:38:58 +02:00
|
|
|
store.test_entityInserted(*e1);
|
2010-07-29 22:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
TestStorageManager store(world, database, eb, propertyManager);
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e1(new Entity(1));
|
2021-05-27 17:38:58 +02:00
|
|
|
store.test_entityUpdated(*e1);
|
2010-07-29 22:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
TestStorageManager store(world, database, eb, propertyManager);
|
2010-07-29 22:30:27 +01:00
|
|
|
|
|
|
|
|
std::string val;
|
|
|
|
|
|
|
|
|
|
// store.test_encodeProperty(0, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
TestStorageManager store(world, database, eb, propertyManager);
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e1(new Entity(1));
|
2021-05-27 17:38:58 +02:00
|
|
|
store.test_restoreProperties(*e1);
|
2010-07-29 22:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
TestStorageManager store(world, database, eb, propertyManager);
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e1(new Entity(1));
|
2021-05-27 17:38:58 +02:00
|
|
|
store.test_insertEntity(*e1);
|
2010-07-29 22:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
TestStorageManager store(world, database, eb, propertyManager);
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e1(new Entity(1));
|
2021-05-27 17:38:58 +02:00
|
|
|
store.test_updateEntity(*e1);
|
2010-07-29 22:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2020-08-01 00:10:01 +02:00
|
|
|
WorldRouter world(le, eb, {});
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2021-06-20 15:40:33 +02:00
|
|
|
TestStorageManager store(world, database, eb, propertyManager);
|
2010-07-29 22:30:27 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e1(new Entity(1));
|
2021-05-27 17:38:58 +02:00
|
|
|
store.test_restoreChildren(*e1);
|
2010-07-29 22:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-07-29 16:14:24 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
2020-03-22 23:36:52 +01:00
|
|
|
#include "rules/simulation/CorePropertyManager.h"
|
2010-07-29 16:14:24 +01:00
|
|
|
#include "server/EntityBuilder.h"
|
|
|
|
|
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/Script.h"
|
2010-07-29 16:14:24 +01:00
|
|
|
|
2018-07-22 23:51:33 +02:00
|
|
|
#include "modules/WeakEntityRef.h"
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/Location.h"
|
2010-07-29 16:14:24 +01:00
|
|
|
|
2010-07-29 17:20:06 +01:00
|
|
|
#include "common/const.h"
|
2010-07-29 16:14:24 +01:00
|
|
|
#include "common/Database.h"
|
|
|
|
|
#include "common/globals.h"
|
|
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/Monitors.h"
|
|
|
|
|
#include "common/PropertyManager.h"
|
|
|
|
|
#include "common/Variable.h"
|
|
|
|
|
|
2020-04-13 11:17:52 +02:00
|
|
|
#include "../stubs/rules/simulation/stubWorldRouter.h"
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/stubLocation.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubEntity.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubThing.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubBaseWorld.h"
|
2014-08-27 22:17:09 +02:00
|
|
|
|
2010-07-29 17:08:56 +01:00
|
|
|
#include <Atlas/Objects/RootOperation.h>
|
|
|
|
|
#include <Atlas/Objects/SmartPtr.h>
|
|
|
|
|
|
2010-07-29 16:14:24 +01:00
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
using Atlas::Objects::Entity::RootEntity;
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/server/stubEntityBuilder.h"
|
|
|
|
|
#include "../stubs/rules/stubLocatedEntity.h"
|
|
|
|
|
#include "../stubs/common/stubRouter.h"
|
2018-05-19 21:47:24 +02:00
|
|
|
|
|
|
|
|
#define STUB_Database_selectEntities
|
2021-05-27 17:38:58 +02:00
|
|
|
|
|
|
|
|
DatabaseResult Database::selectEntities(const std::string& loc)
|
2018-05-19 21:47:24 +02:00
|
|
|
{
|
2021-05-27 17:38:58 +02:00
|
|
|
return DatabaseResult(std::make_unique<DatabaseNullResultWorker>());
|
2018-05-19 21:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define STUB_Database_selectProperties
|
2021-05-27 17:38:58 +02:00
|
|
|
|
2018-05-19 21:47:24 +02:00
|
|
|
DatabaseResult Database::selectProperties(const std::string& loc)
|
|
|
|
|
{
|
2021-05-27 17:38:58 +02:00
|
|
|
return DatabaseResult(std::make_unique<DatabaseNullResultWorker>());
|
2018-05-19 21:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define STUB_Database_selectThoughts
|
2021-05-27 17:38:58 +02:00
|
|
|
|
2018-05-19 21:47:24 +02:00
|
|
|
DatabaseResult Database::selectThoughts(const std::string& loc)
|
|
|
|
|
{
|
2021-05-27 17:38:58 +02:00
|
|
|
return DatabaseResult(std::make_unique<DatabaseNullResultWorker>());
|
2018-05-19 21:47:24 +02:00
|
|
|
}
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubDatabase.h"
|
|
|
|
|
#include "../stubs/server/stubPersistence.h"
|
2010-07-29 17:20:06 +01:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubPropertyManager.h"
|
2013-02-22 09:57:10 +00:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/stubScript.h"
|
|
|
|
|
#include "../stubs/modules/stubWeakEntityRef.h"
|
2010-07-29 17:20:06 +01:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
template<typename T>
|
|
|
|
|
Variable<T>::Variable(const T& variable) : m_variable(variable)
|
2010-07-29 16:14:24 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
template<typename T>
|
2010-07-29 16:14:24 +01:00
|
|
|
Variable<T>::~Variable()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
template<typename T>
|
|
|
|
|
void Variable<T>::send(std::ostream& o)
|
2010-07-29 16:14:24 +01:00
|
|
|
{
|
|
|
|
|
o << m_variable;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
template<typename T>
|
2015-04-09 14:50:45 +02:00
|
|
|
bool Variable<T>::isNumeric() const
|
2010-07-29 16:14:24 +01:00
|
|
|
{
|
2015-04-09 14:50:45 +02:00
|
|
|
return false;
|
2010-07-29 16:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
template
|
|
|
|
|
class Variable<int>;
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
class Variable<const char*>;
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
class Variable<std::string>;
|
2010-07-29 16:14:24 +01:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubMonitors.h"
|
|
|
|
|
#include "../stubs/common/stubOperationsDispatcher.h"
|
2021-05-27 17:38:58 +02:00
|
|
|
long forceIntegerId(const std::string& id)
|
2010-07-29 16:14:24 +01:00
|
|
|
{
|
|
|
|
|
long intId = strtol(id.c_str(), 0, 10);
|
|
|
|
|
if (intId == 0 && id != "0") {
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return intId;
|
|
|
|
|
}
|
2021-05-27 17:38:58 +02:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stublog.h"
|
2010-07-29 16:14:24 +01:00
|
|
|
|
2010-07-29 17:08:56 +01:00
|
|
|
bool database_flag = true;
|
2010-07-29 17:20:06 +01:00
|
|
|
|
|
|
|
|
namespace consts {
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
// Id of root world entity
|
|
|
|
|
const char* rootWorldId = "0";
|
|
|
|
|
// Integer id of root world entity
|
|
|
|
|
const long rootWorldIntId = 0L;
|
2010-07-29 17:20:06 +01:00
|
|
|
|
|
|
|
|
}
|
2013-04-20 18:27:53 +02:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubcustom.h"
|
2021-06-20 15:40:33 +02:00
|
|
|
#include "../stubs/common/stubProperty.h"
|