Remove old DB connector

This commit is contained in:
Akkadius 2019-07-04 23:29:54 -05:00
parent 8ad4ef503b
commit d5eb015533
2 changed files with 16 additions and 41 deletions

View File

@ -590,7 +590,6 @@ void Client::DoSuccessfulLogin(const std::string &user, int db_account_id, const
in.s_addr = connection->GetRemoteIP(); in.s_addr = connection->GetRemoteIP();
server.db->UpdateLSAccountData(db_account_id, std::string(inet_ntoa(in))); server.db->UpdateLSAccountData(db_account_id, std::string(inet_ntoa(in)));
GenerateKey(); GenerateKey();
account_id = db_account_id; account_id = db_account_id;

View File

@ -50,47 +50,23 @@ Database::Database(
this->host = host; this->host = host;
this->name = name; this->name = name;
database = mysql_init(nullptr); uint32 errnum = 0;
if (database) { char errbuf[MYSQL_ERRMSG_SIZE];
char r = 1; if (!Open(
mysql_options(database, MYSQL_OPT_RECONNECT, &r); host.c_str(),
if (!mysql_real_connect( user.c_str(),
database, pass.c_str(),
host.c_str(), name.c_str(),
user.c_str(), atoi(port.c_str()),
pass.c_str(), &errnum,
name.c_str(), errbuf
atoi(port.c_str()), )
nullptr, ) {
0 Log(Logs::General, Logs::Error, "Failed to connect to database: Error: %s", errbuf);
)) { exit(1);
mysql_close(database);
Log(Logs::General, Logs::Error, "Failed to connect to MySQL database. Error: %s", mysql_error(database));
exit(1);
}
uint32 errnum = 0;
char errbuf[MYSQL_ERRMSG_SIZE];
if (!Open(
host.c_str(),
user.c_str(),
pass.c_str(),
name.c_str(),
atoi(port.c_str()),
&errnum,
errbuf
)
) {
Log(Logs::General, Logs::Error, "Failed to connect to database: Error: %s", errbuf);
exit(1);
}
else {
Log(Logs::General, Logs::Status, "Using database '%s' at %s:%d", database, host, port);
}
} }
else { else {
Log(Logs::General, Logs::Error, "Failed to create db object in MySQL database."); Log(Logs::General, Logs::Status, "Using database '%s' at %s:%d", database, host, port);
} }
} }
@ -438,7 +414,7 @@ bool Database::GetWorldRegistration(
void Database::UpdateLSAccountData(unsigned int id, std::string ip_address) void Database::UpdateLSAccountData(unsigned int id, std::string ip_address)
{ {
auto query = fmt::format( auto query = fmt::format(
"UPDATE {0} SET LastIPAddress = '{2}', LastLoginDate = now() where LoginServerId = {3}", "UPDATE {0} SET LastIPAddress = '{1}', LastLoginDate = NOW() where LoginServerId = {2}",
server.options.GetAccountTable(), server.options.GetAccountTable(),
ip_address, ip_address,
id id