mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Replaced Session with User - needed for reconnect
This commit is contained in:
parent
3d540160a8
commit
1a43757ed0
24 changed files with 610 additions and 525 deletions
|
@ -54,12 +54,12 @@ public class ChatManager {
|
||||||
return chatSession.getChatId();
|
return chatSession.getChatId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinChat(UUID chatId, String sessionId, String userName) {
|
public void joinChat(UUID chatId, UUID userId) {
|
||||||
chatSessions.get(chatId).join(userName, sessionId);
|
chatSessions.get(chatId).join(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leaveChat(UUID chatId, String sessionId) {
|
public void leaveChat(UUID chatId, UUID userId) {
|
||||||
chatSessions.get(chatId).kill(sessionId);
|
chatSessions.get(chatId).kill(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroyChatSession(UUID chatId) {
|
public void destroyChatSession(UUID chatId) {
|
||||||
|
@ -70,9 +70,9 @@ public class ChatManager {
|
||||||
chatSessions.get(chatId).broadcast(userName, message, color);
|
chatSessions.get(chatId).broadcast(userName, message, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeSession(String sessionId) {
|
void removeUser(UUID userId) {
|
||||||
for (ChatSession chat: chatSessions.values()) {
|
for (ChatSession chat: chatSessions.values()) {
|
||||||
chat.kill(sessionId);
|
chat.kill(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
|
@ -46,7 +47,7 @@ import org.apache.log4j.Logger;
|
||||||
public class ChatSession {
|
public class ChatSession {
|
||||||
|
|
||||||
private final static Logger logger = Logger.getLogger(ChatSession.class);
|
private final static Logger logger = Logger.getLogger(ChatSession.class);
|
||||||
private ConcurrentHashMap<String, String> clients = new ConcurrentHashMap<String, String>();
|
private ConcurrentHashMap<UUID, String> clients = new ConcurrentHashMap<UUID, String>();
|
||||||
private UUID chatId;
|
private UUID chatId;
|
||||||
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
|
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
|
||||||
|
|
||||||
|
@ -56,16 +57,20 @@ public class ChatSession {
|
||||||
chatId = UUID.randomUUID();
|
chatId = UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join(String userName, String sessionId) {
|
public void join(UUID userId) {
|
||||||
clients.put(sessionId, userName);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
broadcast(userName, " has joined", MessageColor.BLACK);
|
if (user != null) {
|
||||||
logger.info(userName + " joined chat " + chatId);
|
String userName = user.getName();
|
||||||
|
clients.put(userId, userName);
|
||||||
|
broadcast(userName, " has joined", MessageColor.BLACK);
|
||||||
|
logger.info(userName + " joined chat " + chatId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(String sessionId) {
|
public void kill(UUID userId) {
|
||||||
if (clients.containsKey(sessionId)) {
|
if (clients.containsKey(userId)) {
|
||||||
String userName = clients.get(sessionId);
|
String userName = clients.get(userId);
|
||||||
clients.remove(sessionId);
|
clients.remove(userId);
|
||||||
broadcast(userName, " has left", MessageColor.BLACK);
|
broadcast(userName, " has left", MessageColor.BLACK);
|
||||||
logger.info(userName + " has left chat " + chatId);
|
logger.info(userName + " has left chat " + chatId);
|
||||||
}
|
}
|
||||||
|
@ -77,12 +82,12 @@ public class ChatSession {
|
||||||
final String time = timeFormatter.format(cal.getTime());
|
final String time = timeFormatter.format(cal.getTime());
|
||||||
final String username = userName;
|
final String username = userName;
|
||||||
logger.debug("Broadcasting '" + msg + "' for " + chatId);
|
logger.debug("Broadcasting '" + msg + "' for " + chatId);
|
||||||
for (String sessionId: clients.keySet()) {
|
for (UUID userId: clients.keySet()) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null)
|
if (user != null)
|
||||||
session.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(username, msg, time, color)));
|
user.fireCallback(new ClientCallback("chatMessage", chatId, new ChatMessage(username, msg, time, color)));
|
||||||
else
|
else
|
||||||
kill(sessionId);
|
kill(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public TableView createTable(String sessionId, UUID roomId, MatchOptions options) throws MageException {
|
public TableView createTable(String sessionId, UUID roomId, MatchOptions options) throws MageException {
|
||||||
try {
|
try {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(sessionId, options);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(userId, options);
|
||||||
logger.info("Table " + table.getTableId() + " created");
|
logger.info("Table " + table.getTableId() + " created");
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
@ -122,7 +123,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions options) throws MageException {
|
public TableView createTournamentTable(String sessionId, UUID roomId, TournamentOptions options) throws MageException {
|
||||||
try {
|
try {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(sessionId, options);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(userId, options);
|
||||||
logger.info("Tournament table " + table.getTableId() + " created");
|
logger.info("Tournament table " + table.getTableId() + " created");
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
@ -141,7 +143,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TableManager.getInstance().removeTable(sessionId, tableId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TableManager.getInstance().removeTable(userId, tableId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -156,7 +159,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException, GameException {
|
public boolean joinTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException, GameException {
|
||||||
try {
|
try {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, name, playerType, skill, deckList);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(userId, tableId, name, playerType, skill, deckList);
|
||||||
logger.info("Session " + sessionId + " joined table " + tableId);
|
logger.info("Session " + sessionId + " joined table " + tableId);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +177,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws MageException, GameException {
|
public boolean joinTournamentTable(String sessionId, UUID roomId, UUID tableId, String name, String playerType, int skill) throws MageException, GameException {
|
||||||
try {
|
try {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(sessionId, tableId, name, playerType, skill);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTournamentTable(userId, tableId, name, playerType, skill);
|
||||||
logger.info("Session " + sessionId + " joined table " + tableId);
|
logger.info("Session " + sessionId + " joined table " + tableId);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +195,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException {
|
public boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException {
|
||||||
try {
|
try {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
boolean ret = TableManager.getInstance().submitDeck(sessionId, tableId, deckList);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
boolean ret = TableManager.getInstance().submitDeck(userId, tableId, deckList);
|
||||||
logger.info("Session " + sessionId + " submitted deck");
|
logger.info("Session " + sessionId + " submitted deck");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -218,8 +224,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public List<String> getConnectedPlayers(UUID roomId) throws MageException {
|
public List<String> getConnectedPlayers(UUID roomId) throws MageException {
|
||||||
try {
|
try {
|
||||||
List<String> players = new ArrayList<String>();
|
List<String> players = new ArrayList<String>();
|
||||||
for (Session session : SessionManager.getInstance().getSessions().values()) {
|
for (User user : UserManager.getInstance().getUsers()) {
|
||||||
players.add(session.getUser().getName());
|
players.add(user.getName());
|
||||||
}
|
}
|
||||||
return players;
|
return players;
|
||||||
}
|
}
|
||||||
|
@ -266,7 +272,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TableManager.getInstance().startMatch(sessionId, roomId, tableId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TableManager.getInstance().startMatch(userId, roomId, tableId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -285,7 +292,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TableManager.getInstance().startChallenge(sessionId, roomId, tableId, challengeId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TableManager.getInstance().startChallenge(userId, roomId, tableId, challengeId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -304,7 +312,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TableManager.getInstance().startTournament(sessionId, roomId, tableId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TableManager.getInstance().startTournament(userId, roomId, tableId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -350,7 +359,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ChatManager.getInstance().joinChat(chatId, sessionId, userName);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
ChatManager.getInstance().joinChat(chatId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -367,7 +377,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ChatManager.getInstance().leaveChat(chatId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
ChatManager.getInstance().leaveChat(chatId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -402,7 +413,8 @@ public class MageServerImpl implements MageServer {
|
||||||
@Override
|
@Override
|
||||||
public boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException {
|
public boolean isTableOwner(String sessionId, UUID roomId, UUID tableId) throws MageException {
|
||||||
try {
|
try {
|
||||||
return TableManager.getInstance().isTableOwner(tableId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
return TableManager.getInstance().isTableOwner(tableId, userId);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
handleException(ex);
|
handleException(ex);
|
||||||
|
@ -418,7 +430,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TableManager.getInstance().swapSeats(tableId, sessionId, seatNum1, seatNum2);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TableManager.getInstance().swapSeats(tableId, userId, seatNum1, seatNum2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -437,7 +450,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(sessionId, tableId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(userId, tableId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -467,7 +481,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().joinGame(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().joinGame(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -486,7 +501,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DraftManager.getInstance().joinDraft(draftId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
DraftManager.getInstance().joinDraft(draftId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -505,7 +521,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TournamentManager.getInstance().joinTournament(tournamentId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TournamentManager.getInstance().joinTournament(tournamentId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -546,7 +563,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().sendPlayerUUID(gameId, sessionId, data);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().sendPlayerUUID(gameId, userId, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -565,7 +583,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().sendPlayerString(gameId, sessionId, data);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().sendPlayerString(gameId, userId, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -584,7 +603,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().sendPlayerBoolean(gameId, sessionId, data);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().sendPlayerBoolean(gameId, userId, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -603,7 +623,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().sendPlayerInteger(gameId, sessionId, data);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().sendPlayerInteger(gameId, userId, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -618,7 +639,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
public DraftPickView sendCardPick(final UUID draftId, final String sessionId, final UUID cardPick) throws MageException {
|
||||||
try {
|
try {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
return DraftManager.getInstance().sendCardPick(draftId, sessionId, cardPick);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
return DraftManager.getInstance().sendCardPick(draftId, userId, cardPick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@ -635,7 +657,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().concedeGame(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().concedeGame(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -650,7 +673,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException {
|
public boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException {
|
||||||
try {
|
try {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
return GamesRoomManager.getInstance().getRoom(roomId).watchTable(sessionId, tableId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
return GamesRoomManager.getInstance().getRoom(roomId).watchTable(userId, tableId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@ -667,7 +691,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().watchGame(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().watchGame(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -686,7 +711,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().stopWatching(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().stopWatching(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -705,7 +731,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ReplayManager.getInstance().replayGame(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
ReplayManager.getInstance().replayGame(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -724,7 +751,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ReplayManager.getInstance().startReplay(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
ReplayManager.getInstance().startReplay(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -743,7 +771,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ReplayManager.getInstance().stopReplay(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
ReplayManager.getInstance().stopReplay(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -762,7 +791,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ReplayManager.getInstance().nextPlay(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
ReplayManager.getInstance().nextPlay(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -781,7 +811,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ReplayManager.getInstance().previousPlay(gameId, sessionId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
ReplayManager.getInstance().previousPlay(gameId, userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -817,8 +848,10 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (testMode)
|
if (testMode) {
|
||||||
GameManager.getInstance().cheat(gameId, sessionId, playerId, deckList);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
GameManager.getInstance().cheat(gameId, userId, playerId, deckList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -833,7 +866,8 @@ public class MageServerImpl implements MageServer {
|
||||||
public boolean cheat(final UUID gameId, final String sessionId, final UUID playerId, final String cardName) throws MageException {
|
public boolean cheat(final UUID gameId, final String sessionId, final UUID playerId, final String cardName) throws MageException {
|
||||||
if (testMode) {
|
if (testMode) {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
return GameManager.getInstance().cheat(gameId, sessionId, playerId, cardName);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
return GameManager.getInstance().cheat(gameId, userId, playerId, cardName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -847,15 +881,20 @@ public class MageServerImpl implements MageServer {
|
||||||
@Override
|
@Override
|
||||||
public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) {
|
public GameView getGameView(final UUID gameId, final String sessionId, final UUID playerId) {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
return GameManager.getInstance().getGameView(gameId, sessionId, playerId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
return GameManager.getInstance().getGameView(gameId, userId, playerId);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UserView> getUsers(String sessionId) throws MageException {
|
public List<UserView> getUsers(String sessionId) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId) && SessionManager.getInstance().isAdmin(sessionId)) {
|
||||||
return SessionManager.getInstance().getUsers(sessionId);
|
List<UserView> users = new ArrayList<UserView>();
|
||||||
|
for (User user: UserManager.getInstance().getUsers()) {
|
||||||
|
users.add(new UserView(user.getName(), "", user.getSessionId(), user.getConnectionTime()));
|
||||||
|
}
|
||||||
|
return users;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -887,7 +926,8 @@ public class MageServerImpl implements MageServer {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TableManager.getInstance().removeTable(sessionId, tableId);
|
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||||
|
TableManager.getInstance().removeTable(userId, tableId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -131,7 +131,12 @@ public class Main {
|
||||||
public void handleConnectionException(Throwable throwable, Client client) {
|
public void handleConnectionException(Throwable throwable, Client client) {
|
||||||
Session session = SessionManager.getInstance().getSession(client.getSessionId());
|
Session session = SessionManager.getInstance().getSession(client.getSessionId());
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
String sessionName = session.getUser().getName() + " at " + session.getHost();
|
String sessionName;
|
||||||
|
User user = UserManager.getInstance().getUser(session.getUserId());
|
||||||
|
if (user != null)
|
||||||
|
sessionName = user.getName() + " at " + session.getHost();
|
||||||
|
else
|
||||||
|
sessionName = session.getHost();
|
||||||
if (throwable instanceof ClientDisconnectedException) {
|
if (throwable instanceof ClientDisconnectedException) {
|
||||||
logger.info("client disconnected - " + sessionName);
|
logger.info("client disconnected - " + sessionName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,7 @@ package mage.server;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.cards.decks.Deck;
|
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.game.GameManager;
|
|
||||||
import mage.view.TableClientMessage;
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jboss.remoting.callback.AsynchInvokerCallbackHandler;
|
import org.jboss.remoting.callback.AsynchInvokerCallbackHandler;
|
||||||
import org.jboss.remoting.callback.Callback;
|
import org.jboss.remoting.callback.Callback;
|
||||||
|
@ -50,8 +47,9 @@ public class Session {
|
||||||
private final static Logger logger = Logger.getLogger(Session.class);
|
private final static Logger logger = Logger.getLogger(Session.class);
|
||||||
|
|
||||||
private String sessionId;
|
private String sessionId;
|
||||||
private User user;
|
private UUID userId;
|
||||||
private String host;
|
private String host;
|
||||||
|
private int messageId = 0;
|
||||||
private Date timeConnected;
|
private Date timeConnected;
|
||||||
private boolean isAdmin = false;
|
private boolean isAdmin = false;
|
||||||
private AsynchInvokerCallbackHandler callbackHandler;
|
private AsynchInvokerCallbackHandler callbackHandler;
|
||||||
|
@ -65,25 +63,30 @@ public class Session {
|
||||||
|
|
||||||
public void registerUser(String userName) throws MageException {
|
public void registerUser(String userName) throws MageException {
|
||||||
this.isAdmin = false;
|
this.isAdmin = false;
|
||||||
User user = UserManager.getInstance().findUser(userName);
|
if (userName.equals("Admin"))
|
||||||
if (user == null) {
|
throw new MageException("User name already in use");
|
||||||
user = UserManager.getInstance().createUser(userName, host);
|
User user = UserManager.getInstance().createUser(userName, host);
|
||||||
}
|
if (user == null) { // user already exists
|
||||||
else {
|
user = UserManager.getInstance().findUser(userName);
|
||||||
if (user.getHost().equals(host)) {
|
if (user.getHost().equals(host)) {
|
||||||
logger.info("Reconnecting session for " + userName);
|
if (user.getSessionId().isEmpty())
|
||||||
|
logger.info("Reconnecting session for " + userName);
|
||||||
|
else
|
||||||
|
throw new MageException("This machine is already connected");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new MageException("User name already in use");
|
throw new MageException("User name already in use");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UserManager.getInstance().connectToSession(sessionId, userName);
|
if (!UserManager.getInstance().connectToSession(sessionId, user.getId()))
|
||||||
this.user = user;
|
throw new MageException("Error connecting");
|
||||||
|
this.userId = user.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerAdmin() {
|
public void registerAdmin() {
|
||||||
this.isAdmin = true;
|
this.isAdmin = true;
|
||||||
this.user = UserManager.getInstance().createUser("Admin", host);
|
User user = UserManager.getInstance().createUser("Admin", host);
|
||||||
|
this.userId = user.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -91,50 +94,23 @@ public class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill() {
|
public void kill() {
|
||||||
TableManager.getInstance().removeSession(sessionId);
|
// TableManager.getInstance().removeSession(sessionId);
|
||||||
GameManager.getInstance().removeSession(sessionId);
|
// GameManager.getInstance().removeSession(sessionId);
|
||||||
ChatManager.getInstance().removeSession(sessionId);
|
// ChatManager.getInstance().removeSession(sessionId);
|
||||||
UserManager.getInstance().disconnect(user.getName());
|
UserManager.getInstance().disconnect(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void fireCallback(final ClientCallback call) {
|
synchronized void fireCallback(final ClientCallback call) {
|
||||||
try {
|
try {
|
||||||
|
call.setMessageId(messageId++);
|
||||||
callbackHandler.handleCallbackOneway(new Callback(call));
|
callbackHandler.handleCallbackOneway(new Callback(call));
|
||||||
} catch (HandleCallbackException ex) {
|
} catch (HandleCallbackException ex) {
|
||||||
logger.fatal("Session fireCallback error", ex);
|
logger.fatal("Session fireCallback error", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameStarted(final UUID gameId, final UUID playerId) {
|
public UUID getUserId() {
|
||||||
fireCallback(new ClientCallback("startGame", gameId, new TableClientMessage(gameId, playerId)));
|
return userId;
|
||||||
}
|
|
||||||
|
|
||||||
public void draftStarted(final UUID draftId, final UUID playerId) {
|
|
||||||
fireCallback(new ClientCallback("startDraft", draftId, new TableClientMessage(draftId, playerId)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tournamentStarted(final UUID tournamentId, final UUID playerId) {
|
|
||||||
fireCallback(new ClientCallback("startTournament", tournamentId, new TableClientMessage(tournamentId, playerId)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sideboard(final Deck deck, final UUID tableId, final int time) {
|
|
||||||
fireCallback(new ClientCallback("sideboard", tableId, new TableClientMessage(deck, tableId, time)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void construct(final Deck deck, final UUID tableId, final int time) {
|
|
||||||
fireCallback(new ClientCallback("construct", tableId, new TableClientMessage(deck, tableId, time)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void watchGame(final UUID gameId) {
|
|
||||||
fireCallback(new ClientCallback("watchGame", gameId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void replayGame(final UUID gameId) {
|
|
||||||
fireCallback(new ClientCallback("replayGame", gameId));
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAdmin() {
|
public boolean isAdmin() {
|
||||||
|
|
|
@ -99,17 +99,6 @@ public class SessionManager {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<UserView> getUsers(String sessionId) {
|
|
||||||
List<UserView> users = new ArrayList<UserView>();
|
|
||||||
Session admin = sessions.get(sessionId);
|
|
||||||
if (admin != null && admin.isAdmin()) {
|
|
||||||
for (Session session: sessions.values()) {
|
|
||||||
users.add(new UserView(session.getUser().getName(), "", session.getId(), session.getConnectionTime()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return users;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnectUser(String sessionId, String userSessionId) {
|
public void disconnectUser(String sessionId, String userSessionId) {
|
||||||
if (isAdmin(sessionId)) {
|
if (isAdmin(sessionId)) {
|
||||||
Session session = sessions.get(userSessionId);
|
Session session = sessions.get(userSessionId);
|
||||||
|
|
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import mage.Constants.RangeOfInfluence;
|
import mage.Constants.RangeOfInfluence;
|
||||||
import mage.Constants.TableState;
|
import mage.Constants.TableState;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
|
@ -67,36 +66,38 @@ public class TableController {
|
||||||
|
|
||||||
private final static Logger logger = Logger.getLogger(TableController.class);
|
private final static Logger logger = Logger.getLogger(TableController.class);
|
||||||
|
|
||||||
private String sessionId;
|
private UUID userId;
|
||||||
private UUID chatId;
|
private UUID chatId;
|
||||||
private String controllerName;
|
private String controllerName;
|
||||||
private Table table;
|
private Table table;
|
||||||
private Match match;
|
private Match match;
|
||||||
private MatchOptions options;
|
private MatchOptions options;
|
||||||
private Tournament tournament;
|
private Tournament tournament;
|
||||||
private ConcurrentHashMap<String, UUID> sessionPlayerMap = new ConcurrentHashMap<String, UUID>();
|
private ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<UUID, UUID>();
|
||||||
|
|
||||||
public TableController(UUID roomId, String sessionId, MatchOptions options) {
|
public TableController(UUID roomId, UUID userId, MatchOptions options) {
|
||||||
this.sessionId = sessionId;
|
this.userId = userId;
|
||||||
chatId = ChatManager.getInstance().createChatSession();
|
chatId = ChatManager.getInstance().createChatSession();
|
||||||
this.options = options;
|
this.options = options;
|
||||||
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
|
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
if (userId != null) {
|
||||||
if (session != null)
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
controllerName = session.getUser().getName();
|
controllerName = user.getName();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
controllerName = "System";
|
controllerName = "System";
|
||||||
table = new Table(roomId, options.getGameType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
|
table = new Table(roomId, options.getGameType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableController(UUID roomId, String sessionId, TournamentOptions options) {
|
public TableController(UUID roomId, UUID userId, TournamentOptions options) {
|
||||||
this.sessionId = sessionId;
|
this.userId = userId;
|
||||||
chatId = ChatManager.getInstance().createChatSession();
|
chatId = ChatManager.getInstance().createChatSession();
|
||||||
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
if (userId != null) {
|
||||||
if (session != null)
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
controllerName = session.getUser().getName();
|
controllerName = user.getName();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
controllerName = "System";
|
controllerName = "System";
|
||||||
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
|
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
|
||||||
|
@ -124,7 +125,7 @@ public class TableController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean joinTournament(String sessionId, String name, String playerType, int skill) throws GameException {
|
public synchronized boolean joinTournament(UUID userId, String name, String playerType, int skill) throws GameException {
|
||||||
if (table.getState() != TableState.WAITING) {
|
if (table.getState() != TableState.WAITING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -138,13 +139,13 @@ public class TableController {
|
||||||
logger.info("player joined " + player.getId());
|
logger.info("player joined " + player.getId());
|
||||||
//only add human players to sessionPlayerMap
|
//only add human players to sessionPlayerMap
|
||||||
if (seat.getPlayer().isHuman()) {
|
if (seat.getPlayer().isHuman()) {
|
||||||
sessionPlayerMap.put(sessionId, player.getId());
|
userPlayerMap.put(userId, player.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean joinTable(String sessionId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
public synchronized boolean joinTable(UUID userId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||||
if (table.getState() != TableState.WAITING) {
|
if (table.getState() != TableState.WAITING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -163,13 +164,13 @@ public class TableController {
|
||||||
logger.info("player joined " + player.getId());
|
logger.info("player joined " + player.getId());
|
||||||
//only add human players to sessionPlayerMap
|
//only add human players to sessionPlayerMap
|
||||||
if (seat.getPlayer().isHuman()) {
|
if (seat.getPlayer().isHuman()) {
|
||||||
sessionPlayerMap.put(sessionId, player.getId());
|
userPlayerMap.put(userId, player.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(String sessionId, Player player, String playerType, Deck deck) throws GameException {
|
public void addPlayer(UUID userId, Player player, String playerType, Deck deck) throws GameException {
|
||||||
if (table.getState() != TableState.WAITING) {
|
if (table.getState() != TableState.WAITING) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -180,15 +181,12 @@ public class TableController {
|
||||||
match.addPlayer(player, deck);
|
match.addPlayer(player, deck);
|
||||||
table.joinTable(player, seat);
|
table.joinTable(player, seat);
|
||||||
if (player.isHuman()) {
|
if (player.isHuman()) {
|
||||||
sessionPlayerMap.put(sessionId, player.getId());
|
userPlayerMap.put(userId, player.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean submitDeck(String sessionId, DeckCardLists deckList) throws MageException {
|
public synchronized boolean submitDeck(UUID userId, DeckCardLists deckList) throws MageException {
|
||||||
return submitDeck(sessionPlayerMap.get(sessionId), deckList);
|
UUID playerId = userPlayerMap.get(userId);
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized boolean submitDeck(UUID playerId, DeckCardLists deckList) throws MageException {
|
|
||||||
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
|
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -209,19 +207,19 @@ public class TableController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean watchTable(String sessionId) {
|
public boolean watchTable(UUID userId) {
|
||||||
if (table.getState() != TableState.DUELING) {
|
if (table.getState() != TableState.DUELING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SessionManager.getInstance().getSession(sessionId).watchGame(match.getGame().getId());
|
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean replayTable(String sessionId) {
|
public boolean replayTable(UUID userId) {
|
||||||
if (table.getState() != TableState.FINISHED) {
|
if (table.getState() != TableState.FINISHED) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ReplayManager.getInstance().replayGame(table.getId(), sessionId);
|
ReplayManager.getInstance().replayGame(table.getId(), userId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,24 +235,24 @@ public class TableController {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(String sessionId) {
|
public void kill(UUID userId) {
|
||||||
leaveTable(sessionId);
|
leaveTable(userId);
|
||||||
sessionPlayerMap.remove(sessionId);
|
userPlayerMap.remove(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void leaveTable(String sessionId) {
|
public synchronized void leaveTable(UUID userId) {
|
||||||
if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING)
|
if (table.getState() == TableState.WAITING || table.getState() == TableState.STARTING)
|
||||||
table.leaveTable(sessionPlayerMap.get(sessionId));
|
table.leaveTable(userPlayerMap.get(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void startMatch(String sessionId) {
|
public synchronized void startMatch(UUID userId) {
|
||||||
if (sessionId.equals(this.sessionId)) {
|
if (userId.equals(this.userId)) {
|
||||||
startMatch();
|
startMatch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void startChallenge(String sessionId, UUID challengeId) {
|
public synchronized void startChallenge(UUID userId, UUID challengeId) {
|
||||||
if (sessionId.equals(this.sessionId)) {
|
if (userId.equals(this.userId)) {
|
||||||
try {
|
try {
|
||||||
match.startMatch();
|
match.startMatch();
|
||||||
match.startGame();
|
match.startGame();
|
||||||
|
@ -262,11 +260,10 @@ public class TableController {
|
||||||
GameOptions options = new GameOptions();
|
GameOptions options = new GameOptions();
|
||||||
options.testMode = true;
|
options.testMode = true;
|
||||||
// match.getGame().setGameOptions(options);
|
// match.getGame().setGameOptions(options);
|
||||||
GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), null);
|
GameManager.getInstance().createGameSession(match.getGame(), userPlayerMap, table.getId(), null);
|
||||||
ChallengeManager.getInstance().prepareChallenge(getPlayerId(), match);
|
ChallengeManager.getInstance().prepareChallenge(getPlayerId(), match);
|
||||||
SessionManager sessionManager = SessionManager.getInstance();
|
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
UserManager.getInstance().getUser(entry.getKey()).gameStarted(match.getGame().getId(), entry.getValue());
|
||||||
sessionManager.getSession(entry.getKey()).gameStarted(match.getGame().getId(), entry.getValue());
|
|
||||||
}
|
}
|
||||||
} catch (GameException ex) {
|
} catch (GameException ex) {
|
||||||
logger.fatal(null, ex);
|
logger.fatal(null, ex);
|
||||||
|
@ -276,7 +273,7 @@ public class TableController {
|
||||||
|
|
||||||
private UUID getPlayerId() throws GameException {
|
private UUID getPlayerId() throws GameException {
|
||||||
UUID playerId = null;
|
UUID playerId = null;
|
||||||
for (Entry<String, UUID> entry : sessionPlayerMap.entrySet()) {
|
for (Entry<UUID, UUID> entry : userPlayerMap.entrySet()) {
|
||||||
playerId = entry.getValue();
|
playerId = entry.getValue();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -301,12 +298,11 @@ public class TableController {
|
||||||
try {
|
try {
|
||||||
match.startGame();
|
match.startGame();
|
||||||
table.initGame();
|
table.initGame();
|
||||||
GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), choosingPlayerId);
|
GameManager.getInstance().createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId);
|
||||||
SessionManager sessionManager = SessionManager.getInstance();
|
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||||
Session session = sessionManager.getSession(entry.getKey());
|
if (user != null) {
|
||||||
if (session != null) {
|
user.gameStarted(match.getGame().getId(), entry.getValue());
|
||||||
session.gameStarted(match.getGame().getId(), entry.getValue());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
TableManager.getInstance().removeTable(table.getId());
|
TableManager.getInstance().removeTable(table.getId());
|
||||||
|
@ -323,38 +319,35 @@ public class TableController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void startTournament(String sessionId) {
|
public synchronized void startTournament(UUID userId) {
|
||||||
try {
|
try {
|
||||||
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) {
|
if (userId.equals(this.userId) && table.getState() == TableState.STARTING) {
|
||||||
TournamentManager.getInstance().createTournamentSession(tournament, sessionPlayerMap, table.getId());
|
TournamentManager.getInstance().createTournamentSession(tournament, userPlayerMap, table.getId());
|
||||||
SessionManager sessionManager = SessionManager.getInstance();
|
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
User user = UserManager.getInstance().getUser(entry.getKey());
|
||||||
Session session = sessionManager.getSession(entry.getKey());
|
user.tournamentStarted(tournament.getId(), entry.getValue());
|
||||||
session.tournamentStarted(tournament.getId(), entry.getValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.fatal("Error starting tournament", ex);
|
logger.fatal("Error starting tournament", ex);
|
||||||
TableManager.getInstance().removeTable(table.getId());
|
TableManager.getInstance().removeTable(table.getId());
|
||||||
TournamentManager.getInstance().kill(tournament.getId(), sessionId);
|
TournamentManager.getInstance().kill(tournament.getId(), userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDraft(Draft draft) {
|
public void startDraft(Draft draft) {
|
||||||
table.initDraft();
|
table.initDraft();
|
||||||
DraftManager.getInstance().createDraftSession(draft, sessionPlayerMap, table.getId());
|
DraftManager.getInstance().createDraftSession(draft, userPlayerMap, table.getId());
|
||||||
SessionManager sessionManager = SessionManager.getInstance();
|
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
UserManager.getInstance().getUser(entry.getKey()).draftStarted(draft.getId(), entry.getValue());
|
||||||
sessionManager.getSession(entry.getKey()).draftStarted(draft.getId(), entry.getValue());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sideboard(UUID playerId, Deck deck, int timeout) throws MageException {
|
private void sideboard(UUID playerId, Deck deck, int timeout) throws MageException {
|
||||||
SessionManager sessionManager = SessionManager.getInstance();
|
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
|
||||||
if (entry.getValue().equals(playerId)) {
|
if (entry.getValue().equals(playerId)) {
|
||||||
sessionManager.getSession(entry.getKey()).sideboard(deck, table.getId(), timeout);
|
UserManager.getInstance().getUser(entry.getKey()).sideboard(deck, table.getId(), timeout);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,8 +397,8 @@ public class TableController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOwner(String sessionId) {
|
public boolean isOwner(UUID userId) {
|
||||||
return sessionId.equals(this.sessionId);
|
return userId.equals(this.userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Table getTable() {
|
public Table getTable() {
|
||||||
|
|
|
@ -60,22 +60,22 @@ public class TableManager {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Table createTable(UUID roomId, String sessionId, MatchOptions options) {
|
public Table createTable(UUID roomId, UUID userId, MatchOptions options) {
|
||||||
TableController tableController = new TableController(roomId, sessionId, options);
|
TableController tableController = new TableController(roomId, userId, options);
|
||||||
controllers.put(tableController.getTable().getId(), tableController);
|
controllers.put(tableController.getTable().getId(), tableController);
|
||||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||||
return tableController.getTable();
|
return tableController.getTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Table createTable(UUID roomId, MatchOptions options) {
|
public Table createTable(UUID roomId, MatchOptions options) {
|
||||||
TableController tableController = new TableController(roomId, UUID.randomUUID().toString(), options);
|
TableController tableController = new TableController(roomId, null, options);
|
||||||
controllers.put(tableController.getTable().getId(), tableController);
|
controllers.put(tableController.getTable().getId(), tableController);
|
||||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||||
return tableController.getTable();
|
return tableController.getTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Table createTournamentTable(UUID roomId, String sessionId, TournamentOptions options) {
|
public Table createTournamentTable(UUID roomId, UUID userId, TournamentOptions options) {
|
||||||
TableController tableController = new TableController(roomId, sessionId, options);
|
TableController tableController = new TableController(roomId, userId, options);
|
||||||
controllers.put(tableController.getTable().getId(), tableController);
|
controllers.put(tableController.getTable().getId(), tableController);
|
||||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||||
return tableController.getTable();
|
return tableController.getTable();
|
||||||
|
@ -95,47 +95,47 @@ public class TableManager {
|
||||||
return tables.values();
|
return tables.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean joinTable(String sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
return controllers.get(tableId).joinTable(sessionId, name, playerType, skill, deckList);
|
return controllers.get(tableId).joinTable(userId, name, playerType, skill, deckList);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean joinTournament(String sessionId, UUID tableId, String name, String playerType, int skill) throws GameException {
|
public boolean joinTournament(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
return controllers.get(tableId).joinTournament(sessionId, name, playerType, skill);
|
return controllers.get(tableId).joinTournament(userId, name, playerType, skill);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException {
|
public boolean submitDeck(UUID userId, UUID tableId, DeckCardLists deckList) throws MageException {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
return controllers.get(tableId).submitDeck(sessionId, deckList);
|
return controllers.get(tableId).submitDeck(userId, deckList);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSession(String sessionId) {
|
public void removeSession(UUID userId) {
|
||||||
for (TableController controller: controllers.values()) {
|
for (TableController controller: controllers.values()) {
|
||||||
controller.kill(sessionId);
|
controller.kill(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTableOwner(UUID tableId, String sessionId) {
|
public boolean isTableOwner(UUID tableId, UUID userId) {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
return controllers.get(tableId).isOwner(sessionId);
|
return controllers.get(tableId).isOwner(userId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeTable(String sessionId, UUID tableId) {
|
public boolean removeTable(UUID userId, UUID tableId) {
|
||||||
if (isTableOwner(tableId, sessionId) || SessionManager.getInstance().isAdmin(sessionId)) {
|
if (isTableOwner(tableId, userId) || UserManager.getInstance().isAdmin(userId)) {
|
||||||
removeTable(tableId);
|
removeTable(tableId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leaveTable(String sessionId, UUID tableId) {
|
public void leaveTable(UUID userId, UUID tableId) {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
controllers.get(tableId).leaveTable(sessionId);
|
controllers.get(tableId).leaveTable(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getChatId(UUID tableId) {
|
public UUID getChatId(UUID tableId) {
|
||||||
|
@ -144,9 +144,9 @@ public class TableManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startMatch(String sessionId, UUID roomId, UUID tableId) {
|
public void startMatch(UUID userId, UUID roomId, UUID tableId) {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
controllers.get(tableId).startMatch(sessionId);
|
controllers.get(tableId).startMatch(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startMatch(UUID roomId, UUID tableId) {
|
public void startMatch(UUID roomId, UUID tableId) {
|
||||||
|
@ -154,14 +154,14 @@ public class TableManager {
|
||||||
controllers.get(tableId).startMatch();
|
controllers.get(tableId).startMatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startChallenge(String sessionId, UUID roomId, UUID tableId, UUID challengeId) {
|
public void startChallenge(UUID userId, UUID roomId, UUID tableId, UUID challengeId) {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
controllers.get(tableId).startChallenge(sessionId, challengeId);
|
controllers.get(tableId).startChallenge(userId, challengeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTournament(String sessionId, UUID roomId, UUID tableId) {
|
public void startTournament(UUID userId, UUID roomId, UUID tableId) {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
controllers.get(tableId).startTournament(sessionId);
|
controllers.get(tableId).startTournament(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDraft(UUID tableId, Draft draft) {
|
public void startDraft(UUID tableId, Draft draft) {
|
||||||
|
@ -169,15 +169,15 @@ public class TableManager {
|
||||||
controllers.get(tableId).startDraft(draft);
|
controllers.get(tableId).startDraft(draft);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean watchTable(String sessionId, UUID tableId) {
|
public boolean watchTable(UUID userId, UUID tableId) {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
return controllers.get(tableId).watchTable(sessionId);
|
return controllers.get(tableId).watchTable(userId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean replayTable(String sessionId, UUID tableId) {
|
public boolean replayTable(UUID userId, UUID tableId) {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
return controllers.get(tableId).replayTable(sessionId);
|
return controllers.get(tableId).replayTable(userId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,8 +191,8 @@ public class TableManager {
|
||||||
controllers.get(tableId).endDraft(draft);
|
controllers.get(tableId).endDraft(draft);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void swapSeats(UUID tableId, String sessionId, int seatNum1, int seatNum2) {
|
public void swapSeats(UUID tableId, UUID userId, int seatNum1, int seatNum2) {
|
||||||
if (controllers.containsKey(tableId) && isTableOwner(tableId, sessionId)) {
|
if (controllers.containsKey(tableId) && isTableOwner(tableId, userId)) {
|
||||||
controllers.get(tableId).swapSeats(seatNum1, seatNum2);
|
controllers.get(tableId).swapSeats(seatNum1, seatNum2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,9 +202,9 @@ public class TableManager {
|
||||||
controllers.get(tableId).construct();
|
controllers.get(tableId).construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addPlayer(String sessionId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
|
public void addPlayer(UUID userId, UUID tableId, Player player, String playerType, Deck deck) throws GameException {
|
||||||
if (controllers.containsKey(tableId))
|
if (controllers.containsKey(tableId))
|
||||||
controllers.get(tableId).addPlayer(sessionId, player, playerType, deck);
|
controllers.get(tableId).addPlayer(userId, player, playerType, deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTable(UUID tableId) {
|
public void removeTable(UUID tableId) {
|
||||||
|
|
|
@ -27,7 +27,12 @@
|
||||||
*/
|
*/
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import mage.cards.decks.Deck;
|
||||||
|
import mage.interfaces.callback.ClientCallback;
|
||||||
|
import mage.view.TableClientMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -35,14 +40,23 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public class User {
|
public class User {
|
||||||
|
|
||||||
|
public enum UserState {
|
||||||
|
Created, Connected, Disconnected, Reconnected;
|
||||||
|
}
|
||||||
|
|
||||||
private UUID userId = UUID.randomUUID();
|
private UUID userId = UUID.randomUUID();
|
||||||
private String userName;
|
private String userName;
|
||||||
private String sessionId;
|
private String sessionId = "";
|
||||||
private String host;
|
private String host;
|
||||||
|
private Date connectionTime = new Date();
|
||||||
|
private Date lastActivity = new Date();
|
||||||
|
private UserState userState;
|
||||||
|
private CountDownLatch connectionSignal = new CountDownLatch(1);
|
||||||
|
|
||||||
public User(String userName, String host) {
|
public User(String userName, String host) {
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
|
this.userState = UserState.Created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -63,5 +77,60 @@ public class User {
|
||||||
|
|
||||||
public void setSessionId(String sessionId) {
|
public void setSessionId(String sessionId) {
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
|
if (sessionId.isEmpty())
|
||||||
|
userState = UserState.Disconnected;
|
||||||
|
else if (userState == UserState.Created)
|
||||||
|
userState = UserState.Connected;
|
||||||
|
else {
|
||||||
|
userState = UserState.Reconnected;
|
||||||
|
reconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConnected() {
|
||||||
|
return userState == UserState.Connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getConnectionTime() {
|
||||||
|
return connectionTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void fireCallback(final ClientCallback call) {
|
||||||
|
if (isConnected()) {
|
||||||
|
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||||
|
session.fireCallback(call);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void gameStarted(final UUID gameId, final UUID playerId) {
|
||||||
|
fireCallback(new ClientCallback("startGame", gameId, new TableClientMessage(gameId, playerId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draftStarted(final UUID draftId, final UUID playerId) {
|
||||||
|
fireCallback(new ClientCallback("startDraft", draftId, new TableClientMessage(draftId, playerId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void tournamentStarted(final UUID tournamentId, final UUID playerId) {
|
||||||
|
fireCallback(new ClientCallback("startTournament", tournamentId, new TableClientMessage(tournamentId, playerId)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sideboard(final Deck deck, final UUID tableId, final int time) {
|
||||||
|
fireCallback(new ClientCallback("sideboard", tableId, new TableClientMessage(deck, tableId, time)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void construct(final Deck deck, final UUID tableId, final int time) {
|
||||||
|
fireCallback(new ClientCallback("construct", tableId, new TableClientMessage(deck, tableId, time)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void watchGame(final UUID gameId) {
|
||||||
|
fireCallback(new ClientCallback("watchGame", gameId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replayGame(final UUID gameId) {
|
||||||
|
fireCallback(new ClientCallback("replayGame", gameId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reconnect() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
@ -44,30 +45,51 @@ public class UserManager {
|
||||||
|
|
||||||
private UserManager() {}
|
private UserManager() {}
|
||||||
|
|
||||||
private ConcurrentHashMap<String, User> users = new ConcurrentHashMap<String, User>();
|
private ConcurrentHashMap<UUID, User> users = new ConcurrentHashMap<UUID, User>();
|
||||||
|
|
||||||
public User createUser(String userName, String host) {
|
public User createUser(String userName, String host) {
|
||||||
if (users.containsKey(userName))
|
if (findUser(userName) != null)
|
||||||
return null;
|
return null; //user already exists
|
||||||
User user = new User(userName, host);
|
User user = new User(userName, host);
|
||||||
users.put(userName, user);
|
users.put(user.getId(), user);
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User getUser(UUID userId) {
|
||||||
|
return users.get(userId);
|
||||||
|
}
|
||||||
|
|
||||||
public User findUser(String userName) {
|
public User findUser(String userName) {
|
||||||
return users.get(userName);
|
for (User user: users.values()) {
|
||||||
|
if (user.getName().equals(userName))
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<User> getUsers() {
|
||||||
|
return users.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connectToSession(String sessionId, String userName) {
|
public boolean connectToSession(String sessionId, UUID userId) {
|
||||||
if (users.containsKey(userName)) {
|
if (users.containsKey(userId)) {
|
||||||
users.get(userName).setSessionId(sessionId);
|
users.get(userId).setSessionId(sessionId);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect(UUID userId) {
|
||||||
|
if (users.containsKey(userId)) {
|
||||||
|
users.get(userId).setSessionId("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(String userName) {
|
public boolean isAdmin(UUID userId) {
|
||||||
if (users.containsKey(userName)) {
|
if (users.containsKey(userId)) {
|
||||||
users.get(userName).setSessionId("");
|
return users.get(userId).getName().equals("Admin");
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import mage.game.events.TableEvent;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.server.game.GameController;
|
import mage.server.game.GameController;
|
||||||
import mage.server.TableManager;
|
import mage.server.TableManager;
|
||||||
|
import mage.server.UserManager;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.view.DraftPickView;
|
import mage.view.DraftPickView;
|
||||||
import mage.view.DraftView;
|
import mage.view.DraftView;
|
||||||
|
@ -56,14 +57,14 @@ public class DraftController {
|
||||||
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
|
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
|
||||||
|
|
||||||
private ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<UUID, DraftSession>();
|
private ConcurrentHashMap<UUID, DraftSession> draftSessions = new ConcurrentHashMap<UUID, DraftSession>();
|
||||||
private ConcurrentHashMap<String, UUID> sessionPlayerMap;
|
private ConcurrentHashMap<UUID, UUID> userPlayerMap;
|
||||||
private UUID draftSessionId;
|
private UUID draftSessionId;
|
||||||
private Draft draft;
|
private Draft draft;
|
||||||
private UUID tableId;
|
private UUID tableId;
|
||||||
|
|
||||||
public DraftController(Draft draft, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
public DraftController(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||||
draftSessionId = UUID.randomUUID();
|
draftSessionId = UUID.randomUUID();
|
||||||
this.sessionPlayerMap = sessionPlayerMap;
|
this.userPlayerMap = userPlayerMap;
|
||||||
this.draft = draft;
|
this.draft = draft;
|
||||||
this.tableId = tableId;
|
this.tableId = tableId;
|
||||||
init();
|
init();
|
||||||
|
@ -116,15 +117,15 @@ public class DraftController {
|
||||||
checkStart();
|
checkStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID getPlayerId(String sessionId) {
|
private UUID getPlayerId(UUID userId) {
|
||||||
return sessionPlayerMap.get(sessionId);
|
return userPlayerMap.get(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join(String sessionId) {
|
public void join(UUID userId) {
|
||||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
UUID playerId = userPlayerMap.get(userId);
|
||||||
DraftSession draftSession = new DraftSession(draft, sessionId, playerId);
|
DraftSession draftSession = new DraftSession(draft, userId, playerId);
|
||||||
draftSessions.put(playerId, draftSession);
|
draftSessions.put(playerId, draftSession);
|
||||||
logger.info("player " + playerId + " has joined draft " + draft.getId());
|
logger.info("User " + UserManager.getInstance().getUser(userId).getName() + " has joined draft " + draft.getId());
|
||||||
draft.getPlayer(playerId).setJoined();
|
draft.getPlayer(playerId).setJoined();
|
||||||
checkStart();
|
checkStart();
|
||||||
}
|
}
|
||||||
|
@ -163,8 +164,8 @@ public class DraftController {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void leave(String sessionId) {
|
private void leave(UUID userId) {
|
||||||
draft.leave(getPlayerId(sessionId));
|
draft.leave(getPlayerId(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endDraft() throws MageException {
|
private void endDraft() throws MageException {
|
||||||
|
@ -174,18 +175,18 @@ public class DraftController {
|
||||||
TableManager.getInstance().endDraft(tableId, draft);
|
TableManager.getInstance().endDraft(tableId, draft);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(String sessionId) {
|
public void kill(UUID userId) {
|
||||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
if (userPlayerMap.containsKey(userId)) {
|
||||||
draftSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
draftSessions.get(userPlayerMap.get(userId)).setKilled();
|
||||||
draftSessions.remove(sessionPlayerMap.get(sessionId));
|
draftSessions.remove(userPlayerMap.get(userId));
|
||||||
leave(sessionId);
|
leave(userId);
|
||||||
sessionPlayerMap.remove(sessionId);
|
userPlayerMap.remove(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void timeout(String sessionId) {
|
public void timeout(UUID userId) {
|
||||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
if (userPlayerMap.containsKey(userId)) {
|
||||||
draft.autoPick(sessionPlayerMap.get(sessionId));
|
draft.autoPick(userPlayerMap.get(userId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,9 +194,9 @@ public class DraftController {
|
||||||
return this.draftSessionId;
|
return this.draftSessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DraftPickView sendCardPick(String sessionId, UUID cardId) {
|
public DraftPickView sendCardPick(UUID userId, UUID cardId) {
|
||||||
if (draftSessions.get(sessionPlayerMap.get(sessionId)).sendCardPick(cardId)) {
|
if (draftSessions.get(userPlayerMap.get(userId)).sendCardPick(cardId)) {
|
||||||
return getDraftPickView(sessionPlayerMap.get(sessionId), 0);
|
return getDraftPickView(userPlayerMap.get(userId), 0);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,36 +48,36 @@ public class DraftManager {
|
||||||
|
|
||||||
private ConcurrentHashMap<UUID, DraftController> draftControllers = new ConcurrentHashMap<UUID, DraftController>();
|
private ConcurrentHashMap<UUID, DraftController> draftControllers = new ConcurrentHashMap<UUID, DraftController>();
|
||||||
|
|
||||||
public UUID createDraftSession(Draft draft, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
public UUID createDraftSession(Draft draft, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||||
DraftController draftController = new DraftController(draft, sessionPlayerMap, tableId);
|
DraftController draftController = new DraftController(draft, userPlayerMap, tableId);
|
||||||
draftControllers.put(draft.getId(), draftController);
|
draftControllers.put(draft.getId(), draftController);
|
||||||
return draftController.getSessionId();
|
return draftController.getSessionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinDraft(UUID draftId, String sessionId) {
|
public void joinDraft(UUID draftId, UUID userId) {
|
||||||
draftControllers.get(draftId).join(sessionId);
|
draftControllers.get(draftId).join(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroyChatSession(UUID gameId) {
|
public void destroyChatSession(UUID gameId) {
|
||||||
draftControllers.remove(gameId);
|
draftControllers.remove(gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DraftPickView sendCardPick(UUID draftId, String sessionId, UUID cardId) {
|
public DraftPickView sendCardPick(UUID draftId, UUID userId, UUID cardId) {
|
||||||
return draftControllers.get(draftId).sendCardPick(sessionId, cardId);
|
return draftControllers.get(draftId).sendCardPick(userId, cardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSession(String sessionId) {
|
public void removeSession(UUID userId) {
|
||||||
for (DraftController controller: draftControllers.values()) {
|
for (DraftController controller: draftControllers.values()) {
|
||||||
controller.kill(sessionId);
|
controller.kill(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(UUID draftId, String sessionId) {
|
public void kill(UUID draftId, UUID userId) {
|
||||||
draftControllers.get(draftId).kill(sessionId);
|
draftControllers.get(draftId).kill(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void timeout(UUID gameId, String sessionId) {
|
public void timeout(UUID gameId, UUID userId) {
|
||||||
draftControllers.get(gameId).timeout(sessionId);
|
draftControllers.get(gameId).timeout(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDraft(UUID draftId) {
|
public void removeDraft(UUID draftId) {
|
||||||
|
|
|
@ -35,8 +35,8 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import mage.game.draft.Draft;
|
import mage.game.draft.Draft;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.Session;
|
import mage.server.User;
|
||||||
import mage.server.SessionManager;
|
import mage.server.UserManager;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.view.DraftClientMessage;
|
import mage.view.DraftClientMessage;
|
||||||
import mage.view.DraftPickView;
|
import mage.view.DraftPickView;
|
||||||
|
@ -51,7 +51,7 @@ public class DraftSession {
|
||||||
|
|
||||||
protected final static Logger logger = Logger.getLogger(DraftSession.class);
|
protected final static Logger logger = Logger.getLogger(DraftSession.class);
|
||||||
|
|
||||||
protected String sessionId;
|
protected UUID userId;
|
||||||
protected UUID playerId;
|
protected UUID playerId;
|
||||||
protected Draft draft;
|
protected Draft draft;
|
||||||
protected boolean killed = false;
|
protected boolean killed = false;
|
||||||
|
@ -59,17 +59,17 @@ public class DraftSession {
|
||||||
private ScheduledFuture<?> futureTimeout;
|
private ScheduledFuture<?> futureTimeout;
|
||||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||||
|
|
||||||
public DraftSession(Draft draft, String sessionId, UUID playerId) {
|
public DraftSession(Draft draft, UUID userId, UUID playerId) {
|
||||||
this.sessionId = sessionId;
|
this.userId = userId;
|
||||||
this.draft = draft;
|
this.draft = draft;
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean init(final DraftView draftView) {
|
public boolean init(final DraftView draftView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("draftInit", draft.getId(), draftView));
|
user.fireCallback(new ClientCallback("draftInit", draft.getId(), draftView));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,27 +86,27 @@ public class DraftSession {
|
||||||
|
|
||||||
public void update(final DraftView draftView) {
|
public void update(final DraftView draftView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("draftUpdate", draft.getId(), draftView));
|
user.fireCallback(new ClientCallback("draftUpdate", draft.getId(), draftView));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inform(final String message, final DraftView draftView) {
|
public void inform(final String message, final DraftView draftView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("draftInform", draft.getId(), new DraftClientMessage(draftView, message)));
|
user.fireCallback(new ClientCallback("draftInform", draft.getId(), new DraftClientMessage(draftView, message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draftOver() {
|
public void draftOver() {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("draftOver", draft.getId()));
|
user.fireCallback(new ClientCallback("draftOver", draft.getId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,9 +114,9 @@ public class DraftSession {
|
||||||
public void pickCard(final DraftPickView draftPickView, int timeout) {
|
public void pickCard(final DraftPickView draftPickView, int timeout) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout(timeout);
|
setupTimeout(timeout);
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("draftPick", draft.getId(), new DraftClientMessage(draftPickView)));
|
user.fireCallback(new ClientCallback("draftPick", draft.getId(), new DraftClientMessage(draftPickView)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ public class DraftSession {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
DraftManager.getInstance().timeout(draft.getId(), sessionId);
|
DraftManager.getInstance().timeout(draft.getId(), userId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
seconds, TimeUnit.SECONDS
|
seconds, TimeUnit.SECONDS
|
||||||
|
@ -144,7 +144,7 @@ public class DraftSession {
|
||||||
|
|
||||||
protected void handleRemoteException(RemoteException ex) {
|
protected void handleRemoteException(RemoteException ex) {
|
||||||
logger.fatal("DraftSession error ", ex);
|
logger.fatal("DraftSession error ", ex);
|
||||||
DraftManager.getInstance().kill(draft.getId(), sessionId);
|
DraftManager.getInstance().kill(draft.getId(), userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKilled() {
|
public void setKilled() {
|
||||||
|
|
|
@ -29,9 +29,7 @@
|
||||||
package mage.server.game;
|
package mage.server.game;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import mage.game.LookedAt;
|
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.server.TableManager;
|
import mage.server.TableManager;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -81,8 +79,8 @@ public class GameController implements GameCallback {
|
||||||
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
|
public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt";
|
||||||
|
|
||||||
private ConcurrentHashMap<UUID, GameSession> gameSessions = new ConcurrentHashMap<UUID, GameSession>();
|
private ConcurrentHashMap<UUID, GameSession> gameSessions = new ConcurrentHashMap<UUID, GameSession>();
|
||||||
private ConcurrentHashMap<String, GameWatcher> watchers = new ConcurrentHashMap<String, GameWatcher>();
|
private ConcurrentHashMap<UUID, GameWatcher> watchers = new ConcurrentHashMap<UUID, GameWatcher>();
|
||||||
private ConcurrentHashMap<String, UUID> sessionPlayerMap;
|
private ConcurrentHashMap<UUID, UUID> userPlayerMap;
|
||||||
private UUID gameSessionId;
|
private UUID gameSessionId;
|
||||||
private Game game;
|
private Game game;
|
||||||
private UUID chatId;
|
private UUID chatId;
|
||||||
|
@ -91,9 +89,9 @@ public class GameController implements GameCallback {
|
||||||
private Future<?> gameFuture;
|
private Future<?> gameFuture;
|
||||||
|
|
||||||
|
|
||||||
public GameController(Game game, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
public GameController(Game game, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||||
gameSessionId = UUID.randomUUID();
|
gameSessionId = UUID.randomUUID();
|
||||||
this.sessionPlayerMap = sessionPlayerMap;
|
this.userPlayerMap = userPlayerMap;
|
||||||
chatId = ChatManager.getInstance().createChatSession();
|
chatId = ChatManager.getInstance().createChatSession();
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.tableId = tableId;
|
this.tableId = tableId;
|
||||||
|
@ -180,13 +178,13 @@ public class GameController implements GameCallback {
|
||||||
checkStart();
|
checkStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID getPlayerId(String sessionId) {
|
private UUID getPlayerId(UUID userId) {
|
||||||
return sessionPlayerMap.get(sessionId);
|
return userPlayerMap.get(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void join(String sessionId) {
|
public void join(UUID userId) {
|
||||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
UUID playerId = userPlayerMap.get(userId);
|
||||||
GameSession gameSession = new GameSession(game, sessionId, playerId);
|
GameSession gameSession = new GameSession(game, userId, playerId);
|
||||||
gameSessions.put(playerId, gameSession);
|
gameSessions.put(playerId, gameSession);
|
||||||
logger.info("player " + playerId + " has joined game " + game.getId());
|
logger.info("player " + playerId + " has joined game " + game.getId());
|
||||||
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game", MessageColor.BLACK);
|
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game", MessageColor.BLACK);
|
||||||
|
@ -228,27 +226,27 @@ public class GameController implements GameCallback {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void watch(String sessionId) {
|
public void watch(UUID userId) {
|
||||||
GameWatcher gameWatcher = new GameWatcher(sessionId, game.getId());
|
GameWatcher gameWatcher = new GameWatcher(userId, game.getId());
|
||||||
watchers.put(sessionId, gameWatcher);
|
watchers.put(userId, gameWatcher);
|
||||||
gameWatcher.init(getGameView());
|
gameWatcher.init(getGameView());
|
||||||
ChatManager.getInstance().broadcast(chatId, "", " has started watching", MessageColor.BLACK);
|
ChatManager.getInstance().broadcast(chatId, "", " has started watching", MessageColor.BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopWatching(String sessionId) {
|
public void stopWatching(UUID userId) {
|
||||||
watchers.remove(sessionId);
|
watchers.remove(userId);
|
||||||
ChatManager.getInstance().broadcast(chatId, "", " has stopped watching", MessageColor.BLACK);
|
ChatManager.getInstance().broadcast(chatId, "", " has stopped watching", MessageColor.BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void concede(String sessionId) {
|
public void concede(UUID userId) {
|
||||||
game.concede(getPlayerId(sessionId));
|
game.concede(getPlayerId(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void leave(String sessionId) {
|
private void leave(UUID userId) {
|
||||||
game.quit(getPlayerId(sessionId));
|
game.quit(getPlayerId(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cheat(String sessionId, UUID playerId, DeckCardLists deckList) {
|
public void cheat(UUID userId, UUID playerId, DeckCardLists deckList) {
|
||||||
Deck deck;
|
Deck deck;
|
||||||
try {
|
try {
|
||||||
deck = Deck.load(deckList);
|
deck = Deck.load(deckList);
|
||||||
|
@ -263,7 +261,7 @@ public class GameController implements GameCallback {
|
||||||
updateGame();
|
updateGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cheat(String sessionId, UUID playerId, String cardName) {
|
public boolean cheat(UUID userId, UUID playerId, String cardName) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
Card card = Sets.findCard(cardName, true);
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
Set<Card> cards = new HashSet<Card>();
|
Set<Card> cards = new HashSet<Card>();
|
||||||
|
@ -276,23 +274,23 @@ public class GameController implements GameCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(String sessionId) {
|
public void kill(UUID userId) {
|
||||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
if (userPlayerMap.containsKey(userId)) {
|
||||||
gameSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
gameSessions.get(userPlayerMap.get(userId)).setKilled();
|
||||||
gameSessions.remove(sessionPlayerMap.get(sessionId));
|
gameSessions.remove(userPlayerMap.get(userId));
|
||||||
leave(sessionId);
|
leave(userId);
|
||||||
sessionPlayerMap.remove(sessionId);
|
userPlayerMap.remove(userId);
|
||||||
}
|
}
|
||||||
if (watchers.containsKey(sessionId)) {
|
if (watchers.containsKey(userId)) {
|
||||||
watchers.get(sessionId).setKilled();
|
watchers.get(userId).setKilled();
|
||||||
watchers.remove(sessionId);
|
watchers.remove(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void timeout(String sessionId) {
|
public void timeout(UUID userId) {
|
||||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
if (userPlayerMap.containsKey(userId)) {
|
||||||
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(sessionPlayerMap.get(sessionId)).getName() + " has timed out. Auto concede.", MessageColor.BLACK);
|
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(userPlayerMap.get(userId)).getName() + " has timed out. Auto concede.", MessageColor.BLACK);
|
||||||
concede(sessionId);
|
concede(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,20 +312,20 @@ public class GameController implements GameCallback {
|
||||||
return chatId;
|
return chatId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerUUID(String sessionId, UUID data) {
|
public void sendPlayerUUID(UUID userId, UUID data) {
|
||||||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerUUID(data);
|
gameSessions.get(userPlayerMap.get(userId)).sendPlayerUUID(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerString(String sessionId, String data) {
|
public void sendPlayerString(UUID userId, String data) {
|
||||||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerString(data);
|
gameSessions.get(userPlayerMap.get(userId)).sendPlayerString(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerBoolean(String sessionId, Boolean data) {
|
public void sendPlayerBoolean(UUID userId, Boolean data) {
|
||||||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerBoolean(data);
|
gameSessions.get(userPlayerMap.get(userId)).sendPlayerBoolean(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerInteger(String sessionId, Integer data) {
|
public void sendPlayerInteger(UUID userId, Integer data) {
|
||||||
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerInteger(data);
|
gameSessions.get(userPlayerMap.get(userId)).sendPlayerInteger(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void updateGame() {
|
private synchronized void updateGame() {
|
||||||
|
|
|
@ -32,7 +32,6 @@ import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.MageException;
|
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,15 +49,15 @@ public class GameManager {
|
||||||
|
|
||||||
private ConcurrentHashMap<UUID, GameController> gameControllers = new ConcurrentHashMap<UUID, GameController>();
|
private ConcurrentHashMap<UUID, GameController> gameControllers = new ConcurrentHashMap<UUID, GameController>();
|
||||||
|
|
||||||
public UUID createGameSession(Game game, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
public UUID createGameSession(Game game, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||||
GameController gameController = new GameController(game, sessionPlayerMap, tableId, choosingPlayerId);
|
GameController gameController = new GameController(game, userPlayerMap, tableId, choosingPlayerId);
|
||||||
gameControllers.put(game.getId(), gameController);
|
gameControllers.put(game.getId(), gameController);
|
||||||
return gameController.getSessionId();
|
return gameController.getSessionId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinGame(UUID gameId, String sessionId) {
|
public void joinGame(UUID gameId, UUID userId) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).join(sessionId);
|
gameControllers.get(gameId).join(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroyChatSession(UUID gameId) {
|
public void destroyChatSession(UUID gameId) {
|
||||||
|
@ -71,66 +70,66 @@ public class GameManager {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerUUID(UUID gameId, String sessionId, UUID data) {
|
public void sendPlayerUUID(UUID gameId, UUID userId, UUID data) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).sendPlayerUUID(sessionId, data);
|
gameControllers.get(gameId).sendPlayerUUID(userId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerString(UUID gameId, String sessionId, String data) {
|
public void sendPlayerString(UUID gameId, UUID userId, String data) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).sendPlayerString(sessionId, data);
|
gameControllers.get(gameId).sendPlayerString(userId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) {
|
public void sendPlayerBoolean(UUID gameId, UUID userId, Boolean data) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).sendPlayerBoolean(sessionId, data);
|
gameControllers.get(gameId).sendPlayerBoolean(userId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerInteger(UUID gameId, String sessionId, Integer data) {
|
public void sendPlayerInteger(UUID gameId, UUID userId, Integer data) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).sendPlayerInteger(sessionId, data);
|
gameControllers.get(gameId).sendPlayerInteger(userId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void concedeGame(UUID gameId, String sessionId) {
|
public void concedeGame(UUID gameId, UUID userId) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).concede(sessionId);
|
gameControllers.get(gameId).concede(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void watchGame(UUID gameId, String sessionId) {
|
public void watchGame(UUID gameId, UUID userId) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).watch(sessionId);
|
gameControllers.get(gameId).watch(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopWatching(UUID gameId, String sessionId) {
|
public void stopWatching(UUID gameId, UUID userId) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).stopWatching(sessionId);
|
gameControllers.get(gameId).stopWatching(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSession(String sessionId) {
|
public void removeSession(UUID userId) {
|
||||||
for (GameController controller: gameControllers.values()) {
|
for (GameController controller: gameControllers.values()) {
|
||||||
controller.kill(sessionId);
|
controller.kill(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(UUID gameId, String sessionId) {
|
public void kill(UUID gameId, UUID userId) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).kill(sessionId);
|
gameControllers.get(gameId).kill(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cheat(UUID gameId, String sessionId, UUID playerId, DeckCardLists deckList) {
|
public void cheat(UUID gameId, UUID userId, UUID playerId, DeckCardLists deckList) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).cheat(sessionId, playerId, deckList);
|
gameControllers.get(gameId).cheat(userId, playerId, deckList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cheat(UUID gameId, String sessionId, UUID playerId, String cardName) {
|
public boolean cheat(UUID gameId, UUID userId, UUID playerId, String cardName) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
return gameControllers.get(gameId).cheat(sessionId, playerId, cardName);
|
return gameControllers.get(gameId).cheat(userId, playerId, cardName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void timeout(UUID gameId, String sessionId) {
|
public void timeout(UUID gameId, UUID userId) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
gameControllers.get(gameId).timeout(sessionId);
|
gameControllers.get(gameId).timeout(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeGame(UUID gameId) {
|
public void removeGame(UUID gameId) {
|
||||||
|
@ -142,7 +141,7 @@ public class GameManager {
|
||||||
gameControllers.get(gameId).saveGame();
|
gameControllers.get(gameId).saveGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameView getGameView(UUID gameId, String sessionId, UUID playerId) {
|
public GameView getGameView(UUID gameId, UUID userId, UUID playerId) {
|
||||||
if (gameControllers.containsKey(gameId))
|
if (gameControllers.containsKey(gameId))
|
||||||
return gameControllers.get(gameId).getGameView(playerId);
|
return gameControllers.get(gameId).getGameView(playerId);
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -37,8 +37,8 @@ import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.Session;
|
import mage.server.User;
|
||||||
import mage.server.SessionManager;
|
import mage.server.UserManager;
|
||||||
import mage.server.util.ConfigSettings;
|
import mage.server.util.ConfigSettings;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.view.AbilityPickerView;
|
import mage.view.AbilityPickerView;
|
||||||
|
@ -58,8 +58,8 @@ public class GameSession extends GameWatcher {
|
||||||
private ScheduledFuture<?> futureTimeout;
|
private ScheduledFuture<?> futureTimeout;
|
||||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||||
|
|
||||||
public GameSession(Game game, String sessionId, UUID playerId) {
|
public GameSession(Game game, UUID userId, UUID playerId) {
|
||||||
super(sessionId, game.getId());
|
super(userId, game.getId());
|
||||||
this.game = game;
|
this.game = game;
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
}
|
}
|
||||||
|
@ -67,9 +67,9 @@ public class GameSession extends GameWatcher {
|
||||||
public void ask(final String question, final GameView gameView) {
|
public void ask(final String question, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
setupTimeout();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameAsk", game.getId(), new GameClientMessage(gameView, question)));
|
user.fireCallback(new ClientCallback("gameAsk", game.getId(), new GameClientMessage(gameView, question)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,9 +77,9 @@ public class GameSession extends GameWatcher {
|
||||||
public void target(final String question, final CardsView cardView, final Set<UUID> targets, final boolean required, final GameView gameView, final Map<String, Serializable> options) {
|
public void target(final String question, final CardsView cardView, final Set<UUID> targets, final boolean required, final GameView gameView, final Map<String, Serializable> options) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
setupTimeout();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameTarget", game.getId(), new GameClientMessage(gameView, question, cardView, targets, required, options)));
|
user.fireCallback(new ClientCallback("gameTarget", game.getId(), new GameClientMessage(gameView, question, cardView, targets, required, options)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,9 +87,9 @@ public class GameSession extends GameWatcher {
|
||||||
public void select(final String message, final GameView gameView) {
|
public void select(final String message, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
setupTimeout();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameSelect", game.getId(), new GameClientMessage(gameView, message)));
|
user.fireCallback(new ClientCallback("gameSelect", game.getId(), new GameClientMessage(gameView, message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,9 +97,9 @@ public class GameSession extends GameWatcher {
|
||||||
public void chooseAbility(final AbilityPickerView abilities) {
|
public void chooseAbility(final AbilityPickerView abilities) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
setupTimeout();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameChooseAbility", game.getId(), abilities));
|
user.fireCallback(new ClientCallback("gameChooseAbility", game.getId(), abilities));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,9 +107,9 @@ public class GameSession extends GameWatcher {
|
||||||
public void choose(final String message, final Set<String> choices) {
|
public void choose(final String message, final Set<String> choices) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
setupTimeout();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameChoose", game.getId(), new GameClientMessage(choices.toArray(new String[0]), message)));
|
user.fireCallback(new ClientCallback("gameChoose", game.getId(), new GameClientMessage(choices.toArray(new String[0]), message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,9 +117,9 @@ public class GameSession extends GameWatcher {
|
||||||
public void playMana(final String message, final GameView gameView) {
|
public void playMana(final String message, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
setupTimeout();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gamePlayMana", game.getId(), new GameClientMessage(gameView, message)));
|
user.fireCallback(new ClientCallback("gamePlayMana", game.getId(), new GameClientMessage(gameView, message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,9 +127,9 @@ public class GameSession extends GameWatcher {
|
||||||
public void playXMana(final String message, final GameView gameView) {
|
public void playXMana(final String message, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
setupTimeout();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gamePlayXMana", game.getId(), new GameClientMessage(gameView, message)));
|
user.fireCallback(new ClientCallback("gamePlayXMana", game.getId(), new GameClientMessage(gameView, message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,18 +137,18 @@ public class GameSession extends GameWatcher {
|
||||||
public void getAmount(final String message, final int min, final int max) {
|
public void getAmount(final String message, final int min, final int max) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout();
|
setupTimeout();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameSelectAmount", game.getId(), new GameClientMessage(message, min, max)));
|
user.fireCallback(new ClientCallback("gameSelectAmount", game.getId(), new GameClientMessage(message, min, max)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revealCards(final String name, final CardsView cardView) {
|
public void revealCards(final String name, final CardsView cardView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameReveal", game.getId(), new GameClientMessage(cardView, name)));
|
user.fireCallback(new ClientCallback("gameReveal", game.getId(), new GameClientMessage(cardView, name)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ public class GameSession extends GameWatcher {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GameManager.getInstance().timeout(gameId, sessionId);
|
GameManager.getInstance().timeout(gameId, userId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ConfigSettings.getInstance().getMaxSecondsIdle(), TimeUnit.SECONDS
|
ConfigSettings.getInstance().getMaxSecondsIdle(), TimeUnit.SECONDS
|
||||||
|
|
|
@ -31,8 +31,8 @@ package mage.server.game;
|
||||||
import java.rmi.RemoteException;
|
import java.rmi.RemoteException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.Session;
|
import mage.server.User;
|
||||||
import mage.server.SessionManager;
|
import mage.server.UserManager;
|
||||||
import mage.view.GameClientMessage;
|
import mage.view.GameClientMessage;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
@ -45,20 +45,20 @@ public class GameWatcher {
|
||||||
|
|
||||||
protected final static Logger logger = Logger.getLogger(GameWatcher.class);
|
protected final static Logger logger = Logger.getLogger(GameWatcher.class);
|
||||||
|
|
||||||
protected String sessionId;
|
protected UUID userId;
|
||||||
protected UUID gameId;
|
protected UUID gameId;
|
||||||
protected boolean killed = false;
|
protected boolean killed = false;
|
||||||
|
|
||||||
public GameWatcher(String sessionId, UUID gameId) {
|
public GameWatcher(UUID userId, UUID gameId) {
|
||||||
this.sessionId = sessionId;
|
this.userId = userId;
|
||||||
this.gameId = gameId;
|
this.gameId = gameId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean init(final GameView gameView) {
|
public boolean init(final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameInit", gameId, gameView));
|
user.fireCallback(new ClientCallback("gameInit", gameId, gameView));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,43 +67,43 @@ public class GameWatcher {
|
||||||
|
|
||||||
public void update(final GameView gameView) {
|
public void update(final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameUpdate", gameId, gameView));
|
user.fireCallback(new ClientCallback("gameUpdate", gameId, gameView));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void inform(final String message, final GameView gameView) {
|
public void inform(final String message, final GameView gameView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameInform", gameId, new GameClientMessage(gameView, message)));
|
user.fireCallback(new ClientCallback("gameInform", gameId, new GameClientMessage(gameView, message)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameOver(final String message) {
|
public void gameOver(final String message) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameOver", gameId, message));
|
user.fireCallback(new ClientCallback("gameOver", gameId, message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameError(final String message) {
|
public void gameError(final String message) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("gameError", gameId, message));
|
user.fireCallback(new ClientCallback("gameError", gameId, message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleRemoteException(RemoteException ex) {
|
protected void handleRemoteException(RemoteException ex) {
|
||||||
logger.fatal("GameWatcher error", ex);
|
logger.fatal("GameWatcher error", ex);
|
||||||
GameManager.getInstance().kill(gameId, sessionId);
|
GameManager.getInstance().kill(gameId, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKilled() {
|
public void setKilled() {
|
||||||
|
|
|
@ -45,14 +45,14 @@ import mage.view.TableView;
|
||||||
public interface GamesRoom extends Room {
|
public interface GamesRoom extends Room {
|
||||||
|
|
||||||
public List<TableView> getTables();
|
public List<TableView> getTables();
|
||||||
public boolean joinTable(String sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException;
|
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException;
|
||||||
public boolean joinTournamentTable(String sessionId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
public boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
||||||
public TableView createTable(String sessionId, MatchOptions options);
|
public TableView createTable(UUID userId, MatchOptions options);
|
||||||
public TableView createTournamentTable(String sessionId, TournamentOptions options);
|
public TableView createTournamentTable(UUID userId, TournamentOptions options);
|
||||||
public void removeTable(String sessionId, UUID tableId);
|
public void removeTable(UUID userId, UUID tableId);
|
||||||
public void removeTable(UUID tableId);
|
public void removeTable(UUID tableId);
|
||||||
public TableView getTable(UUID tableId);
|
public TableView getTable(UUID tableId);
|
||||||
public void leaveTable(String sessionId, UUID tableId);
|
public void leaveTable(UUID userId, UUID tableId);
|
||||||
public boolean watchTable(String sessionId, UUID tableId) throws MageException;
|
public boolean watchTable(UUID userId, UUID tableId) throws MageException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,33 +64,33 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean joinTable(String sessionId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||||
if (tables.containsKey(tableId)) {
|
if (tables.containsKey(tableId)) {
|
||||||
return TableManager.getInstance().joinTable(sessionId, tableId, name, playerType, skill, deckList);
|
return TableManager.getInstance().joinTable(userId, tableId, name, playerType, skill, deckList);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableView createTable(String sessionId, MatchOptions options) {
|
public TableView createTable(UUID userId, MatchOptions options) {
|
||||||
Table table = TableManager.getInstance().createTable(this.getRoomId(), sessionId, options);
|
Table table = TableManager.getInstance().createTable(this.getRoomId(), userId, options);
|
||||||
tables.put(table.getId(), table);
|
tables.put(table.getId(), table);
|
||||||
return new TableView(table);
|
return new TableView(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean joinTournamentTable(String sessionId, UUID tableId, String name, String playerType, int skill) throws GameException {
|
public boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException {
|
||||||
if (tables.containsKey(tableId)) {
|
if (tables.containsKey(tableId)) {
|
||||||
return TableManager.getInstance().joinTournament(sessionId, tableId, name, playerType, skill);
|
return TableManager.getInstance().joinTournament(userId, tableId, name, playerType, skill);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableView createTournamentTable(String sessionId, TournamentOptions options) {
|
public TableView createTournamentTable(UUID userId, TournamentOptions options) {
|
||||||
Table table = TableManager.getInstance().createTournamentTable(this.getRoomId(), sessionId, options);
|
Table table = TableManager.getInstance().createTournamentTable(this.getRoomId(), userId, options);
|
||||||
tables.put(table.getId(), table);
|
tables.put(table.getId(), table);
|
||||||
return new TableView(table);
|
return new TableView(table);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeTable(String sessionId, UUID tableId) {
|
public void removeTable(UUID userId, UUID tableId) {
|
||||||
tables.remove(tableId);
|
tables.remove(tableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,13 +115,13 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void leaveTable(String sessionId, UUID tableId) {
|
public void leaveTable(UUID userId, UUID tableId) {
|
||||||
TableManager.getInstance().leaveTable(sessionId, tableId);
|
TableManager.getInstance().leaveTable(userId, tableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean watchTable(String sessionId, UUID tableId) throws MageException {
|
public boolean watchTable(UUID userId, UUID tableId) throws MageException {
|
||||||
return TableManager.getInstance().watchTable(sessionId, tableId);
|
return TableManager.getInstance().watchTable(userId, tableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,7 @@ package mage.server.game;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.MageException;
|
import mage.server.UserManager;
|
||||||
import mage.server.SessionManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -48,26 +47,26 @@ public class ReplayManager {
|
||||||
|
|
||||||
private ConcurrentHashMap<String, ReplaySession> replaySessions = new ConcurrentHashMap<String, ReplaySession>();
|
private ConcurrentHashMap<String, ReplaySession> replaySessions = new ConcurrentHashMap<String, ReplaySession>();
|
||||||
|
|
||||||
public void replayGame(UUID gameId, String sessionId) {
|
public void replayGame(UUID gameId, UUID userId) {
|
||||||
ReplaySession replaySession = new ReplaySession(gameId, sessionId);
|
ReplaySession replaySession = new ReplaySession(gameId, userId);
|
||||||
replaySessions.put(gameId.toString() + sessionId.toString(), replaySession);
|
replaySessions.put(gameId.toString() + userId.toString(), replaySession);
|
||||||
SessionManager.getInstance().getSession(sessionId).replayGame(gameId);
|
UserManager.getInstance().getUser(userId).replayGame(gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startReplay(UUID gameId, String sessionId) {
|
public void startReplay(UUID gameId, UUID userId) {
|
||||||
replaySessions.get(gameId.toString() + sessionId.toString()).replay();
|
replaySessions.get(gameId.toString() + userId.toString()).replay();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopReplay(UUID gameId, String sessionId) {
|
public void stopReplay(UUID gameId, UUID userId) {
|
||||||
replaySessions.get(gameId.toString() + sessionId.toString()).stop();
|
replaySessions.get(gameId.toString() + userId.toString()).stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void nextPlay(UUID gameId, String sessionId) {
|
public void nextPlay(UUID gameId, UUID userId) {
|
||||||
replaySessions.get(gameId.toString() + sessionId.toString()).next();
|
replaySessions.get(gameId.toString() + userId.toString()).next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void previousPlay(UUID gameId, String sessionId) {
|
public void previousPlay(UUID gameId, UUID userId) {
|
||||||
replaySessions.get(gameId.toString() + sessionId.toString()).previous();
|
replaySessions.get(gameId.toString() + userId.toString()).previous();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ import java.util.UUID;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameState;
|
import mage.game.GameState;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.Session;
|
import mage.server.User;
|
||||||
import mage.server.SessionManager;
|
import mage.server.UserManager;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
@ -45,18 +45,18 @@ public class ReplaySession implements GameCallback {
|
||||||
|
|
||||||
private final static Logger logger = Logger.getLogger(ReplaySession.class);
|
private final static Logger logger = Logger.getLogger(ReplaySession.class);
|
||||||
private GameReplay replay;
|
private GameReplay replay;
|
||||||
protected String sessionId;
|
protected UUID userId;
|
||||||
|
|
||||||
ReplaySession(UUID gameId, String sessionId) {
|
ReplaySession(UUID gameId, UUID userId) {
|
||||||
this.replay = new GameReplay(gameId);
|
this.replay = new GameReplay(gameId);
|
||||||
this.sessionId = sessionId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replay() {
|
public void replay() {
|
||||||
replay.start();
|
replay.start();
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("replayInit", replay.getGame().getId(), new GameView(replay.next(), replay.getGame())));
|
user.fireCallback(new ClientCallback("replayInit", replay.getGame().getId(), new GameView(replay.next(), replay.getGame())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,9 +74,9 @@ public class ReplaySession implements GameCallback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void gameResult(final String result) {
|
public void gameResult(final String result) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("replayDone", replay.getGame().getId(), result));
|
user.fireCallback(new ClientCallback("replayDone", replay.getGame().getId(), result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +85,9 @@ public class ReplaySession implements GameCallback {
|
||||||
gameResult("game ended");
|
gameResult("game ended");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("replayUpdate", replay.getGame().getId(), new GameView(state, game)));
|
user.fireCallback(new ClientCallback("replayUpdate", replay.getGame().getId(), new GameView(state, game)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ package mage.server.tournament;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Level;
|
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.game.GameException;
|
import mage.game.GameException;
|
||||||
import mage.game.Table;
|
import mage.game.Table;
|
||||||
|
@ -60,16 +59,14 @@ public class TournamentController {
|
||||||
|
|
||||||
private final static Logger logger = Logger.getLogger(TournamentController.class);
|
private final static Logger logger = Logger.getLogger(TournamentController.class);
|
||||||
|
|
||||||
private UUID sessionId;
|
|
||||||
private UUID chatId;
|
private UUID chatId;
|
||||||
private UUID tableId;
|
private UUID tableId;
|
||||||
private Tournament tournament;
|
private Tournament tournament;
|
||||||
private ConcurrentHashMap<String, UUID> sessionPlayerMap = new ConcurrentHashMap<String, UUID>();
|
private ConcurrentHashMap<UUID, UUID> userPlayerMap = new ConcurrentHashMap<UUID, UUID>();
|
||||||
private ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<UUID, TournamentSession>();
|
private ConcurrentHashMap<UUID, TournamentSession> tournamentSessions = new ConcurrentHashMap<UUID, TournamentSession>();
|
||||||
|
|
||||||
public TournamentController(Tournament tournament, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||||
sessionId = UUID.randomUUID();
|
this.userPlayerMap = userPlayerMap;
|
||||||
this.sessionPlayerMap = sessionPlayerMap;
|
|
||||||
chatId = ChatManager.getInstance().createChatSession();
|
chatId = ChatManager.getInstance().createChatSession();
|
||||||
this.tournament = tournament;
|
this.tournament = tournament;
|
||||||
this.tableId = tableId;
|
this.tableId = tableId;
|
||||||
|
@ -128,9 +125,9 @@ public class TournamentController {
|
||||||
checkStart();
|
checkStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void join(String sessionId) {
|
public synchronized void join(UUID userId) {
|
||||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
UUID playerId = userPlayerMap.get(userId);
|
||||||
TournamentSession tournamentSession = new TournamentSession(tournament, sessionId, tableId, playerId);
|
TournamentSession tournamentSession = new TournamentSession(tournament, null, tableId, playerId);
|
||||||
tournamentSessions.put(playerId, tournamentSession);
|
tournamentSessions.put(playerId, tournamentSession);
|
||||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||||
player.setJoined();
|
player.setJoined();
|
||||||
|
@ -205,40 +202,40 @@ public class TournamentController {
|
||||||
tournamentSessions.get(playerId).submitDeck(deck);
|
tournamentSessions.get(playerId).submitDeck(deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void timeout(String sessionId) {
|
public void timeout(UUID userId) {
|
||||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
if (userPlayerMap.containsKey(userId)) {
|
||||||
TournamentPlayer player = tournament.getPlayer(sessionPlayerMap.get(sessionId));
|
TournamentPlayer player = tournament.getPlayer(userPlayerMap.get(userId));
|
||||||
tournament.autoSubmit(sessionPlayerMap.get(sessionId), player.getDeck());
|
tournament.autoSubmit(userPlayerMap.get(userId), player.getDeck());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getSessionId() {
|
// public UUID getSessionId() {
|
||||||
return this.sessionId;
|
// return this.sessionId;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public UUID getChatId() {
|
public UUID getChatId() {
|
||||||
return chatId;
|
return chatId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(String sessionId) {
|
public void kill(UUID userId) {
|
||||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
if (userPlayerMap.containsKey(userId)) {
|
||||||
tournamentSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
tournamentSessions.get(userPlayerMap.get(userId)).setKilled();
|
||||||
tournamentSessions.remove(sessionPlayerMap.get(sessionId));
|
tournamentSessions.remove(userPlayerMap.get(userId));
|
||||||
leave(sessionId);
|
leave(userId);
|
||||||
sessionPlayerMap.remove(sessionId);
|
userPlayerMap.remove(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void leave(String sessionId) {
|
private void leave(UUID userId) {
|
||||||
tournament.leave(getPlayerId(sessionId));
|
tournament.leave(getPlayerId(userId));
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID getPlayerId(String sessionId) {
|
private UUID getPlayerId(UUID userId) {
|
||||||
return sessionPlayerMap.get(sessionId);
|
return userPlayerMap.get(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPlayerSessionId(UUID playerId) {
|
private UUID getPlayerSessionId(UUID playerId) {
|
||||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||||
if (entry.getValue().equals(playerId))
|
if (entry.getValue().equals(playerId))
|
||||||
return entry.getKey();
|
return entry.getKey();
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,22 +48,21 @@ public class TournamentManager {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID createTournamentSession(Tournament tournament, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
public void createTournamentSession(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||||
TournamentController tournamentController = new TournamentController(tournament, sessionPlayerMap, tableId);
|
TournamentController tournamentController = new TournamentController(tournament, userPlayerMap, tableId);
|
||||||
controllers.put(tournament.getId(), tournamentController);
|
controllers.put(tournament.getId(), tournamentController);
|
||||||
return tournamentController.getSessionId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void joinTournament(UUID tournamentId, String sessionId) {
|
public void joinTournament(UUID tournamentId, UUID userId) {
|
||||||
controllers.get(tournamentId).join(sessionId);
|
controllers.get(tournamentId).join(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kill(UUID tournamentId, String sessionId) {
|
public void kill(UUID tournamentId, UUID userId) {
|
||||||
controllers.get(tournamentId).kill(sessionId);
|
controllers.get(tournamentId).kill(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void timeout(UUID tournamentId, String sessionId) {
|
public void timeout(UUID tournamentId, UUID userId) {
|
||||||
controllers.get(tournamentId).timeout(sessionId);
|
controllers.get(tournamentId).timeout(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void submitDeck(UUID tournamentId, UUID playerId, Deck deck) {
|
public void submitDeck(UUID tournamentId, UUID playerId, Deck deck) {
|
||||||
|
|
|
@ -37,8 +37,8 @@ import mage.cards.decks.Deck;
|
||||||
import mage.game.tournament.Tournament;
|
import mage.game.tournament.Tournament;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.server.Session;
|
import mage.server.User;
|
||||||
import mage.server.SessionManager;
|
import mage.server.UserManager;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.view.TournamentView;
|
import mage.view.TournamentView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
@ -50,7 +50,7 @@ import org.apache.log4j.Logger;
|
||||||
public class TournamentSession {
|
public class TournamentSession {
|
||||||
protected final static Logger logger = Logger.getLogger(TournamentSession.class);
|
protected final static Logger logger = Logger.getLogger(TournamentSession.class);
|
||||||
|
|
||||||
protected String sessionId;
|
protected UUID userId;
|
||||||
protected UUID playerId;
|
protected UUID playerId;
|
||||||
protected UUID tableId;
|
protected UUID tableId;
|
||||||
protected Tournament tournament;
|
protected Tournament tournament;
|
||||||
|
@ -59,8 +59,8 @@ public class TournamentSession {
|
||||||
private ScheduledFuture<?> futureTimeout;
|
private ScheduledFuture<?> futureTimeout;
|
||||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||||
|
|
||||||
public TournamentSession(Tournament tournament, String sessionId, UUID tableId, UUID playerId) {
|
public TournamentSession(Tournament tournament, UUID userId, UUID tableId, UUID playerId) {
|
||||||
this.sessionId = sessionId;
|
this.userId = userId;
|
||||||
this.tournament = tournament;
|
this.tournament = tournament;
|
||||||
this.playerId = playerId;
|
this.playerId = playerId;
|
||||||
this.tableId = tableId;
|
this.tableId = tableId;
|
||||||
|
@ -68,37 +68,29 @@ public class TournamentSession {
|
||||||
|
|
||||||
public boolean init(final TournamentView tournamentView) {
|
public boolean init(final TournamentView tournamentView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("tournamentInit", tournament.getId(), tournamentView));
|
user.fireCallback(new ClientCallback("tournamentInit", tournament.getId(), tournamentView));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public boolean waitForAck(String message) {
|
|
||||||
// Session session = SessionManager.getInstance().getSession(sessionId);
|
|
||||||
// do {
|
|
||||||
// //TODO: add timeout
|
|
||||||
// } while (!session.getAckMessage().equals(message) && !killed);
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void update(final TournamentView tournamentView) {
|
public void update(final TournamentView tournamentView) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("tournamentUpdate", tournament.getId(), tournamentView));
|
user.fireCallback(new ClientCallback("tournamentUpdate", tournament.getId(), tournamentView));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void gameOver(final String message) {
|
public void gameOver(final String message) {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null) {
|
if (user != null) {
|
||||||
session.fireCallback(new ClientCallback("tournamentOver", tournament.getId(), message));
|
user.fireCallback(new ClientCallback("tournamentOver", tournament.getId(), message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,9 +98,10 @@ public class TournamentSession {
|
||||||
public void construct(Deck deck, int timeout) throws MageException {
|
public void construct(Deck deck, int timeout) throws MageException {
|
||||||
if (!killed) {
|
if (!killed) {
|
||||||
setupTimeout(timeout);
|
setupTimeout(timeout);
|
||||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
User user = UserManager.getInstance().getUser(userId);
|
||||||
if (session != null)
|
if (user != null) {
|
||||||
session.construct(deck, tableId, timeout);
|
user.construct(deck, tableId, timeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +112,7 @@ public class TournamentSession {
|
||||||
|
|
||||||
protected void handleRemoteException(RemoteException ex) {
|
protected void handleRemoteException(RemoteException ex) {
|
||||||
logger.fatal("TournamentSession error ", ex);
|
logger.fatal("TournamentSession error ", ex);
|
||||||
TournamentManager.getInstance().kill(tournament.getId(), sessionId);
|
TournamentManager.getInstance().kill(tournament.getId(), userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKilled() {
|
public void setKilled() {
|
||||||
|
@ -133,7 +126,7 @@ public class TournamentSession {
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
TournamentManager.getInstance().timeout(tournament.getId(), sessionId);
|
TournamentManager.getInstance().timeout(tournament.getId(), userId);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
seconds, TimeUnit.SECONDS
|
seconds, TimeUnit.SECONDS
|
||||||
|
|
Loading…
Reference in a new issue