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

@ -37,6 +37,7 @@ message Response {
RespRegistrationAcceptedNeedsActivation = 33; // Server accepted cient registration, but it will need token activation
RespClientIdRequired = 34; // Server requires client to generate and send its client id before allowing access
RespClientUpdateRequired = 35; // Client is missing features that the server is requiring
RespServerFull = 36; // Server user limit reached
}
enum ResponseType {
JOIN_ROOM = 1000;

View file

@ -62,6 +62,7 @@ public:
virtual bool getGameShouldPing() const { return false; }
virtual bool getClientIdRequired() const { return false; }
virtual bool getRegOnlyServer() const { return false; }
virtual bool getmaxUserLimitEnabled() const { return false; }
virtual int getPingClockInterval() const { return 0; }
virtual int getMaxGameInactivityTime() const { return 9999999; }
virtual int getMaxPlayerInactivityTime() const { return 9999999; }
@ -71,6 +72,7 @@ public:
virtual int getMaxGamesPerUser() const { return 0; }
virtual int getCommandCountingInterval() const { return 0; }
virtual int getMaxCommandCountPerInterval() const { return 0; }
virtual int getMaxUserLimit() const { return 9999999; }
Server_DatabaseInterface *getDatabaseInterface() const;
int getNextLocalGameId() { QMutexLocker locker(&nextLocalGameIdMutex); return ++nextLocalGameId; }
@ -89,6 +91,8 @@ public:
void addPersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
void removePersistentPlayer(const QString &userName, int roomId, int gameId, int playerId);
QList<PlayerReference> getPersistentPlayerReferences(const QString &userName) const;
int getUsersCount() const;
int getGamesCount() const;
private:
QMultiMap<QString, PlayerReference> persistentPlayers;
mutable QReadWriteLock persistentPlayersLock;
@ -118,9 +122,6 @@ protected:
QMap<QString, Server_AbstractUserInterface *> externalUsers;
QMap<int, Server_Room *> rooms;
QMap<QThread *, Server_DatabaseInterface *> databaseInterfaces;
int getUsersCount() const;
int getGamesCount() const;
void addRoom(Server_Room *newRoom);
};

View file

@ -383,6 +383,14 @@ Response::ResponseCode Server_ProtocolHandler::cmdPing(const Command_Ping & /*cm
Response::ResponseCode Server_ProtocolHandler::cmdLogin(const Command_Login &cmd, ResponseContainer &rc)
{
// limit the number of users that can connect to the server based on configuration settings
if (server->getmaxUserLimitEnabled()) {
if (server->getUsersCount() >= server->getMaxUserLimit()) {
qDebug() << "Max Users Total Limit Reached, please increase the max_users_total setting.";
return Response::RespServerFull;
}
}
QString userName = QString::fromStdString(cmd.user_name()).simplified();
QString clientId = QString::fromStdString(cmd.clientid()).simplified();
QString clientVersion = QString::fromStdString(cmd.clientver()).simplified();