From 3fd597b580591ac36cc2f07b40b9580227f74f19 Mon Sep 17 00:00:00 2001 From: Andy Janata Date: Mon, 30 Jan 2012 00:36:52 -0800 Subject: [PATCH] kill the next round timer when a game resets due to losing players --- src/net/socialgamer/cah/data/Game.java | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/net/socialgamer/cah/data/Game.java b/src/net/socialgamer/cah/data/Game.java index b0a1d74..851baca 100644 --- a/src/net/socialgamer/cah/data/Game.java +++ b/src/net/socialgamer/cah/data/Game.java @@ -68,6 +68,8 @@ public class Game { private final int maxPlayers = 10; private int judgeIndex = 0; private final static int ROUND_INTERMISSION = 8 * 1000; + private Timer nextRoundTimer; + private final Object nextRoundTimerLock = new Object(); /** * TODO Injection here would be much nicer, but that would need a Provider for the id... Too much @@ -367,7 +369,12 @@ public class Game { * previous game finished. */ private void resetState(final boolean lostPlayer) { - // Reset the game. + synchronized (nextRoundTimerLock) { + if (nextRoundTimer != null) { + nextRoundTimer.cancel(); + nextRoundTimer = null; + } + } synchronized (players) { for (final Player player : players) { player.getHand().clear(); @@ -584,13 +591,15 @@ public class Game { data.put(LongPollResponse.PLAYER_INFO, getPlayerInfo(cardPlayer)); broadcastToPlayers(MessageType.GAME_PLAYER_EVENT, data); - final Timer timer = new Timer(); - timer.schedule(new TimerTask() { - @Override - public void run() { - startNextRound(); - } - }, ROUND_INTERMISSION); + synchronized (nextRoundTimerLock) { + nextRoundTimer = new Timer(); + nextRoundTimer.schedule(new TimerTask() { + @Override + public void run() { + startNextRound(); + } + }, ROUND_INTERMISSION); + } return null; }