2006-12-07 08:22:33 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
|
|
|
|
// Copyright (C) 2006 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
|
|
|
|
|
|
2011-04-20 20:03:30 +01:00
|
|
|
#include "common/Storage.h"
|
2006-12-07 08:22:33 +00:00
|
|
|
|
2010-03-27 01:06:20 +00:00
|
|
|
#include "common/log.h"
|
|
|
|
|
|
2006-12-07 08:22:33 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2010-03-27 01:06:20 +00:00
|
|
|
bool test_newid_fail = false;
|
|
|
|
|
|
2006-12-07 08:22:33 +00:00
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage a;
|
2006-12-07 08:22:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2006-12-07 08:22:33 +00:00
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 01:06:20 +00:00
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
a->init();
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
a->putAccount(acc);
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["username"] = 1;
|
|
|
|
|
a->putAccount(acc);
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["username"] = "fred";
|
|
|
|
|
a->putAccount(acc);
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["username"] = "fred";
|
|
|
|
|
acc["password"] = 1;
|
|
|
|
|
a->putAccount(acc);
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["username"] = "fred";
|
|
|
|
|
acc["password"] = "bob";
|
|
|
|
|
a->putAccount(acc);
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["username"] = "fred";
|
|
|
|
|
acc["password"] = "bob";
|
|
|
|
|
acc["type"] = "admin";
|
|
|
|
|
a->putAccount(acc);
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test_newid_fail = true;
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["username"] = "fred";
|
|
|
|
|
acc["password"] = "bob";
|
|
|
|
|
a->putAccount(acc);
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
test_newid_fail = false;
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
a->modAccount(acc, "1");
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["type"] = 1;
|
|
|
|
|
a->modAccount(acc, "1");
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["type"] = "admin";
|
|
|
|
|
a->modAccount(acc, "1");
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["password"] = 1;
|
|
|
|
|
a->modAccount(acc, "1");
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["password"] = "bill";
|
|
|
|
|
a->modAccount(acc, "1");
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
acc["password"] = "bill";
|
|
|
|
|
acc["type"] = "admin";
|
|
|
|
|
a->modAccount(acc, "1");
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
a->delAccount("1");
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
2011-04-20 20:10:53 +01:00
|
|
|
Storage * a = new Storage;
|
2010-03-27 01:06:20 +00:00
|
|
|
|
|
|
|
|
Atlas::Message::MapType acc;
|
|
|
|
|
a->getAccount("1", acc);
|
|
|
|
|
|
|
|
|
|
delete a;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// stubs
|
|
|
|
|
|
|
|
|
|
bool database_flag = true;
|
|
|
|
|
|
|
|
|
|
void log(LogLevel lvl, const std::string & msg)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Database * Database::m_instance = NULL;
|
|
|
|
|
|
|
|
|
|
Database * Database::instance()
|
|
|
|
|
{
|
|
|
|
|
if (m_instance == NULL) {
|
|
|
|
|
m_instance = new Database();
|
|
|
|
|
}
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Database::Database() : m_rule_db("rules"),
|
|
|
|
|
m_queryInProgress(false),
|
|
|
|
|
m_connection(NULL)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Database::initConnection()
|
|
|
|
|
{
|
2006-12-07 08:22:33 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2010-03-27 01:06:20 +00:00
|
|
|
|
2011-09-28 22:54:35 +01:00
|
|
|
int Database::initRule(bool)
|
2011-04-21 11:13:42 +01:00
|
|
|
{
|
2011-09-28 22:54:35 +01:00
|
|
|
return 0;
|
2011-04-21 11:13:42 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-27 01:06:20 +00:00
|
|
|
void Database::shutdownConnection()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long Database::newId(std::string & id)
|
|
|
|
|
{
|
|
|
|
|
if (test_newid_fail) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DatabaseResult Database::selectSimpleRowBy(const std::string & name,
|
|
|
|
|
const std::string & column,
|
|
|
|
|
const std::string & value)
|
|
|
|
|
{
|
|
|
|
|
return DatabaseResult(0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::updateSimpleRow(const std::string & name,
|
2010-03-27 01:06:20 +00:00
|
|
|
const std::string & key,
|
|
|
|
|
const std::string & value,
|
|
|
|
|
const std::string & columns)
|
|
|
|
|
{
|
2011-09-29 12:11:15 +01:00
|
|
|
return 0;
|
2010-03-27 01:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 12:11:15 +01:00
|
|
|
int Database::createSimpleRow(const std::string & name,
|
2010-03-27 01:06:20 +00:00
|
|
|
const std::string & id,
|
|
|
|
|
const std::string & columns,
|
|
|
|
|
const std::string & values)
|
|
|
|
|
{
|
2011-09-29 12:11:15 +01:00
|
|
|
return 0;
|
2010-03-27 01:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-29 10:31:41 +01:00
|
|
|
int Database::clearTable(const std::string & table)
|
2011-04-20 23:10:03 +01:00
|
|
|
{
|
2011-09-29 10:31:41 +01:00
|
|
|
return 0;
|
2011-04-20 23:10:03 +01:00
|
|
|
}
|
|
|
|
|
|
2011-09-28 22:32:39 +01:00
|
|
|
int Database::clearPendingQuery()
|
2011-04-20 23:10:03 +01:00
|
|
|
{
|
2011-09-28 22:32:39 +01:00
|
|
|
return 0;
|
2011-04-20 23:10:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Database::hasKey(const std::string & table, const std::string & key)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-28 23:28:47 +01:00
|
|
|
int Database::putObject(const std::string & table,
|
2011-04-20 23:10:03 +01:00
|
|
|
const std::string & key,
|
|
|
|
|
const Atlas::Message::MapType & o,
|
|
|
|
|
const StringVector & c)
|
|
|
|
|
{
|
2011-09-28 23:28:47 +01:00
|
|
|
return 0;
|
2011-04-20 23:10:03 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-27 01:06:20 +00:00
|
|
|
const char * DatabaseResult::field(const char * column, int row) const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void encrypt_password(const std::string & pwd, std::string & hash)
|
|
|
|
|
{
|
|
|
|
|
hash = pwd;
|
|
|
|
|
}
|