2010-07-31 01:20:53 +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
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/ExternalMind.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
#include "server/Connection.h"
|
|
|
|
|
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/simulation/Entity.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/BaseWorld.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
class TestExternalMind : public ExternalMind
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-07-04 15:37:51 +02:00
|
|
|
TestExternalMind(Ref<Entity> & e) : ExternalMind(0, e) { }
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
void test_deleteEntity(const std::string & id) {
|
2014-01-23 21:17:13 +01:00
|
|
|
deleteEntity(id, false);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void test_purgeEntity(const LocatedEntity & ent) {
|
|
|
|
|
purgeEntity(ent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int stub_baseworld_receieved_op = -1;
|
2012-08-02 15:29:49 +01:00
|
|
|
int stub_link_send_op = -1;
|
|
|
|
|
int stub_link_send_count = 0;
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../TestWorld.h"
|
2018-07-24 21:18:50 +02:00
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2018-07-24 21:18:50 +02:00
|
|
|
TestWorld::extension.messageFn = [](const Operation & op, LocatedEntity & ent){stub_baseworld_receieved_op = op->getClassNo();};
|
|
|
|
|
TestWorld world{};
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
ExternalMind em(3, e);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
|
|
|
|
em.test_deleteEntity("3");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Purge with empty contains
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2019-11-19 19:52:00 +01:00
|
|
|
e->m_contains.reset(new LocatedEntitySet);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2019-11-19 19:52:00 +01:00
|
|
|
em.test_purgeEntity(*e);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Purge with populated contains
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2019-11-19 19:52:00 +01:00
|
|
|
e->m_contains.reset(new LocatedEntitySet);
|
2022-07-04 15:37:51 +02:00
|
|
|
e->m_contains->insert(new Entity(3));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2019-11-19 19:52:00 +01:00
|
|
|
em.test_purgeEntity(*e);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to nothing
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
ExternalMind em(3, e);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(0);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to something
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
ExternalMind em(3, e);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2021-05-18 22:09:57 +02:00
|
|
|
Connection conn(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
2022-07-04 15:37:51 +02:00
|
|
|
"addr", 4);
|
2021-05-18 22:09:57 +02:00
|
|
|
em.linkUp(&conn);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to something, then disconnect
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
ExternalMind em(3, e);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2021-05-18 22:09:57 +02:00
|
|
|
Connection conn(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
2022-07-04 15:37:51 +02:00
|
|
|
"addr", 4);
|
2021-05-18 22:09:57 +02:00
|
|
|
em.linkUp(&conn);
|
2012-08-13 22:08:22 +01:00
|
|
|
em.linkUp(0);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connect to something, then check connection ID
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
ExternalMind em(3, e);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2021-05-18 22:09:57 +02:00
|
|
|
Connection conn(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
2022-07-04 15:37:51 +02:00
|
|
|
"addr", 4);
|
2021-05-18 22:09:57 +02:00
|
|
|
em.linkUp(&conn);
|
2010-07-31 01:20:53 +01:00
|
|
|
const std::string & id = em.connectionId();
|
|
|
|
|
assert(id == "4");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a random operation
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
|
|
|
|
stub_baseworld_receieved_op = -1;
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::RootOperation(), res);
|
|
|
|
|
assert(stub_baseworld_receieved_op == -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a Delete operation
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
|
|
|
|
stub_baseworld_receieved_op = -1;
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::Delete(), res);
|
|
|
|
|
assert(stub_baseworld_receieved_op == -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a Delete operation to an ephemeral entity
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2019-11-19 19:52:00 +01:00
|
|
|
e->addFlags(entity_ephem);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
|
|
|
|
stub_baseworld_receieved_op = -1;
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::Delete(), res);
|
|
|
|
|
assert(stub_baseworld_receieved_op == -1);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-13 12:20:50 +01:00
|
|
|
// Send a random operation to a connected mind, and make sure it's filtered out. Only Info ops are allowed.
|
2010-07-31 01:20:53 +01:00
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2021-05-18 22:09:57 +02:00
|
|
|
Connection conn(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
2022-07-04 15:37:51 +02:00
|
|
|
"addr", 4);
|
2021-05-18 22:09:57 +02:00
|
|
|
em.linkUp(&conn);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_link_send_op = -1;
|
|
|
|
|
stub_link_send_count = 0;
|
2010-07-31 01:20:53 +01:00
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::RootOperation(), res);
|
2019-12-13 12:20:50 +01:00
|
|
|
assert(stub_link_send_op == -1);
|
|
|
|
|
assert(stub_link_send_count == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send an Info operation and an to a connected mind, and make sure sent filtered out. Only Info ops are allowed.
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2019-12-13 12:20:50 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2021-05-18 22:09:57 +02:00
|
|
|
Connection conn(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
2022-07-04 15:37:51 +02:00
|
|
|
"addr", 4);
|
2021-05-18 22:09:57 +02:00
|
|
|
em.linkUp(&conn);
|
2019-12-13 12:20:50 +01:00
|
|
|
|
|
|
|
|
stub_link_send_op = -1;
|
|
|
|
|
stub_link_send_count = 0;
|
|
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::Info(), res);
|
|
|
|
|
assert(stub_link_send_op == Atlas::Objects::Operation::INFO_NO);
|
|
|
|
|
em.operation(Atlas::Objects::Operation::Sight(), res);
|
|
|
|
|
assert(stub_link_send_op == Atlas::Objects::Operation::SIGHT_NO);
|
|
|
|
|
assert(stub_link_send_count == 2);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send a Sight operation to a connected mind
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(2));
|
2010-07-31 01:20:53 +01:00
|
|
|
|
|
|
|
|
TestExternalMind em(e);
|
|
|
|
|
|
2021-05-18 22:09:57 +02:00
|
|
|
Connection conn(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
2022-07-04 15:37:51 +02:00
|
|
|
"addr", 4);
|
2021-05-18 22:09:57 +02:00
|
|
|
em.linkUp(&conn);
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_link_send_op = -1;
|
|
|
|
|
stub_link_send_count = 0;
|
2010-07-31 01:20:53 +01:00
|
|
|
OpVector res;
|
|
|
|
|
em.operation(Atlas::Objects::Operation::Sight(), res);
|
2012-08-02 15:29:49 +01:00
|
|
|
assert(stub_link_send_op == Atlas::Objects::Operation::SIGHT_NO);
|
|
|
|
|
assert(stub_link_send_count == 1);
|
2010-07-31 01:20:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/Script.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2012-11-13 23:33:23 +00:00
|
|
|
#include "common/log.h"
|
|
|
|
|
|
2010-07-31 01:20:53 +01:00
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/server/stubConnection.h"
|
|
|
|
|
#include "../stubs/common/stubInheritance.h"
|
|
|
|
|
#include "../stubs/common/stubcustom.h"
|
|
|
|
|
#include "../stubs/common/stubTypeNode.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
#define STUB_Entity_destroy
|
2010-07-31 01:20:53 +01:00
|
|
|
void Entity::destroy()
|
|
|
|
|
{
|
|
|
|
|
destroyed.emit();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
#define STUB_Entity_sendWorld
|
2019-12-13 17:32:28 +01:00
|
|
|
void Entity::sendWorld(Operation op)
|
2013-01-17 10:17:07 +00:00
|
|
|
{
|
|
|
|
|
BaseWorld::instance().message(op, *this);
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/simulation/stubEntity.h"
|
2017-07-01 19:36:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/stubLocatedEntity.h"
|
|
|
|
|
#include "../stubs/rules/stubScript.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/stubLocation.h"
|
2010-07-31 01:20:53 +01:00
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
#define STUB_Link_send
|
2012-08-01 21:13:14 +01:00
|
|
|
void Link::send(const Operation & op) const
|
|
|
|
|
{
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_link_send_op = op->getClassNo();
|
|
|
|
|
++stub_link_send_count;
|
2012-08-01 21:13:14 +01:00
|
|
|
}
|
|
|
|
|
|
2018-02-26 12:05:10 +01:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubLink.h"
|
|
|
|
|
#include "../stubs/common/stubRouter.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubBaseWorld.h"
|
|
|
|
|
#include "../stubs/common/stublog.h"
|
2014-02-03 12:19:42 +01:00
|
|
|
|