fixed issue 25 - server waits for all clients to confirm initialization before starting game

This commit is contained in:
BetaSteward 2010-11-30 04:35:26 +00:00
parent f81c238994
commit 3ca748e16d
9 changed files with 56 additions and 45 deletions

View file

@ -165,10 +165,15 @@ public class GameController implements GameCallback {
GameSession gameSession = new GameSession(game, sessionId, playerId);
gameSessions.put(playerId, gameSession);
logger.info("player " + playerId + " has joined game " + game.getId());
// gameSession.init(getGameView(playerId));
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game", MessageColor.BLACK);
if (allJoined()) {
startGame();
ThreadExecutor.getInstance().getRMIExecutor().execute(
new Runnable() {
@Override
public void run() {
startGame();
}
});
}
}
@ -177,6 +182,8 @@ public class GameController implements GameCallback {
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
if (!entry.getValue().init(getGameView(entry.getKey()))) {
logger.severe("Unable to initialize client");
//TODO: generate client error message
return;
}
}
GameWorker worker = new GameWorker(game, this);

View file

@ -60,13 +60,23 @@ public class GameWatcher {
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null) {
session.clearAck();
session.fireCallback(new ClientCallback("gameInit", gameView));
return true;
if (waitForAck("gameInit"))
return true;
}
}
return false;
}
public boolean waitForAck(String message) {
Session session = SessionManager.getInstance().getSession(sessionId);
do {
//TODO: add timeout
} while (!session.getAckMessage().equals(message) && !killed);
return true;
}
public void update(final GameView gameView) {
if (!killed) {
Session session = SessionManager.getInstance().getSession(sessionId);