2009-11-21 16:26:36 +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.
|
|
|
|
|
//
|
|
|
|
|
// 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
|
|
|
|
|
|
2009-11-21 16:26:36 +00:00
|
|
|
#include "server/TrustedConnection.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
|
2019-01-01 21:06:46 +01:00
|
|
|
#include "rules/LocatedEntity.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
#include "server/Account.h"
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/ExternalMind.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
#include "server/Lobby.h"
|
|
|
|
|
#include "server/Player.h"
|
2009-11-21 16:26:36 +00:00
|
|
|
#include "server/ServerRouting.h"
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/Task.h"
|
2020-04-13 11:17:52 +02:00
|
|
|
#include "rules/simulation/WorldRouter.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
#include "server/SystemAccount.h"
|
|
|
|
|
|
2009-11-21 16:26:36 +00:00
|
|
|
#include "common/compose.hpp"
|
2010-03-23 00:36:36 +00:00
|
|
|
#include "common/Inheritance.h"
|
|
|
|
|
#include "common/log.h"
|
2014-02-03 12:19:42 +01:00
|
|
|
#include "common/CommSocket.h"
|
2009-11-21 16:26:36 +00:00
|
|
|
|
|
|
|
|
#include <Atlas/Objects/Anonymous.h>
|
|
|
|
|
#include <Atlas/Objects/Operation.h>
|
|
|
|
|
#include <Atlas/Objects/SmartPtr.h>
|
|
|
|
|
|
2010-03-23 00:36:36 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
|
2009-11-21 16:26:36 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
using Atlas::Message::ListType;
|
|
|
|
|
using Atlas::Message::MapType;
|
|
|
|
|
using Atlas::Objects::Root;
|
|
|
|
|
using Atlas::Objects::Entity::RootEntity;
|
|
|
|
|
using Atlas::Objects::Entity::Anonymous;
|
|
|
|
|
using Atlas::Objects::Operation::Create;
|
|
|
|
|
using Atlas::Objects::Operation::Get;
|
|
|
|
|
using Atlas::Objects::Operation::Login;
|
|
|
|
|
using Atlas::Objects::Operation::Logout;
|
|
|
|
|
using Atlas::Objects::Operation::Move;
|
|
|
|
|
|
2014-02-03 12:19:42 +01:00
|
|
|
class TestCommSocket : public CommSocket
|
|
|
|
|
{
|
2009-11-21 16:26:36 +00: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;
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-21 16:26:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestConnection : public TrustedConnection {
|
|
|
|
|
public:
|
2012-08-01 19:42:36 +01:00
|
|
|
TestConnection(CommSocket & cc, ServerRouting & svr,
|
2022-07-04 15:37:51 +02:00
|
|
|
const std::string & addr, RouterId id) :
|
|
|
|
|
TrustedConnection(cc, svr, addr, id) {
|
2009-11-21 16:26:36 +00:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
std::unique_ptr<Account> test_newAccount(const std::string & type,
|
2010-03-23 00:36:36 +00:00
|
|
|
const std::string & username,
|
|
|
|
|
const std::string & passwd,
|
2022-07-04 15:37:51 +02:00
|
|
|
RouterId id)
|
2010-03-23 00:36:36 +00:00
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
return newAccount(type, username, passwd, id);
|
2009-11-21 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
2010-03-23 00:36:36 +00:00
|
|
|
int test_verifyCredentials(const Account & ac,
|
|
|
|
|
const Atlas::Objects::Root & arg) const
|
|
|
|
|
{
|
|
|
|
|
return verifyCredentials(ac, arg);
|
2009-11-21 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t numObjects() const {
|
2021-08-02 01:20:52 +02:00
|
|
|
return m_routers.size();
|
2009-11-21 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-02 01:20:52 +02:00
|
|
|
const std::map<long, RouterWithQueue> & getObjects() const {
|
|
|
|
|
return m_routers;
|
2009-11-21 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void removeObject(Router * obj) {
|
2021-08-02 01:20:52 +02:00
|
|
|
auto I = m_routers.find(obj->getIntId());
|
|
|
|
|
if (I != m_routers.end()) {
|
|
|
|
|
m_routers.erase(I);
|
2009-11-21 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2011-10-31 12:47:56 +01:00
|
|
|
// WorldRouter world(SystemTime());
|
2010-03-23 00:36:36 +00:00
|
|
|
// Entity & e = world.m_gameWorld;
|
2009-11-21 16:26:36 +00:00
|
|
|
|
2023-10-19 23:04:04 +02:00
|
|
|
ServerRouting server(*(BaseWorld*)0, *(Persistence*)nullptr, "noruleset", "unittesting", 2,AssetsHandler({}));
|
2009-11-21 16:26:36 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
TestCommSocket tcc{};
|
2022-07-04 15:37:51 +02:00
|
|
|
TestConnection tc(tcc, server, "addr", 3);
|
2009-11-21 16:26:36 +00:00
|
|
|
|
|
|
|
|
{
|
2021-05-27 17:38:58 +02:00
|
|
|
auto ac = tc.test_newAccount("_non_type_",
|
2010-03-23 00:36:36 +00:00
|
|
|
"bob",
|
|
|
|
|
"unit_test_hash",
|
2022-07-04 15:37:51 +02:00
|
|
|
1);
|
2009-11-21 16:26:36 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
assert(ac.get() != 0);
|
2010-03-23 00:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-21 16:26:36 +00:00
|
|
|
{
|
2021-05-27 17:38:58 +02:00
|
|
|
auto ac = tc.test_newAccount("sys",
|
2010-03-23 00:36:36 +00:00
|
|
|
"bob",
|
|
|
|
|
"unit_test_hash",
|
2022-07-04 15:37:51 +02:00
|
|
|
1);
|
2010-03-23 00:36:36 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
assert(ac.get() != 0);
|
2009-11-21 16:26:36 +00:00
|
|
|
}
|
2010-03-23 00:36:36 +00:00
|
|
|
|
|
|
|
|
{
|
2021-05-27 17:38:58 +02:00
|
|
|
auto ac = tc.test_newAccount("admin",
|
2010-03-23 00:36:36 +00:00
|
|
|
"bob",
|
|
|
|
|
"unit_test_hash",
|
2022-07-04 15:37:51 +02:00
|
|
|
1);
|
2009-11-21 16:26:36 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
assert(ac.get() != 0);
|
2010-03-23 00:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
2009-11-21 16:26:36 +00:00
|
|
|
{
|
2021-05-27 17:38:58 +02:00
|
|
|
auto ac = tc.test_newAccount("player",
|
2010-03-23 00:36:36 +00:00
|
|
|
"bob",
|
|
|
|
|
"unit_test_hash",
|
2022-07-04 15:37:51 +02:00
|
|
|
1);
|
2010-03-23 00:36:36 +00:00
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
assert(ac.get() != 0);
|
2009-11-21 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2022-07-04 15:37:51 +02:00
|
|
|
Account * ac = new Player(0, "bill", "unit_test_password", 2);
|
2010-03-23 00:36:36 +00:00
|
|
|
Atlas::Objects::Root creds;
|
|
|
|
|
|
2021-05-27 17:38:58 +02:00
|
|
|
int ret = tc.test_verifyCredentials(*ac, creds);
|
2010-03-23 00:36:36 +00:00
|
|
|
|
|
|
|
|
assert(ret == 0);
|
2021-05-27 17:38:58 +02:00
|
|
|
delete ac;
|
2009-11-21 16:26:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-03-23 00:36:36 +00:00
|
|
|
|
|
|
|
|
// Stubs
|
|
|
|
|
|
|
|
|
|
bool restricted_flag;
|
|
|
|
|
|
|
|
|
|
namespace Atlas { namespace Objects { namespace Operation {
|
|
|
|
|
int UPDATE_NO = -1;
|
|
|
|
|
} } }
|
|
|
|
|
|
|
|
|
|
|
2012-08-01 19:42:36 +01:00
|
|
|
int CommSocket::flush()
|
2010-03-23 00:36:36 +00:00
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/server/stubAdmin.h"
|
|
|
|
|
#include "../stubs/server/stubPlayer.h"
|
|
|
|
|
#include "../stubs/server/stubSystemAccount.h"
|
|
|
|
|
#include "../stubs/server/stubAccount.h"
|
|
|
|
|
#include "../stubs/server/stubConnectableRouter.h"
|
|
|
|
|
#include "../stubs/server/stubConnection.h"
|
|
|
|
|
#include "../stubs/server/stubServerRouting.h"
|
|
|
|
|
#include "../stubs/server/stubLobby.h"
|
2023-10-19 23:04:04 +02:00
|
|
|
#include "../stubs/common/stubAssetsHandler.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
#define STUB_ExternalMind_connectionId
|
2010-03-23 00:36:36 +00:00
|
|
|
const std::string & ExternalMind::connectionId()
|
|
|
|
|
{
|
2018-02-08 21:46:49 +01:00
|
|
|
assert(m_link != 0);
|
|
|
|
|
return m_link->getId();
|
2010-03-23 00:36:36 +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-03-23 00:36:36 +00:00
|
|
|
{
|
2018-02-08 21:46:49 +01:00
|
|
|
m_link = c;
|
2010-03-23 00:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/rules/simulation/stubExternalMind.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubThing.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubEntity.h"
|
|
|
|
|
#include "../stubs/rules/stubLocatedEntity.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubLink.h"
|
|
|
|
|
#include "../stubs/common/stubRouter.h"
|
|
|
|
|
#include "../stubs/common/stubTypeNode.h"
|
|
|
|
|
#include "../stubs/rules/stubLocation.h"
|
2014-09-29 19:24:05 +02:00
|
|
|
#include "common/Property_impl.h"
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubProperty.h"
|
|
|
|
|
#include "../stubs/rules/simulation/stubBaseWorld.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
|
|
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
#ifndef STUB_Inheritance_getClass
|
|
|
|
|
#define STUB_Inheritance_getClass
|
2019-08-11 01:38:28 +02:00
|
|
|
const Atlas::Objects::Root& Inheritance::getClass(const std::string & parent, Visibility) const
|
2010-11-23 14:00:38 +00:00
|
|
|
{
|
2018-04-25 20:09:14 +02:00
|
|
|
return noClass;
|
2010-11-23 14:00:38 +00:00
|
|
|
}
|
2018-04-25 20:09:14 +02:00
|
|
|
#endif //STUB_Inheritance_getClass
|
2010-03-23 00:36:36 +00:00
|
|
|
|
2013-08-22 14:20:33 +02:00
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
#ifndef STUB_Inheritance_getType
|
|
|
|
|
#define STUB_Inheritance_getType
|
2018-10-27 13:13:45 +02:00
|
|
|
const TypeNode* Inheritance::getType(const std::string & parent) const
|
2010-03-23 00:36:36 +00:00
|
|
|
{
|
2018-10-27 13:13:45 +02:00
|
|
|
auto I = atlasObjects.find(parent);
|
2014-09-29 19:24:05 +02:00
|
|
|
if (I == atlasObjects.end()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2019-11-17 18:43:43 +01:00
|
|
|
return I->second.get();
|
|
|
|
|
}
|
2018-04-25 20:09:14 +02:00
|
|
|
#endif //STUB_Inheritance_getType
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stubInheritance.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
|
|
|
|
|
|
2014-09-29 19:24:05 +02:00
|
|
|
void encrypt_password(const std::string & pwd, std::string & hash)
|
2010-03-23 00:36:36 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-20 23:17:55 +01:00
|
|
|
#include "../stubs/common/stublog.h"
|
2010-03-23 00:36:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static long idGenerator = 0;
|
|
|
|
|
|
2022-07-04 15:37:51 +02:00
|
|
|
RouterId newId()
|
2010-03-23 00:36:36 +00:00
|
|
|
{
|
|
|
|
|
long new_id = ++idGenerator;
|
2022-07-04 15:37:51 +02:00
|
|
|
return {new_id};
|
2010-03-23 00:36:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void addToEntity(const Vector3D & v, std::vector<double> & vd)
|
|
|
|
|
{
|
|
|
|
|
vd.resize(3);
|
|
|
|
|
vd[0] = v[0];
|
|
|
|
|
vd[1] = v[1];
|
|
|
|
|
vd[2] = v[2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int check_password(const std::string & pwd, const std::string & hash)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2012-10-25 10:43:01 -04:00
|
|
|
|
|
|
|
|
#include <common/Shaker.h>
|
|
|
|
|
|
|
|
|
|
Shaker::Shaker()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Shaker::generateSalt(size_t length)
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|