Fixed game and/or timer freeze on another player concede with 3+ games (see #4476)

This commit is contained in:
Oleg Agafonov 2018-02-03 08:26:01 +04:00
parent db0fc1b439
commit 3bfe5ec5d3

View file

@ -202,19 +202,20 @@ public class HumanPlayer extends PlayerImpl {
// } // }
return; return;
} }
response.clear(); // TODO: only one response for all games (can play only one game per session)?!
//logger.info("Waiting response from player: " + getId()); // wait player's answer loop
game.resumeTimer(getTurnControlledBy());
responseOpenedForAnswer = true; // start waiting for next response
boolean loop = true; boolean loop = true;
while (loop) { while (loop) {
// start waiting for next answer
response.clear();
game.resumeTimer(getTurnControlledBy());
responseOpenedForAnswer = true;
loop = false; loop = false;
synchronized (response) { synchronized (response) {
try { try {
//logger.info("wait start: " + getId());
response.wait(); response.wait();
//logger.info("wait end: " + getId());
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
logger.error("Response error for player " + getName() + " gameId: " + game.getId(), ex); logger.error("Response error for player " + getName() + " gameId: " + game.getId(), ex);
} finally { } 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()) { if (response.getResponseConcedeCheck()) {
((GameImpl) game).checkConcede(); ((GameImpl) game).checkConcede();
if (game.hasEnded()) { if (game.hasEnded()) {
return; return;
} }
response.clear();
if (isInGame()) { if (isInGame()) {
// wait another answer
loop = true; loop = true;
} }
} }
} }
//logger.info("Waiting response DONE (res queue " + actionQueueSaved.size() + "): " + getId() + ", res: " + response.toString());
if (recordingMacro && !macroTriggeredSelectionFlag) { if (recordingMacro && !macroTriggeredSelectionFlag) {
// logger.info("Adding an action " + response);
actionQueueSaved.add(new PlayerResponse(response)); actionQueueSaved.add(new PlayerResponse(response));
} }
} }
@ -646,11 +648,13 @@ public class HumanPlayer extends PlayerImpl {
if (!choosable.isEmpty()) { if (!choosable.isEmpty()) {
options.put("choosable", (Serializable) choosable); options.put("choosable", (Serializable) choosable);
} }
prepareForResponse(game);
if (!isExecutingMacro()) { if (!isExecutingMacro()) {
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage(), getRelatedObjectName(source, game)), cards, required, options); game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage(), getRelatedObjectName(source, game)), cards, required, options);
} }
prepareForResponse(game);
waitForResponse(game); waitForResponse(game);
if (response.getUUID() != null) { if (response.getUUID() != null) {
if (target.getTargets().contains(response.getUUID())) { // if already included remove it if (target.getTargets().contains(response.getUUID())) { // if already included remove it
target.remove(response.getUUID()); target.remove(response.getUUID());