* Multiplayer - Fixed a bug that a player that left a multiplayer game was not handled correctly. Next game did not start. Running game was ended after some minutes.

This commit is contained in:
LevelX2 2014-10-04 11:13:11 +02:00
parent 54f0fd8fc1
commit 8fd2a9e234
2 changed files with 9 additions and 5 deletions

View file

@ -431,6 +431,7 @@ public class TableController {
if (player != null && player.isInGame()) {
GameManager.getInstance().quitMatch(game.getId(), userId);
}
match.quitMatch(playerId);
} else {
if (table.getState().equals(TableState.SIDEBOARDING)) {
if (!matchPlayer.isDoneSideboarding()) {
@ -519,8 +520,10 @@ public class TableController {
GameManager.getInstance().createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId);
String creator = null;
StringBuilder opponent = new StringBuilder();
int activePlayers = 0;
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
if (!match.getPlayer(entry.getValue()).hasQuit()) {
activePlayers++;
User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) {
if (!user.isConnected()) {
@ -549,11 +552,11 @@ public class TableController {
matchPlayer.setQuit(true);
}
}
} else {
// Match player has already quit
throw new MageException("Can't start game - user already quit userId " + entry.getKey());
}
}
if (activePlayers < 2) {
throw new MageException("Can't start game - Less than two players active - " +activePlayers);
}
// Append AI opponents to the log file
for (MatchPlayer mPlayer :match.getPlayers()) {
if (!mPlayer.getPlayer().isHuman()) {
@ -855,7 +858,7 @@ public class TableController {
}
if (matchPlayer.getPlayer().isHuman()) {
humanPlayers++;
if (!matchPlayer.hasQuit()) {
if (!matchPlayer.hasQuit() && match.getGame() != null && matchPlayer.getPlayer().isInGame()) {
User user = UserManager.getInstance().getUser(userPlayerEntry.getKey());
if (user == null) {
logger.debug("- Active user of match is missing: " + matchPlayer.getName());

View file

@ -289,12 +289,13 @@ public class GameSession extends GameWatcher {
} catch (Exception ex) {
if (ex != null) {
logger.fatal("Game session game quit exception " + (ex.getMessage() == null ? "null":ex.getMessage()));
logger.debug("- gameId:" + game.getId() +" playerId: " + playerId);
if (ex.getCause() != null) {
logger.debug("- Cause: " + (ex.getCause().getMessage() == null ? "null":ex.getCause().getMessage()));
}
ex.printStackTrace();
}else {
logger.fatal("Game session game quit exception - null");
logger.fatal("Game session game quit exception - null gameId:" + game.getId() +" playerId: " + playerId);
}
}
}