cyphesis/tests/ConnectionShakerIntegration.cpp

577 lines
12 KiB
C++
Raw Permalink Normal View History

2012-11-12 20:25:19 -05:00
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2012 Anthony Pesce
//
// 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
#ifdef NDEBUG
#undef NDEBUG
#endif
#ifndef DEBUG
#define DEBUG
#endif
#include "TestBase.h"
#include "server/Connection.h"
#include "server/ServerRouting.h"
2012-11-23 16:11:21 +00:00
#include "rulesets/ExternalMind.h"
#include "rulesets/ExternalProperty.h"
2012-11-12 20:25:19 -05:00
#include "rulesets/Character.h"
2012-11-12 20:25:19 -05:00
#include "common/CommSocket.h"
#include "common/Shaker.h"
2012-11-12 20:25:19 -05:00
#include "common/PropertyManager.h"
#include "common/globals.h"
#include "common/log.h"
#include "common/const.h"
2012-11-12 20:25:19 -05:00
#include <cstdio>
using Atlas::Message::Element;
using Atlas::Message::ListType;
using Atlas::Message::MapType;
using String::compose;
2012-11-12 20:25:19 -05:00
bool database_flag = false;
int salt_length = -1;
class ConnectionShakerintegration : public Cyphesis::TestBase
{
private:
long m_id_counter;
2012-11-12 20:25:19 -05:00
ServerRouting * m_server;
Connection * m_connection;
public:
ConnectionShakerintegration();
void setup();
void teardown();
2012-11-12 20:25:19 -05:00
void testShaker();
};
2012-11-12 20:25:19 -05:00
ConnectionShakerintegration::ConnectionShakerintegration() : m_id_counter(0L),
m_server(0),
m_connection(0)
2012-11-12 20:25:19 -05:00
{
ADD_TEST(ConnectionShakerintegration::testShaker);
2012-11-12 20:25:19 -05:00
}
void ConnectionShakerintegration::testShaker()
2012-11-12 20:25:19 -05:00
{
ASSERT_NOT_NULL(m_connection);
2012-12-04 22:44:10 +00:00
m_connection->addNewAccount("player",
"testuser",
"testpassword");
2012-11-12 20:25:19 -05:00
2012-12-04 22:44:10 +00:00
ASSERT_EQUAL(salt_length, 16);
}
2012-11-12 20:25:19 -05:00
void ConnectionShakerintegration::setup()
2012-11-12 20:25:19 -05:00
{
m_server = new ServerRouting(*(BaseWorld*)0,
"b88aa6d3-44b4-40bd-bfa9-8db00045bdc0",
"0f1fc7cb-5ab1-45c1-b0d3-ae49205ea437",
compose("%1", m_id_counter), m_id_counter++,
compose("%1", m_id_counter), m_id_counter++);
m_connection = new Connection(*(CommSocket*)0,
*m_server,
"test_addr",
compose("%1", m_id_counter), m_id_counter++);
2012-11-12 20:25:19 -05:00
}
void ConnectionShakerintegration::teardown()
2012-11-12 20:25:19 -05:00
{
delete m_server;
delete m_connection;
2012-11-12 20:25:19 -05:00
}
int main()
2012-11-12 20:25:19 -05:00
{
ConnectionShakerintegration t;
return t.run();
2012-11-12 20:25:19 -05:00
}
// Stubs
#include "server/Lobby.h"
#include "server/Player.h"
#include "common/Inheritance.h"
using Atlas::Objects::Root;
bool restricted_flag;
namespace Atlas { namespace Objects { namespace Operation {
int UPDATE_NO = -1;
} } }
2012-11-12 20:25:19 -05:00
CommSocket::CommSocket(boost::asio::io_service & svr) : m_io_service(svr) { }
CommSocket::~CommSocket()
2012-11-12 20:25:19 -05:00
{
}
int CommSocket::flush()
2012-11-12 20:25:19 -05:00
{
return 0;
2012-11-12 20:25:19 -05:00
}
Player::Player(Connection * conn,
const std::string & username,
const std::string & passwd,
const std::string & id,
long intId) :
Account(conn, username, passwd, id, intId)
2012-11-12 20:25:19 -05:00
{
}
2012-11-12 20:25:19 -05:00
Player::~Player() { }
2012-11-12 20:25:19 -05:00
const char * Player::getType() const
{
return "player";
}
2012-11-12 20:25:19 -05:00
void Player::addToMessage(MapType & omap) const
{
}
2012-11-12 20:25:19 -05:00
void Player::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
{
}
2012-11-12 20:25:19 -05:00
int Player::characterError(const Operation & op,
const Root & ent, OpVector & res) const
{
return 0;
}
2012-11-12 20:25:19 -05:00
Account::Account(Connection * conn,
const std::string & uname,
const std::string & passwd,
const std::string & id,
long intId) :
ConnectableRouter(id, intId, conn),
m_username(uname), m_password(passwd)
{
}
2012-11-12 20:25:19 -05:00
Account::~Account()
2012-11-12 20:25:19 -05:00
{
}
const char * Account::getType() const
2012-11-12 20:25:19 -05:00
{
return "testaccount";
2012-11-12 20:25:19 -05:00
}
void Account::store() const
2012-11-12 20:25:19 -05:00
{
}
bool Account::isPersisted() const {
return true;
}
void Account::addToMessage(Atlas::Message::MapType &) const
2012-11-12 20:25:19 -05:00
{
}
void Account::addToEntity(const Atlas::Objects::Entity::RootEntity &) const
2012-11-12 20:25:19 -05:00
{
}
void Account::createObject(const std::string & type_str,
const Root & arg,
const Operation & op,
OpVector & res)
{
}
2012-11-12 20:25:19 -05:00
2014-01-24 11:06:20 +01:00
LocatedEntity * Account::createCharacterEntity(const std::string &,
const Atlas::Objects::Entity::RootEntity &,
const Atlas::Objects::Root &)
{
return 0;
}
void Account::externalOperation(const Operation &, Link &)
2012-11-15 23:47:57 +00:00
{
}
void Account::operation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
void Account::LogoutOperation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
void Account::CreateOperation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
void Account::SetOperation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
void Account::ImaginaryOperation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
void Account::TalkOperation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
void Account::LookOperation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
void Account::GetOperation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
void Account::OtherOperation(const Operation &, OpVector &)
2012-11-12 20:25:19 -05:00
{
}
ConnectableRouter::ConnectableRouter(const std::string & id,
long iid,
Connection *c) :
Router(id, iid),
m_connection(c)
{
}
2012-11-12 20:25:19 -05:00
ConnectableRouter::~ConnectableRouter()
2012-11-12 20:25:19 -05:00
{
}
ServerRouting::ServerRouting(BaseWorld & wrld,
const std::string & ruleset,
const std::string & name,
const std::string & id, long intId,
const std::string & lId, long lIntId) :
Router(id, intId),
m_svrRuleset(ruleset), m_svrName(name),
m_numClients(0), m_world(wrld), m_lobby(*(Lobby*)0)
2012-11-12 20:25:19 -05:00
{
}
ServerRouting::~ServerRouting()
2012-11-12 20:25:19 -05:00
{
}
void ServerRouting::addToMessage(Atlas::Message::MapType & omap) const
2012-11-12 20:25:19 -05:00
{
}
void ServerRouting::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
2012-11-12 20:25:19 -05:00
{
}
void ServerRouting::externalOperation(const Operation &, Link &)
2012-11-15 23:47:57 +00:00
{
}
void ServerRouting::operation(const Operation &, OpVector &)
{
}
Account * ServerRouting::getAccountByName(const std::string & username)
2012-11-12 20:25:19 -05:00
{
return 0;
}
void ServerRouting::addAccount(Account * a)
2012-11-12 20:25:19 -05:00
{
}
Lobby::Lobby(ServerRouting & s, const std::string & id, long intId) :
Router(id, intId),
m_server(s)
2012-11-12 20:25:19 -05:00
{
}
Lobby::~Lobby()
2012-11-12 20:25:19 -05:00
{
}
void Lobby::delAccount(Account * ac)
2012-11-12 20:25:19 -05:00
{
}
void Lobby::addToMessage(MapType & omap) const
{
}
2012-11-12 20:25:19 -05:00
void Lobby::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
2012-11-12 20:25:19 -05:00
{
}
void Lobby::addAccount(Account * ac)
{
}
void Lobby::externalOperation(const Operation &, Link &)
2012-11-15 23:47:57 +00:00
{
}
void Lobby::operation(const Operation & op, OpVector & res)
2012-11-12 20:25:19 -05:00
{
}
ExternalMind::ExternalMind(LocatedEntity & e) : Router(e.getId(), e.getIntId()),
2012-11-12 20:25:19 -05:00
m_external(0), m_entity(e)
{
}
ExternalMind::~ExternalMind()
{
}
void ExternalMind::externalOperation(const Operation & op, Link &)
2012-11-15 23:47:57 +00:00
{
}
2012-11-12 20:25:19 -05:00
void ExternalMind::operation(const Operation & op, OpVector & res)
{
}
2012-11-24 16:51:49 +00:00
ExternalProperty::ExternalProperty(ExternalMind * & data) : m_data(data)
{
}
int ExternalProperty::get(Atlas::Message::Element & val) const
{
return 0;
}
void ExternalProperty::set(const Atlas::Message::Element & val)
{
}
void ExternalProperty::add(const std::string & s,
Atlas::Message::MapType & map) const
{
}
void ExternalProperty::add(const std::string & s,
const Atlas::Objects::Entity::RootEntity & ent) const
{
}
ExternalProperty * ExternalProperty::copy() const
{
return 0;
}
2012-11-12 20:25:19 -05:00
const std::string & ExternalMind::connectionId()
{
assert(m_external != 0);
return m_external->getId();
}
void ExternalMind::linkUp(Link * c)
{
m_external = c;
}
#include "stubs/rulesets/stubCharacter.h"
#include "stubs/rulesets/stubThing.h"
#include "stubs/rulesets/stubEntity.h"
#include "stubs/rulesets/stubLocatedEntity.h"
2015-05-23 16:47:45 +02:00
#include "stubs/server/stubExternalMindsManager.h"
#include "stubs/server/stubExternalMindsConnection.h"
#include "stubs/common/stubOperationsDispatcher.h"
2012-11-12 20:25:19 -05:00
Link::Link(CommSocket & socket, const std::string & id, long iid) :
Router(id, iid), m_encoder(0), m_commSocket(socket)
{
}
Link::~Link()
{
}
void Link::send(const Operation & op) const
{
}
2012-11-12 20:25:19 -05:00
2012-11-21 21:43:38 +00:00
void Link::sendError(const Operation & op,
const std::string &,
const std::string &) const
{
}
void Link::disconnect()
2012-11-12 20:25:19 -05:00
{
}
Router::Router(const std::string & id, long intId) : m_id(id),
m_intId(intId)
2012-11-12 20:25:19 -05:00
{
}
Router::~Router()
2012-11-12 20:25:19 -05:00
{
}
void Router::addToMessage(Atlas::Message::MapType & omap) const
2012-11-12 20:25:19 -05:00
{
}
void Router::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
{
}
2012-11-12 20:25:19 -05:00
void Router::error(const Operation & op,
const std::string & errstring,
OpVector & res,
const std::string & to) const
{
}
2012-11-12 20:25:19 -05:00
void Router::clientError(const Operation & op,
const std::string & errstring,
OpVector & res,
const std::string & to) const
2012-11-12 20:25:19 -05:00
{
}
Location::Location() : m_loc(0)
2012-11-12 20:25:19 -05:00
{
}
PropertyBase::PropertyBase(unsigned int flags) : m_flags(flags)
{
}
PropertyBase::~PropertyBase()
{
}
void PropertyBase::install(LocatedEntity *, const std::string & name)
{
}
void PropertyBase::remove(LocatedEntity *, const std::string & name)
{
}
void PropertyBase::apply(LocatedEntity *)
{
}
void PropertyBase::add(const std::string & s,
Atlas::Message::MapType & ent) const
{
}
void PropertyBase::add(const std::string & s,
const Atlas::Objects::Entity::RootEntity & ent) const
{
}
HandlerResult PropertyBase::operation(LocatedEntity *,
const Operation &,
OpVector &)
{
return OPERATION_IGNORED;
}
Inheritance * Inheritance::m_instance = NULL;
Inheritance::Inheritance() : noClass(0)
{
}
Inheritance & Inheritance::instance()
2012-11-12 20:25:19 -05:00
{
if (m_instance == NULL) {
m_instance = new Inheritance();
2012-11-12 20:25:19 -05:00
}
return *m_instance;
2012-11-12 20:25:19 -05:00
}
const TypeNode * Inheritance::getType(const std::string & parent)
2012-11-12 20:25:19 -05:00
{
TypeNodeDict::const_iterator I = atlasObjects.find(parent);
if (I == atlasObjects.end()) {
return 0;
}
return I->second;
2012-11-12 20:25:19 -05:00
}
const Root & Inheritance::getClass(const std::string & parent)
2012-11-12 20:25:19 -05:00
{
return noClass;
2012-11-12 20:25:19 -05:00
}
void log(LogLevel lvl, const std::string & msg)
{
}
void hash_password(const std::string & pwd, const std::string & salt,
std::string & hash )
{
salt_length=salt.length();
}
void logEvent(LogEvent lev, const std::string & msg)
2012-11-12 20:25:19 -05:00
{
}
long integerId(const std::string & id)
{
long intId = strtol(id.c_str(), 0, 10);
if (intId == 0 && id != "0") {
intId = -1L;
}
return intId;
}
static long idGenerator = 0;
2012-11-12 20:25:19 -05:00
long newId(std::string & id)
2012-11-12 20:25:19 -05:00
{
static char buf[32];
long new_id = ++idGenerator;
sprintf(buf, "%ld", new_id);
id = buf;
assert(!id.empty());
return new_id;
2012-11-12 20:25:19 -05:00
}
void addToEntity(const Vector3D & v, std::vector<double> & vd)
2012-11-12 20:25:19 -05:00
{
vd.resize(3);
vd[0] = v[0];
vd[1] = v[1];
vd[2] = v[2];
2012-11-12 20:25:19 -05:00
}
int check_password(const std::string & pwd, const std::string & hash)
2012-11-12 20:25:19 -05:00
{
return 0;
2012-11-12 20:25:19 -05:00
}