mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 08:34:52 -07:00
changed leave game shortcut, server cleanups, added max_games_per_user
This commit is contained in:
parent
d0b8c6ebd9
commit
38b31681e2
11 changed files with 85 additions and 64 deletions
|
|
@ -87,26 +87,33 @@ Server_Game *Server_Room::createGame(const QString &description, const QString &
|
|||
// This mutex needs to be unlocked by the caller.
|
||||
newGame->gameMutex.lock();
|
||||
games.insert(newGame->getGameId(), newGame);
|
||||
connect(newGame, SIGNAL(gameClosing()), this, SLOT(removeGame()));
|
||||
|
||||
broadcastGameListUpdate(newGame);
|
||||
|
||||
emit gameCreated(newGame);
|
||||
emit roomInfoChanged();
|
||||
|
||||
return newGame;
|
||||
}
|
||||
|
||||
void Server_Room::removeGame()
|
||||
void Server_Room::removeGame(Server_Game *game)
|
||||
{
|
||||
QMutexLocker locker(&roomMutex);
|
||||
|
||||
Server_Game *game = static_cast<Server_Game *>(sender());
|
||||
QMutexLocker gameLocker(&game->gameMutex);
|
||||
// No need to lock roomMutex or gameMutex. This method is only
|
||||
// called from ~Server_Game, which locks both mutexes anyway beforehand.
|
||||
|
||||
broadcastGameListUpdate(game);
|
||||
games.remove(game->getGameId());
|
||||
|
||||
emit gameClosing(game->getGameId());
|
||||
emit roomInfoChanged();
|
||||
}
|
||||
|
||||
int Server_Room::getGamesCreatedByUser(const QString &userName) const
|
||||
{
|
||||
QMutexLocker locker(&roomMutex);
|
||||
|
||||
QMapIterator<int, Server_Game *> gamesIterator(games);
|
||||
int result = 0;
|
||||
while (gamesIterator.hasNext())
|
||||
if (gamesIterator.next().value()->getCreatorInfo()->getName() == userName)
|
||||
++result;
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue