Use one database class

This commit is contained in:
Akkadius 2019-07-03 21:56:24 -05:00
parent 7fcf6b51d8
commit ff5783965a
5 changed files with 14 additions and 173 deletions

View File

@ -13,7 +13,6 @@ SET(eqlogin_sources
SET(eqlogin_headers SET(eqlogin_headers
client.h client.h
client_manager.h client_manager.h
database.h
database_mysql.h database_mysql.h
encryption.h encryption.h
login_server.h login_server.h

View File

@ -1,148 +0,0 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2019 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* 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; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_DATABASE_H
#define EQEMU_DATABASE_H
#include <string>
#define EQEMU_MYSQL_ENABLED
/**
* Base database class, intended to be extended.
*/
class Database {
public:
Database() : user(""), pass(""), host(""), port(""), name("") {}
virtual ~Database() {}
virtual bool IsConnected() { return false; }
/**
* Retrieves the login data (password hash and account id) from the account name provided needed for client login procedure
*
* @param name
* @param loginserver
* @param password
* @param id
* @return
*/
virtual bool GetLoginDataFromAccountInfo(
const std::string &name,
const std::string &loginserver,
std::string &password,
unsigned int &id
) { return false; }
virtual bool GetLoginTokenDataFromToken(
const std::string &token,
const std::string &ip,
unsigned int &db_account_id,
std::string &db_loginserver,
std::string &user
) { return false; }
virtual bool CreateLoginData(
const std::string &name,
const std::string &password,
const std::string &loginserver,
unsigned int &id
) { return false; }
virtual bool CreateLoginDataWithID(
const std::string &name,
const std::string &password,
const std::string &loginserver,
unsigned int id
) { return false; }
virtual void UpdateLoginHash(const std::string &name, const std::string &loginserver, const std::string &hash) {}
virtual bool DoesLoginServerAccountExist(
const std::string &name,
const std::string &password,
const std::string &loginserver,
unsigned int id
) { return false; }
/**
* Retrieves the world registration from the long and short names provided
* Needed for world login procedure
* Returns true if the record was found, false otherwise
*
* @param long_name
* @param short_name
* @param id
* @param desc
* @param list_id
* @param trusted
* @param list_desc
* @param account
* @param password
* @return
*/
virtual bool GetWorldRegistration(
std::string long_name,
std::string short_name,
unsigned int &id,
std::string &desc,
unsigned int &list_id,
unsigned int &trusted,
std::string &list_desc,
std::string &account,
std::string &password
) { return false; }
virtual void UpdateLSAccountData(unsigned int id, std::string ip_address) {}
/**
* Updates or creates the login server account with info from world server
*
* @param id
* @param name
* @param password
* @param email
*/
virtual void UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email) {}
/**
* Updates the ip address of the world with account id = id
*
* @param id
* @param long_name
* @param ip_address
*/
virtual void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address) {}
/**
* Creates new world registration for unregistered servers and returns new id
*
* @param long_name
* @param short_name
* @param id
* @return
*/
virtual bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id) { return false; }
protected:
std::string user, pass, host, port, name;
};
#endif

View File

@ -19,9 +19,6 @@
*/ */
#include "../common/global_define.h" #include "../common/global_define.h"
#include "database.h"
#ifdef EQEMU_MYSQL_ENABLED
#include "database_mysql.h" #include "database_mysql.h"
#include "login_server.h" #include "login_server.h"
@ -605,5 +602,3 @@ bool DatabaseMySQL::CreateWorldRegistration(std::string long_name, std::string s
short_name.c_str()); short_name.c_str());
return false; return false;
} }
#endif

View File

@ -21,11 +21,8 @@
#ifndef EQEMU_DATABASEMYSQL_H #ifndef EQEMU_DATABASEMYSQL_H
#define EQEMU_DATABASEMYSQL_H #define EQEMU_DATABASEMYSQL_H
#include "database.h"
#include "../common/dbcore.h" #include "../common/dbcore.h"
#ifdef EQEMU_MYSQL_ENABLED
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <stdlib.h> #include <stdlib.h>
@ -50,8 +47,8 @@ public:
/** /**
* Destructor, frees our database if needed. * Destructor, frees our database if needed.
*/ */
virtual ~DatabaseMySQL(); ~DatabaseMySQL();
virtual bool IsConnected() { return (database != nullptr); } bool IsConnected() { return (database != nullptr); }
/** /**
* Retrieves the login data (password hash and account id) from the account name provided needed for client login procedure. * Retrieves the login data (password hash and account id) from the account name provided needed for client login procedure.
@ -61,36 +58,36 @@ public:
* @param id * @param id
* @return * @return
*/ */
virtual bool GetLoginDataFromAccountInfo( bool GetLoginDataFromAccountInfo(
const std::string &name, const std::string &name,
const std::string &loginserver, const std::string &loginserver,
std::string &password, std::string &password,
unsigned int &id unsigned int &id
); );
virtual bool GetLoginTokenDataFromToken( bool GetLoginTokenDataFromToken(
const std::string &token, const std::string &token,
const std::string &ip, const std::string &ip,
unsigned int &db_account_id, unsigned int &db_account_id,
std::string &db_loginserver, std::string &db_loginserver,
std::string &user std::string &user
); );
virtual unsigned int GetFreeID(const std::string &loginserver); unsigned int GetFreeID(const std::string &loginserver);
virtual bool CreateLoginData( bool CreateLoginData(
const std::string &name, const std::string &name,
const std::string &password, const std::string &password,
const std::string &loginserver, const std::string &loginserver,
unsigned int &id unsigned int &id
); );
virtual bool CreateLoginDataWithID( bool CreateLoginDataWithID(
const std::string &name, const std::string &name,
const std::string &password, const std::string &password,
const std::string &loginserver, const std::string &loginserver,
unsigned int id unsigned int id
); );
virtual void UpdateLoginHash(const std::string &name, const std::string &loginserver, const std::string &hash); void UpdateLoginHash(const std::string &name, const std::string &loginserver, const std::string &hash);
virtual bool DoesLoginServerAccountExist( bool DoesLoginServerAccountExist(
const std::string &name, const std::string &name,
const std::string &password, const std::string &password,
const std::string &loginserver, const std::string &loginserver,
@ -113,7 +110,7 @@ public:
* @param password * @param password
* @return * @return
*/ */
virtual bool GetWorldRegistration( bool GetWorldRegistration(
std::string long_name, std::string long_name,
std::string short_name, std::string short_name,
unsigned int &id, unsigned int &id,
@ -125,15 +122,14 @@ public:
std::string &password std::string &password
); );
virtual void UpdateLSAccountData(unsigned int id, std::string ip_address); void UpdateLSAccountData(unsigned int id, std::string ip_address);
virtual void UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email); void UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email);
virtual void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address); void UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address);
virtual bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id); bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id);
protected: protected:
std::string user, pass, host, port, name; std::string user, pass, host, port, name;
MYSQL *database; MYSQL *database;
}; };
#endif #endif
#endif

View File

@ -23,7 +23,6 @@
#define EQEMU_LOGINSERVER_H #define EQEMU_LOGINSERVER_H
#include "../common/json_config.h" #include "../common/json_config.h"
#include "database.h"
#include "database_mysql.h" #include "database_mysql.h"
#include "encryption.h" #include "encryption.h"
#include "options.h" #include "options.h"