Cleanup max user check at login

This change accomplishes two goals.  The first is it moves the checking
for if the servers set user limit is reached out of the socket interface
and into the protocol handler portion of the code (were it should live).
It also eleminates the need for a DB query at login to check the user
count.  The user account is actually already maintained by the server
and a function already existed to get the user count total.
This commit is contained in:
woogerboy21 2016-10-16 12:48:39 -04:00
parent f20e2ce2bd
commit 10b677acdf
7 changed files with 23 additions and 25 deletions

View file

@ -234,11 +234,11 @@ bool Servatrice::initServer()
qDebug() << "Store Replays: " << settingsCache->value("game/store_replays", true).toBool();
qDebug() << "Client ID Required: " << clientIdRequired;
bool maxUserLimitEnabled = settingsCache->value("security/enable_max_user_limit", false).toBool();
maxUserLimitEnabled = settingsCache->value("security/enable_max_user_limit", false).toBool();
qDebug() << "Maximum user limit enabled: " << maxUserLimitEnabled;
if (maxUserLimitEnabled){
int maxUserLimit = settingsCache->value("security/max_users_total", 500).toInt();
maxUserLimit = settingsCache->value("security/max_users_total", 500).toInt();
qDebug() << "Maximum total user limit: " << maxUserLimit;
int maxTcpUserLimit = settingsCache->value("security/max_users_tcp", 500).toInt();
qDebug() << "Maximum tcp user limit: " << maxTcpUserLimit;

View file

@ -134,14 +134,14 @@ private:
int uptime;
QMutex txBytesMutex, rxBytesMutex;
quint64 txBytes, rxBytes;
int maxGameInactivityTime, maxPlayerInactivityTime;
int maxGameInactivityTime, maxPlayerInactivityTime, maxUserLimit;
int maxUsersPerAddress, messageCountingInterval, maxMessageCountPerInterval, maxMessageSizePerInterval, maxGamesPerUser, commandCountingInterval, maxCommandCountPerInterval, pingClockInterval;
QString shutdownReason;
int shutdownMinutes;
int nextShutdownMessageMinutes;
QTimer *shutdownTimer;
bool isFirstShutdownMessage, clientIdRequired, regServerOnly;
bool isFirstShutdownMessage, clientIdRequired, regServerOnly, maxUserLimitEnabled;
mutable QMutex serverListMutex;
QList<ServerProperties> serverList;
@ -164,6 +164,7 @@ public:
bool getGameShouldPing() const { return true; }
bool getClientIdRequired() const { return clientIdRequired; }
bool getRegOnlyServer() const { return regServerOnly; }
bool getmaxUserLimitEnabled() const {return maxUserLimitEnabled; }
int getPingClockInterval() const { return pingClockInterval; }
int getMaxGameInactivityTime() const { return maxGameInactivityTime; }
int getMaxPlayerInactivityTime() const { return maxPlayerInactivityTime; }
@ -174,6 +175,7 @@ public:
int getMaxGamesPerUser() const { return maxGamesPerUser; }
int getCommandCountingInterval() const { return commandCountingInterval; }
int getMaxCommandCountPerInterval() const { return maxCommandCountPerInterval; }
int getMaxUserLimit() const { return maxUserLimit; }
AuthenticationMethod getAuthenticationMethod() const { return authenticationMethod; }
QString getDbPrefix() const { return dbPrefix; }
int getServerId() const { return serverId; }

View file

@ -94,23 +94,6 @@ bool AbstractServerSocketInterface::initSession()
sendProtocolItem(*identSe);
delete identSe;
//limit the number of total users based on configuration settings
bool enforceUserLimit = settingsCache->value("security/enable_max_user_limit", false).toBool();
if (enforceUserLimit){
int userLimit = settingsCache->value("security/max_users_total", 500).toInt();
int playerCount = (databaseInterface->getActiveUserCount() + 1);
if (playerCount > userLimit){
std::cerr << "Max Users Total Limit Reached, please increase the max_users_total setting." << std::endl;
logger->logMessage(QString("Max Users Total Limit Reached, please increase the max_users_total setting."), this);
Event_ConnectionClosed event;
event.set_reason(Event_ConnectionClosed::USER_LIMIT_REACHED);
SessionEvent *se = prepareSessionEvent(event);
sendProtocolItem(*se);
delete se;
return false;
}
}
//allow unlimited number of connections from the trusted sources
QString trustedSources = settingsCache->value("security/trusted_sources","127.0.0.1,::1").toString();
if (trustedSources.contains(getAddress(),Qt::CaseInsensitive))
@ -123,7 +106,6 @@ bool AbstractServerSocketInterface::initSession()
SessionEvent *se = prepareSessionEvent(event);
sendProtocolItem(*se);
delete se;
return false;
}