cyphesis/tests/server/TrustedConnectionTest.cpp

289 lines
7 KiB
C++
Raw Permalink Normal View History

// 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
#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"
#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"
#include "common/compose.hpp"
2010-03-23 00:36:36 +00:00
#include "common/Inheritance.h"
#include "common/log.h"
#include "common/CommSocket.h"
#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>
#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;
class TestCommSocket : public CommSocket
{
public:
2019-06-24 21:12:55 +02:00
TestCommSocket() : CommSocket(*(boost::asio::io_context*)0)
{
}
virtual void disconnect()
{
}
virtual int flush()
{
return 0;
}
};
class TestConnection : public TrustedConnection {
public:
TestConnection(CommSocket & cc, ServerRouting & svr,
const std::string & addr, RouterId id) :
TrustedConnection(cc, svr, addr, id) {
}
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,
RouterId id)
2010-03-23 00:36:36 +00:00
{
return newAccount(type, username, passwd, id);
}
2010-03-23 00:36:36 +00:00
int test_verifyCredentials(const Account & ac,
const Atlas::Objects::Root & arg) const
{
return verifyCredentials(ac, arg);
}
size_t numObjects() const {
return m_routers.size();
}
const std::map<long, RouterWithQueue> & getObjects() const {
return m_routers;
}
void removeObject(Router * obj) {
auto I = m_routers.find(obj->getIntId());
if (I != m_routers.end()) {
m_routers.erase(I);
}
}
};
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;
ServerRouting server(*(BaseWorld*)0, *(Persistence*)nullptr, "noruleset", "unittesting", 2,AssetsHandler({}));
TestCommSocket tcc{};
TestConnection tc(tcc, server, "addr", 3);
{
auto ac = tc.test_newAccount("_non_type_",
2010-03-23 00:36:36 +00:00
"bob",
"unit_test_hash",
1);
assert(ac.get() != 0);
2010-03-23 00:36:36 +00:00
}
{
auto ac = tc.test_newAccount("sys",
2010-03-23 00:36:36 +00:00
"bob",
"unit_test_hash",
1);
2010-03-23 00:36:36 +00:00
assert(ac.get() != 0);
}
2010-03-23 00:36:36 +00:00
{
auto ac = tc.test_newAccount("admin",
2010-03-23 00:36:36 +00:00
"bob",
"unit_test_hash",
1);
assert(ac.get() != 0);
2010-03-23 00:36:36 +00:00
}
{
auto ac = tc.test_newAccount("player",
2010-03-23 00:36:36 +00:00
"bob",
"unit_test_hash",
1);
2010-03-23 00:36:36 +00:00
assert(ac.get() != 0);
}
{
Account * ac = new Player(0, "bill", "unit_test_password", 2);
2010-03-23 00:36:36 +00:00
Atlas::Objects::Root creds;
int ret = tc.test_verifyCredentials(*ac, creds);
2010-03-23 00:36:36 +00:00
assert(ret == 0);
delete ac;
}
}
2010-03-23 00:36:36 +00:00
// Stubs
bool restricted_flag;
namespace Atlas { namespace Objects { namespace Operation {
int UPDATE_NO = -1;
} } }
int CommSocket::flush()
2010-03-23 00:36:36 +00:00
{
return 0;
}
#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"
#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()
{
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
void ExternalMind::linkUp(Link * c)
2010-03-23 00:36:36 +00:00
{
m_link = c;
2010-03-23 00:36:36 +00: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
#include "../stubs/common/stubLink.h"
#include "../stubs/common/stubRouter.h"
#include "../stubs/common/stubTypeNode.h"
#include "../stubs/rules/stubLocation.h"
#include "common/Property_impl.h"
#include "../stubs/common/stubProperty.h"
#include "../stubs/rules/simulation/stubBaseWorld.h"
2010-03-23 00:36:36 +00:00
#ifndef STUB_Inheritance_getClass
#define STUB_Inheritance_getClass
const Atlas::Objects::Root& Inheritance::getClass(const std::string & parent, Visibility) const
{
return noClass;
}
#endif //STUB_Inheritance_getClass
2010-03-23 00:36:36 +00:00
2013-08-22 14:20:33 +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);
if (I == atlasObjects.end()) {
return 0;
}
return I->second.get();
}
#endif //STUB_Inheritance_getType
#include "../stubs/common/stubInheritance.h"
2010-03-23 00:36:36 +00:00
void encrypt_password(const std::string & pwd, std::string & hash)
2010-03-23 00:36:36 +00:00
{
}
#include "../stubs/common/stublog.h"
2010-03-23 00:36:36 +00:00
static long idGenerator = 0;
RouterId newId()
2010-03-23 00:36:36 +00:00
{
long new_id = ++idGenerator;
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 "";
}