synchronized addPlayer() in Lobby.addPlayer

This commit is contained in:
Sebastian Lenzlinger 2022-04-08 16:54:57 +02:00
parent 37a8caa64d
commit 372a02a093
2 changed files with 3 additions and 1 deletions

View File

@ -223,6 +223,8 @@ public class ClientHandler implements Runnable {
serverData.addLobbyToListOfAllLobbies(newGame);
LOGGER.debug(
this.getClientUserName() + " created a new lobby with ID: " + newGame.getLobbyID());
//TODO add server response. Here a possibility:
sendMsgToClient("New lobby with ID: " + newGame + " created.");
}
/**

View File

@ -85,7 +85,7 @@ public class Lobby {
* TODO: Does this method need to implemented somewhere else, e.g. in the ClientHandler?
* @param player who wants to join the lobby.
*/
public void addPlayer(ClientHandler player) {
public synchronized void addPlayer(ClientHandler player) {
if (players.size() <= MAX_NO_OF_CLIENTS) {
players.add(player);
numberOfPlayersInLobby++;