forked from External/mage
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
|
|
@ -31,7 +31,6 @@ package mage.server.tournament;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.GameException;
|
||||
import mage.game.Table;
|
||||
|
|
@ -60,16 +59,14 @@ public class TournamentController {
|
|||
|
||||
private final static Logger logger = Logger.getLogger(TournamentController.class);
|
||||
|
||||
private UUID sessionId;
|
||||
private UUID chatId;
|
||||
private UUID tableId;
|
||||
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>();
|
||||
|
||||
public TournamentController(Tournament tournament, ConcurrentHashMap<String, UUID> sessionPlayerMap, UUID tableId) {
|
||||
sessionId = UUID.randomUUID();
|
||||
this.sessionPlayerMap = sessionPlayerMap;
|
||||
public TournamentController(Tournament tournament, ConcurrentHashMap<UUID, UUID> userPlayerMap, UUID tableId) {
|
||||
this.userPlayerMap = userPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.tournament = tournament;
|
||||
this.tableId = tableId;
|
||||
|
|
@ -128,9 +125,9 @@ public class TournamentController {
|
|||
checkStart();
|
||||
}
|
||||
|
||||
public synchronized void join(String sessionId) {
|
||||
UUID playerId = sessionPlayerMap.get(sessionId);
|
||||
TournamentSession tournamentSession = new TournamentSession(tournament, sessionId, tableId, playerId);
|
||||
public synchronized void join(UUID userId) {
|
||||
UUID playerId = userPlayerMap.get(userId);
|
||||
TournamentSession tournamentSession = new TournamentSession(tournament, null, tableId, playerId);
|
||||
tournamentSessions.put(playerId, tournamentSession);
|
||||
TournamentPlayer player = tournament.getPlayer(playerId);
|
||||
player.setJoined();
|
||||
|
|
@ -205,40 +202,40 @@ public class TournamentController {
|
|||
tournamentSessions.get(playerId).submitDeck(deck);
|
||||
}
|
||||
|
||||
public void timeout(String sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
TournamentPlayer player = tournament.getPlayer(sessionPlayerMap.get(sessionId));
|
||||
tournament.autoSubmit(sessionPlayerMap.get(sessionId), player.getDeck());
|
||||
public void timeout(UUID userId) {
|
||||
if (userPlayerMap.containsKey(userId)) {
|
||||
TournamentPlayer player = tournament.getPlayer(userPlayerMap.get(userId));
|
||||
tournament.autoSubmit(userPlayerMap.get(userId), player.getDeck());
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
return this.sessionId;
|
||||
}
|
||||
// public UUID getSessionId() {
|
||||
// return this.sessionId;
|
||||
// }
|
||||
|
||||
public UUID getChatId() {
|
||||
return chatId;
|
||||
}
|
||||
|
||||
public void kill(String sessionId) {
|
||||
if (sessionPlayerMap.containsKey(sessionId)) {
|
||||
tournamentSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
|
||||
tournamentSessions.remove(sessionPlayerMap.get(sessionId));
|
||||
leave(sessionId);
|
||||
sessionPlayerMap.remove(sessionId);
|
||||
public void kill(UUID userId) {
|
||||
if (userPlayerMap.containsKey(userId)) {
|
||||
tournamentSessions.get(userPlayerMap.get(userId)).setKilled();
|
||||
tournamentSessions.remove(userPlayerMap.get(userId));
|
||||
leave(userId);
|
||||
userPlayerMap.remove(userId);
|
||||
}
|
||||
}
|
||||
|
||||
private void leave(String sessionId) {
|
||||
tournament.leave(getPlayerId(sessionId));
|
||||
private void leave(UUID userId) {
|
||||
tournament.leave(getPlayerId(userId));
|
||||
}
|
||||
|
||||
private UUID getPlayerId(String sessionId) {
|
||||
return sessionPlayerMap.get(sessionId);
|
||||
private UUID getPlayerId(UUID userId) {
|
||||
return userPlayerMap.get(userId);
|
||||
}
|
||||
|
||||
private String getPlayerSessionId(UUID playerId) {
|
||||
for (Entry<String, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
private UUID getPlayerSessionId(UUID playerId) {
|
||||
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId))
|
||||
return entry.getKey();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue