Create game as spectator (#4281)

* refactoring

* allow for creation of games as spectator

allow setting the amount of games per user to none
remove limit on amount of games when creating a game as judge as
spectator

* refactor common/server_player.cpp

* do not close games with spectating host automatically

* remove check that filters out 0 player games

this check didn't really do anything, deleted games are removed before
it would be reached

* don't transfer host to spectators

this seems to cause a bug, also present on master
This commit is contained in:
ebbit1q
2021-03-13 20:39:25 +01:00
committed by GitHub
parent b722864caf
commit 06bfc0291a
13 changed files with 153 additions and 140 deletions

View File

@@ -243,8 +243,8 @@ Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGam
// server->roomsMutex is always locked.
QReadLocker roomGamesLocker(&gamesLock);
Server_Game *g = games.value(cmd.game_id());
if (!g) {
Server_Game *game = games.value(cmd.game_id());
if (!game) {
if (externalGames.contains(cmd.game_id())) {
CommandContainer cont;
cont.set_cmd_id(rc.getCmdId());
@@ -256,16 +256,18 @@ Response::ResponseCode Server_Room::processJoinGameCommand(const Command_JoinGam
userInterface->getUserInfo()->session_id(), id);
return Response::RespNothing;
} else
} else {
return Response::RespNameNotFound;
}
}
QMutexLocker gameLocker(&g->gameMutex);
QMutexLocker gameLocker(&game->gameMutex);
Response::ResponseCode result = g->checkJoin(userInterface->getUserInfo(), QString::fromStdString(cmd.password()),
cmd.spectator(), cmd.override_restrictions(), cmd.join_as_judge());
Response::ResponseCode result =
game->checkJoin(userInterface->getUserInfo(), QString::fromStdString(cmd.password()), cmd.spectator(),
cmd.override_restrictions(), cmd.join_as_judge());
if (result == Response::RespOk)
g->addPlayer(userInterface, rc, cmd.spectator(), cmd.join_as_judge());
game->addPlayer(userInterface, rc, cmd.spectator(), cmd.join_as_judge());
return result;
}