Refactoring user access.
This commit is contained in:
@@ -8,7 +8,6 @@ import com.gempukku.lotro.common.Keyword;
|
||||
import com.gempukku.lotro.db.DbAccess;
|
||||
import com.gempukku.lotro.db.DeckDAO;
|
||||
import com.gempukku.lotro.db.GameHistoryDAO;
|
||||
import com.gempukku.lotro.db.PlayerDAO;
|
||||
import com.gempukku.lotro.db.vo.GameHistoryEntry;
|
||||
import com.gempukku.lotro.db.vo.Player;
|
||||
import com.gempukku.lotro.logic.timing.GameResultListener;
|
||||
@@ -32,7 +31,6 @@ public class LotroServer extends AbstractServer {
|
||||
|
||||
private int _nextGameId = 1;
|
||||
|
||||
private PlayerDAO _playerDao;
|
||||
private DeckDAO _deckDao;
|
||||
private GameHistoryDAO _gameHistoryDao;
|
||||
private DefaultCardCollection _defaultCollection;
|
||||
@@ -69,7 +67,6 @@ public class LotroServer extends AbstractServer {
|
||||
);
|
||||
thr.start();
|
||||
|
||||
_playerDao = new PlayerDAO(dbAccess);
|
||||
_deckDao = new DeckDAO(dbAccess);
|
||||
|
||||
_gameHistoryDao = new GameHistoryDAO(dbAccess);
|
||||
@@ -97,10 +94,6 @@ public class LotroServer extends AbstractServer {
|
||||
return _lotroCardBlueprintLibrary;
|
||||
}
|
||||
|
||||
public PlayerDAO getPlayerDao() {
|
||||
return _playerDao;
|
||||
}
|
||||
|
||||
public DeckDAO getDeckDao() {
|
||||
return _deckDao;
|
||||
}
|
||||
@@ -216,8 +209,7 @@ public class LotroServer extends AbstractServer {
|
||||
}
|
||||
}
|
||||
|
||||
public LotroDeck getParticipantDeck(String participantId, String deckName) {
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
public LotroDeck getParticipantDeck(Player player, String deckName) {
|
||||
LotroDeck deck = _deckDao.getDeckForPlayer(player, deckName);
|
||||
if (deck == null)
|
||||
return null;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.gempukku.lotro.hall;
|
||||
|
||||
import com.gempukku.lotro.AbstractServer;
|
||||
import com.gempukku.lotro.chat.ChatServer;
|
||||
import com.gempukku.lotro.db.CollectionDAO;
|
||||
import com.gempukku.lotro.db.vo.League;
|
||||
import com.gempukku.lotro.db.vo.Player;
|
||||
import com.gempukku.lotro.game.*;
|
||||
@@ -16,7 +15,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
public class HallServer extends AbstractServer {
|
||||
private ChatServer _chatServer;
|
||||
private LeagueService _leagueService;
|
||||
private CollectionDAO _collectionDao;
|
||||
private LotroServer _lotroServer;
|
||||
|
||||
private Map<String, String> _supportedFormatNames = new LinkedHashMap<String, String>();
|
||||
@@ -33,11 +31,10 @@ public class HallServer extends AbstractServer {
|
||||
|
||||
private Map<Player, Long> _lastVisitedPlayers = Collections.synchronizedMap(new LinkedHashMap<Player, Long>());
|
||||
|
||||
public HallServer(LotroServer lotroServer, ChatServer chatServer, LeagueService leagueService, CollectionDAO collectionDao, boolean test) {
|
||||
public HallServer(LotroServer lotroServer, ChatServer chatServer, LeagueService leagueService, boolean test) {
|
||||
_lotroServer = lotroServer;
|
||||
_chatServer = chatServer;
|
||||
_leagueService = leagueService;
|
||||
_collectionDao = collectionDao;
|
||||
_chatServer.createChatRoom("Game Hall");
|
||||
|
||||
addFormat("fotr_block", "Fellowship block", "default", new FotRBlockFormat(_lotroServer.getLotroCardBlueprintLibrary(), false));
|
||||
@@ -101,7 +98,7 @@ public class HallServer extends AbstractServer {
|
||||
if (isPlayerBusy(player.getName()))
|
||||
throw new HallException("You can't play more than one game at a time or wait at more than one table");
|
||||
|
||||
LotroDeck lotroDeck = _lotroServer.getParticipantDeck(player.getName(), deckName);
|
||||
LotroDeck lotroDeck = _lotroServer.getParticipantDeck(player, deckName);
|
||||
if (lotroDeck == null)
|
||||
throw new HallException("You don't have a deck registered yet");
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ public class ServerResource {
|
||||
private ChatServer _chatServer;
|
||||
private LeagueService _leagueService;
|
||||
private CollectionDAO _collectionDao;
|
||||
private PlayerDAO _playerDao;
|
||||
private PackBox _packBox;
|
||||
|
||||
public ServerResource() {
|
||||
@@ -73,10 +74,11 @@ public class ServerResource {
|
||||
_lotroServer.startServer();
|
||||
|
||||
_collectionDao = new CollectionDAO(dbAccess, _library);
|
||||
_playerDao = new PlayerDAO(dbAccess);
|
||||
|
||||
_leagueService = new LeagueService(dbAccess, _collectionDao, _library);
|
||||
|
||||
_hallServer = new HallServer(_lotroServer, _chatServer, _leagueService, _collectionDao, _test);
|
||||
_hallServer = new HallServer(_lotroServer, _chatServer, _leagueService, _test);
|
||||
_hallServer.startServer();
|
||||
|
||||
DefaultPackBox packBox = new DefaultPackBox();
|
||||
@@ -97,7 +99,7 @@ public class ServerResource {
|
||||
@FormParam("login") String login,
|
||||
@FormParam("password") String password,
|
||||
@Context HttpServletRequest request) throws Exception {
|
||||
if (_lotroServer.getPlayerDao().loginUser(login, password) != null) {
|
||||
if (_playerDao.loginUser(login, password) != null) {
|
||||
logUser(request, login);
|
||||
return "<script>location.href='hall.html';</script>";
|
||||
} else {
|
||||
@@ -112,7 +114,7 @@ public class ServerResource {
|
||||
@FormParam("login") String login,
|
||||
@FormParam("password") String password,
|
||||
@Context HttpServletRequest request) throws Exception {
|
||||
if (_lotroServer.getPlayerDao().registerUser(login, password)) {
|
||||
if (_playerDao.registerUser(login, password)) {
|
||||
logUser(request, login);
|
||||
return "<script>location.href='hall.html';</script>";
|
||||
} else {
|
||||
@@ -178,9 +180,7 @@ public class ServerResource {
|
||||
if (start < 0 || count < 1 || count > 100)
|
||||
sendError(Response.Status.BAD_REQUEST);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
@@ -334,13 +334,12 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
List<String> names = new ArrayList<String>(deckDao.getPlayerDeckNames(player));
|
||||
Collections.sort(names);
|
||||
|
||||
@@ -367,13 +366,12 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
LotroDeck deck = deckDao.getDeckForPlayer(player, deckName);
|
||||
if (deck == null) {
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
@@ -398,13 +396,12 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
LotroDeck deck = _lotroServer.validateDeck(contents);
|
||||
if (deck == null)
|
||||
sendError(Response.Status.BAD_REQUEST);
|
||||
@@ -432,13 +429,12 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
LotroDeck deck = deckDao.renameDeck(player, oldDeckName, deckName);
|
||||
if (deck == null)
|
||||
sendError(Response.Status.NOT_FOUND);
|
||||
@@ -455,13 +451,12 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
DeckDAO deckDao = _lotroServer.getDeckDao();
|
||||
|
||||
deckDao.deleteDeckForPlayer(player, deckName);
|
||||
}
|
||||
|
||||
@@ -551,7 +546,9 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
Player player = _lotroServer.getPlayerDao().getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
CardCollection collection = getCollection(player, collectionType);
|
||||
if (collection == null)
|
||||
@@ -618,7 +615,9 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
Player player = _lotroServer.getPlayerDao().getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
CardCollection collection = getCollection(player, collectionType);
|
||||
if (collection == null || !(collection instanceof MutableCardCollection))
|
||||
@@ -731,9 +730,7 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
@@ -774,9 +771,7 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
@@ -798,9 +793,7 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
@@ -820,9 +813,7 @@ public class ServerResource {
|
||||
if (!_test)
|
||||
participantId = getLoggedUser(request);
|
||||
|
||||
PlayerDAO playerDao = _lotroServer.getPlayerDao();
|
||||
|
||||
Player player = playerDao.getPlayer(participantId);
|
||||
Player player = _playerDao.getPlayer(participantId);
|
||||
if (player == null)
|
||||
sendError(Response.Status.UNAUTHORIZED);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user