2010-07-28 15:59:01 +01:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2010 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
|
|
|
|
|
|
2010-07-28 15:59:01 +01:00
|
|
|
#include "server/ServerRouting.h"
|
|
|
|
|
|
|
|
|
|
#include "server/Account.h"
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "rules/simulation/BaseWorld.h"
|
2010-07-28 15:59:01 +01:00
|
|
|
#include "common/id.h"
|
|
|
|
|
#include "common/log.h"
|
2018-05-19 21:47:24 +02:00
|
|
|
#include "DatabaseNull.h"
|
2010-07-28 15:59:01 +01:00
|
|
|
|
|
|
|
|
#include <Atlas/Objects/Anonymous.h>
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
2018-05-19 21:47:24 +02:00
|
|
|
#include <server/Persistence.h>
|
2010-07-28 15:59:01 +01:00
|
|
|
|
|
|
|
|
class Entity;
|
|
|
|
|
|
|
|
|
|
static bool stub_deny_newid = false;
|
|
|
|
|
static bool stub_generate_accounts = false;
|
|
|
|
|
|
2018-07-24 21:18:50 +02:00
|
|
|
#include "TestWorld.h"
|
2010-07-28 15:59:01 +01:00
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
class TestRouter : public ConnectableRouter
|
2010-07-28 15:59:01 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2018-04-25 20:09:14 +02:00
|
|
|
TestRouter(const std::string &id, int iid) : ConnectableRouter(id, iid) { }
|
2010-07-28 15:59:01 +01:00
|
|
|
|
2017-07-01 15:26:47 +02:00
|
|
|
void externalOperation(const Operation &, Link &) override { }
|
|
|
|
|
void operation(const Operation &, OpVector &) override { }
|
2018-10-27 13:13:45 +02:00
|
|
|
|
|
|
|
|
void setConnection(Connection* connection) override {}
|
|
|
|
|
|
|
|
|
|
Connection* getConnection() const override {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2010-07-28 15:59:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class TestAccount : public Account {
|
|
|
|
|
public:
|
|
|
|
|
TestAccount(Connection * conn, const std::string & username,
|
|
|
|
|
const std::string & passwd,
|
|
|
|
|
const std::string & id, long intId) :
|
|
|
|
|
Account(conn, username, passwd, id, intId) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual int characterError(const Operation & op,
|
2010-12-03 22:01:22 +00:00
|
|
|
const Atlas::Objects::Root & ent,
|
2010-07-28 15:59:01 +01:00
|
|
|
OpVector & res) const {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
TestWorld world;
|
|
|
|
|
|
|
|
|
|
std::string ruleset = "test_rules";
|
|
|
|
|
std::string server_name = "test_svr";
|
|
|
|
|
std::string server_id, lobby_id;
|
|
|
|
|
long int_id, lobby_int_id;
|
|
|
|
|
|
|
|
|
|
if (((int_id = newId(server_id)) < 0) ||
|
|
|
|
|
((lobby_int_id = newId(lobby_id)) < 0)) {
|
|
|
|
|
std::cerr << "Unable to get server IDs newid";
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
|
|
|
|
server.addObject(new TestRouter(id, iid));
|
|
|
|
|
assert(server.getObjects().size() == 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
ConnectableRouter * r = new TestRouter(id, iid);
|
2010-07-28 15:59:01 +01:00
|
|
|
server.addObject(r);
|
|
|
|
|
assert(server.getObjects().size() == 1);
|
|
|
|
|
server.delObject(r);
|
|
|
|
|
assert(server.getObjects().size() == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
std::string id, id2;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
|
|
|
|
newId(id2);
|
|
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
ConnectableRouter * r = new TestRouter(id, iid);
|
2010-07-28 15:59:01 +01:00
|
|
|
server.addObject(r);
|
|
|
|
|
assert(server.getObjects().size() == 1);
|
|
|
|
|
|
2018-04-25 20:09:14 +02:00
|
|
|
ConnectableRouter * r2 = server.getObject(id);
|
2010-07-28 15:59:01 +01:00
|
|
|
assert(r == r2);
|
|
|
|
|
|
|
|
|
|
r2 = server.getObject(id2);
|
|
|
|
|
assert(0 == r2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
|
|
|
|
server.addAccount(new TestAccount(0, "bob", "", id, iid));
|
|
|
|
|
assert(server.getObjects().size() == 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
|
|
|
|
Account * ac = new TestAccount(0, "bob", "", id, iid);
|
|
|
|
|
server.addAccount(ac);;
|
|
|
|
|
assert(server.getObjects().size() == 1);
|
|
|
|
|
Account * rac = server.getAccountByName("bob");
|
|
|
|
|
assert(rac == ac);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2018-05-19 23:18:40 +02:00
|
|
|
DatabaseNull database;
|
|
|
|
|
Persistence persistence(database);
|
|
|
|
|
|
2010-07-28 15:59:01 +01:00
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
|
|
|
|
Account * ac = new TestAccount(0, "bob", "", id, iid);
|
|
|
|
|
server.addAccount(ac);;
|
|
|
|
|
assert(server.getObjects().size() == 1);
|
|
|
|
|
Account * rac = server.getAccountByName("alice");
|
|
|
|
|
assert(rac == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2018-05-19 21:47:24 +02:00
|
|
|
DatabaseNull database;
|
|
|
|
|
Persistence persistence(database);
|
2010-07-28 15:59:01 +01:00
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
|
|
|
|
Account * rac = server.getAccountByName("alice");
|
|
|
|
|
assert(rac == 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
stub_generate_accounts = true;
|
2018-05-19 21:47:24 +02:00
|
|
|
DatabaseNull database;
|
|
|
|
|
Persistence persistence(database);
|
2010-07-28 15:59:01 +01:00
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
|
|
|
|
Account * rac = server.getAccountByName("alice");
|
|
|
|
|
assert(rac != 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
Atlas::Message::MapType map;
|
|
|
|
|
server.addToMessage(map);
|
|
|
|
|
restricted_flag = true;
|
|
|
|
|
server.addToMessage(map);
|
|
|
|
|
restricted_flag = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
ServerRouting server(world, ruleset, server_name,
|
|
|
|
|
server_id, int_id,
|
|
|
|
|
lobby_id, lobby_int_id);
|
|
|
|
|
|
|
|
|
|
Atlas::Objects::Entity::Anonymous ent;
|
|
|
|
|
server.addToEntity(ent);
|
|
|
|
|
restricted_flag = true;
|
|
|
|
|
server.addToEntity(ent);
|
|
|
|
|
restricted_flag = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
#include "server/Lobby.h"
|
|
|
|
|
#include "server/Persistence.h"
|
|
|
|
|
|
|
|
|
|
#include "common/const.h"
|
|
|
|
|
#include "common/Monitors.h"
|
|
|
|
|
#include "common/Variable.h"
|
|
|
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
2018-05-19 21:47:24 +02:00
|
|
|
#include "stubs/common/stubDatabase.h"
|
2018-08-05 20:47:09 +02:00
|
|
|
#include "stubs/server/stubAccount.h"
|
2018-10-27 13:13:45 +02:00
|
|
|
#include "stubs/server/stubConnectableRouter.h"
|
2010-07-28 15:59:01 +01:00
|
|
|
|
2018-05-19 21:47:24 +02:00
|
|
|
#define STUB_Persistence_getAccount
|
2010-07-28 15:59:01 +01:00
|
|
|
Account * Persistence::getAccount(const std::string & name)
|
|
|
|
|
{
|
|
|
|
|
if (!stub_generate_accounts) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string id;
|
|
|
|
|
int iid = newId(id);
|
|
|
|
|
assert(iid >= 0);
|
|
|
|
|
|
|
|
|
|
return new TestAccount(0, name, "", id, iid);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-19 21:47:24 +02:00
|
|
|
#include "stubs/server/stubPersistence.h"
|
2010-07-28 15:59:01 +01:00
|
|
|
|
|
|
|
|
Lobby::Lobby(ServerRouting & s, const std::string & id, long intId) :
|
|
|
|
|
Router(id, intId),
|
|
|
|
|
m_server(s)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Lobby::~Lobby()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-04 20:39:35 +00:00
|
|
|
void Lobby::externalOperation(const Operation &, Link &)
|
2012-11-13 23:33:23 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 15:59:01 +01:00
|
|
|
void Lobby::operation(const Operation & op, OpVector & res)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Lobby::addToMessage(Atlas::Message::MapType & omap) const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Lobby::addToEntity(const Atlas::Objects::Entity::RootEntity & ent) const
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 14:50:45 +02:00
|
|
|
#include "stubs/common/stubVariable.h"
|
|
|
|
|
#include "stubs/common/stubMonitors.h"
|
2016-01-20 16:14:21 +01:00
|
|
|
#include "stubs/server/stubBuildid.h"
|
2010-07-28 15:59:01 +01:00
|
|
|
|
|
|
|
|
bool_config_register::bool_config_register(bool & var,
|
|
|
|
|
const char * section,
|
|
|
|
|
const char * setting,
|
|
|
|
|
const char * help)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-27 13:13:45 +02:00
|
|
|
#include "stubs/common/stubRouter.h"
|
2010-07-28 15:59:01 +01:00
|
|
|
|
2018-07-25 00:16:09 +02:00
|
|
|
#ifndef STUB_BaseWorld_getEntity
|
|
|
|
|
#define STUB_BaseWorld_getEntity
|
2018-08-05 20:47:09 +02:00
|
|
|
Ref<LocatedEntity> BaseWorld::getEntity(const std::string & id) const
|
2010-07-28 15:59:01 +01:00
|
|
|
{
|
2018-07-25 00:16:09 +02:00
|
|
|
return getEntity(integerId(id));
|
2010-07-28 15:59:01 +01:00
|
|
|
}
|
|
|
|
|
|
2018-08-05 20:47:09 +02:00
|
|
|
Ref<LocatedEntity> BaseWorld::getEntity(long id) const
|
2010-07-28 15:59:01 +01:00
|
|
|
{
|
2018-07-25 00:16:09 +02:00
|
|
|
auto I = m_eobjects.find(id);
|
|
|
|
|
if (I != m_eobjects.end()) {
|
|
|
|
|
assert(I->second);
|
|
|
|
|
return I->second;
|
|
|
|
|
} else {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2010-07-28 15:59:01 +01:00
|
|
|
}
|
2018-07-25 00:16:09 +02:00
|
|
|
#endif //STUB_BaseWorld_getEntity
|
|
|
|
|
|
2018-11-03 16:43:33 +01:00
|
|
|
#include "stubs/rules/simulation/stubBaseWorld.h"
|
2010-07-28 15:59:01 +01:00
|
|
|
|
2014-02-03 12:19:42 +01:00
|
|
|
|
2010-07-28 15:59:01 +01:00
|
|
|
static long idGenerator = 0;
|
|
|
|
|
|
|
|
|
|
long newId(std::string & id)
|
|
|
|
|
{
|
|
|
|
|
if (stub_deny_newid) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
static char buf[32];
|
|
|
|
|
long new_id = ++idGenerator;
|
|
|
|
|
sprintf(buf, "%ld", new_id);
|
|
|
|
|
id = buf;
|
|
|
|
|
assert(!id.empty());
|
|
|
|
|
return new_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long integerId(const std::string & id)
|
|
|
|
|
{
|
|
|
|
|
long intId = strtol(id.c_str(), 0, 10);
|
|
|
|
|
if (intId == 0 && id != "0") {
|
|
|
|
|
intId = -1L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return intId;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-15 00:16:17 +01:00
|
|
|
const char * const CYPHESIS = "cyphesis";
|
2010-07-28 15:59:01 +01:00
|
|
|
|
|
|
|
|
static const char * DEFAULT_INSTANCE = "cyphesis";
|
|
|
|
|
|
|
|
|
|
std::string instance(DEFAULT_INSTANCE);
|
|
|
|
|
int timeoffset = 0;
|
|
|
|
|
bool database_flag = false;
|
2018-02-06 10:26:54 +01:00
|
|
|
std::string assets_directory = "";
|
2010-07-28 15:59:01 +01:00
|
|
|
|
|
|
|
|
namespace consts {
|
|
|
|
|
const char * version = "test_version";
|
|
|
|
|
}
|
2012-10-25 10:42:24 -04:00
|
|
|
|
|
|
|
|
#include <common/Shaker.h>
|
|
|
|
|
|
|
|
|
|
Shaker::Shaker()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Shaker::generateSalt(size_t length)
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|