mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
fixed replay + some other fixes
This commit is contained in:
parent
ff3e0108cd
commit
35f0767f1b
24 changed files with 218 additions and 187 deletions
|
|
@ -69,7 +69,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (session.isConnected())
|
||||
if (session != null && session.isConnected())
|
||||
session.leaveChat(chatId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
this.pnlReplay.setVisible(true);
|
||||
this.setVisible(true);
|
||||
this.chatPanel.clear();
|
||||
if (!session.replayGame(gameId))
|
||||
if (!session.startReplay(gameId))
|
||||
hideGame();
|
||||
}
|
||||
|
||||
|
|
@ -734,16 +734,16 @@ public class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
private void btnStopReplayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopReplayActionPerformed
|
||||
if (modalQuestion("Are you sure you want to stop replay?", "Stop replay") == JOptionPane.YES_OPTION) {
|
||||
session.stopReplay();
|
||||
session.stopReplay(gameId);
|
||||
}
|
||||
}//GEN-LAST:event_btnStopReplayActionPerformed
|
||||
|
||||
private void btnNextPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextPlayActionPerformed
|
||||
session.nextPlay();
|
||||
session.nextPlay(gameId);
|
||||
}//GEN-LAST:event_btnNextPlayActionPerformed
|
||||
|
||||
private void btnPreviousPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreviousPlayActionPerformed
|
||||
session.previousPlay();
|
||||
session.previousPlay(gameId);
|
||||
}//GEN-LAST:event_btnPreviousPlayActionPerformed
|
||||
|
||||
private class HandContainer extends JPanel {
|
||||
|
|
|
|||
|
|
@ -262,18 +262,6 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean replayTable(UUID roomId, UUID tableId) {
|
||||
try {
|
||||
server.replayTable(sessionId, roomId, tableId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, DeckCardLists deckList) {
|
||||
try {
|
||||
return server.joinTable(sessionId, roomId, tableId, playerName, playerType, deckList);
|
||||
|
|
@ -622,9 +610,9 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean stopReplay() {
|
||||
public boolean startReplay(UUID gameId) {
|
||||
try {
|
||||
server.stopReplay(sessionId);
|
||||
server.startReplay(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
|
|
@ -634,9 +622,9 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean nextPlay() {
|
||||
public boolean stopReplay(UUID gameId) {
|
||||
try {
|
||||
server.nextPlay(sessionId);
|
||||
server.stopReplay(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
|
|
@ -646,9 +634,21 @@ public class Session {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean previousPlay() {
|
||||
public boolean nextPlay(UUID gameId) {
|
||||
try {
|
||||
server.previousPlay(sessionId);
|
||||
server.nextPlay(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
} catch (MageException ex) {
|
||||
handleMageException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean previousPlay(UUID gameId) {
|
||||
try {
|
||||
server.previousPlay(gameId, sessionId);
|
||||
return true;
|
||||
} catch (RemoteException ex) {
|
||||
handleRemoteException(ex);
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
{
|
||||
int modelRow = Integer.valueOf( e.getActionCommand() );
|
||||
UUID tableId = UUID.fromString((String)tableModel.getValueAt(modelRow, 0));
|
||||
UUID gameId = (UUID)tableModel.getValueAt(modelRow, 6);
|
||||
String state = (String)tableModel.getValueAt(modelRow, 4);
|
||||
boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, 5);
|
||||
|
||||
|
|
@ -114,8 +115,8 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
if (!session.watchTable(roomId, tableId))
|
||||
hideTables();
|
||||
} else if (state.equals("Replay")) {
|
||||
logger.info("Replaying table " + tableId);
|
||||
if (!session.replayTable(roomId, tableId))
|
||||
logger.info("Replaying game " + gameId);
|
||||
if (!session.replayGame(gameId))
|
||||
hideTables();
|
||||
}
|
||||
}
|
||||
|
|
@ -346,7 +347,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
|
|||
}
|
||||
|
||||
class TableTableModel extends AbstractTableModel {
|
||||
private String[] columnNames = new String[]{"Game Id", "Game Type", "Deck Type", "Status", "Action"};
|
||||
private String[] columnNames = new String[]{"Table Id", "Game Type", "Deck Type", "Status", "Action"};
|
||||
private TableView[] tables = new TableView[0];
|
||||
|
||||
|
||||
|
|
@ -389,6 +390,10 @@ class TableTableModel extends AbstractTableModel {
|
|||
}
|
||||
case 5:
|
||||
return tables[arg0].isTournament();
|
||||
case 6:
|
||||
if (!tables[arg0].getGames().isEmpty())
|
||||
return tables[arg0].getGames().get(0);
|
||||
return null;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,12 +84,12 @@ public class TournamentPanel extends javax.swing.JPanel implements Observer {
|
|||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
int modelRow = Integer.valueOf( e.getActionCommand() );
|
||||
UUID tableId = UUID.fromString((String)tableMatches.getValueAt(modelRow, 3));
|
||||
UUID gameId = UUID.fromString((String)tableMatches.getValueAt(modelRow, 3));
|
||||
String state = (String)tableMatches.getValueAt(modelRow, 4);
|
||||
|
||||
if (state.equals("Finished")) {
|
||||
logger.info("Replaying table " + tableId);
|
||||
session.replayTable(null, tableId);
|
||||
logger.info("Replaying game " + gameId);
|
||||
session.replayGame(gameId);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ public interface Server extends Remote, CallbackServer {
|
|||
public boolean joinTournamentTable(UUID sessionId, UUID roomId, UUID tableId, String name, String playerType) throws RemoteException, MageException, GameException;
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws RemoteException, MageException, GameException;
|
||||
public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public boolean replayTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void leaveTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
public void swapSeats(UUID sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws RemoteException, MageException;
|
||||
public void removeTable(UUID sessionId, UUID roomId, UUID tableId) throws RemoteException, MageException;
|
||||
|
|
@ -103,9 +102,10 @@ public interface Server extends Remote, CallbackServer {
|
|||
|
||||
//replay methods
|
||||
public void replayGame(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void stopReplay(UUID sessionId) throws RemoteException, MageException;
|
||||
public void nextPlay(UUID sessionId) throws RemoteException, MageException;
|
||||
public void previousPlay(UUID sessionId) throws RemoteException, MageException;
|
||||
public void startReplay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void stopReplay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void nextPlay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
public void previousPlay(UUID gameId, UUID sessionId) throws RemoteException, MageException;
|
||||
|
||||
//test methods
|
||||
public void cheat(UUID gameId, UUID sessionId, UUID playerId, DeckCardLists deckList) throws RemoteException, MageException;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.TableState;
|
||||
import mage.game.Game;
|
||||
import mage.game.Seat;
|
||||
import mage.game.Table;
|
||||
|
||||
|
|
@ -49,6 +50,7 @@ public class TableView implements Serializable {
|
|||
private TableState tableState;
|
||||
private boolean isTournament;
|
||||
private List<SeatView> seats = new ArrayList<SeatView>();
|
||||
private List<UUID> games = new ArrayList<UUID>();
|
||||
|
||||
public TableView(Table table) {
|
||||
this.tableId = table.getId();
|
||||
|
|
@ -59,6 +61,11 @@ public class TableView implements Serializable {
|
|||
for (Seat seat: table.getSeats()) {
|
||||
seats.add(new SeatView(seat));
|
||||
}
|
||||
if (!table.isTournament()) {
|
||||
for (Game game: table.getMatch().getGames()) {
|
||||
games.add(game.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getTableId() {
|
||||
|
|
@ -81,6 +88,10 @@ public class TableView implements Serializable {
|
|||
return seats;
|
||||
}
|
||||
|
||||
public List<UUID> getGames() {
|
||||
return games;
|
||||
}
|
||||
|
||||
public boolean isTournament() {
|
||||
return this.isTournament;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,8 +37,6 @@ import java.rmi.server.UnicastRemoteObject;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.interfaces.MageException;
|
||||
|
|
@ -57,12 +55,12 @@ import mage.server.game.ReplayManager;
|
|||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.util.Logging;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -70,7 +68,7 @@ import mage.view.TournamentView;
|
|||
*/
|
||||
public class ServerImpl extends RemoteServer implements Server {
|
||||
|
||||
private final static Logger logger = Logging.getLogger("Mage Server");
|
||||
private final static Logger logger = Logger.getLogger("Mage Server");
|
||||
private static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
|
||||
|
||||
private boolean testMode;
|
||||
|
|
@ -86,9 +84,9 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
if (testMode)
|
||||
logger.info("MAGE server running in test mode");
|
||||
} catch (ExportException ex) {
|
||||
logger.severe("ERROR: Unable to start Mage Server - another server is likely running");
|
||||
logger.fatal("ERROR: Unable to start Mage Server - another server is likely running");
|
||||
} catch (RemoteException ex) {
|
||||
logger.log(Level.SEVERE, "Failed to start RMI server at port " + port, ex);
|
||||
logger.fatal("Failed to start RMI server at port " + port, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +134,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
public TableView createTournamentTable(UUID sessionId, UUID roomId, TournamentOptions options) throws MageException {
|
||||
try {
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(sessionId, options);
|
||||
logger.log(Level.INFO, "Tournament table {0} created", table.getTableId());
|
||||
logger.info("Tournament table " + table.getTableId() + " created");
|
||||
return table;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
|
@ -636,13 +634,13 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void replayGame(final UUID gameID, final UUID sessionId) throws MageException {
|
||||
public void replayGame(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayManager.getInstance().startReplay(sessionId);
|
||||
ReplayManager.getInstance().replayGame(gameId, sessionId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -653,13 +651,13 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void stopReplay(final UUID sessionId) throws MageException {
|
||||
public void startReplay(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayManager.getInstance().stopReplay(sessionId);
|
||||
ReplayManager.getInstance().startReplay(gameId, sessionId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -670,13 +668,13 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void nextPlay(final UUID sessionId) throws MageException {
|
||||
public void stopReplay(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayManager.getInstance().nextPlay(sessionId);
|
||||
ReplayManager.getInstance().stopReplay(gameId, sessionId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -687,13 +685,13 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void previousPlay(final UUID sessionId) throws MageException {
|
||||
public void nextPlay(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayManager.getInstance().previousPlay(sessionId);
|
||||
ReplayManager.getInstance().nextPlay(gameId, sessionId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
@ -704,14 +702,20 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean replayTable(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
|
||||
public void previousPlay(final UUID gameId, final UUID sessionId) throws MageException {
|
||||
try {
|
||||
return TableManager.getInstance().replayTable(sessionId, tableId);
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayManager.getInstance().previousPlay(gameId, sessionId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -758,7 +762,7 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
public void handleException(Exception ex) throws MageException {
|
||||
logger.log(Level.SEVERE, "", ex);
|
||||
logger.fatal("", ex);
|
||||
throw new MageException("Server error: " + ex.getMessage());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ public class Session {
|
|||
fireCallback(new ClientCallback("watchGame", gameId));
|
||||
}
|
||||
|
||||
public void replayGame() {
|
||||
fireCallback(new ClientCallback("replayGame", null));
|
||||
public void replayGame(final UUID gameId) {
|
||||
fireCallback(new ClientCallback("replayGame", gameId));
|
||||
}
|
||||
|
||||
public void ack(String message) {
|
||||
|
|
|
|||
|
|
@ -32,30 +32,14 @@ import mage.server.draft.DraftManager;
|
|||
import mage.server.tournament.TournamentFactory;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.game.Table;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.Constants.TableState;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameException;
|
||||
import mage.game.GameStates;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.Seat;
|
||||
import mage.game.draft.Draft;
|
||||
|
|
@ -63,18 +47,15 @@ import mage.game.draft.DraftPlayer;
|
|||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.players.Player;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
import mage.server.game.GameFactory;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.server.game.GameReplay;
|
||||
import mage.server.game.PlayerFactory;
|
||||
import mage.server.game.ReplayManager;
|
||||
import mage.util.CopierObjectInputStream;
|
||||
import mage.util.Logging;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -82,7 +63,7 @@ import mage.util.Logging;
|
|||
*/
|
||||
public class TableController {
|
||||
|
||||
private final static Logger logger = Logging.getLogger(TableController.class.getName());
|
||||
private final static Logger logger = Logger.getLogger(TableController.class);
|
||||
|
||||
private UUID sessionId;
|
||||
private UUID chatId;
|
||||
|
|
@ -97,7 +78,7 @@ public class TableController {
|
|||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.options = options;
|
||||
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
|
||||
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), false);
|
||||
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +86,7 @@ public class TableController {
|
|||
this.sessionId = sessionId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
|
||||
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), true);
|
||||
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
|
|
@ -215,13 +196,6 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public GameReplay createReplay() {
|
||||
if (table.getState() == TableState.FINISHED) {
|
||||
return new GameReplay(loadGame());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean replayTable(UUID sessionId) {
|
||||
if (table.getState() != TableState.FINISHED) {
|
||||
return false;
|
||||
|
|
@ -263,7 +237,7 @@ public class TableController {
|
|||
match.startMatch();
|
||||
startGame(null);
|
||||
} catch (GameException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
logger.fatal(null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -315,7 +289,7 @@ public class TableController {
|
|||
UUID choosingPlayerId = match.getChooser();
|
||||
match.endGame();
|
||||
table.endGame();
|
||||
saveGame();
|
||||
GameManager.getInstance().saveGame(match.getGame().getId());
|
||||
GameManager.getInstance().removeGame(match.getGame().getId());
|
||||
try {
|
||||
if (!match.isMatchOver()) {
|
||||
|
|
@ -324,7 +298,7 @@ public class TableController {
|
|||
startGame(choosingPlayerId);
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
logger.fatal(null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -348,49 +322,6 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
private void saveGame() {
|
||||
try {
|
||||
OutputStream file = new FileOutputStream("saved/" + match.getGame().getId().toString() + ".game");
|
||||
OutputStream buffer = new BufferedOutputStream(file);
|
||||
ObjectOutput output = new ObjectOutputStream(new GZIPOutputStream(buffer));
|
||||
try {
|
||||
output.writeObject(match.getGame());
|
||||
output.writeObject(match.getGame().getGameStates());
|
||||
}
|
||||
finally {
|
||||
output.close();
|
||||
}
|
||||
logger.log(Level.INFO, "Saved game:" + match.getGame().getId());
|
||||
}
|
||||
catch(IOException ex) {
|
||||
logger.log(Level.SEVERE, "Cannot save game.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Game loadGame() {
|
||||
try{
|
||||
InputStream file = new FileInputStream("saved/" + match.getGame().getId().toString() + ".game");
|
||||
InputStream buffer = new BufferedInputStream(file);
|
||||
ObjectInput input = new CopierObjectInputStream(Main.classLoader, new GZIPInputStream(buffer));
|
||||
try {
|
||||
Game game = (Game)input.readObject();
|
||||
GameStates states = (GameStates)input.readObject();
|
||||
game.loadGameStates(states);
|
||||
return game;
|
||||
}
|
||||
finally {
|
||||
input.close();
|
||||
}
|
||||
}
|
||||
catch(ClassNotFoundException ex) {
|
||||
logger.log(Level.SEVERE, "Cannot load game. Class not found.", ex);
|
||||
}
|
||||
catch(IOException ex) {
|
||||
logger.log(Level.SEVERE, "Cannot load game:" + match.getGame().getId(), ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isOwner(UUID sessionId) {
|
||||
return sessionId.equals(this.sessionId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,10 +162,6 @@ public class TableManager {
|
|||
controllers.get(tableId).endDraft(draft);
|
||||
}
|
||||
|
||||
public GameReplay createReplay(UUID tableId) {
|
||||
return controllers.get(tableId).createReplay();
|
||||
}
|
||||
|
||||
public void swapSeats(UUID tableId, UUID sessionId, int seatNum1, int seatNum2) {
|
||||
if (isTableOwner(tableId, sessionId)) {
|
||||
controllers.get(tableId).swapSeats(seatNum1, seatNum2);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,14 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import mage.server.TableManager;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
|
@ -38,6 +44,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Future;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
import mage.Constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -415,6 +422,25 @@ public class GameController implements GameCallback {
|
|||
endGame(result);
|
||||
}
|
||||
|
||||
public void saveGame() {
|
||||
try {
|
||||
OutputStream file = new FileOutputStream("saved/" + game.getId().toString() + ".game");
|
||||
OutputStream buffer = new BufferedOutputStream(file);
|
||||
ObjectOutput output = new ObjectOutputStream(new GZIPOutputStream(buffer));
|
||||
try {
|
||||
output.writeObject(game);
|
||||
output.writeObject(game.getGameStates());
|
||||
}
|
||||
finally {
|
||||
output.close();
|
||||
}
|
||||
logger.info("Saved game:" + game.getId());
|
||||
}
|
||||
catch(IOException ex) {
|
||||
logger.fatal("Cannot save game.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces cards in player's hands by specified in config/init.txt.<br/>
|
||||
* <br/>
|
||||
|
|
|
|||
|
|
@ -105,10 +105,6 @@ public class GameManager {
|
|||
gameControllers.get(gameId).kill(sessionId);
|
||||
}
|
||||
|
||||
// public GameReplay createReplay(UUID gameId) {
|
||||
// return gameControllers.get(gameId).createReplay();
|
||||
// }
|
||||
|
||||
public void cheat(UUID gameId, UUID sessionId, UUID playerId, DeckCardLists deckList) {
|
||||
gameControllers.get(gameId).cheat(sessionId, playerId, deckList);
|
||||
}
|
||||
|
|
@ -125,7 +121,12 @@ public class GameManager {
|
|||
gameControllers.remove(gameId);
|
||||
}
|
||||
|
||||
public void saveGame(UUID gameId) {
|
||||
gameControllers.get(gameId).saveGame();
|
||||
}
|
||||
|
||||
public GameView getGameView(UUID gameId, UUID sessionId, UUID playerId) {
|
||||
return gameControllers.get(gameId).getGameView(playerId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,17 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectInput;
|
||||
import java.util.UUID;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import mage.game.*;
|
||||
import mage.server.Main;
|
||||
import mage.util.CopierObjectInputStream;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -36,13 +46,15 @@ import mage.game.*;
|
|||
*/
|
||||
public class GameReplay {
|
||||
|
||||
private final static Logger logger = Logger.getLogger(GameReplay.class);
|
||||
|
||||
private GameStates savedGame;
|
||||
private Game game;
|
||||
private int stateIndex;
|
||||
|
||||
public GameReplay(Game game) {
|
||||
public GameReplay(UUID gameId) {
|
||||
this.game = loadGame(gameId);
|
||||
this.savedGame = game.getGameStates();
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
|
@ -66,4 +78,29 @@ public class GameReplay {
|
|||
public Game getGame() {
|
||||
return this.game;
|
||||
}
|
||||
|
||||
private Game loadGame(UUID gameId) {
|
||||
try{
|
||||
InputStream file = new FileInputStream("saved/" + gameId.toString() + ".game");
|
||||
InputStream buffer = new BufferedInputStream(file);
|
||||
ObjectInput input = new CopierObjectInputStream(Main.classLoader, new GZIPInputStream(buffer));
|
||||
try {
|
||||
Game loadGame = (Game)input.readObject();
|
||||
GameStates states = (GameStates)input.readObject();
|
||||
loadGame.loadGameStates(states);
|
||||
return loadGame;
|
||||
}
|
||||
finally {
|
||||
input.close();
|
||||
}
|
||||
}
|
||||
catch(ClassNotFoundException ex) {
|
||||
logger.fatal("Cannot load game. Class not found.", ex);
|
||||
}
|
||||
catch(IOException ex) {
|
||||
logger.fatal("Cannot load game:" + gameId, ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,28 +45,28 @@ public class ReplayManager {
|
|||
|
||||
private ReplayManager() {}
|
||||
|
||||
private ConcurrentHashMap<UUID, ReplaySession> replaySessions = new ConcurrentHashMap<UUID, ReplaySession>();
|
||||
private ConcurrentHashMap<String, ReplaySession> replaySessions = new ConcurrentHashMap<String, ReplaySession>();
|
||||
|
||||
public void replayGame(UUID sessionId, UUID tableId) {
|
||||
ReplaySession replaySession = new ReplaySession(tableId, sessionId);
|
||||
replaySessions.put(sessionId, replaySession);
|
||||
SessionManager.getInstance().getSession(sessionId).replayGame();
|
||||
public void replayGame(UUID gameId, UUID sessionId) {
|
||||
ReplaySession replaySession = new ReplaySession(gameId, sessionId);
|
||||
replaySessions.put(gameId.toString() + sessionId.toString(), replaySession);
|
||||
SessionManager.getInstance().getSession(sessionId).replayGame(gameId);
|
||||
}
|
||||
|
||||
public void startReplay(UUID sessionId) {
|
||||
replaySessions.get(sessionId).replay();
|
||||
public void startReplay(UUID gameId, UUID sessionId) {
|
||||
replaySessions.get(gameId.toString() + sessionId.toString()).replay();
|
||||
}
|
||||
|
||||
public void stopReplay(UUID sessionId) {
|
||||
replaySessions.get(sessionId).stop();
|
||||
public void stopReplay(UUID gameId, UUID sessionId) {
|
||||
replaySessions.get(gameId.toString() + sessionId.toString()).stop();
|
||||
}
|
||||
|
||||
public void nextPlay(UUID sessionId) {
|
||||
replaySessions.get(sessionId).next();
|
||||
public void nextPlay(UUID gameId, UUID sessionId) {
|
||||
replaySessions.get(gameId.toString() + sessionId.toString()).next();
|
||||
}
|
||||
|
||||
public void previousPlay(UUID sessionId) {
|
||||
replaySessions.get(sessionId).previous();
|
||||
public void previousPlay(UUID gameId, UUID sessionId) {
|
||||
replaySessions.get(gameId.toString() + sessionId.toString()).previous();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,15 +28,12 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import mage.server.TableManager;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.Game;
|
||||
import mage.game.GameState;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.Session;
|
||||
import mage.server.SessionManager;
|
||||
import mage.util.Logging;
|
||||
import mage.view.GameView;
|
||||
|
||||
/**
|
||||
|
|
@ -45,13 +42,11 @@ import mage.view.GameView;
|
|||
*/
|
||||
public class ReplaySession implements GameCallback {
|
||||
|
||||
private final static Logger logger = Logging.getLogger(ReplaySession.class.getName());
|
||||
|
||||
private GameReplay replay;
|
||||
protected UUID sessionId;
|
||||
|
||||
ReplaySession(UUID tableId, UUID sessionId) {
|
||||
this.replay = TableManager.getInstance().createReplay(tableId);
|
||||
ReplaySession(UUID gameId, UUID sessionId) {
|
||||
this.replay = new GameReplay(gameId);
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ public class ColoredManaCost extends ManaCostImpl<ColoredManaCost> {
|
|||
addColoredOption(mana);
|
||||
}
|
||||
|
||||
public ColoredManaCost(ColoredManaCost cost) {
|
||||
super(cost);
|
||||
this.mana = cost.mana;
|
||||
public ColoredManaCost(ColoredManaCost manaCost) {
|
||||
super(manaCost);
|
||||
this.mana = manaCost.mana;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ public class GenericManaCost extends ManaCostImpl<GenericManaCost> {
|
|||
this.options.addMana(Mana.ColorlessMana(mana));
|
||||
}
|
||||
|
||||
public GenericManaCost(GenericManaCost cost) {
|
||||
super(cost);
|
||||
this.mana = cost.mana;
|
||||
public GenericManaCost(GenericManaCost manaCost) {
|
||||
super(manaCost);
|
||||
this.mana = manaCost.mana;
|
||||
}
|
||||
|
||||
public void setMana(int mana) {
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ public class HybridManaCost extends ManaCostImpl<HybridManaCost> {
|
|||
addColoredOption(mana2);
|
||||
}
|
||||
|
||||
public HybridManaCost(HybridManaCost cost) {
|
||||
super(cost);
|
||||
this.mana1 = cost.mana1;
|
||||
this.mana2 = cost.mana2;
|
||||
public HybridManaCost(HybridManaCost manaCost) {
|
||||
super(manaCost);
|
||||
this.mana1 = manaCost.mana1;
|
||||
this.mana2 = manaCost.mana2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -51,10 +51,11 @@ public abstract class ManaCostImpl<T extends ManaCostImpl<T>> extends CostImpl<T
|
|||
options = new ManaOptions();
|
||||
}
|
||||
|
||||
public ManaCostImpl(final ManaCostImpl cost) {
|
||||
super(cost);
|
||||
this.payment = cost.payment.copy();
|
||||
this.options = cost.options.copy();
|
||||
public ManaCostImpl(final ManaCostImpl manaCost) {
|
||||
super(manaCost);
|
||||
this.payment = manaCost.payment.copy();
|
||||
this.cost = manaCost.cost.copy();
|
||||
this.options = manaCost.options.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ public class MonoHybridManaCost extends ManaCostImpl<MonoHybridManaCost> {
|
|||
options.add(Mana.ColorlessMana(2));
|
||||
}
|
||||
|
||||
public MonoHybridManaCost(MonoHybridManaCost cost) {
|
||||
super(cost);
|
||||
this.mana = cost.mana;
|
||||
this.mana2 = cost.mana2;
|
||||
public MonoHybridManaCost(MonoHybridManaCost manaCost) {
|
||||
super(manaCost);
|
||||
this.mana = manaCost.mana;
|
||||
this.mana2 = manaCost.mana2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -50,9 +50,9 @@ public class VariableManaCost extends ManaCostImpl<VariableManaCost> implements
|
|||
this.multiplier = multiplier;
|
||||
}
|
||||
|
||||
public VariableManaCost(VariableManaCost cost) {
|
||||
super(cost);
|
||||
this.multiplier = cost.multiplier;
|
||||
public VariableManaCost(VariableManaCost manaCost) {
|
||||
super(manaCost);
|
||||
this.multiplier = manaCost.multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -323,8 +323,11 @@ public abstract class ExpansionSet implements Serializable {
|
|||
|
||||
protected void addToBooster(List<Card> booster, ExpansionSet set, Rarity rarity) {
|
||||
Card card = set.getRandom(rarity);
|
||||
if (card != null)
|
||||
booster.add(card);
|
||||
if (card != null) {
|
||||
Card newCard = card.copy();
|
||||
newCard.assignNewId();
|
||||
booster.add(newCard);
|
||||
}
|
||||
}
|
||||
|
||||
protected Card getRandom(Rarity rarity) {
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ import java.io.Serializable;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.TableState;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.decks.DeckValidator;
|
||||
import mage.game.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.events.TableEvent.EventType;
|
||||
import mage.game.events.TableEventSource;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.tournament.Tournament;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
|
|
@ -54,15 +54,28 @@ public class Table implements Serializable {
|
|||
private boolean isTournament;
|
||||
private DeckValidator validator;
|
||||
private TableState state = TableState.WAITING;
|
||||
private Match match;
|
||||
private Tournament tournament;
|
||||
|
||||
protected TableEventSource tableEventSource = new TableEventSource();
|
||||
|
||||
public Table(String gameType, String name, DeckValidator validator, List<String> playerTypes, boolean isTournament) {
|
||||
public Table(String gameType, String name, DeckValidator validator, List<String> playerTypes, Tournament tournament) {
|
||||
this(gameType, name, validator, playerTypes);
|
||||
this.tournament = tournament;
|
||||
this.isTournament = true;
|
||||
}
|
||||
|
||||
public Table(String gameType, String name, DeckValidator validator, List<String> playerTypes, Match match) {
|
||||
this(gameType, name, validator, playerTypes);
|
||||
this.match = match;
|
||||
this.isTournament = false;
|
||||
}
|
||||
|
||||
protected Table(String gameType, String name, DeckValidator validator, List<String> playerTypes) {
|
||||
tableId = UUID.randomUUID();
|
||||
this.numSeats = playerTypes.size();
|
||||
this.gameType = gameType;
|
||||
this.name = name;
|
||||
this.isTournament = isTournament;
|
||||
createSeats(playerTypes);
|
||||
this.validator = validator;
|
||||
}
|
||||
|
|
@ -169,4 +182,12 @@ public class Table implements Serializable {
|
|||
tableEventSource.addListener(listener);
|
||||
}
|
||||
|
||||
public Match getMatch() {
|
||||
return match;
|
||||
}
|
||||
|
||||
public Tournament getTournament() {
|
||||
return tournament;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue