mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 10:26:28 +01:00
Core/Auth: Moved expiring bans to background task - no longer blocking queries during login by default running every minute (configurable)
This commit is contained in:
@@ -73,6 +73,8 @@ variables_map GetConsoleArguments(int argc, char** argv, std::string& configFile
|
||||
boost::asio::io_service* _ioService;
|
||||
boost::asio::deadline_timer* _dbPingTimer;
|
||||
uint32 _dbPingInterval;
|
||||
boost::asio::deadline_timer* _banExpiryCheckTimer;
|
||||
uint32 _banExpiryCheckInterval;
|
||||
LoginDatabaseWorkerPool LoginDatabase;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
@@ -169,6 +171,11 @@ int main(int argc, char** argv)
|
||||
_dbPingTimer->expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer->async_wait(KeepDatabaseAliveHandler);
|
||||
|
||||
_banExpiryCheckInterval = sConfigMgr->GetIntDefault("BanExpiryCheckInterval", 60);
|
||||
_banExpiryCheckTimer = new boost::asio::deadline_timer(*_ioService);
|
||||
_banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(_banExpiryCheckInterval));
|
||||
_banExpiryCheckTimer->async_wait(BanExpiryHandler);
|
||||
|
||||
#if PLATFORM == PLATFORM_WINDOWS
|
||||
if (m_ServiceStatus != -1)
|
||||
{
|
||||
@@ -192,6 +199,7 @@ int main(int argc, char** argv)
|
||||
|
||||
signals.cancel();
|
||||
|
||||
delete _banExpiryCheckTimer;
|
||||
delete _dbPingTimer;
|
||||
delete _ioService;
|
||||
return 0;
|
||||
@@ -242,6 +250,18 @@ void KeepDatabaseAliveHandler(const boost::system::error_code& error)
|
||||
}
|
||||
}
|
||||
|
||||
void BanExpiryHandler(boost::system::error_code const& error)
|
||||
{
|
||||
if (!error)
|
||||
{
|
||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
|
||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS));
|
||||
|
||||
_banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(_banExpiryCheckInterval));
|
||||
_banExpiryCheckTimer->async_wait(BanExpiryHandler);
|
||||
}
|
||||
}
|
||||
|
||||
#if PLATFORM == PLATFORM_WINDOWS
|
||||
void ServiceStatusWatcher(boost::system::error_code const& error)
|
||||
{
|
||||
|
||||
@@ -161,10 +161,6 @@ void AuthSession::Start()
|
||||
std::string ip_address = GetRemoteIpAddress().to_string();
|
||||
TC_LOG_TRACE("session", "Accepted connection from %s", ip_address.c_str());
|
||||
|
||||
// Remove expired ip ban if needed - login might fail for the first time
|
||||
// but its better than allowing ourselves to be flooded by connections triggering blocking queries
|
||||
LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS));
|
||||
|
||||
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_INFO);
|
||||
stmt->setString(0, ip_address);
|
||||
stmt->setUInt32(1, inet_addr(ip_address.c_str()));
|
||||
@@ -382,9 +378,6 @@ void AuthSession::LogonChallengeCallback(PreparedQueryResult result)
|
||||
}
|
||||
}
|
||||
|
||||
//set expired bans to inactive
|
||||
LoginDatabase.DirectExecute(LoginDatabase.GetPreparedStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS));
|
||||
|
||||
// If the account is banned, reject the logon attempt
|
||||
if (_accountInfo.IsBanned)
|
||||
{
|
||||
|
||||
@@ -130,6 +130,13 @@ WrongPass.BanType = 0
|
||||
|
||||
WrongPass.Logging = 0
|
||||
|
||||
#
|
||||
# BanExpiryCheckInterval
|
||||
# Description: Time (in seconds) between checks for expired bans
|
||||
# Default: 60
|
||||
|
||||
BanExpiryCheckInterval = 60
|
||||
|
||||
#
|
||||
###################################################################################################
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ void LoginDatabaseConnection::DoPrepareStatements()
|
||||
|
||||
PrepareStatement(LOGIN_SEL_REALMLIST, "SELECT id, name, address, localAddress, localSubnetMask, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE flag <> 3 ORDER BY name", CONNECTION_SYNCH);
|
||||
PrepareStatement(LOGIN_DEL_EXPIRED_IP_BANS, "DELETE FROM ip_banned WHERE unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()", CONNECTION_ASYNC);
|
||||
PrepareStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS, "UPDATE account_banned SET active = 0 WHERE active = 1 AND unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()", CONNECTION_SYNCH);
|
||||
PrepareStatement(LOGIN_UPD_EXPIRED_ACCOUNT_BANS, "UPDATE account_banned SET active = 0 WHERE active = 1 AND unbandate<>bandate AND unbandate<=UNIX_TIMESTAMP()", CONNECTION_ASYNC);
|
||||
PrepareStatement(LOGIN_SEL_IP_INFO, "(SELECT unbandate > UNIX_TIMESTAMP() OR unbandate = bandate AS banned, NULL as country FROM ip_banned WHERE ip = ?) "
|
||||
"UNION "
|
||||
"(SELECT NULL AS banned, country FROM ip2nation WHERE INET_NTOA(ip) = ?)", CONNECTION_ASYNC);
|
||||
|
||||
Reference in New Issue
Block a user