From 65fdaba28daf96dbb00be65f8245e5cf3c44d124 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 7 Sep 2014 22:01:38 +0200 Subject: [PATCH] Fixed some possible NPE of server. --- .../java/mage/server/TableController.java | 58 ++++++++++--------- .../java/mage/server/game/GamesRoomImpl.java | 7 ++- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/Mage.Server/src/main/java/mage/server/TableController.java b/Mage.Server/src/main/java/mage/server/TableController.java index 7746cec845..4baaf62a0a 100644 --- a/Mage.Server/src/main/java/mage/server/TableController.java +++ b/Mage.Server/src/main/java/mage/server/TableController.java @@ -700,39 +700,41 @@ public class TableController { } private void matchEnd() { - for (Entry entry: userPlayerMap.entrySet()) { - MatchPlayer matchPlayer = match.getPlayer(entry.getValue()); - // opponent(s) left during sideboarding - if (matchPlayer != null) { - if(!matchPlayer.hasQuit()) { - User user = UserManager.getInstance().getUser(entry.getKey()); - if (user != null) { - if (table.getState().equals(TableState.SIDEBOARDING)) { - StringBuilder sb = new StringBuilder(); - if (table.isTournamentSubTable()) { - sb.append("Your tournament match of round "); - sb.append(table.getTournament().getRounds().size()); - sb.append(" is over. "); - } else { - sb.append("Match [").append(match.getName()).append("] is over. "); + if (match != null) { + for (Entry entry: userPlayerMap.entrySet()) { + MatchPlayer matchPlayer = match.getPlayer(entry.getValue()); + // opponent(s) left during sideboarding + if (matchPlayer != null) { + if(!matchPlayer.hasQuit()) { + User user = UserManager.getInstance().getUser(entry.getKey()); + if (user != null) { + if (table.getState().equals(TableState.SIDEBOARDING)) { + StringBuilder sb = new StringBuilder(); + if (table.isTournamentSubTable()) { + sb.append("Your tournament match of round "); + sb.append(table.getTournament().getRounds().size()); + sb.append(" is over. "); + } else { + sb.append("Match [").append(match.getName()).append("] is over. "); + } + if (match.getPlayers().size() > 2) { + sb.append("All your opponents have lost or quit the match."); + } else { + sb.append("Your opponent has quit the match."); + } + user.showUserMessage("Match info", sb.toString()); } - if (match.getPlayers().size() > 2) { - sb.append("All your opponents have lost or quit the match."); - } else { - sb.append("Your opponent has quit the match."); + // remove table from user - table manager holds table for display of finished matches + if (!table.isTournamentSubTable()) { + user.removeTable(entry.getValue()); } - user.showUserMessage("Match info", sb.toString()); - } - // remove table from user - table manager holds table for display of finished matches - if (!table.isTournamentSubTable()) { - user.removeTable(entry.getValue()); } } - } - } + } + } + // free resources no longer needed + match.cleanUpOnMatchEnd(ConfigSettings.getInstance().isSaveGameActivated()); } - // free resources no longer needed - match.cleanUpOnMatchEnd(ConfigSettings.getInstance().isSaveGameActivated()); } private synchronized void setupTimeout(int seconds) { diff --git a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java index b6de8b227a..1dd32dd7b8 100644 --- a/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java +++ b/Mage.Server/src/main/java/mage/server/game/GamesRoomImpl.java @@ -230,7 +230,12 @@ class TableListSorter implements Comparator { if (two.getState().equals(TableState.READY_TO_START) || two.getState().equals(TableState.WAITING) || two.getState().equals(TableState.STARTING)) { return 1; // two has higher priority } else if (one.getEndTime() == null) { - if (two.getEndTime() == null) { + if (two.getEndTime() == null) { + if (two.getStartTime() == null) { + return -1; + } else if (one.getStartTime() == null) { + return 1; + } return two.getStartTime().compareTo(one.getStartTime()); } else { return -1;