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 * This program is free software; you can redistribute it and/or modify
the Free Software Foundation; version 2 of the License. * 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 * This program is distributed in the hope that it will be useful,
are required to give you total support for your newly bought product; * but WITHOUT ANY WARRANTY except by those people which sell it, which
without even the implied warranty of MERCHANTABILITY or FITNESS FOR * are required to give you total support for your newly bought product;
A PARTICULAR PURPOSE. See the GNU General Public License for more details. * 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 * You should have received a copy of the GNU General Public License
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 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/global_define.h"
#include "database.h" #include "database.h"
#ifdef EQEMU_MYSQL_ENABLED #ifdef EQEMU_MYSQL_ENABLED
#include "database_mysql.h" #include "database_mysql.h"
#include "login_server.h" #include "login_server.h"
#include "../common/eqemu_logsys.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; 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->user = user;
this->pass = pass; this->pass = pass;
@ -35,59 +46,66 @@ DatabaseMySQL::DatabaseMySQL(std::string user, std::string pass, std::string hos
this->name = name; this->name = name;
database = mysql_init(nullptr); database = mysql_init(nullptr);
if (database) if (database) {
{
char r = 1; char r = 1;
mysql_options(database, MYSQL_OPT_RECONNECT, &r); 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); mysql_close(database);
Log(Logs::General, Logs::Error, "Failed to connect to MySQL database. Error: %s", mysql_error(database)); Log(Logs::General, Logs::Error, "Failed to connect to MySQL database. Error: %s", mysql_error(database));
exit(1); exit(1);
} }
} }
else else {
{
Log(Logs::General, Logs::Error, "Failed to create db object in MySQL database."); Log(Logs::General, Logs::Error, "Failed to create db object in MySQL database.");
} }
} }
DatabaseMySQL::~DatabaseMySQL() DatabaseMySQL::~DatabaseMySQL()
{ {
if (database) if (database) {
{
mysql_close(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,
if (!database) const std::string &loginserver,
std::string &password,
unsigned int &id
)
{ {
if (!database) {
return false; return false;
} }
MYSQL_RES *res; MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
std::stringstream query(std::stringstream::in | std::stringstream::out); 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 << EscapeString(name);
query << "' AND AccountLoginserver='"; query << "' AND AccountLoginserver='";
query << EscapeString(loginserver); query << EscapeString(loginserver);
query << "'"; 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()); LogF(Logs::General, Logs::Error, "Mysql query failed: {0}", query.str());
return false; return false;
} }
res = mysql_use_result(database); res = mysql_use_result(database);
if (res) if (res) {
{ while ((row = mysql_fetch_row(res)) != nullptr) {
while ((row = mysql_fetch_row(res)) != nullptr)
{
id = atoi(row[0]); id = atoi(row[0]);
password = row[1]; password = row[1];
mysql_free_result(res); mysql_free_result(res);
@ -99,22 +117,28 @@ bool DatabaseMySQL::GetLoginDataFromAccountInfo(const std::string &name, const s
return false; 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,
if (!database) const std::string &ip,
unsigned int &db_account_id,
std::string &db_loginserver,
std::string &user
)
{ {
if (!database) {
return false; return false;
} }
MYSQL_RES *res; MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
std::stringstream query(std::stringstream::in | std::stringstream::out); std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT tbllogintokens.Id, tbllogintokens.IpAddress, tbllogintokenclaims.Name, tbllogintokenclaims.Value FROM tbllogintokens "; query
query << "JOIN tbllogintokenclaims ON tbllogintokens.Id = tbllogintokenclaims.TokenId WHERE tbllogintokens.Expires > NOW() AND tbllogintokens.Id='"; << "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) << "'"; 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()); Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false; return false;
} }
@ -124,10 +148,8 @@ bool DatabaseMySQL::GetLoginTokenDataFromToken(const std::string &token, const s
bool found_username = false; bool found_username = false;
bool found_login_id = false; bool found_login_id = false;
bool found_login_server_name = false; bool found_login_server_name = false;
if (res) if (res) {
{ while ((row = mysql_fetch_row(res)) != nullptr) {
while ((row = mysql_fetch_row(res)) != nullptr)
{
if (strcmp(row[2], "username") == 0) { if (strcmp(row[2], "username") == 0) {
user = row[3]; user = row[3];
found_username = true; found_username = true;
@ -155,8 +177,7 @@ bool DatabaseMySQL::GetLoginTokenDataFromToken(const std::string &token, const s
unsigned int DatabaseMySQL::GetFreeID(const std::string &loginserver) unsigned int DatabaseMySQL::GetFreeID(const std::string &loginserver)
{ {
if (!database) if (!database) {
{
return false; 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 << "SELECT MAX(LoginServerID) + 1 FROM " << server.options.GetAccountTable() << " WHERE AccountLoginServer='";
query << EscapeString(loginserver) << "'"; 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()); Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return 0; return 0;
} }
res = mysql_use_result(database); res = mysql_use_result(database);
if (res) if (res) {
{ while ((row = mysql_fetch_row(res)) != nullptr) {
while ((row = mysql_fetch_row(res)) != nullptr)
{
if (row[0] == nullptr) { if (row[0] == nullptr) {
mysql_free_result(res); mysql_free_result(res);
return 1; return 1;
@ -194,12 +212,22 @@ unsigned int DatabaseMySQL::GetFreeID(const std::string &loginserver)
return 1; 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)); 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) { if (!database) {
return false; return false;
@ -213,8 +241,10 @@ bool DatabaseMySQL::CreateLoginDataWithID(const std::string & name, const std::s
MYSQL_ROW row; MYSQL_ROW row;
std::stringstream query(std::stringstream::in | std::stringstream::out); std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "INSERT INTO " << server.options.GetAccountTable() << " (LoginServerID, AccountLoginserver, AccountName, AccountPassword, AccountEmail, LastLoginDate, LastIPAddress) "; query << "INSERT INTO " << server.options.GetAccountTable()
query << " VALUES(" << id << ", '" << EscapeString(loginserver) << "', '" << EscapeString(name) << "', '" << EscapeString(password) << "', 'local_creation', NOW(), '127.0.0.1'); "; << " (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) { if (mysql_query(database, query.str().c_str()) != 0) {
Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str()); Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
@ -226,28 +256,28 @@ 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) void DatabaseMySQL::UpdateLoginHash(const std::string &name, const std::string &loginserver, const std::string &hash)
{ {
if (!database) if (!database) {
{
return; 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(), server.options.GetAccountTable(),
hash, hash,
EscapeString(name), EscapeString(name),
EscapeString(loginserver)); 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()); 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, bool DatabaseMySQL::GetWorldRegistration(
unsigned int &trusted, std::string &list_desc, std::string &account, std::string &password) 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; return false;
} }
@ -255,27 +285,31 @@ bool DatabaseMySQL::GetWorldRegistration(std::string long_name, std::string shor
MYSQL_ROW row; MYSQL_ROW row;
char escaped_short_name[101]; char escaped_short_name[101];
unsigned long length; 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; escaped_short_name[length + 1] = 0;
std::stringstream query(std::stringstream::in | std::stringstream::out); 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
query << "SLT.ServerListTypeDescription, ifnull(WSR.ServerAdminID,0) AS ServerAdminID FROM " << server.options.GetWorldRegistrationTable(); << "SELECT ifnull(WSR.ServerID,999999) AS ServerID, WSR.ServerTagDescription, ifnull(WSR.ServerTrusted,0) AS ServerTrusted, ifnull(SLT.ServerListTypeID,3) AS ServerListTypeID, ";
query << " AS WSR JOIN " << server.options.GetWorldServerTypeTable() << " AS SLT ON WSR.ServerListTypeID = SLT.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 << " WHERE WSR.ServerShortName = '";
query << escaped_short_name; query << escaped_short_name;
query << "'"; 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()); Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false; return false;
} }
res = mysql_use_result(database); res = mysql_use_result(database);
if (res) if (res) {
{ if ((row = mysql_fetch_row(res)) != nullptr) {
if ((row = mysql_fetch_row(res)) != nullptr)
{
id = atoi(row[0]); id = atoi(row[0]);
desc = row[1]; desc = row[1];
trusted = atoi(row[2]); trusted = atoi(row[2]);
@ -284,23 +318,19 @@ bool DatabaseMySQL::GetWorldRegistration(std::string long_name, std::string shor
int db_account_id = atoi(row[5]); int db_account_id = atoi(row[5]);
mysql_free_result(res); mysql_free_result(res);
if (db_account_id > 0) if (db_account_id > 0) {
{
std::stringstream query(std::stringstream::in | std::stringstream::out); std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT AccountName, AccountPassword FROM " << server.options.GetWorldAdminRegistrationTable(); query << "SELECT AccountName, AccountPassword FROM " << server.options.GetWorldAdminRegistrationTable();
query << " WHERE ServerAdminID = " << db_account_id; 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()); Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false; return false;
} }
res = mysql_use_result(database); res = mysql_use_result(database);
if (res) if (res) {
{ if ((row = mysql_fetch_row(res)) != nullptr) {
if ((row = mysql_fetch_row(res)) != nullptr)
{
account = row[0]; account = row[0];
password = row[1]; password = row[1];
mysql_free_result(res); mysql_free_result(res);
@ -321,8 +351,7 @@ bool DatabaseMySQL::GetWorldRegistration(std::string long_name, std::string shor
void DatabaseMySQL::UpdateLSAccountData(unsigned int id, std::string ip_address) void DatabaseMySQL::UpdateLSAccountData(unsigned int id, std::string ip_address)
{ {
if (!database) if (!database) {
{
return; return;
} }
@ -332,16 +361,14 @@ void DatabaseMySQL::UpdateLSAccountData(unsigned int id, std::string ip_address)
query << "', LastLoginDate = now() where LoginServerID = "; query << "', LastLoginDate = now() where LoginServerID = ";
query << id; 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()); 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) void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, std::string name, std::string password, std::string email)
{ {
if (!database) if (!database) {
{
return; return;
} }
@ -351,41 +378,42 @@ void DatabaseMySQL::UpdateLSAccountInfo(unsigned int id, std::string name, std::
query << password << "'), AccountCreateDate = now(), AccountEmail = '" << email; query << password << "'), AccountCreateDate = now(), AccountEmail = '" << email;
query << "', LastIPAddress = '0.0.0.0', LastLoginDate = now()"; 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()); 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) void DatabaseMySQL::UpdateWorldRegistration(unsigned int id, std::string long_name, std::string ip_address)
{ {
if (!database) if (!database) {
{
return; return;
} }
char escaped_long_name[101]; char escaped_long_name[101];
unsigned long length; 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; escaped_long_name[length + 1] = 0;
std::stringstream query(std::stringstream::in | std::stringstream::out); 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 << ip_address;
query << "', ServerLongName = '"; query << "', ServerLongName = '";
query << escaped_long_name; query << escaped_long_name;
query << "' WHERE ServerID = "; query << "' WHERE ServerID = ";
query << id; 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()); 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) bool DatabaseMySQL::CreateWorldRegistration(std::string long_name, std::string short_name, unsigned int &id)
{ {
if (!database) if (!database) {
{
return false; return false;
} }
@ -394,24 +422,29 @@ bool DatabaseMySQL::CreateWorldRegistration(std::string long_name, std::string s
char escaped_long_name[201]; char escaped_long_name[201];
char escaped_short_name[101]; char escaped_short_name[101];
unsigned long length; 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; 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; escaped_short_name[length + 1] = 0;
std::stringstream query(std::stringstream::in | std::stringstream::out); std::stringstream query(std::stringstream::in | std::stringstream::out);
query << "SELECT ifnull(max(ServerID),0) FROM " << server.options.GetWorldRegistrationTable(); 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()); Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false; return false;
} }
res = mysql_use_result(database); res = mysql_use_result(database);
if (res) if (res) {
{ if ((row = mysql_fetch_row(res)) != nullptr) {
if ((row = mysql_fetch_row(res)) != nullptr)
{
id = atoi(row[0]) + 1; id = atoi(row[0]) + 1;
mysql_free_result(res); 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 << ", ServerLongName = '" << escaped_long_name << "', ServerShortName = '" << escaped_short_name;
query << "', ServerListTypeID = 3, ServerAdminID = 0, ServerTrusted = 0, ServerTagDescription = ''"; 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()); Log(Logs::General, Logs::Error, "Mysql query failed: %s", query.str().c_str());
return false; return false;
} }
return true; 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; 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 * This program is free software; you can redistribute it and/or modify
the Free Software Foundation; version 2 of the License. * 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 * This program is distributed in the hope that it will be useful,
are required to give you total support for your newly bought product; * but WITHOUT ANY WARRANTY except by those people which sell it, which
without even the implied warranty of MERCHANTABILITY or FITNESS FOR * are required to give you total support for your newly bought product;
A PARTICULAR PURPOSE. See the GNU General Public License for more details. * 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 * You should have received a copy of the GNU General Public License
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 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 #ifndef EQEMU_DATABASEMYSQL_H
#define EQEMU_DATABASEMYSQL_H #define EQEMU_DATABASEMYSQL_H
#include "database.h" #include "database.h"
#ifdef EQEMU_MYSQL_ENABLED #ifdef EQEMU_MYSQL_ENABLED
#include <string> #include <string>
@ -26,19 +30,19 @@
#include <stdlib.h> #include <stdlib.h>
#include <mysql.h> #include <mysql.h>
/** class DatabaseMySQL : public Database {
* Mysql Database class
*/
class DatabaseMySQL : public Database
{
public: public:
/**
* Constructor, sets our database to null.
*/
DatabaseMySQL() { database = nullptr; } 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); DatabaseMySQL(std::string user, std::string pass, std::string host, std::string port, std::string name);
@ -46,55 +50,75 @@ public:
* Destructor, frees our database if needed. * Destructor, frees our database if needed.
*/ */
virtual ~DatabaseMySQL(); virtual ~DatabaseMySQL();
/**
* @return Returns true if the database successfully connected.
*/
virtual bool IsConnected() { return (database != nullptr); } virtual bool IsConnected() { return (database != nullptr); }
/** /**
* Retrieves the login data (password hash and account id) from the account name provided * Retrieves the login data (password hash and account id) from the account name provided needed for client login procedure.
* Needed for client login procedure. * @param name
* Returns true if the record was found, false otherwise. * @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 GetLoginDataFromAccountInfo(
const std::string &name,
virtual bool GetLoginTokenDataFromToken(const std::string &token, const std::string &ip, unsigned int &db_account_id, std::string &db_loginserver, std::string &user); 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 unsigned int GetFreeID(const std::string &loginserver);
virtual bool CreateLoginData(
virtual bool CreateLoginData(const std::string &name, const std::string &password, const std::string &loginserver, unsigned int &id); const std::string &name,
const std::string &password,
virtual bool CreateLoginDataWithID(const std::string &name, const std::string &password, const std::string &loginserver, unsigned int id); 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); 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. * Retrieves the world registration from the long and short names provided
* Needed for world login procedure. * Needed for world login procedure
* Returns true if the record was found, false otherwise. * 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, virtual bool GetWorldRegistration(
unsigned int &trusted, std::string &list_desc, std::string &account, std::string &password); 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); 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); 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); 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); virtual 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;

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 * This program is free software; you can redistribute it and/or modify
the Free Software Foundation; version 2 of the License. * 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 * This program is distributed in the hope that it will be useful,
are required to give you total support for your newly bought product; * but WITHOUT ANY WARRANTY except by those people which sell it, which
without even the implied warranty of MERCHANTABILITY or FITNESS FOR * are required to give you total support for your newly bought product;
A PARTICULAR PURPOSE. See the GNU General Public License for more details. * 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 * You should have received a copy of the GNU General Public License
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 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/global_define.h"
#include "../common/types.h" #include "../common/types.h"
#include "../common/opcodemgr.h" #include "../common/opcodemgr.h"
@ -41,6 +44,7 @@ int main()
{ {
RegisterExecutablePlatform(ExePlatformLogin); RegisterExecutablePlatform(ExePlatformLogin);
set_exception_handler(); set_exception_handler();
LogSys.LoadLogSettingsDefaults(); LogSys.LoadLogSettingsDefaults();
LogSys.log_settings[Logs::Error].log_to_console = Logs::General; LogSys.log_settings[Logs::Error].log_to_console = Logs::General;
@ -59,8 +63,22 @@ int main()
server.options.RejectDuplicateServers(server.config.GetVariableBool("general", "reject_duplicate_servers", false)); server.options.RejectDuplicateServers(server.config.GetVariableBool("general", "reject_duplicate_servers", false));
server.options.AutoCreateAccounts(server.config.GetVariableBool("general", "auto_create_accounts", true)); server.options.AutoCreateAccounts(server.config.GetVariableBool("general", "auto_create_accounts", true));
server.options.AutoLinkAccounts(server.config.GetVariableBool("general", "auto_link_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 #ifdef ENABLE_SECURITY
server.options.EncryptionMode(server.config.GetVariableInt("security", "mode", 13)); 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.AllowUnregistered(server.config.GetVariableBool("security", "unregistered_allowed", true));
server.options.AllowTokenLogin(server.config.GetVariableBool("security", "allow_token_login", false)); server.options.AllowTokenLogin(server.config.GetVariableBool("security", "allow_token_login", false));
server.options.AllowPasswordLogin(server.config.GetVariableBool("security", "allow_password_login", true)); 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.AccountTable(server.config.GetVariableString("schema", "account_table", "tblLoginServerAccounts"));
server.options.WorldRegistrationTable(server.config.GetVariableString("schema", "world_registration_table", "tblWorldServerRegistration")); server.options.WorldRegistrationTable(
server.options.WorldAdminRegistrationTable(server.config.GetVariableString("schema", "world_admin_registration_table", "tblServerAdminRegistration")); server.config.GetVariableString(
server.options.WorldServerTypeTable(server.config.GetVariableString("schema", "world_server_type_table", "tblServerListType")); "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) { if (server.config.GetVariableString("database", "subsystem", "MySQL").compare("MySQL") == 0) {
#ifdef EQEMU_MYSQL_ENABLED
Log(Logs::General, Logs::Login_Server, "MySQL Database Init."); 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", "user", "root"),
server.config.GetVariableString("database", "password", ""), server.config.GetVariableString("database", "password", ""),
server.config.GetVariableString("database", "host", "localhost"), server.config.GetVariableString("database", "host", "localhost"),
server.config.GetVariableString("database", "port", "3306"), server.config.GetVariableString("database", "port", "3306"),
server.config.GetVariableString("database", "db", "peq")); server.config.GetVariableString("database", "db", "peq")
#endif );
} }
/* 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) { if (!server.db) {
Log(Logs::General, Logs::Error, "Database Initialization Failure."); Log(Logs::General, Logs::Error, "Database Initialization Failure.");
Log(Logs::General, Logs::Login_Server, "Log System Shutdown."); Log(Logs::General, Logs::Login_Server, "Log System Shutdown.");
return 1; return 1;
} }
//create our server manager. /**
* create server manager
*/
Log(Logs::General, Logs::Login_Server, "Server Manager Initialize."); Log(Logs::General, Logs::Login_Server, "Server Manager Initialize.");
server.server_manager = new ServerManager(); server.server_manager = new ServerManager();
if (!server.server_manager) { if (!server.server_manager)
//We can't run without a server manager, cleanup and exit.
Log(Logs::General, Logs::Error, "Server Manager Failed to Start."); Log(Logs::General, Logs::Error, "Server Manager Failed to Start.");
Log(Logs::General, Logs::Login_Server, "Database System Shutdown."); Log(Logs::General, Logs::Login_Server, "Database System Shutdown.");
delete server.db; delete server.db;
return 1; return 1;
} }
//create our client manager. /**
* create client manager
*/
Log(Logs::General, Logs::Login_Server, "Client Manager Initialize."); Log(Logs::General, Logs::Login_Server, "Client Manager Initialize.");
server.client_manager = new ClientManager(); server.client_manager = new ClientManager();
if (!server.client_manager) { 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::Error, "Client Manager Failed to Start.");
Log(Logs::General, Logs::Login_Server, "Server Manager Shutdown."); Log(Logs::General, Logs::Login_Server, "Server Manager Shutdown.");
delete server.server_manager; delete server.server_manager;