This commit is contained in:
Akkadius 2019-07-03 02:16:16 -05:00
parent ea02042ace
commit 6638b9ade5
3 changed files with 337 additions and 234 deletions

View File

@ -1,24 +1,29 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net)
/**
* 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
*
*/
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
*/
#include "../common/global_define.h"
#include "database.h"
#ifdef EQEMU_MYSQL_ENABLED
#include "database_mysql.h"
#include "login_server.h"
#include "../common/eqemu_logsys.h"
@ -27,7 +32,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
extern LoginServer server;
DatabaseMySQL::DatabaseMySQL(std::string user, std::string pass, std::string host, std::string port, std::string name)
DatabaseMySQL::DatabaseMySQL(
std::string user,
std::string pass,
std::string host,
std::string port,
std::string name
)
{
this->user = user;
this->pass = pass;
@ -35,60 +46,67 @@ DatabaseMySQL::DatabaseMySQL(std::string user, std::string pass, std::string hos
this->name = name;
database = mysql_init(nullptr);
if (database)
{
if (database) {
char r = 1;
mysql_options(database, MYSQL_OPT_RECONNECT, &r);
if (!mysql_real_connect(database, host.c_str(), user.c_str(), pass.c_str(), name.c_str(), atoi(port.c_str()), nullptr, 0))
{
if (!mysql_real_connect(
database,
host.c_str(),
user.c_str(),
pass.c_str(),
name.c_str(),
atoi(port.c_str()),
nullptr,
0
)) {
mysql_close(database);
Log(Logs::General, Logs::Error, "Failed to connect to MySQL database. Error: %s", mysql_error(database));
exit(1);
}
}
else
{
else {
Log(Logs::General, Logs::Error, "Failed to create db object in MySQL database.");
}
}
DatabaseMySQL::~DatabaseMySQL()
{
if (database)
{
if (database) {
mysql_close(database);
}
}
bool DatabaseMySQL::GetLoginDataFromAccountInfo(const std::string &name, const std::string &loginserver, std::string &password, unsigned int &id)
bool DatabaseMySQL::GetLoginDataFromAccountInfo(
const std::string &name,
const std::string &loginserver,
std::string &password,
unsigned int &id
)
{
if (!database)
{
if (!database) {
return false;
}
MYSQL_RES *res;
MYSQL_ROW row;
std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT LoginServerID, AccountPassword FROM " << server.options.GetAccountTable() << " WHERE AccountName = '";
query << "SELECT LoginServerID, AccountPassword FROM " << server.options.GetAccountTable()
<< " WHERE AccountName = '";
query << EscapeString(name);
query << "' AND AccountLoginserver='";
query << EscapeString(loginserver);
query << "'";
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
LogF(Logs::General, Logs::Error, "Mysql query failed: {0}", query.str());
return false;
}
res = mysql_use_result(database);
if (res)
{
while ((row = mysql_fetch_row(res)) != nullptr)
{
id = atoi(row[0]);
if (res) {
while ((row = mysql_fetch_row(res)) != nullptr) {
id = atoi(row[0]);
password = row[1];
mysql_free_result(res);
return true;
@ -99,49 +117,53 @@ bool DatabaseMySQL::GetLoginDataFromAccountInfo(const std::string &name, const s
return false;
}
bool DatabaseMySQL::GetLoginTokenDataFromToken(const std::string &token, const std::string &ip, unsigned int &db_account_id, std::string &db_loginserver, std::string &user)
bool DatabaseMySQL::GetLoginTokenDataFromToken(
const std::string &token,
const std::string &ip,
unsigned int &db_account_id,
std::string &db_loginserver,
std::string &user
)
{
if (!database)
{
if (!database) {
return false;
}
MYSQL_RES *res;
MYSQL_ROW row;
std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT tbllogintokens.Id, tbllogintokens.IpAddress, tbllogintokenclaims.Name, tbllogintokenclaims.Value FROM tbllogintokens ";
query << "JOIN tbllogintokenclaims ON tbllogintokens.Id = tbllogintokenclaims.TokenId WHERE tbllogintokens.Expires > NOW() AND tbllogintokens.Id='";
query
<< "SELECT tbllogintokens.Id, tbllogintokens.IpAddress, tbllogintokenclaims.Name, tbllogintokenclaims.Value FROM tbllogintokens ";
query
<< "JOIN tbllogintokenclaims ON tbllogintokens.Id = tbllogintokenclaims.TokenId WHERE tbllogintokens.Expires > NOW() AND tbllogintokens.Id='";
query << EscapeString(token) << "' AND tbllogintokens.IpAddress='" << EscapeString(ip) << "'";
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false;
}
res = mysql_use_result(database);
bool found_username = false;
bool found_login_id = false;
bool found_username = false;
bool found_login_id = false;
bool found_login_server_name = false;
if (res)
{
while ((row = mysql_fetch_row(res)) != nullptr)
{
if (res) {
while ((row = mysql_fetch_row(res)) != nullptr) {
if (strcmp(row[2], "username") == 0) {
user = row[3];
user = row[3];
found_username = true;
continue;
}
if (strcmp(row[2], "login_server_id") == 0) {
db_account_id = atoi(row[3]);
db_account_id = atoi(row[3]);
found_login_id = true;
continue;
}
if (strcmp(row[2], "login_server_name") == 0) {
db_loginserver = row[3];
db_loginserver = row[3];
found_login_server_name = true;
continue;
}
@ -155,8 +177,7 @@ bool DatabaseMySQL::GetLoginTokenDataFromToken(const std::string &token, const s
unsigned int DatabaseMySQL::GetFreeID(const std::string &loginserver)
{
if (!database)
{
if (!database) {
return false;
}
@ -166,18 +187,15 @@ unsigned int DatabaseMySQL::GetFreeID(const std::string &loginserver)
query << "SELECT MAX(LoginServerID) + 1 FROM " << server.options.GetAccountTable() << " WHERE AccountLoginServer='";
query << EscapeString(loginserver) << "'";
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return 0;
}
res = mysql_use_result(database);
if (res)
{
while ((row = mysql_fetch_row(res)) != nullptr)
{
if (res) {
while ((row = mysql_fetch_row(res)) != nullptr) {
if (row[0] == nullptr) {
mysql_free_result(res);
return 1;
@ -194,12 +212,22 @@ unsigned int DatabaseMySQL::GetFreeID(const std::string &loginserver)
return 1;
}
bool DatabaseMySQL::CreateLoginData(const std::string &name, const std::string &password, const std::string &loginserver, unsigned int &id)
bool DatabaseMySQL::CreateLoginData(
const std::string &name,
const std::string &password,
const std::string &loginserver,
unsigned int &id
)
{
return CreateLoginDataWithID(name, password, loginserver, GetFreeID(loginserver));
}
bool DatabaseMySQL::CreateLoginDataWithID(const std::string & name, const std::string & password, const std::string & loginserver, unsigned int id)
bool DatabaseMySQL::CreateLoginDataWithID(
const std::string &name,
const std::string &password,
const std::string &loginserver,
unsigned int id
)
{
if (!database) {
return false;
@ -213,8 +241,10 @@ bool DatabaseMySQL::CreateLoginDataWithID(const std::string & name, const std::s
MYSQL_ROW row;
std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "INSERT INTO " << server.options.GetAccountTable() << " (LoginServerID, AccountLoginserver, AccountName, AccountPassword, AccountEmail, LastLoginDate, LastIPAddress) ";
query << " VALUES(" << id << ", '" << EscapeString(loginserver) << "', '" << EscapeString(name) << "', '" << EscapeString(password) << "', 'local_creation', NOW(), '127.0.0.1'); ";
query << "INSERT INTO " << server.options.GetAccountTable()
<< " (LoginServerID, AccountLoginserver, AccountName, AccountPassword, AccountEmail, LastLoginDate, LastIPAddress) ";
query << " VALUES(" << id << ", '" << EscapeString(loginserver) << "', '" << EscapeString(name) << "', '"
<< EscapeString(password) << "', 'local_creation', NOW(), '127.0.0.1'); ";
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
@ -226,82 +256,82 @@ bool DatabaseMySQL::CreateLoginDataWithID(const std::string & name, const std::s
void DatabaseMySQL::UpdateLoginHash(const std::string &name, const std::string &loginserver, const std::string &hash)
{
if (!database)
{
if (!database) {
return;
}
auto query = fmt::format("UPDATE {0} SET AccountPassword='{1}' WHERE AccountName='{2}' AND AccountLoginserver='{3}'",
auto query = fmt::format(
"UPDATE {0} SET AccountPassword='{1}' WHERE AccountName='{2}' AND AccountLoginserver='{3}'",
server.options.GetAccountTable(),
hash,
EscapeString(name),
EscapeString(loginserver));
if (mysql_query(database, query.c_str()) != 0)
{
if (mysql_query(database, query.c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.c_str());
}
}
bool DatabaseMySQL::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)
bool DatabaseMySQL::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
)
{
if (!database)
{
if (!database) {
return false;
}
MYSQL_RES *res;
MYSQL_ROW row;
char escaped_short_name[101];
MYSQL_RES *res;
MYSQL_ROW row;
char escaped_short_name[101];
unsigned long length;
length = mysql_real_escape_string(database, escaped_short_name, short_name.substr(0, 100).c_str(), short_name.substr(0, 100).length());
length = mysql_real_escape_string(
database,
escaped_short_name,
short_name.substr(0, 100).c_str(),
short_name.substr(0, 100).length());
escaped_short_name[length + 1] = 0;
std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT ifnull(WSR.ServerID,999999) AS ServerID, WSR.ServerTagDescription, ifnull(WSR.ServerTrusted,0) AS ServerTrusted, ifnull(SLT.ServerListTypeID,3) AS ServerListTypeID, ";
query << "SLT.ServerListTypeDescription, ifnull(WSR.ServerAdminID,0) AS ServerAdminID FROM " << server.options.GetWorldRegistrationTable();
query << " AS WSR JOIN " << server.options.GetWorldServerTypeTable() << " AS SLT ON WSR.ServerListTypeID = SLT.ServerListTypeID";
query
<< "SELECT ifnull(WSR.ServerID,999999) AS ServerID, WSR.ServerTagDescription, ifnull(WSR.ServerTrusted,0) AS ServerTrusted, ifnull(SLT.ServerListTypeID,3) AS ServerListTypeID, ";
query << "SLT.ServerListTypeDescription, ifnull(WSR.ServerAdminID,0) AS ServerAdminID FROM "
<< server.options.GetWorldRegistrationTable();
query << " AS WSR JOIN " << server.options.GetWorldServerTypeTable()
<< " AS SLT ON WSR.ServerListTypeID = SLT.ServerListTypeID";
query << " WHERE WSR.ServerShortName = '";
query << escaped_short_name;
query << "'";
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false;
}
res = mysql_use_result(database);
if (res)
{
if ((row = mysql_fetch_row(res)) != nullptr)
{
id = atoi(row[0]);
desc = row[1];
trusted = atoi(row[2]);
list_id = atoi(row[3]);
if (res) {
if ((row = mysql_fetch_row(res)) != nullptr) {
id = atoi(row[0]);
desc = row[1];
trusted = atoi(row[2]);
list_id = atoi(row[3]);
list_desc = row[4];
int db_account_id = atoi(row[5]);
mysql_free_result(res);
if (db_account_id > 0)
{
if (db_account_id > 0) {
std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT AccountName, AccountPassword FROM " << server.options.GetWorldAdminRegistrationTable();
query << " WHERE ServerAdminID = " << db_account_id;
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false;
}
res = mysql_use_result(database);
if (res)
{
if ((row = mysql_fetch_row(res)) != nullptr)
{
account = row[0];
if (res) {
if ((row = mysql_fetch_row(res)) != nullptr) {
account = row[0];
password = row[1];
mysql_free_result(res);
return true;
@ -321,8 +351,7 @@ bool DatabaseMySQL::GetWorldRegistration(std::string long_name, std::string shor
void DatabaseMySQL::UpdateLSAccountData(unsigned int id, std::string ip_address)
{
if (!database)
{
if (!database) {
return;
}
@ -332,16 +361,14 @@ void DatabaseMySQL::UpdateLSAccountData(unsigned int id, std::string ip_address)
query << "', LastLoginDate = now() where LoginServerID = ";
query << id;
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
}
}
void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email)
{
if (!database)
{
if (!database) {
return;
}
@ -351,67 +378,73 @@ void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, std::string name, std::
query << password << "'), AccountCreateDate = now(), AccountEmail = '" << email;
query << "', LastIPAddress = '0.0.0.0', LastLoginDate = now()";
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
}
}
void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address)
{
if (!database)
{
if (!database) {
return;
}
char escaped_long_name[101];
char escaped_long_name[101];
unsigned long length;
length = mysql_real_escape_string(database, escaped_long_name, long_name.substr(0, 100).c_str(), long_name.substr(0, 100).length());
length = mysql_real_escape_string(
database,
escaped_long_name,
long_name.substr(0, 100).c_str(),
long_name.substr(0, 100).length());
escaped_long_name[length + 1] = 0;
std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "UPDATE " << server.options.GetWorldRegistrationTable() << " SET ServerLastLoginDate = now(), ServerLastIPAddr = '";
query << "UPDATE " << server.options.GetWorldRegistrationTable()
<< " SET ServerLastLoginDate = now(), ServerLastIPAddr = '";
query << ip_address;
query << "', ServerLongName = '";
query << escaped_long_name;
query << "' WHERE ServerID = ";
query << id;
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
}
}
bool DatabaseMySQL::CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id)
{
if (!database)
{
if (!database) {
return false;
}
MYSQL_RES *res;
MYSQL_ROW row;
char escaped_long_name[201];
char escaped_short_name[101];
MYSQL_RES *res;
MYSQL_ROW row;
char escaped_long_name[201];
char escaped_short_name[101];
unsigned long length;
length = mysql_real_escape_string(database, escaped_long_name, long_name.substr(0, 100).c_str(), long_name.substr(0, 100).length());
length = mysql_real_escape_string(
database,
escaped_long_name,
long_name.substr(0, 100).c_str(),
long_name.substr(0, 100).length());
escaped_long_name[length + 1] = 0;
length = mysql_real_escape_string(database, escaped_short_name, short_name.substr(0, 100).c_str(), short_name.substr(0, 100).length());
length = mysql_real_escape_string(
database,
escaped_short_name,
short_name.substr(0, 100).c_str(),
short_name.substr(0, 100).length());
escaped_short_name[length + 1] = 0;
std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT ifnull(max(ServerID),0) FROM " << server.options.GetWorldRegistrationTable();
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false;
}
res = mysql_use_result(database);
if (res)
{
if ((row = mysql_fetch_row(res)) != nullptr)
{
if (res) {
if ((row = mysql_fetch_row(res)) != nullptr) {
id = atoi(row[0]) + 1;
mysql_free_result(res);
@ -420,15 +453,18 @@ bool DatabaseMySQL::CreateWorldRegistration(std::string long_name, std::string s
query << ", ServerLongName = '" << escaped_long_name << "', ServerShortName = '" << escaped_short_name;
query << "', ServerListTypeID = 3, ServerAdminID = 0, ServerTrusted = 0, ServerTagDescription = ''";
if (mysql_query(database, query.str().c_str()) != 0)
{
if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false;
}
return true;
}
}
Log(Logs::General, Logs::Error, "World registration did not exist in the database for %s %s", long_name.c_str(), short_name.c_str());
Log(Logs::General,
Logs::Error,
"World registration did not exist in the database for %s %s",
long_name.c_str(),
short_name.c_str());
return false;
}

View File

@ -1,24 +1,28 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net)
/**
* 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
*
*/
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_DATABASEMYSQL_H
#define EQEMU_DATABASEMYSQL_H
#include "database.h"
#ifdef EQEMU_MYSQL_ENABLED
#include <string>
@ -26,79 +30,99 @@
#include <stdlib.h>
#include <mysql.h>
/**
* Mysql Database class
*/
class DatabaseMySQL : public Database
{
class DatabaseMySQL : public Database {
public:
/**
* Constructor, sets our database to null.
*/
DatabaseMySQL() { database = nullptr; }
/**
* Constructor, tries to set our database to connect to the supplied options.
*/
* Constructor, tries to set our database to connect to the supplied options.
*
* @param user
* @param pass
* @param host
* @param port
* @param name
*/
DatabaseMySQL(std::string user, std::string pass, std::string host, std::string port, std::string name);
/**
* Destructor, frees our database if needed.
*/
* Destructor, frees our database if needed.
*/
virtual ~DatabaseMySQL();
/**
* @return Returns true if the database successfully connected.
*/
virtual bool IsConnected() { return (database != nullptr); }
/**
* Retrieves the login data (password hash and account id) from the account name provided
* Needed for client login procedure.
* Returns true if the record was found, false otherwise.
*/
virtual bool GetLoginDataFromAccountInfo(const std::string &name, const std::string &loginserver, std::string &password, unsigned int &id);
virtual bool GetLoginTokenDataFromToken(const std::string &token, const std::string &ip, unsigned int &db_account_id, std::string &db_loginserver, std::string &user);
* 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
);
virtual bool GetLoginTokenDataFromToken(
const std::string &token,
const std::string &ip,
unsigned int &db_account_id,
std::string &db_loginserver,
std::string &user
);
virtual unsigned int GetFreeID(const std::string &loginserver);
virtual bool CreateLoginData(const std::string &name, const std::string &password, const std::string &loginserver, unsigned int &id);
virtual bool CreateLoginDataWithID(const std::string &name, const std::string &password, const std::string &loginserver, unsigned int id);
virtual bool CreateLoginData(
const std::string &name,
const std::string &password,
const std::string &loginserver,
unsigned int &id
);
virtual bool CreateLoginDataWithID(
const std::string &name,
const std::string &password,
const std::string &loginserver,
unsigned int id
);
virtual void UpdateLoginHash(const std::string &name, const std::string &loginserver, const std::string &hash);
/**
* 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.
*/
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);
* 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
);
/**
* Updates the ip address of the client with account id = id
*/
virtual void UpdateLSAccountData(unsigned int id, std::string ip_address);
/**
* Updates or creates the login server account with info from world server
*/
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
*/
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
*/
virtual bool CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id);
protected:
std::string user, pass, host, port, name;
MYSQL *database;
MYSQL *database;
};
#endif

View File

@ -1,20 +1,23 @@
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2010 EQEMu Development Team (http://eqemulator.net)
/**
* 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
*
*/
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
*/
#include "../common/global_define.h"
#include "../common/types.h"
#include "../common/opcodemgr.h"
@ -31,7 +34,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
LoginServer server;
EQEmuLogSys LogSys;
bool run_server = true;
bool run_server = true;
void CatchSignal(int sig_num)
{
@ -41,9 +44,10 @@ int main()
{
RegisterExecutablePlatform(ExePlatformLogin);
set_exception_handler();
LogSys.LoadLogSettingsDefaults();
LogSys.log_settings[Logs::Error].log_to_console = Logs::General;
LogSys.log_settings[Logs::Error].log_to_console = Logs::General;
LogSys.log_settings[Logs::Error].is_category_enabled = 1;
Log(Logs::General, Logs::Login_Server, "Logging System Init.");
@ -59,8 +63,22 @@ int main()
server.options.RejectDuplicateServers(server.config.GetVariableBool("general", "reject_duplicate_servers", false));
server.options.AutoCreateAccounts(server.config.GetVariableBool("general", "auto_create_accounts", true));
server.options.AutoLinkAccounts(server.config.GetVariableBool("general", "auto_link_accounts", true));
server.options.EQEmuLoginServerAddress(server.config.GetVariableString("general", "eqemu_loginserver_address", "login.eqemulator.net:5999"));
server.options.DefaultLoginServerName(server.config.GetVariableString("general", "default_loginserver_name", "peq"));
server.options.EQEmuLoginServerAddress(
server.config.GetVariableString(
"general",
"eqemu_loginserver_address",
"login.eqemulator.net:5999"
)
);
server.options.DefaultLoginServerName(
server.config.GetVariableString(
"general",
"default_loginserver_name",
"peq"
)
);
#ifdef ENABLE_SECURITY
server.options.EncryptionMode(server.config.GetVariableInt("security", "mode", 13));
@ -70,49 +88,74 @@ int main()
server.options.AllowUnregistered(server.config.GetVariableBool("security", "unregistered_allowed", true));
server.options.AllowTokenLogin(server.config.GetVariableBool("security", "allow_token_login", false));
server.options.AllowPasswordLogin(server.config.GetVariableBool("security", "allow_password_login", true));
server.options.UpdateInsecurePasswords(server.config.GetVariableBool("security", "update_insecure_passwords", true));
server.options.UpdateInsecurePasswords(
server.config.GetVariableBool(
"security",
"update_insecure_passwords",
true
));
server.options.AccountTable(server.config.GetVariableString("schema", "account_table", "tblLoginServerAccounts"));
server.options.WorldRegistrationTable(server.config.GetVariableString("schema", "world_registration_table", "tblWorldServerRegistration"));
server.options.WorldAdminRegistrationTable(server.config.GetVariableString("schema", "world_admin_registration_table", "tblServerAdminRegistration"));
server.options.WorldServerTypeTable(server.config.GetVariableString("schema", "world_server_type_table", "tblServerListType"));
server.options.WorldRegistrationTable(
server.config.GetVariableString(
"schema",
"world_registration_table",
"tblWorldServerRegistration"
));
server.options.WorldAdminRegistrationTable(
server.config.GetVariableString(
"schema",
"world_admin_registration_table",
"tblServerAdminRegistration"
));
server.options.WorldServerTypeTable(
server.config.GetVariableString(
"schema",
"world_server_type_table",
"tblServerListType"
));
/* Create database connection */
/**
* mysql connect
*/
if (server.config.GetVariableString("database", "subsystem", "MySQL").compare("MySQL") == 0) {
#ifdef EQEMU_MYSQL_ENABLED
Log(Logs::General, Logs::Login_Server, "MySQL Database Init.");
server.db = (Database*)new DatabaseMySQL(
server.db = (Database *) new DatabaseMySQL(
server.config.GetVariableString("database", "user", "root"),
server.config.GetVariableString("database", "password", ""),
server.config.GetVariableString("database", "host", "localhost"),
server.config.GetVariableString("database", "port", "3306"),
server.config.GetVariableString("database", "db", "peq"));
#endif
server.config.GetVariableString("database", "db", "peq")
);
}
/* Make sure our database got created okay, otherwise cleanup and exit. */
/**
* Make sure our database got created okay, otherwise cleanup and exit
*/
if (!server.db) {
Log(Logs::General, Logs::Error, "Database Initialization Failure.");
Log(Logs::General, Logs::Login_Server, "Log System Shutdown.");
return 1;
}
//create our server manager.
/**
* create server manager
*/
Log(Logs::General, Logs::Login_Server, "Server Manager Initialize.");
server.server_manager = new ServerManager();
if (!server.server_manager) {
//We can't run without a server manager, cleanup and exit.
if (!server.server_manager)
Log(Logs::General, Logs::Error, "Server Manager Failed to Start.");
Log(Logs::General, Logs::Login_Server, "Database System Shutdown.");
delete server.db;
return 1;
}
//create our client manager.
/**
* create client manager
*/
Log(Logs::General, Logs::Login_Server, "Client Manager Initialize.");
server.client_manager = new ClientManager();
if (!server.client_manager) {
//We can't run without a client manager, cleanup and exit.
Log(Logs::General, Logs::Error, "Client Manager Failed to Start.");
Log(Logs::General, Logs::Login_Server, "Server Manager Shutdown.");
delete server.server_manager;
@ -124,9 +167,9 @@ int main()
#ifdef WIN32
#ifdef UNICODE
SetConsoleTitle(L"EQEmu Login Server");
SetConsoleTitle(L"EQEmu Login Server");
#else
SetConsoleTitle("EQEmu Login Server");
SetConsoleTitle("EQEmu Login Server");
#endif
#endif