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
|
|
@ -37,8 +37,8 @@ import mage.cards.decks.Deck;
|
|||
import mage.game.tournament.Tournament;
|
||||
import mage.MageException;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.view.TournamentView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
@ -50,7 +50,7 @@ import org.apache.log4j.Logger;
|
|||
public class TournamentSession {
|
||||
protected final static Logger logger = Logger.getLogger(TournamentSession.class);
|
||||
|
||||
protected String sessionId;
|
||||
protected UUID userId;
|
||||
protected UUID playerId;
|
||||
protected UUID tableId;
|
||||
protected Tournament tournament;
|
||||
|
|
@ -59,8 +59,8 @@ public class TournamentSession {
|
|||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
||||
public TournamentSession(Tournament tournament, String sessionId, UUID tableId, UUID playerId) {
|
||||
this.sessionId = sessionId;
|
||||
public TournamentSession(Tournament tournament, UUID userId, UUID tableId, UUID playerId) {
|
||||
this.userId = userId;
|
||||
this.tournament = tournament;
|
||||
this.playerId = playerId;
|
||||
this.tableId = tableId;
|
||||
|
|
@ -68,37 +68,29 @@ public class TournamentSession {
|
|||
|
||||
public boolean init(final TournamentView tournamentView) {
|
||||
if (!killed) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.fireCallback(new ClientCallback("tournamentInit", tournament.getId(), tournamentView));
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.fireCallback(new ClientCallback("tournamentInit", tournament.getId(), tournamentView));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
if (!killed) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.fireCallback(new ClientCallback("tournamentUpdate", tournament.getId(), tournamentView));
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.fireCallback(new ClientCallback("tournamentUpdate", tournament.getId(), tournamentView));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void gameOver(final String message) {
|
||||
if (!killed) {
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null) {
|
||||
session.fireCallback(new ClientCallback("tournamentOver", tournament.getId(), message));
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.fireCallback(new ClientCallback("tournamentOver", tournament.getId(), message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -106,9 +98,10 @@ public class TournamentSession {
|
|||
public void construct(Deck deck, int timeout) throws MageException {
|
||||
if (!killed) {
|
||||
setupTimeout(timeout);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.construct(deck, tableId, timeout);
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.construct(deck, tableId, timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +112,7 @@ public class TournamentSession {
|
|||
|
||||
protected void handleRemoteException(RemoteException ex) {
|
||||
logger.fatal("TournamentSession error ", ex);
|
||||
TournamentManager.getInstance().kill(tournament.getId(), sessionId);
|
||||
TournamentManager.getInstance().kill(tournament.getId(), userId);
|
||||
}
|
||||
|
||||
public void setKilled() {
|
||||
|
|
@ -133,7 +126,7 @@ public class TournamentSession {
|
|||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TournamentManager.getInstance().timeout(tournament.getId(), sessionId);
|
||||
TournamentManager.getInstance().timeout(tournament.getId(), userId);
|
||||
}
|
||||
},
|
||||
seconds, TimeUnit.SECONDS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue