From ca6e1556f0b9aaf2ba4ac90b7e3466b8e446c3f0 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Thu, 20 Oct 2011 12:49:31 -0400 Subject: [PATCH] fixed several NPEs on server --- Mage.Server/src/main/java/mage/server/ChatSession.java | 2 +- Mage.Server/src/main/java/mage/server/MageServerImpl.java | 7 +++++-- .../src/main/java/mage/server/TableController.java | 3 ++- Mage.Server/src/main/java/mage/server/User.java | 3 ++- .../java/mage/server/tournament/TournamentController.java | 8 ++++++-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Mage.Server/src/main/java/mage/server/ChatSession.java b/Mage.Server/src/main/java/mage/server/ChatSession.java index 46b3018290..41b92d70dd 100644 --- a/Mage.Server/src/main/java/mage/server/ChatSession.java +++ b/Mage.Server/src/main/java/mage/server/ChatSession.java @@ -65,7 +65,7 @@ public class ChatSession { } public void kill(UUID userId) { - if (clients.containsKey(userId)) { + if (userId != null && clients.containsKey(userId)) { String userName = clients.get(userId); clients.remove(userId); broadcast(userName, " has left", MessageColor.BLACK); diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index db03630709..3b14896440 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -451,8 +451,11 @@ public class MageServerImpl implements MageServer { @Override public boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException { try { - UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); - return TableManager.getInstance().isTableOwner(tableId, userId); + Session session = SessionManager.getInstance().getSession(sessionId); + if (session != null) { + UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId(); + return TableManager.getInstance().isTableOwner(tableId, userId); + } } catch (Exception ex) { handleException(ex); diff --git a/Mage.Server/src/main/java/mage/server/TableController.java b/Mage.Server/src/main/java/mage/server/TableController.java index 3731a868e9..83408474ce 100644 --- a/Mage.Server/src/main/java/mage/server/TableController.java +++ b/Mage.Server/src/main/java/mage/server/TableController.java @@ -263,7 +263,8 @@ public class TableController { else { player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange(), skill); } - logger.info("Player created " + player.getId()); + if (player != null) + logger.info("Player created " + player.getId()); return player; } diff --git a/Mage.Server/src/main/java/mage/server/User.java b/Mage.Server/src/main/java/mage/server/User.java index 58c106d0a9..5a4d75726f 100644 --- a/Mage.Server/src/main/java/mage/server/User.java +++ b/Mage.Server/src/main/java/mage/server/User.java @@ -119,7 +119,8 @@ public class User { public synchronized void fireCallback(final ClientCallback call) { if (isConnected()) { Session session = SessionManager.getInstance().getSession(sessionId); - session.fireCallback(call); + if (session != null) + session.fireCallback(call); } } diff --git a/Mage.Server/src/main/java/mage/server/tournament/TournamentController.java b/Mage.Server/src/main/java/mage/server/tournament/TournamentController.java index c4c21e1fad..c38805603a 100644 --- a/Mage.Server/src/main/java/mage/server/tournament/TournamentController.java +++ b/Mage.Server/src/main/java/mage/server/tournament/TournamentController.java @@ -217,11 +217,15 @@ public class TournamentController { } public void submitDeck(UUID playerId, Deck deck) { - tournamentSessions.get(playerId).submitDeck(deck); + if (tournamentSessions.containsKey(playerId)) { + tournamentSessions.get(playerId).submitDeck(deck); + } } public void updateDeck(UUID playerId, Deck deck) { - tournamentSessions.get(playerId).updateDeck(deck); + if (tournamentSessions.containsKey(playerId)) { + tournamentSessions.get(playerId).updateDeck(deck); + } } public void timeout(UUID userId) {