Hi, in the game there is a matchmaking room that search for game rooms with an odd number of players every few seconds and if there is one, the user will be joined to that game room to balance the battle. I'm doing the search with the MatchExpression class, the thing is, if this is done in a number of matchmaking rooms, there is a chance that more than one will find the same game room and will try to join the user, which would maintain the unbalance. How could I do the check for odd players and join event synchronous?
Code: Select all
// Would this work?
synchronized (Matchmaking.class) {
if (gameRoom.getPlayersList().size() % 2 == 0) { // Odd number.
getApi().joinRoom(user, gameRoom);
}
}
Thanks!