Some fixes to player quits game handling.

This commit is contained in:
LevelX2 2014-09-28 15:45:35 +02:00
parent 2835a4e152
commit 350897b0e2
4 changed files with 47 additions and 14 deletions

View file

@ -338,25 +338,30 @@ public class User {
logger.debug("REMOVE " + getName() + " Game sessions: " + gameSessions.size() );
for (GameSession gameSession: gameSessions.values()) {
logger.debug("-- kill game session of gameId: " + gameSession.getGameId() );
gameSession.kill();
gameSession.quitGame();
}
gameSessions.clear();
logger.debug("REMOVE " + getName() + " Draft sessions " + draftSessions.size());
for (DraftSession draftSession: draftSessions.values()) {
draftSession.setKilled();
}
draftSessions.clear();
logger.debug("REMOVE " + getName() + " Tournament sessions " + tournamentSessions.size());
for (TournamentSession tournamentSession: tournamentSessions.values()) {
tournamentSession.setKilled();
}
tournamentSessions.clear();
logger.debug("REMOVE " + getName() + " Tables " + tables.size());
for (Entry<UUID, Table> entry: tables.entrySet()) {
logger.debug("-- leave tableId: " + entry.getValue().getId());
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
}
tables.clear();
logger.debug("REMOVE " + getName() + " watched Games " + watchedGames.size());
for (UUID gameId: watchedGames) {
GameManager.getInstance().stopWatching(gameId, userId);
}
watchedGames.clear();
logger.debug("REMOVE " + getName() + " Chats ");
ChatManager.getInstance().removeUser(userId, reason);
}

View file

@ -379,7 +379,13 @@ public class GameController implements GameCallback {
// }
public void quitMatch(UUID userId) {
game.quit(getPlayerId(userId));
UUID playerId = getPlayerId(userId);
if (playerId != null) {
GameSession gameSession = gameSessions.get(playerId);
if (gameSession != null) {
gameSession.quitGame();
}
}
}
public void sendPlayerAction(PlayerAction playerAction, UUID userId) {

View file

@ -44,6 +44,7 @@ import org.apache.log4j.Logger;
import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
@ -62,6 +63,7 @@ public class GameSession extends GameWatcher {
private ScheduledFuture<?> futureTimeout;
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
private static final ExecutorService callExecutor = ThreadExecutor.getInstance().getCallExecutor();
private UserData userData;
@ -274,11 +276,31 @@ public class GameSession extends GameWatcher {
return game.getId();
}
public void kill() {
public void quitGame() {
if (game != null) {
if (game.getPlayer(playerId).isInGame()) {
logger.debug("QUIT game playerId: " + playerId + " gameId: " + game.getId());
game.quit(playerId);
final Player player = game.getPlayer(playerId);
if (player != null && player.isInGame()) {
callExecutor.execute(
new Runnable() {
@Override
public void run() {
try {
player.quit(game);
} catch (Exception ex) {
if (ex != null) {
logger.fatal("Game session game quit exception " + (ex.getMessage() == null ? "null":ex.getMessage()));
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");
}
}
}
}
);
}
} else {
logger.error("game object missing playerId: " + (playerId == null ? "[null]":playerId));