From 3bfe5ec5d3c4a82dc79052597c23b4f59318a50b Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 3 Feb 2018 08:26:01 +0400 Subject: [PATCH] Fixed game and/or timer freeze on another player concede with 3+ games (see #4476) --- .../src/mage/player/human/HumanPlayer.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index bdda0915ed..c5da0b9cc3 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -202,19 +202,20 @@ public class HumanPlayer extends PlayerImpl { // } return; } - response.clear(); // TODO: only one response for all games (can play only one game per session)?! - //logger.info("Waiting response from player: " + getId()); - game.resumeTimer(getTurnControlledBy()); - responseOpenedForAnswer = true; // start waiting for next response + + // wait player's answer loop boolean loop = true; while (loop) { + // start waiting for next answer + response.clear(); + game.resumeTimer(getTurnControlledBy()); + responseOpenedForAnswer = true; + loop = false; synchronized (response) { try { - //logger.info("wait start: " + getId()); response.wait(); - //logger.info("wait end: " + getId()); } catch (InterruptedException ex) { logger.error("Response error for player " + getName() + " gameId: " + game.getId(), ex); } finally { @@ -223,20 +224,21 @@ public class HumanPlayer extends PlayerImpl { } } + // game recived immidiate response on OTHER player concede -- need to process end game and continue to wait if (response.getResponseConcedeCheck()) { ((GameImpl) game).checkConcede(); if (game.hasEnded()) { return; } - response.clear(); + if (isInGame()) { + // wait another answer loop = true; } } } - //logger.info("Waiting response DONE (res queue " + actionQueueSaved.size() + "): " + getId() + ", res: " + response.toString()); + if (recordingMacro && !macroTriggeredSelectionFlag) { -// logger.info("Adding an action " + response); actionQueueSaved.add(new PlayerResponse(response)); } } @@ -646,11 +648,13 @@ public class HumanPlayer extends PlayerImpl { if (!choosable.isEmpty()) { options.put("choosable", (Serializable) choosable); } + + prepareForResponse(game); if (!isExecutingMacro()) { game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage(), getRelatedObjectName(source, game)), cards, required, options); } - prepareForResponse(game); waitForResponse(game); + if (response.getUUID() != null) { if (target.getTargets().contains(response.getUUID())) { // if already included remove it target.remove(response.getUUID());