"cockatrice/src/tab_deck_editor.cpp" did not exist on "579628b4c4cf65c5909da502cf98c691bfb9d603"
Commit 6d5b2939 authored by Max-Wilhelm Bruker's avatar Max-Wilhelm Bruker
Browse files

mutex and ghost games fixes

parent 8e0f7dcf
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <QDebug> #include <QDebug>
Server::Server(QObject *parent) Server::Server(QObject *parent)
: QObject(parent), nextGameId(0) : QObject(parent), serverMutex(QMutex::Recursive), nextGameId(0)
{ {
} }
...@@ -46,12 +46,8 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString ...@@ -46,12 +46,8 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString
return authState; return authState;
if (authState == PasswordRight) { if (authState == PasswordRight) {
Server_ProtocolHandler *oldSession = users.value(name); if (users.contains(name))
if (oldSession) { return WouldOverwriteOldSession;
if (!(oldSession->getUserInfo()->getUserLevel() & ServerInfo_User::IsRegistered))
return WouldOverwriteOldSession;
delete oldSession; // ~Server_ProtocolHandler() will call Server::removeClient
}
} else if (authState == UnknownUser) { } else if (authState == UnknownUser) {
// Change user name so that no two users have the same names, // Change user name so that no two users have the same names,
// don't interfere with registered user names though. // don't interfere with registered user names though.
...@@ -100,11 +96,6 @@ void Server::removeClient(Server_ProtocolHandler *client) ...@@ -100,11 +96,6 @@ void Server::removeClient(Server_ProtocolHandler *client)
qDebug() << "Server::removeClient: " << clients.size() << "clients; " << users.size() << "users left"; qDebug() << "Server::removeClient: " << clients.size() << "clients; " << users.size() << "users left";
} }
Server_Game *Server::getGame(int gameId) const
{
return games.value(gameId);
}
void Server::broadcastRoomUpdate() void Server::broadcastRoomUpdate()
{ {
QMutexLocker locker(&serverMutex); QMutexLocker locker(&serverMutex);
......
...@@ -28,7 +28,6 @@ public: ...@@ -28,7 +28,6 @@ public:
~Server(); ~Server();
AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password); AuthenticationResult loginUser(Server_ProtocolHandler *session, QString &name, const QString &password);
QList<Server_Game *> getGames() const { return games.values(); } QList<Server_Game *> getGames() const { return games.values(); }
Server_Game *getGame(int gameId) const;
const QMap<int, Server_Room *> &getRooms() { return rooms; } const QMap<int, Server_Room *> &getRooms() { return rooms; }
int getNextGameId() { return nextGameId++; } int getNextGameId() { return nextGameId++; }
......
...@@ -64,8 +64,11 @@ void Server_Game::pingClockTimeout() ...@@ -64,8 +64,11 @@ void Server_Game::pingClockTimeout()
QList<ServerInfo_PlayerPing *> pingList; QList<ServerInfo_PlayerPing *> pingList;
QMapIterator<int, Server_Player *> playerIterator(players); QMapIterator<int, Server_Player *> playerIterator(players);
bool allPlayersInactive = true; bool allPlayersInactive = true;
int playerCount = 0;
while (playerIterator.hasNext()) { while (playerIterator.hasNext()) {
Server_Player *player = playerIterator.next().value(); Server_Player *player = playerIterator.next().value();
if (!player->getSpectator())
++playerCount;
int pingTime; int pingTime;
if (player->getProtocolHandler()) { if (player->getProtocolHandler()) {
pingTime = player->getProtocolHandler()->getLastCommandTime(); pingTime = player->getProtocolHandler()->getLastCommandTime();
...@@ -78,7 +81,7 @@ void Server_Game::pingClockTimeout() ...@@ -78,7 +81,7 @@ void Server_Game::pingClockTimeout()
const int maxTime = static_cast<Server_Room *>(parent())->getServer()->getMaxGameInactivityTime(); const int maxTime = static_cast<Server_Room *>(parent())->getServer()->getMaxGameInactivityTime();
if (allPlayersInactive) { if (allPlayersInactive) {
if ((++inactivityCounter >= maxTime) && (maxTime > 0)) if (((++inactivityCounter >= maxTime) && (maxTime > 0)) || (playerCount < maxPlayers))
deleteLater(); deleteLater();
} else } else
inactivityCounter = 0; inactivityCounter = 0;
......
...@@ -263,8 +263,10 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain ...@@ -263,8 +263,10 @@ ResponseCode Server_ProtocolHandler::cmdLogin(Command_Login *cmd, CommandContain
ignoreList = server->getIgnoreList(userInfo->getName()); ignoreList = server->getIgnoreList(userInfo->getName());
// This might not scale very well. Use an extra QMap if it becomes a problem. // This might not scale very well. Use an extra QMap if it becomes a problem.
QMutexLocker serverLocker(&server->serverMutex);
const QList<Server_Game *> &serverGames = server->getGames(); const QList<Server_Game *> &serverGames = server->getGames();
for (int i = 0; i < serverGames.size(); ++i) { for (int i = 0; i < serverGames.size(); ++i) {
QMutexLocker gameLocker(&serverGames[i]->gameMutex);
const QList<Server_Player *> &gamePlayers = serverGames[i]->getPlayers().values(); const QList<Server_Player *> &gamePlayers = serverGames[i]->getPlayers().values();
for (int j = 0; j < gamePlayers.size(); ++j) for (int j = 0; j < gamePlayers.size(); ++j)
if (gamePlayers[j]->getUserInfo()->getName() == userInfo->getName()) { if (gamePlayers[j]->getUserInfo()->getName() == userInfo->getName()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment