2010-03-18 01:42:51 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
2010-03-18 01:51:46 +00:00
|
|
|
// Copyright (C) 2010 Alistair Riddoch
|
2010-03-18 01:42:51 +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
|
|
|
|
|
|
|
|
|
|
// $Id$
|
|
|
|
|
|
2011-02-15 09:30:46 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
|
#undef NDEBUG
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
|
#define DEBUG
|
|
|
|
|
#endif
|
|
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
#include "TestBase.h"
|
|
|
|
|
|
2010-03-18 01:42:51 +00:00
|
|
|
#include "server/Lobby.h"
|
|
|
|
|
|
|
|
|
|
#include "server/CommClient.h"
|
|
|
|
|
#include "server/Connection.h"
|
|
|
|
|
#include "server/Account.h"
|
|
|
|
|
|
|
|
|
|
#include <Atlas/Objects/RootOperation.h>
|
|
|
|
|
#include <Atlas/Objects/RootEntity.h>
|
|
|
|
|
#include <Atlas/Objects/SmartPtr.h>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
|
class TestAccount : public Account
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TestAccount() : Account(0, "bob", "foo", "2", 2) { }
|
|
|
|
|
|
|
|
|
|
virtual int characterError(const Operation &,
|
2010-12-03 22:01:22 +00:00
|
|
|
const Atlas::Objects::Root & ent,
|
2010-03-18 01:42:51 +00:00
|
|
|
OpVector & res) const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
class Lobbytest : public Cyphesis::TestBase
|
2010-03-18 01:42:51 +00:00
|
|
|
{
|
2012-12-29 13:09:38 +00:00
|
|
|
private:
|
|
|
|
|
Lobby * m_lobby;
|
|
|
|
|
public:
|
|
|
|
|
Lobbytest();
|
|
|
|
|
|
|
|
|
|
void setup();
|
|
|
|
|
void teardown();
|
|
|
|
|
|
|
|
|
|
void test_constructor();
|
|
|
|
|
void test_addAccount();
|
|
|
|
|
void test_delAccount();
|
|
|
|
|
void test_delAccount_empty();
|
|
|
|
|
void test_operation();
|
|
|
|
|
void test_addAccount_connected();
|
|
|
|
|
void test_operation_connected();
|
|
|
|
|
void test_operation_connected_other();
|
|
|
|
|
void test_operation_account();
|
|
|
|
|
void test_addToMessage();
|
|
|
|
|
void test_addToEntity();
|
|
|
|
|
};
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
Lobbytest::Lobbytest()
|
|
|
|
|
{
|
|
|
|
|
ADD_TEST(Lobbytest::test_constructor);
|
|
|
|
|
ADD_TEST(Lobbytest::test_addAccount);
|
|
|
|
|
ADD_TEST(Lobbytest::test_delAccount);
|
|
|
|
|
ADD_TEST(Lobbytest::test_delAccount_empty);
|
|
|
|
|
ADD_TEST(Lobbytest::test_operation);
|
|
|
|
|
ADD_TEST(Lobbytest::test_addAccount_connected);
|
|
|
|
|
ADD_TEST(Lobbytest::test_operation_connected);
|
|
|
|
|
ADD_TEST(Lobbytest::test_operation_connected_other);
|
|
|
|
|
ADD_TEST(Lobbytest::test_operation_account);
|
|
|
|
|
ADD_TEST(Lobbytest::test_addToMessage);
|
|
|
|
|
ADD_TEST(Lobbytest::test_addToEntity);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::setup()
|
|
|
|
|
{
|
|
|
|
|
m_lobby = new Lobby(*(ServerRouting*)0, "1", 1);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::teardown()
|
|
|
|
|
{
|
|
|
|
|
delete m_lobby;
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_constructor()
|
|
|
|
|
{
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_addAccount()
|
|
|
|
|
{
|
|
|
|
|
assert(m_lobby->getAccounts().size() == 0);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
m_lobby->addAccount(new TestAccount());
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
assert(m_lobby->getAccounts().size() == 1);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_delAccount()
|
|
|
|
|
{
|
|
|
|
|
assert(m_lobby->getAccounts().size() == 0);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
Account * tac = new TestAccount();
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
m_lobby->addAccount(tac);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
assert(m_lobby->getAccounts().size() == 1);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
m_lobby->delAccount(tac);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
assert(m_lobby->getAccounts().size() == 0);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_delAccount_empty()
|
|
|
|
|
{
|
|
|
|
|
assert(m_lobby->getAccounts().size() == 0);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
m_lobby->delAccount(new TestAccount());
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
assert(m_lobby->getAccounts().size() == 0);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_operation()
|
|
|
|
|
{
|
|
|
|
|
Atlas::Objects::Operation::RootOperation op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
m_lobby->operation(op, res);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_addAccount_connected()
|
|
|
|
|
{
|
|
|
|
|
Account * tac = new TestAccount();
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
tac->m_connection = new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"foo", "3", 3);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
m_lobby->addAccount(tac);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
Atlas::Objects::Operation::RootOperation op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
m_lobby->operation(op, res);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_operation_connected()
|
|
|
|
|
{
|
|
|
|
|
Account * tac = new TestAccount();
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
tac->m_connection = new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"foo", "3", 3);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
m_lobby->addAccount(tac);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
Atlas::Objects::Operation::RootOperation op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
op->setTo("3");
|
|
|
|
|
m_lobby->operation(op, res);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_operation_connected_other()
|
|
|
|
|
{
|
|
|
|
|
Account * tac = new TestAccount();
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
tac->m_connection = new Connection(*(CommSocket*)0,
|
|
|
|
|
*(ServerRouting*)0,
|
|
|
|
|
"foo", "3", 3);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
m_lobby->addAccount(tac);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
Atlas::Objects::Operation::RootOperation op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
op->setTo("2");
|
|
|
|
|
m_lobby->operation(op, res);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_operation_account()
|
|
|
|
|
{
|
|
|
|
|
Account * tac = new TestAccount();
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
m_lobby->addAccount(tac);
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
Atlas::Objects::Operation::RootOperation op;
|
|
|
|
|
OpVector res;
|
|
|
|
|
op->setTo("2");
|
|
|
|
|
m_lobby->operation(op, res);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_addToMessage()
|
|
|
|
|
{
|
|
|
|
|
m_lobby->addAccount(new TestAccount());
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
Atlas::Message::MapType e;
|
|
|
|
|
m_lobby->addToMessage(e);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
void Lobbytest::test_addToEntity()
|
|
|
|
|
{
|
|
|
|
|
m_lobby->addAccount(new TestAccount());
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
Atlas::Objects::Entity::RootEntity e;
|
|
|
|
|
m_lobby->addToEntity(e);
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
|
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
Lobbytest t;
|
2010-03-18 01:42:51 +00:00
|
|
|
|
2012-12-29 13:09:38 +00:00
|
|
|
return t.run();
|
2010-03-18 01:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stub functions
|
|
|
|
|
|
2012-12-29 13:12:43 +00:00
|
|
|
#include "common/log.h"
|
|
|
|
|
|
2010-03-18 01:42:51 +00:00
|
|
|
Account::Account(Connection * conn,
|
|
|
|
|
const std::string & uname,
|
|
|
|
|
const std::string & passwd,
|
|
|
|
|
const std::string & id,
|
|
|
|
|
long intId) :
|
2012-11-13 00:09:05 +00:00
|
|
|
ConnectableRouter(id, intId, conn),
|
2010-12-13 14:16:09 +00:00
|
|
|
m_username(uname), m_password(passwd)
|
2010-03-18 01:42:51 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Account::~Account()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char * Account::getType() const
|
|
|
|
|
{
|
|
|
|
|
return "testaccount";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::store() const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::addToMessage(Atlas::Message::MapType &) const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::addToEntity(const Atlas::Objects::Entity::RootEntity &) const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-12-04 20:39:35 +00:00
|
|
|
void Account::externalOperation(const Operation & op, Link &)
|
2012-11-13 23:33:23 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-18 01:42:51 +00:00
|
|
|
void Account::operation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-06 00:11:18 +00:00
|
|
|
void Account::createObject(const std::string & type_str,
|
|
|
|
|
const Atlas::Objects::Root & arg,
|
|
|
|
|
const Operation & op,
|
|
|
|
|
OpVector & res)
|
|
|
|
|
{
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
|
|
|
|
void Account::LogoutOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::CreateOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::SetOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::ImaginaryOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::TalkOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::LookOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::GetOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Account::OtherOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-13 00:09:05 +00:00
|
|
|
ConnectableRouter::ConnectableRouter(const std::string & id,
|
2010-12-13 14:16:09 +00:00
|
|
|
long iid,
|
|
|
|
|
Connection *c) :
|
|
|
|
|
Router(id, iid),
|
|
|
|
|
m_connection(c)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-13 00:09:05 +00:00
|
|
|
ConnectableRouter::~ConnectableRouter()
|
2010-12-13 14:16:09 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-01 20:31:29 +01: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
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Link::disconnect()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connection::Connection(CommSocket & client,
|
2010-03-18 01:42:51 +00:00
|
|
|
ServerRouting & svr,
|
|
|
|
|
const std::string & addr,
|
2010-11-26 16:15:39 +00:00
|
|
|
const std::string & id, long iid) :
|
2012-08-01 20:31:29 +01:00
|
|
|
Link(client, id, iid), m_obsolete(false),
|
2010-03-18 01:42:51 +00:00
|
|
|
m_server(svr)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Account * Connection::newAccount(const std::string & type,
|
|
|
|
|
const std::string & username,
|
|
|
|
|
const std::string & passwd,
|
|
|
|
|
const std::string & id, long intId)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Connection::verifyCredentials(const Account &,
|
|
|
|
|
const Atlas::Objects::Root &) const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection::~Connection()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-04 20:39:35 +00:00
|
|
|
void Connection::externalOperation(const Operation & op, Link &)
|
2012-11-13 23:33:23 +00:00
|
|
|
{
|
|
|
|
|
}
|
2010-03-18 01:42:51 +00:00
|
|
|
|
|
|
|
|
void Connection::operation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Connection::LoginOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Connection::LogoutOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Connection::CreateOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Connection::GetOperation(const Operation &, OpVector &)
|
|
|
|
|
{
|
|
|
|
|
}
|
2012-12-29 13:12:43 +00:00
|
|
|
|
|
|
|
|
Router::Router(const std::string & id, long intId) : m_id(id),
|
|
|
|
|
m_intId(intId)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Router::~Router()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Router::addToMessage(Atlas::Message::MapType & omap) const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Router::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Router::error(const Operation & op,
|
|
|
|
|
const std::string & errstring,
|
|
|
|
|
OpVector & res,
|
|
|
|
|
const std::string & to) const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
|
|
|
{
|
|
|
|
|
}
|