server: fixed game errors in rare use cases for big games (related to #11285);

This commit is contained in:
Oleg Agafonov 2024-06-12 23:40:49 +04:00
parent 3ae1f0d7fb
commit 4f0691ad08

View file

@ -209,16 +209,20 @@ public class GameSessionPlayer extends GameSessionWatcher {
* @return * @return
*/ */
public static GameView prepareGameView(Game game, UUID playerId, UUID userId) { public static GameView prepareGameView(Game game, UUID playerId, UUID userId) {
Player player = game.getPlayer(playerId); // null for watcher // game view calculation can take some time and can be called from non-game thread,
GameView gameView = new GameView(game.getState(), game, playerId, null); // so use copy for thread save (protection from ConcurrentModificationException)
Game sourceGame = game.copy();
Player player = sourceGame.getPlayer(playerId); // null for watcher
GameView gameView = new GameView(sourceGame.getState(), sourceGame, playerId, null);
if (player != null) { if (player != null) {
if (gameView.getPriorityPlayerName().equals(player.getName())) { if (gameView.getPriorityPlayerName().equals(player.getName())) {
gameView.setCanPlayObjects(player.getPlayableObjects(game, Zone.ALL)); gameView.setCanPlayObjects(player.getPlayableObjects(sourceGame, Zone.ALL));
} }
} }
processControlledPlayers(game, player, gameView); processControlledPlayers(sourceGame, player, gameView);
processWatchedHands(game, userId, gameView); processWatchedHands(sourceGame, userId, gameView);
//TODO: should player who controls another player's turn be able to look at all these cards? //TODO: should player who controls another player's turn be able to look at all these cards?
return gameView; return gameView;