forked from External/mage
...
This commit is contained in:
parent
345d364d76
commit
de6a672d24
23 changed files with 492 additions and 383 deletions
|
|
@ -28,17 +28,19 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import mage.game.Game;
|
||||
import mage.interfaces.GameClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.view.AbilityPickerView;
|
||||
import mage.view.CardsView;
|
||||
import mage.view.GameClientMessage;
|
||||
import mage.view.GameView;
|
||||
|
||||
/**
|
||||
|
|
@ -53,171 +55,215 @@ public class GameSession extends GameWatcher {
|
|||
private ScheduledFuture<?> futureTimeout;
|
||||
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
|
||||
|
||||
public GameSession(GameClient client, Game game, UUID sessionId, UUID playerId) {
|
||||
super(client, sessionId, game.getId());
|
||||
public GameSession(Game game, UUID sessionId, UUID playerId) {
|
||||
super(sessionId, game.getId());
|
||||
this.game = game;
|
||||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public void ask(final String question, final GameView gameView) {
|
||||
if (!killed) {
|
||||
setupTimeout();
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.ask(question, gameView);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gameAsk", new GameClientMessage(gameView, question)));
|
||||
}
|
||||
// setupTimeout();
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.ask(question, gameView);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public void target(final String question, final CardsView cardView, final boolean required, final GameView gameView) {
|
||||
if (!killed) {
|
||||
setupTimeout();
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.target(question, cardView, required, gameView);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gameTarget", new GameClientMessage(gameView, question, cardView, required)));
|
||||
}
|
||||
// if (!killed) {
|
||||
// setupTimeout();
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.target(question, cardView, required, gameView);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public void select(final String message, final GameView gameView) {
|
||||
if (!killed) {
|
||||
setupTimeout();
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.select(message, gameView);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gameSelect", new GameClientMessage(gameView, message)));
|
||||
}
|
||||
// if (!killed) {
|
||||
// setupTimeout();
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.select(message, gameView);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public void chooseAbility(final AbilityPickerView abilities) {
|
||||
if (!killed) {
|
||||
setupTimeout();
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.chooseAbility(abilities);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gameChooseAbility", abilities));
|
||||
}
|
||||
// if (!killed) {
|
||||
// setupTimeout();
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.chooseAbility(abilities);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public void choose(final String message, final String[] choices) {
|
||||
if (!killed) {
|
||||
setupTimeout();
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.choose(message, choices);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gameChoose", new GameClientMessage(choices, message)));
|
||||
}
|
||||
// if (!killed) {
|
||||
// setupTimeout();
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.choose(message, choices);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public void playMana(final String message, final GameView gameView) {
|
||||
if (!killed) {
|
||||
setupTimeout();
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.playMana(message, gameView);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gamePlayMana", new GameClientMessage(gameView, message)));
|
||||
}
|
||||
// if (!killed) {
|
||||
// setupTimeout();
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.playMana(message, gameView);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public void playXMana(final String message, final GameView gameView) {
|
||||
if (!killed) {
|
||||
setupTimeout();
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.playXMana(message, gameView);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gamePlayXMana", new GameClientMessage(gameView, message)));
|
||||
}
|
||||
// if (!killed) {
|
||||
// setupTimeout();
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.playXMana(message, gameView);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public void getAmount(final String message, final int min, final int max) {
|
||||
if (!killed) {
|
||||
setupTimeout();
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.getAmount(min, max);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gameSelectAmount", new GameClientMessage(message, min, max)));
|
||||
}
|
||||
// if (!killed) {
|
||||
// setupTimeout();
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.getAmount(min, max);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
public void revealCards(final String name, final CardsView cardView) {
|
||||
if (!killed) {
|
||||
rmiExecutor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
client.revealCards(name, cardView);
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
Session session = SessionManager.getInstance().getSession(sessionId);
|
||||
if (session != null)
|
||||
session.fireCallback(new ClientCallback("gameReveal", new GameClientMessage(cardView, name)));
|
||||
}
|
||||
// if (!killed) {
|
||||
// rmiExecutor.submit(
|
||||
// new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// client.revealCards(name, cardView);
|
||||
// } catch (RemoteException ex) {
|
||||
// handleRemoteException(ex);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue