Some server NPE fixes

This commit is contained in:
magenoxx 2011-10-24 20:48:58 +04:00
parent db30dbd5d6
commit 8983a26e5b

View file

@ -154,10 +154,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().removeTable(userId, tableId);
}
}
}
);
}
catch (Exception ex) {
@ -310,10 +312,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().startMatch(userId, roomId, tableId);
}
}
}
);
}
catch (Exception ex) {
@ -330,10 +334,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().startChallenge(userId, roomId, tableId, challengeId);
}
}
}
);
}
catch (Exception ex) {
@ -350,10 +356,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().startTournament(userId, roomId, tableId);
}
}
}
);
}
catch (Exception ex) {
@ -397,10 +405,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ChatManager.getInstance().joinChat(chatId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -415,10 +425,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ChatManager.getInstance().leaveChat(chatId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -451,8 +463,7 @@ public class MageServerImpl implements MageServer {
@Override
public boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException {
try {
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null) {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return TableManager.getInstance().isTableOwner(tableId, userId);
}
@ -471,10 +482,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().swapSeats(tableId, userId, seatNum1, seatNum2);
}
}
}
);
}
catch (Exception ex) {
@ -491,10 +504,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(userId, tableId);
}
}
}
);
}
catch (Exception ex) {
@ -522,10 +537,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().joinGame(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -542,10 +559,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
DraftManager.getInstance().joinDraft(draftId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -562,10 +581,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TournamentManager.getInstance().joinTournament(tournamentId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -624,10 +645,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
User user = SessionManager.getInstance().getUser(sessionId);
user.sendPlayerString(gameId, data);
}
}
}
);
}
catch (Exception ex) {
@ -644,10 +667,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
User user = SessionManager.getInstance().getUser(sessionId);
user.sendPlayerBoolean(gameId, data);
}
}
}
);
}
catch (Exception ex) {
@ -664,10 +689,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
User user = SessionManager.getInstance().getUser(sessionId);
user.sendPlayerInteger(gameId, data);
}
}
}
);
}
catch (Exception ex) {
@ -698,10 +725,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().concedeGame(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -732,10 +761,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().watchGame(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -752,10 +783,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().stopWatching(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -772,10 +805,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().replayGame(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -792,10 +827,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().startReplay(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -812,10 +849,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().stopReplay(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -832,10 +871,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().nextPlay(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -852,10 +893,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().previousPlay(gameId, userId);
}
}
}
);
}
catch (Exception ex) {
@ -872,10 +915,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
ReplayManager.getInstance().skipForward(gameId, userId, moves);
}
}
}
);
}
catch (Exception ex) {
@ -910,11 +955,13 @@ public class MageServerImpl implements MageServer {
@Override
public void run() {
if (testMode) {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().cheat(gameId, userId, playerId, deckList);
}
}
}
}
);
}
catch (Exception ex) {
@ -987,10 +1034,12 @@ public class MageServerImpl implements MageServer {
new Runnable() {
@Override
public void run() {
if (SessionManager.getInstance().isValidSession(sessionId)) {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
TableManager.getInstance().removeTable(userId, tableId);
}
}
}
);
}
catch (Exception ex) {