2009-11-18 01:28:45 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2009 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.
|
2012-09-12 15:10:00 +01:00
|
|
|
//
|
2009-11-18 01:28:45 +00:00
|
|
|
// 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.
|
2012-09-12 15:10:00 +01:00
|
|
|
//
|
2009-11-18 01:28:45 +00:00
|
|
|
// 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
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../TestBase.h"
|
|
|
|
|
#include "../TestWorld.h"
|
2012-08-01 19:42:36 +01:00
|
|
|
|
2009-11-18 01:28:45 +00:00
|
|
|
#include "server/Player.h"
|
2012-09-12 15:10:00 +01:00
|
|
|
|
2009-11-18 01:28:45 +00:00
|
|
|
#include "server/Connection.h"
|
2012-09-12 15:10:00 +01:00
|
|
|
#include "server/Ruleset.h"
|
|
|
|
|
#include "server/ServerRouting.h"
|
2019-11-17 18:43:43 +01:00
|
|
|
#include "rules/simulation/ExternalMind.h"
|
2009-11-18 01:28:45 +00:00
|
|
|
|
2018-10-31 21:38:35 +01:00
|
|
|
#include "rules/simulation/Entity.h"
|
2009-11-18 01:28:45 +00:00
|
|
|
|
2012-11-23 11:05:59 +00:00
|
|
|
#include "common/CommSocket.h"
|
2012-09-12 15:10:00 +01:00
|
|
|
#include "common/compose.hpp"
|
2012-09-13 15:14:14 +01:00
|
|
|
#include "common/debug.h"
|
2020-03-22 23:36:52 +01:00
|
|
|
#include "../NullPropertyManager.h"
|
2009-11-18 01:28:45 +00:00
|
|
|
|
2012-09-12 18:16:26 +01:00
|
|
|
#include <Atlas/Objects/Anonymous.h>
|
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
2009-11-18 01:28:45 +00:00
|
|
|
#include <Atlas/Objects/SmartPtr.h>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
2019-11-17 18:43:43 +01:00
|
|
|
#include <server/EntityBuilder.h>
|
2009-11-18 01:28:45 +00:00
|
|
|
|
2012-09-13 15:14:14 +01:00
|
|
|
using Atlas::Message::Element;
|
2012-09-12 18:16:26 +01:00
|
|
|
using Atlas::Message::ListType;
|
2009-11-18 01:28:45 +00:00
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
using Atlas::Objects::Root;
|
2012-09-12 18:16:26 +01:00
|
|
|
using Atlas::Objects::Entity::Anonymous;
|
2009-11-18 01:28:45 +00:00
|
|
|
using Atlas::Objects::Entity::RootEntity;
|
|
|
|
|
|
2012-09-12 15:10:00 +01:00
|
|
|
using String::compose;
|
|
|
|
|
|
2012-09-13 15:14:14 +01:00
|
|
|
template <typename T>
|
|
|
|
|
std::ostream & operator<<(std::ostream & os,
|
|
|
|
|
const std::list<T> & sl)
|
|
|
|
|
{
|
|
|
|
|
typename std::list<T>::const_iterator I = sl.begin();
|
|
|
|
|
typename std::list<T>::const_iterator Iend = sl.end();
|
|
|
|
|
os << "[";
|
|
|
|
|
for (; I != Iend; ++I) {
|
|
|
|
|
if (I != sl.begin()) {
|
|
|
|
|
os << ", ";
|
|
|
|
|
}
|
|
|
|
|
os << *I;
|
|
|
|
|
}
|
|
|
|
|
os << "]";
|
|
|
|
|
return os;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-12 15:10:00 +01:00
|
|
|
class Playertest : public Cyphesis::TestBase
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
static long m_id_counter;
|
|
|
|
|
|
|
|
|
|
ServerRouting * m_server;
|
|
|
|
|
Connection * m_connection;
|
|
|
|
|
Player * m_account;
|
2018-08-04 01:12:45 +02:00
|
|
|
TestWorld* m_world;
|
|
|
|
|
|
|
|
|
|
public:
|
2012-09-12 15:10:00 +01:00
|
|
|
Playertest();
|
2009-11-18 01:28:45 +00:00
|
|
|
|
2012-09-12 15:10:00 +01:00
|
|
|
static long newId();
|
2009-11-18 01:28:45 +00:00
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
void setup() override;
|
|
|
|
|
void teardown() override;
|
2012-09-12 15:10:00 +01:00
|
|
|
|
2012-09-12 18:16:26 +01:00
|
|
|
void test_getType();
|
|
|
|
|
|
2009-11-18 01:28:45 +00:00
|
|
|
};
|
|
|
|
|
|
2012-09-12 15:10:00 +01:00
|
|
|
long Playertest::m_id_counter = 0L;
|
|
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
Playertest::Playertest() : m_server(nullptr),
|
|
|
|
|
m_connection(nullptr),
|
|
|
|
|
m_account(nullptr)
|
2012-09-12 15:10:00 +01:00
|
|
|
{
|
2012-09-12 18:16:26 +01:00
|
|
|
ADD_TEST(Playertest::test_getType);
|
2012-09-12 15:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long Playertest::newId()
|
|
|
|
|
{
|
|
|
|
|
return ++m_id_counter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Playertest::setup()
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Ref<Entity> gw = new Entity(m_id_counter++);
|
2018-08-05 14:31:04 +02:00
|
|
|
m_world = new TestWorld(gw);
|
2021-08-01 23:17:40 +02:00
|
|
|
|
2018-08-04 01:12:45 +02:00
|
|
|
m_server = new ServerRouting(*m_world,
|
2021-08-01 23:17:40 +02:00
|
|
|
*(Persistence*)nullptr,
|
2012-09-12 15:10:00 +01:00
|
|
|
"5529d7a4-0158-4dc1-b4a5-b5f260cac635",
|
|
|
|
|
"bad621d4-616d-4faf-b9e6-471d12b139a9",
|
2023-10-19 23:04:04 +02:00
|
|
|
m_id_counter++,
|
|
|
|
|
AssetsHandler({}));
|
2012-09-12 15:10:00 +01:00
|
|
|
m_connection = new Connection(*(CommSocket*)0, *m_server,
|
|
|
|
|
"8d18a4e8-f14f-4a46-997e-ada120d5438f",
|
2022-07-04 15:37:51 +02:00
|
|
|
m_id_counter++);
|
2012-09-12 15:10:00 +01:00
|
|
|
m_account = new Player(m_connection,
|
|
|
|
|
"6c9f3236-5de7-4ba4-8b7a-b0222df0af38",
|
|
|
|
|
"fa1a03a2-a745-4033-85cb-bb694e921e62",
|
2022-07-04 15:37:51 +02:00
|
|
|
m_id_counter++);
|
2012-09-12 15:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Playertest::teardown()
|
|
|
|
|
{
|
2018-08-04 01:12:45 +02:00
|
|
|
delete m_world;
|
2012-09-12 15:10:00 +01:00
|
|
|
delete m_server;
|
2012-09-13 00:02:41 +01:00
|
|
|
delete m_account;
|
|
|
|
|
delete m_connection;
|
2012-09-12 15:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-12 18:16:26 +01:00
|
|
|
void Playertest::test_getType()
|
2012-09-12 15:10:00 +01:00
|
|
|
{
|
|
|
|
|
ASSERT_TRUE(m_account != 0);
|
2012-09-12 18:16:26 +01:00
|
|
|
|
|
|
|
|
const char * type = m_account->getType();
|
|
|
|
|
ASSERT_EQUAL(std::string("player"), type);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-12 15:10:00 +01:00
|
|
|
|
2009-11-18 01:28:45 +00:00
|
|
|
int main()
|
|
|
|
|
{
|
2019-06-24 21:12:55 +02:00
|
|
|
boost::asio::io_context io_context;
|
2019-11-17 18:43:43 +01:00
|
|
|
EntityBuilder eb;
|
2020-03-22 23:36:52 +01:00
|
|
|
NullPropertyManager propertyManager;
|
|
|
|
|
Ruleset ruleset(eb, io_context, propertyManager);
|
2009-11-18 01:28:45 +00:00
|
|
|
|
2012-09-12 15:10:00 +01:00
|
|
|
Playertest t;
|
2010-09-01 14:06:37 +01:00
|
|
|
|
2012-09-12 15:10:00 +01:00
|
|
|
return t.run();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
#include "server/Connection.h"
|
|
|
|
|
#include "server/Juncture.h"
|
|
|
|
|
#include "server/Persistence.h"
|
2013-07-26 20:14:33 +02:00
|
|
|
#include "server/PossessionAuthenticator.h"
|
2009-11-18 01:28:45 +00:00
|
|
|
|
2012-09-12 15:10:00 +01:00
|
|
|
#include "common/globals.h"
|
|
|
|
|
#include "common/id.h"
|
|
|
|
|
#include "common/Inheritance.h"
|
|
|
|
|
#include "common/log.h"
|
|
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/server/stubAccount.h"
|
|
|
|
|
#include "../stubs/server/stubConnection.h"
|
|
|
|
|
#include "../stubs/server/stubEntityBuilder.h"
|
|
|
|
|
|
|
|
|
|
#include "../stubs/server/stubRuleHandler.h"
|
|
|
|
|
|
|
|
|
|
#include "../stubs/server/stubEntityRuleHandler.h"
|
|
|
|
|
#include "../stubs/server/stubArchetypeRuleHandler.h"
|
|
|
|
|
#include "../stubs/server/stubOpRuleHandler.h"
|
|
|
|
|
#include "../stubs/server/stubPropertyRuleHandler.h"
|
|
|
|
|
#include "../stubs/server/stubConnectableRouter.h"
|
|
|
|
|
#include "../stubs/server/stubRuleset.h"
|
|
|
|
|
#include "../stubs/server/stubJuncture.h"
|
|
|
|
|
#include "../stubs/server/stubServerRouting.h"
|
|
|
|
|
#include "../stubs/server/stubLobby.h"
|
|
|
|
|
#include "../stubs/server/stubPossessionAuthenticator.h"
|
|
|
|
|
|
|
|
|
|
#include "../stubs/server/stubPersistence.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubThing.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubEntity.h"
|
|
|
|
|
#include "../stubs/rules/stubLocatedEntity.h"
|
|
|
|
|
#include "../stubs/common/stubLink.h"
|
|
|
|
|
#include "../stubs/common/stubTypeNode.h"
|
2023-10-19 23:04:04 +02:00
|
|
|
#include "../stubs/common/stubAssetsHandler.h"
|
2012-09-12 15:10:00 +01:00
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
#define STUB_Inheritance_getClass
|
2019-08-11 01:38:28 +02:00
|
|
|
const Atlas::Objects::Root& Inheritance::getClass(const std::string & parent, Visibility) const
|
2012-09-12 15:10:00 +01:00
|
|
|
{
|
2018-04-25 20:09:14 +02:00
|
|
|
return noClass;
|
2012-09-12 15:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
#define STUB_Inheritance_getType
|
2018-10-27 13:13:45 +02:00
|
|
|
const TypeNode* Inheritance::getType(const std::string & parent) const
|
2012-09-12 15:10:00 +01:00
|
|
|
{
|
2018-10-27 13:13:45 +02:00
|
|
|
auto I = atlasObjects.find(parent);
|
2012-09-12 15:10:00 +01:00
|
|
|
if (I == atlasObjects.end()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-11-17 18:43:43 +01:00
|
|
|
return I->second.get();
|
2012-09-12 15:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
#define STUB_Inheritance_hasClass
|
2012-09-12 15:10:00 +01:00
|
|
|
bool Inheritance::hasClass(const std::string & parent)
|
|
|
|
|
{
|
2018-10-27 13:13:45 +02:00
|
|
|
auto I = atlasObjects.find(parent);
|
2012-09-12 15:10:00 +01:00
|
|
|
if (I == atlasObjects.end()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubInheritance.h"
|
2018-04-25 20:09:14 +02:00
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
#define STUB_Router_clientError
|
2012-09-12 15:10:00 +01:00
|
|
|
void Router::clientError(const Operation & op,
|
|
|
|
|
const std::string & errstring,
|
|
|
|
|
OpVector & res,
|
|
|
|
|
const std::string & to) const
|
|
|
|
|
{
|
2012-09-12 18:16:26 +01:00
|
|
|
res.push_back(Atlas::Objects::Operation::Error());
|
2012-09-12 15:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
#define STUB_Router_error
|
2012-09-12 15:10:00 +01:00
|
|
|
void Router::error(const Operation & op,
|
|
|
|
|
const std::string & errstring,
|
|
|
|
|
OpVector & res,
|
|
|
|
|
const std::string & to) const
|
|
|
|
|
{
|
2012-09-12 18:16:26 +01:00
|
|
|
res.push_back(Atlas::Objects::Operation::Error());
|
2012-09-12 15:10:00 +01:00
|
|
|
}
|
2018-10-27 13:13:45 +02:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubRouter.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubBaseWorld.h"
|
|
|
|
|
#include "../stubs/rules/stubLocation.h"
|
2020-03-22 23:36:52 +01:00
|
|
|
#include "../stubs/common/stubProperty.h"
|
|
|
|
|
#include "../stubs/common/stubPropertyManager.h"
|
2012-09-12 15:10:00 +01:00
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
RouterId newId()
|
2012-09-12 15:10:00 +01:00
|
|
|
{
|
|
|
|
|
long new_id = Playertest::newId();
|
2022-07-04 15:37:51 +02:00
|
|
|
return {new_id};
|
2012-09-12 15:10:00 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stublog.h"
|
2012-09-12 15:10:00 +01:00
|
|
|
|
|
|
|
|
bool database_flag = false;
|
|
|
|
|
|
|
|
|
|
namespace Atlas { namespace Objects { namespace Operation {
|
|
|
|
|
int MONITOR_NO = -1;
|
|
|
|
|
} } }
|
2012-10-25 10:41:44 -04:00
|
|
|
|
|
|
|
|
#include <common/Shaker.h>
|
|
|
|
|
|
|
|
|
|
Shaker::Shaker()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
std::string Shaker::generateSalt(size_t length)
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|