2010-03-16 01:03:50 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
2010-03-18 01:51:46 +00:00
|
|
|
// Copyright (C) 2010 Alistair Riddoch
|
2010-03-16 01:03:50 +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
|
|
|
|
|
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-03-16 01:03:50 +00:00
|
|
|
#include "server/Peer.h"
|
|
|
|
|
|
2018-09-25 23:30:03 +02:00
|
|
|
#include "common/CommAsioClient_impl.h"
|
2010-11-25 17:39:38 +00:00
|
|
|
#include "server/CommPeer.h"
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/ExternalMind.h"
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/simulation/Entity.h"
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/BaseWorld.h"
|
2014-02-03 12:19:42 +01:00
|
|
|
#include "common/CommSocket.h"
|
2010-08-20 17:47:37 +05:30
|
|
|
|
2010-12-03 21:46:22 +00:00
|
|
|
#include <Atlas/Objects/Operation.h>
|
2010-03-16 01:03:50 +00:00
|
|
|
#include <Atlas/Objects/SmartPtr.h>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
2010-08-20 17:47:37 +05:30
|
|
|
#include <string>
|
2018-11-03 16:43:33 +01:00
|
|
|
#include <rules/simulation/MindsProperty.h>
|
2010-08-20 17:47:37 +05:30
|
|
|
|
2014-02-03 12:19:42 +01:00
|
|
|
class TestCommSocket : public CommSocket
|
|
|
|
|
{
|
2012-08-01 20:31:29 +01:00
|
|
|
public:
|
2019-06-24 21:12:55 +02:00
|
|
|
TestCommSocket() : CommSocket(*(boost::asio::io_context*)0)
|
2014-02-03 12:19:42 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void disconnect()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual int flush()
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 20:31:29 +01:00
|
|
|
};
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../TestWorld.h"
|
2018-07-24 21:18:50 +02:00
|
|
|
class MyTestWorld : public TestWorld {
|
2010-11-25 12:16:46 +00:00
|
|
|
public:
|
2018-07-24 21:18:50 +02:00
|
|
|
explicit MyTestWorld() : TestWorld() {
|
2010-11-25 12:16:46 +00:00
|
|
|
}
|
2010-08-20 17:47:37 +05:30
|
|
|
|
|
|
|
|
|
2018-07-24 21:18:50 +02:00
|
|
|
LocatedEntity * test_addEntity(LocatedEntity * ent, long intId) {
|
2010-11-25 12:16:46 +00:00
|
|
|
m_eobjects[intId] = ent;
|
2018-08-05 14:31:04 +02:00
|
|
|
return ent;
|
2010-11-25 12:16:46 +00:00
|
|
|
}
|
2010-11-25 17:39:38 +00:00
|
|
|
void test_delEntity(long intId) {
|
|
|
|
|
m_eobjects.erase(intId);
|
|
|
|
|
}
|
2020-06-22 22:36:30 +02:00
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
|
2010-11-25 12:16:46 +00:00
|
|
|
};
|
2010-08-20 17:47:37 +05:30
|
|
|
|
2011-04-08 21:59:32 +02:00
|
|
|
class TestPeer : public Peer {
|
|
|
|
|
public:
|
2012-08-01 20:31:29 +01:00
|
|
|
TestPeer(CommSocket & client, ServerRouting & svr,
|
2022-07-04 15:37:51 +02:00
|
|
|
const std::string & addr, RouterId id)
|
|
|
|
|
: Peer(client, svr, addr, 6767, id)
|
2011-04-08 21:59:32 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const std::string& getAccountType() const {
|
|
|
|
|
return m_accountType;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-30 09:45:16 +00:00
|
|
|
Atlas::Objects::Operation::RootOperation stub_CommClient_sent_op(0);
|
|
|
|
|
|
2010-11-25 12:16:46 +00:00
|
|
|
int main()
|
|
|
|
|
{
|
2018-07-24 21:18:50 +02:00
|
|
|
MyTestWorld world;
|
2010-08-20 17:47:37 +05:30
|
|
|
|
2010-03-16 01:03:50 +00:00
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-03-16 01:03:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-03-16 01:03:50 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::RootOperation op;
|
|
|
|
|
OpVector res;
|
2021-05-27 17:38:58 +02:00
|
|
|
p.operation(op, res);
|
2010-03-16 01:03:50 +00:00
|
|
|
|
|
|
|
|
}
|
2010-08-10 19:21:24 +05:30
|
|
|
|
|
|
|
|
{
|
|
|
|
|
// Test the setting of authentiaction states
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-08-10 19:21:24 +05:30
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
assert(p.getAuthState() == PEER_INIT);
|
|
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
|
|
|
|
assert(p.getAuthState() == PEER_AUTHENTICATED);
|
2010-08-19 02:11:06 +05:30
|
|
|
|
2010-08-10 19:21:24 +05:30
|
|
|
}
|
|
|
|
|
|
2010-08-20 17:47:37 +05:30
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-08-20 17:47:37 +05:30
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
2021-05-27 17:38:58 +02:00
|
|
|
p.operation(op, res);
|
2010-08-20 17:47:37 +05:30
|
|
|
}
|
|
|
|
|
|
2010-11-25 16:11:07 +00:00
|
|
|
// Authenticating (no args)
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATING);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
2021-05-27 17:38:58 +02:00
|
|
|
p.operation(op, res);
|
2010-11-25 16:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Authenticating (empty arg)
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATING);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
op->setArgs1(arg);
|
|
|
|
|
OpVector res;
|
2021-05-27 17:38:58 +02:00
|
|
|
p.operation(op, res);
|
2010-11-25 16:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Authenticating (full arg)
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
TestPeer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 1);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATING);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
arg->setId("2");
|
2017-07-24 13:39:22 +02:00
|
|
|
arg->setParent("server");
|
2010-11-25 16:11:07 +00:00
|
|
|
op->setArgs1(arg);
|
|
|
|
|
OpVector res;
|
2021-05-27 17:38:58 +02:00
|
|
|
p.operation(op, res);
|
|
|
|
|
assert(p.getAccountType() == "server");
|
2010-11-25 16:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Authenticated (no args)
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
2021-05-27 17:38:58 +02:00
|
|
|
p.operation(op, res);
|
2010-11-25 16:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Error op;
|
|
|
|
|
OpVector res;
|
2021-05-27 17:38:58 +02:00
|
|
|
p.operation(op, res);
|
2010-11-25 16:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-25 16:48:51 +00:00
|
|
|
// Not authenticated
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 16:48:51 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(3));
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 16:48:51 +00:00
|
|
|
assert(ret == -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Authenticated
|
|
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 16:48:51 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 16:48:51 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(3));
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 16:48:51 +00:00
|
|
|
assert(ret == 0);
|
2010-11-30 09:45:16 +00:00
|
|
|
assert(stub_CommClient_sent_op.isValid());
|
|
|
|
|
assert(stub_CommClient_sent_op->getArgs().size() == 1);
|
2010-11-25 16:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-25 17:12:08 +00:00
|
|
|
// Re-teleport same entity
|
|
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(3));
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 17:12:08 +00:00
|
|
|
assert(ret == 0);
|
2010-11-30 09:45:16 +00:00
|
|
|
assert(stub_CommClient_sent_op.isValid());
|
|
|
|
|
assert(stub_CommClient_sent_op->getArgs().size() == 1);
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
ret = p.teleportEntity(e.get());
|
2010-11-25 17:12:08 +00:00
|
|
|
assert(ret != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
// Entity (no mind)
|
2010-11-25 17:12:08 +00:00
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(3));
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 17:12:08 +00:00
|
|
|
assert(ret == 0);
|
2010-11-30 09:45:16 +00:00
|
|
|
assert(stub_CommClient_sent_op.isValid());
|
|
|
|
|
assert(stub_CommClient_sent_op->getArgs().size() == 1);
|
2010-11-25 17:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
// Entity (external mind, unconnected)
|
2010-11-25 17:12:08 +00:00
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(3));
|
|
|
|
|
ExternalMind mind(1, e);
|
2018-10-27 13:13:45 +02:00
|
|
|
auto mindsProp = e->modPropertyClassFixed<MindsProperty>();
|
2021-05-27 17:38:58 +02:00
|
|
|
mindsProp->addMind(&mind);
|
|
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 17:12:08 +00:00
|
|
|
assert(ret == 0);
|
2010-11-30 09:45:16 +00:00
|
|
|
assert(stub_CommClient_sent_op.isValid());
|
|
|
|
|
assert(stub_CommClient_sent_op->getArgs().size() == 1);
|
2010-11-25 17:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
// Entity (external mind, connected)
|
2010-11-25 17:12:08 +00:00
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:12:08 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2018-10-27 13:13:45 +02:00
|
|
|
|
|
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(3));
|
|
|
|
|
ExternalMind mind(1, e);
|
2021-05-27 17:38:58 +02:00
|
|
|
mind.linkUp((Link*)23);
|
2018-10-27 13:13:45 +02:00
|
|
|
auto mindsProp = e->modPropertyClassFixed<MindsProperty>();
|
2021-05-27 17:38:58 +02:00
|
|
|
mindsProp->addMind(&mind);
|
2018-10-27 13:13:45 +02:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 17:12:08 +00:00
|
|
|
assert(ret == 0);
|
2010-11-30 09:45:16 +00:00
|
|
|
assert(stub_CommClient_sent_op.isValid());
|
2018-10-27 13:13:45 +02:00
|
|
|
assert(stub_CommClient_sent_op->getArgs().size() == 1);
|
2010-11-25 17:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-25 17:39:38 +00:00
|
|
|
// No arg
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.peerTeleportResponse(op, res);
|
2010-11-25 17:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty arg, no refno
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
op->setArgs1(arg);
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.peerTeleportResponse(op, res);
|
2010-11-25 17:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty arg, made up refno, not CommPeer
|
|
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
op->setArgs1(arg);
|
|
|
|
|
op->setRefno(23);
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.peerTeleportResponse(op, res);
|
2010-11-25 17:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty arg, made up refno
|
|
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
op->setArgs1(arg);
|
|
|
|
|
op->setRefno(23);
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.peerTeleportResponse(op, res);
|
2010-11-25 17:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty arg, refno that matches earlier teleport, not in world
|
|
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(23));
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 17:39:38 +00:00
|
|
|
assert(ret == 0);
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
op->setArgs1(arg);
|
|
|
|
|
op->setRefno(23);
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.peerTeleportResponse(op, res);
|
2010-11-25 17:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty arg, refno that matches earlier teleport, in world
|
|
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(23));
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 17:39:38 +00:00
|
|
|
assert(ret == 0);
|
|
|
|
|
|
2018-08-05 20:47:09 +02:00
|
|
|
world.test_addEntity(e.get(), 23);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
op->setArgs1(arg);
|
|
|
|
|
op->setRefno(23);
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.peerTeleportResponse(op, res);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
|
|
|
|
world.test_delEntity(23);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Empty arg, refno that matches earlier teleport, with mind
|
|
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(23));
|
|
|
|
|
ExternalMind mind(1, e);
|
2021-05-27 17:38:58 +02:00
|
|
|
mind.linkUp((Link*)23);
|
2018-10-27 13:13:45 +02:00
|
|
|
auto mindsProp = e->modPropertyClassFixed<MindsProperty>();
|
2021-05-27 17:38:58 +02:00
|
|
|
mindsProp->addMind(&mind);
|
|
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 17:39:38 +00:00
|
|
|
assert(ret == 0);
|
|
|
|
|
|
2018-08-05 20:47:09 +02:00
|
|
|
world.test_addEntity(e.get(), 23);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
|
|
|
|
Atlas::Objects::Operation::Info op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Root arg;
|
|
|
|
|
op->setArgs1(arg);
|
|
|
|
|
op->setRefno(23);
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.peerTeleportResponse(op, res);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
|
|
|
|
world.test_delEntity(23);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// No teleports to clear
|
2010-11-25 16:11:07 +00:00
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(*(CommSocket*)0, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 16:11:07 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.cleanTeleports();
|
2010-11-25 16:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
2010-11-25 17:39:38 +00:00
|
|
|
// One teleport to clear
|
|
|
|
|
{
|
2014-02-03 12:19:42 +01:00
|
|
|
TestCommSocket client;
|
2022-07-04 15:37:51 +02:00
|
|
|
Peer p(client, *(ServerRouting*)0, "addr", 6767, 1);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.setAuthState(PEER_AUTHENTICATED);
|
2010-11-25 17:39:38 +00:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> e(new Entity(23));
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = p.teleportEntity(e.get());
|
2010-11-25 17:39:38 +00:00
|
|
|
assert(ret == 0);
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
p.cleanTeleports();
|
2010-11-25 17:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-16 01:03:50 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2010-11-25 12:16:46 +00:00
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
#include "server/TeleportState.h"
|
|
|
|
|
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/Script.h"
|
2010-11-25 12:16:46 +00:00
|
|
|
|
|
|
|
|
#include "common/id.h"
|
|
|
|
|
#include "common/log.h"
|
|
|
|
|
#include "common/TypeNode.h"
|
|
|
|
|
|
|
|
|
|
#include <Atlas/Negotiate.h>
|
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
|
2020-01-24 23:14:07 +01:00
|
|
|
TeleportState::TeleportState(std::chrono::steady_clock::time_point time) : m_state(TELEPORT_NONE),
|
2010-11-25 14:29:44 +00:00
|
|
|
m_teleportTime(time)
|
2010-11-25 12:16:46 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TeleportState::setRequested()
|
|
|
|
|
{
|
|
|
|
|
m_state = TELEPORT_REQUESTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TeleportState::setCreated()
|
|
|
|
|
{
|
|
|
|
|
m_state = TELEPORT_CREATED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TeleportState::setKey(const std::string & key)
|
|
|
|
|
{
|
|
|
|
|
m_possessKey = key;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-31 19:33:42 +00:00
|
|
|
|
2014-02-03 12:19:42 +01:00
|
|
|
CommPeer::CommPeer(const std::string & name,
|
2019-09-10 22:42:28 +02:00
|
|
|
boost::asio::io_context& io_context,
|
|
|
|
|
Atlas::Objects::Factories& factories) :
|
|
|
|
|
CommAsioClient<boost::asio::ip::tcp>(name, io_context, factories), m_auth_timer(io_context)
|
2010-11-25 17:39:38 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 12:16:46 +00:00
|
|
|
CommPeer::~CommPeer()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 20:31:29 +01:00
|
|
|
int CommSocket::flush()
|
2010-11-25 12:16:46 +00:00
|
|
|
{
|
2012-08-01 20:31:29 +01:00
|
|
|
return 0;
|
2010-11-25 12:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
#define STUB_ExternalMind_linkUp
|
2012-08-13 22:08:22 +01:00
|
|
|
void ExternalMind::linkUp(Link * c)
|
2010-11-25 17:12:08 +00:00
|
|
|
{
|
2018-02-08 21:46:49 +01:00
|
|
|
m_link = c;
|
2010-11-25 17:12:08 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/simulation/stubExternalMind.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubMindsProperty.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubThing.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubEntity.h"
|
|
|
|
|
#include "../stubs/rules/stubLocatedEntity.h"
|
|
|
|
|
#include "../stubs/common/stubRouter.h"
|
|
|
|
|
#include "../stubs/common/stubProperty.h"
|
2010-11-25 12:16:46 +00:00
|
|
|
|
2012-08-01 20:31:29 +01:00
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
#define STUB_Link_send
|
2012-08-01 20:31:29 +01:00
|
|
|
void Link::send(const Operation & op) const
|
|
|
|
|
{
|
2012-08-02 15:29:49 +01:00
|
|
|
stub_CommClient_sent_op = op;
|
2012-08-01 20:31:29 +01:00
|
|
|
}
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubLink.h"
|
|
|
|
|
#include "../stubs/rules/stubScript.h"
|
|
|
|
|
#include "../stubs/common/stubTypeNode.h"
|
|
|
|
|
#include "../stubs/rules/stubLocation.h"
|
2010-11-25 12:16:46 +00:00
|
|
|
|
|
|
|
|
|
2018-07-25 00:16:09 +02:00
|
|
|
#ifndef STUB_BaseWorld_getEntity
|
|
|
|
|
#define STUB_BaseWorld_getEntity
|
2018-08-05 20:47:09 +02:00
|
|
|
Ref<LocatedEntity> BaseWorld::getEntity(const std::string & id) const
|
2010-11-25 12:16:46 +00:00
|
|
|
{
|
2018-07-25 00:16:09 +02:00
|
|
|
return getEntity(integerId(id));
|
2010-11-25 12:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-05 20:47:09 +02:00
|
|
|
Ref<LocatedEntity> BaseWorld::getEntity(long id) const
|
2010-11-25 12:16:46 +00:00
|
|
|
{
|
2018-07-25 00:16:09 +02:00
|
|
|
auto I = m_eobjects.find(id);
|
2010-11-25 12:16:46 +00:00
|
|
|
if (I != m_eobjects.end()) {
|
2018-07-25 00:16:09 +02:00
|
|
|
assert(I->second);
|
2010-11-25 12:16:46 +00:00
|
|
|
return I->second;
|
|
|
|
|
} else {
|
2018-07-25 00:16:09 +02:00
|
|
|
return nullptr;
|
2010-11-25 12:16:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-07-25 00:16:09 +02:00
|
|
|
#endif //STUB_BaseWorld_getEntity
|
2010-11-25 12:16:46 +00:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/simulation/stubBaseWorld.h"
|
|
|
|
|
#include "../stubs/common/stublog.h"
|
|
|
|
|
#include "../stubs/common/stubid.h"
|