mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Merge
This commit is contained in:
commit
4653a53078
127 changed files with 3754 additions and 788 deletions
|
|
@ -35,7 +35,7 @@ import java.io.FilenameFilter;
|
|||
import java.net.InetAddress;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.game.GameType;
|
||||
import mage.game.match.MatchType;
|
||||
import mage.server.game.DeckValidatorFactory;
|
||||
import mage.server.game.GameFactory;
|
||||
import mage.server.game.PlayerFactory;
|
||||
|
|
@ -119,11 +119,11 @@ public class Main {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static GameType loadGameType(GamePlugin plugin) {
|
||||
private static MatchType loadGameType(GamePlugin plugin) {
|
||||
try {
|
||||
classLoader.addURL(new File(pluginFolder + "/" + plugin.getJar()).toURI().toURL());
|
||||
logger.info("Loading game type: " + plugin.getClassName());
|
||||
return (GameType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
||||
return (MatchType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
|
||||
} catch (ClassNotFoundException ex) {
|
||||
logger.log(Level.SEVERE, "Game type not found:" + plugin.getJar() + " - check plugin folder");
|
||||
} catch (Exception ex) {
|
||||
|
|
|
|||
|
|
@ -39,11 +39,10 @@ import java.util.UUID;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.interfaces.MageException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.interfaces.Server;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
|
|
@ -56,7 +55,6 @@ import mage.server.game.ReplayManager;
|
|||
import mage.server.game.TableManager;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.util.Logging;
|
||||
import mage.view.CardView;
|
||||
import mage.view.ChatMessage.MessageColor;
|
||||
import mage.view.GameView;
|
||||
import mage.view.TableView;
|
||||
|
|
@ -117,9 +115,9 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableView createTable(UUID sessionId, UUID roomId, String gameType, String deckType, List<String> playerTypes, MultiplayerAttackOption attackOption, RangeOfInfluence range) throws MageException {
|
||||
public TableView createTable(UUID sessionId, UUID roomId, MatchOptions options) throws MageException {
|
||||
try {
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(sessionId, gameType, deckType, playerTypes, attackOption, range);
|
||||
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(sessionId, options);
|
||||
logger.info("Table " + table.getTableId() + " created");
|
||||
return table;
|
||||
}
|
||||
|
|
@ -161,6 +159,21 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException {
|
||||
try {
|
||||
boolean ret = TableManager.getInstance().submitDeck(sessionId, tableId, deckList);
|
||||
logger.info("Session " + sessionId + " submitted deck");
|
||||
return ret;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof GameException)
|
||||
throw (GameException)ex;
|
||||
handleException(ex);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableView> getTables(UUID roomId) throws MageException {
|
||||
try {
|
||||
|
|
@ -202,13 +215,13 @@ public class ServerImpl extends RemoteServer implements Server {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startGame(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
public void startMatch(final UUID sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
try {
|
||||
rmiExecutor.execute(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TableManager.getInstance().startGame(sessionId, roomId, tableId);
|
||||
TableManager.getInstance().startMatch(sessionId, roomId, tableId);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -31,11 +31,13 @@ package mage.server;
|
|||
import java.util.logging.Level;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.interfaces.callback.CallbackServerSession;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.game.GameManager;
|
||||
import mage.server.game.TableManager;
|
||||
import mage.util.Logging;
|
||||
import mage.view.TableClientMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -90,7 +92,11 @@ public class Session {
|
|||
}
|
||||
|
||||
public void gameStarted(final UUID gameId, final UUID playerId) {
|
||||
fireCallback(new ClientCallback("startGame", new UUID[] {gameId, playerId}));
|
||||
fireCallback(new ClientCallback("startGame", new TableClientMessage(gameId, playerId)));
|
||||
}
|
||||
|
||||
public void sideboard(final Deck deck, final UUID tableId) {
|
||||
fireCallback(new ClientCallback("sideboard", new TableClientMessage(deck, tableId)));
|
||||
}
|
||||
|
||||
public void watchGame(final UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -82,15 +82,17 @@ public class GameController implements GameCallback {
|
|||
private Game game;
|
||||
private UUID chatId;
|
||||
private UUID tableId;
|
||||
private UUID choosingPlayerId;
|
||||
private Future<?> gameFuture;
|
||||
|
||||
|
||||
public GameController(Game game, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
public GameController(Game game, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||
gameSessionId = UUID.randomUUID();
|
||||
this.sessionPlayerMap = sessionPlayerMap;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
this.game = game;
|
||||
this.tableId = tableId;
|
||||
this.choosingPlayerId = choosingPlayerId;
|
||||
init();
|
||||
}
|
||||
|
||||
|
|
@ -186,7 +188,7 @@ public class GameController implements GameCallback {
|
|||
return;
|
||||
}
|
||||
}
|
||||
GameWorker worker = new GameWorker(game, this);
|
||||
GameWorker worker = new GameWorker(game, choosingPlayerId, this);
|
||||
gameFuture = gameExecutor.submit(worker);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,17 +30,15 @@ package mage.server.game;
|
|||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.game.Game;
|
||||
import mage.game.match.Match;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.util.Logging;
|
||||
import mage.game.GameType;
|
||||
import mage.game.match.MatchType;
|
||||
import mage.view.GameTypeView;
|
||||
|
||||
/**
|
||||
|
|
@ -52,8 +50,8 @@ public class GameFactory {
|
|||
private final static GameFactory INSTANCE = new GameFactory();
|
||||
private final static Logger logger = Logging.getLogger(GameFactory.class.getName());
|
||||
|
||||
private Map<String, Class<Game>> games = new HashMap<String, Class<Game>>();
|
||||
private Map<String, GameType> gameTypes = new HashMap<String, GameType>();
|
||||
private Map<String, Class<Match>> games = new HashMap<String, Class<Match>>();
|
||||
private Map<String, MatchType> gameTypes = new HashMap<String, MatchType>();
|
||||
private List<GameTypeView> gameTypeViews = new ArrayList<GameTypeView>();
|
||||
|
||||
|
||||
|
|
@ -63,31 +61,31 @@ public class GameFactory {
|
|||
|
||||
private GameFactory() {}
|
||||
|
||||
public Game createGame(String gameType, MultiplayerAttackOption attackOption, RangeOfInfluence range) {
|
||||
public Match createMatch(String gameType, MatchOptions options) {
|
||||
|
||||
Game game;
|
||||
Constructor<Game> con;
|
||||
Match match;
|
||||
Constructor<Match> con;
|
||||
try {
|
||||
con = games.get(gameType).getConstructor(new Class[]{MultiplayerAttackOption.class, RangeOfInfluence.class});
|
||||
game = con.newInstance(new Object[] {attackOption, range});
|
||||
con = games.get(gameType).getConstructor(new Class[]{MatchOptions.class});
|
||||
match = con.newInstance(new Object[] {options});
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
}
|
||||
logger.info("Game created: " + game.getId().toString());
|
||||
logger.info("Game created: " + gameType); // + game.getId().toString());
|
||||
|
||||
return game;
|
||||
return match;
|
||||
}
|
||||
|
||||
public List<GameTypeView> getGameTypes() {
|
||||
return gameTypeViews;
|
||||
}
|
||||
|
||||
public void addGameType(String name, GameType gameType, Class game) {
|
||||
public void addGameType(String name, MatchType matchType, Class game) {
|
||||
if (game != null) {
|
||||
this.games.put(name, game);
|
||||
this.gameTypes.put(name, gameType);
|
||||
this.gameTypeViews.add(new GameTypeView(gameType));
|
||||
this.gameTypes.put(name, matchType);
|
||||
this.gameTypeViews.add(new GameTypeView(matchType));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,8 +49,8 @@ public class GameManager {
|
|||
|
||||
private ConcurrentHashMap<UUID, GameController> gameControllers = new ConcurrentHashMap<UUID, GameController>();
|
||||
|
||||
public UUID createGameSession(Game game, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
|
||||
GameController gameController = new GameController(game, sessionPlayerMap, tableId);
|
||||
public UUID createGameSession(Game game, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId, UUID choosingPlayerId) {
|
||||
GameController gameController = new GameController(game, sessionPlayerMap, tableId, choosingPlayerId);
|
||||
gameControllers.put(game.getId(), gameController);
|
||||
return gameController.getSessionId();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.server.game;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -44,16 +45,18 @@ public class GameWorker implements Callable {
|
|||
|
||||
private GameCallback result;
|
||||
private Game game;
|
||||
private UUID choosingPlayerId;
|
||||
|
||||
public GameWorker(Game game, GameCallback result) {
|
||||
public GameWorker(Game game, UUID choosingPlayerId, GameCallback result) {
|
||||
this.game = game;
|
||||
this.choosingPlayerId = choosingPlayerId;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call() {
|
||||
try {
|
||||
game.start();
|
||||
game.start(choosingPlayerId);
|
||||
result.gameResult(game.getWinner());
|
||||
} catch (Exception ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
|
|
|
|||
|
|
@ -30,10 +30,9 @@ package mage.server.game;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.view.TableView;
|
||||
|
||||
/**
|
||||
|
|
@ -44,7 +43,7 @@ public interface GamesRoom extends Room {
|
|||
|
||||
public List<TableView> getTables();
|
||||
public boolean joinTable(UUID sessionId, UUID tableId, String name, DeckCardLists deckList) throws GameException;
|
||||
public TableView createTable(UUID sessionId, String gameType, String deckType, List<String> playerTypes, MultiplayerAttackOption attackOption, RangeOfInfluence range);
|
||||
public TableView createTable(UUID sessionId, MatchOptions options);
|
||||
public void removeTable(UUID sessionId, UUID tableId);
|
||||
public TableView getTable(UUID tableId);
|
||||
public void leaveTable(UUID sessionId, UUID tableId);
|
||||
|
|
|
|||
|
|
@ -35,10 +35,9 @@ import java.util.List;
|
|||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.util.Logging;
|
||||
import mage.view.TableView;
|
||||
|
||||
|
|
@ -71,8 +70,8 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TableView createTable(UUID sessionId, String gameType, String deckType, List<String> playerTypes, MultiplayerAttackOption attackOption, RangeOfInfluence range) {
|
||||
Table table = TableManager.getInstance().createTable(sessionId, gameType, deckType, playerTypes, attackOption, range);
|
||||
public TableView createTable(UUID sessionId, MatchOptions options) {
|
||||
Table table = TableManager.getInstance().createTable(sessionId, options);
|
||||
tables.put(table.getId(), table);
|
||||
return new TableView(table);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import java.io.ObjectInput;
|
|||
import java.io.ObjectOutput;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -47,15 +46,18 @@ import java.util.logging.Level;
|
|||
import java.util.logging.Logger;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
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.events.Listener;
|
||||
import mage.game.events.TableEvent;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.players.Player;
|
||||
import mage.server.ChatManager;
|
||||
import mage.server.Main;
|
||||
|
|
@ -73,17 +75,36 @@ public class TableController {
|
|||
|
||||
private UUID sessionId;
|
||||
private UUID chatId;
|
||||
private UUID gameId;
|
||||
private Table table;
|
||||
private Game game;
|
||||
private Match match;
|
||||
private MatchOptions options;
|
||||
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
|
||||
|
||||
public TableController(UUID sessionId, String gameType, String deckType, List<String> playerTypes, MultiplayerAttackOption attackOption, RangeOfInfluence range) {
|
||||
public TableController(UUID sessionId, MatchOptions options) {
|
||||
this.sessionId = sessionId;
|
||||
chatId = ChatManager.getInstance().createChatSession();
|
||||
game = GameFactory.getInstance().createGame(gameType, attackOption, range);
|
||||
gameId = game.getId();
|
||||
table = new Table(gameType, DeckValidatorFactory.getInstance().createDeckValidator(deckType), playerTypes);
|
||||
this.options = options;
|
||||
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
|
||||
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes());
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
table.addTableEventListener(
|
||||
new Listener<TableEvent> () {
|
||||
@Override
|
||||
public void event(TableEvent event) {
|
||||
switch (event.getEventType()) {
|
||||
case SIDEBOARD:
|
||||
sideboard(event.getPlayerId());
|
||||
break;
|
||||
case SUBMIT_DECK:
|
||||
submitDeck(event.getPlayerId(), event.getDeck());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public synchronized boolean joinTable(UUID sessionId, String name, DeckCardLists deckList) throws GameException {
|
||||
|
|
@ -100,8 +121,7 @@ public class TableController {
|
|||
}
|
||||
|
||||
Player player = createPlayer(name, deck, seat.getPlayerType());
|
||||
game.loadCards(deck.getCards(), player.getId());
|
||||
game.loadCards(deck.getSideboard(), player.getId());
|
||||
match.addPlayer(player, deck);
|
||||
table.joinTable(player, seat);
|
||||
logger.info("player joined " + player.getId());
|
||||
//only add human players to sessionPlayerMap
|
||||
|
|
@ -112,11 +132,29 @@ public class TableController {
|
|||
return true;
|
||||
}
|
||||
|
||||
public synchronized boolean submitDeck(UUID sessionId, DeckCardLists deckList) throws GameException {
|
||||
if (table.getState() != TableState.SIDEBOARDING) {
|
||||
return false;
|
||||
}
|
||||
MatchPlayer player = match.getPlayer(sessionPlayerMap.get(sessionId));
|
||||
Deck deck = Deck.load(deckList);
|
||||
if (!Main.server.isTestMode() && !validDeck(deck)) {
|
||||
throw new GameException(player.getPlayer().getName() + " has an invalid deck for this format");
|
||||
}
|
||||
submitDeck(sessionPlayerMap.get(sessionId), deck);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void submitDeck(UUID playerId, Deck deck) {
|
||||
MatchPlayer player = match.getPlayer(playerId);
|
||||
player.submitDeck(deck);
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID sessionId) {
|
||||
if (table.getState() != TableState.DUELING) {
|
||||
return false;
|
||||
}
|
||||
SessionManager.getInstance().getSession(sessionId).watchGame(game.getId());
|
||||
SessionManager.getInstance().getSession(sessionId).watchGame(match.getGame().getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +179,7 @@ public class TableController {
|
|||
}
|
||||
|
||||
private Player createPlayer(String name, Deck deck, String playerType) {
|
||||
Player player = PlayerFactory.getInstance().createPlayer(playerType, name, deck, game.getRangeOfInfluence());
|
||||
Player player = PlayerFactory.getInstance().createPlayer(playerType, name, deck, options.getRange());
|
||||
logger.info("Player created " + player.getId());
|
||||
return player;
|
||||
}
|
||||
|
|
@ -151,26 +189,66 @@ public class TableController {
|
|||
table.leaveTable(sessionPlayerMap.get(sessionId));
|
||||
}
|
||||
|
||||
public synchronized void startGame(UUID sessionId) {
|
||||
public synchronized void startMatch(UUID sessionId) {
|
||||
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) {
|
||||
try {
|
||||
table.initGame(game);
|
||||
match.startMatch();
|
||||
startGame(null);
|
||||
} catch (GameException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
GameManager.getInstance().createGameSession(game, sessionPlayerMap, table.getId());
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
sessionManager.getSession(entry.getKey()).gameStarted(game.getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void startGame(UUID choosingPlayerId) throws GameException {
|
||||
match.startGame();
|
||||
table.initGame();
|
||||
GameManager.getInstance().createGameSession(match.getGame(), sessionPlayerMap, table.getId(), choosingPlayerId);
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
sessionManager.getSession(entry.getKey()).gameStarted(match.getGame().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void sideboard() {
|
||||
table.sideboard();
|
||||
for (MatchPlayer player: match.getPlayers()) {
|
||||
player.setSideboarding();
|
||||
player.getPlayer().sideboard(table);
|
||||
}
|
||||
while (!match.isDoneSideboarding()){}
|
||||
}
|
||||
|
||||
private void sideboard(UUID playerId) {
|
||||
SessionManager sessionManager = SessionManager.getInstance();
|
||||
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
|
||||
if (entry.getValue().equals(playerId)) {
|
||||
MatchPlayer player = match.getPlayer(entry.getValue());
|
||||
sessionManager.getSession(entry.getKey()).sideboard(player.getDeck(), table.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void endGame() {
|
||||
UUID choosingPlayerId = match.getChooser();
|
||||
match.endGame();
|
||||
table.endGame();
|
||||
saveGame();
|
||||
GameManager.getInstance().removeGame(game.getId());
|
||||
game = null;
|
||||
GameManager.getInstance().removeGame(match.getGame().getId());
|
||||
try {
|
||||
if (!match.isMatchOver()) {
|
||||
sideboard();
|
||||
startGame(choosingPlayerId);
|
||||
}
|
||||
} catch (GameException ex) {
|
||||
logger.log(Level.SEVERE, null, ex);
|
||||
}
|
||||
endMatch();
|
||||
}
|
||||
|
||||
public void endMatch() {
|
||||
match = null;
|
||||
}
|
||||
|
||||
public void swapSeats(int seatNum1, int seatNum2) {
|
||||
|
|
@ -188,17 +266,17 @@ public class TableController {
|
|||
|
||||
private void saveGame() {
|
||||
try {
|
||||
OutputStream file = new FileOutputStream("saved/" + game.getId().toString() + ".game");
|
||||
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(game);
|
||||
output.writeObject(game.getGameStates());
|
||||
output.writeObject(match.getGame());
|
||||
output.writeObject(match.getGame().getGameStates());
|
||||
}
|
||||
finally {
|
||||
output.close();
|
||||
}
|
||||
logger.log(Level.INFO, "Saved game:" + game.getId());
|
||||
logger.log(Level.INFO, "Saved game:" + match.getGame().getId());
|
||||
}
|
||||
catch(IOException ex) {
|
||||
logger.log(Level.SEVERE, "Cannot save game.", ex);
|
||||
|
|
@ -207,7 +285,7 @@ public class TableController {
|
|||
|
||||
private Game loadGame() {
|
||||
try{
|
||||
InputStream file = new FileInputStream("saved/" + gameId.toString() + ".game");
|
||||
InputStream file = new FileInputStream("saved/" + match.getGame().toString() + ".game");
|
||||
InputStream buffer = new BufferedInputStream(file);
|
||||
ObjectInput input = new CopierObjectInputStream(Main.classLoader, new GZIPInputStream(buffer));
|
||||
try {
|
||||
|
|
@ -224,7 +302,7 @@ public class TableController {
|
|||
logger.log(Level.SEVERE, "Cannot load game. Class not found.", ex);
|
||||
}
|
||||
catch(IOException ex) {
|
||||
logger.log(Level.SEVERE, "Cannot load game:" + game.getId(), ex);
|
||||
logger.log(Level.SEVERE, "Cannot load game:" + match.getGame().getId(), ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,14 +30,12 @@ package mage.server.game;
|
|||
|
||||
import mage.game.Table;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
import mage.Constants.MultiplayerAttackOption;
|
||||
import mage.Constants.RangeOfInfluence;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.GameException;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.util.Logging;
|
||||
|
||||
/**
|
||||
|
|
@ -56,8 +54,8 @@ public class TableManager {
|
|||
return INSTANCE;
|
||||
}
|
||||
|
||||
public Table createTable(UUID sessionId, String gameType, String deckType, List<String> playerTypes, MultiplayerAttackOption attackOption, RangeOfInfluence range) {
|
||||
TableController tableController = new TableController(sessionId, gameType, deckType, playerTypes, attackOption, range);
|
||||
public Table createTable(UUID sessionId, MatchOptions options) {
|
||||
TableController tableController = new TableController(sessionId, options);
|
||||
controllers.put(tableController.getTable().getId(), tableController);
|
||||
tables.put(tableController.getTable().getId(), tableController.getTable());
|
||||
return tableController.getTable();
|
||||
|
|
@ -75,6 +73,10 @@ public class TableManager {
|
|||
return controllers.get(tableId).joinTable(sessionId, name, deckList);
|
||||
}
|
||||
|
||||
public boolean submitDeck(UUID sessionId, UUID tableId, DeckCardLists deckList) throws GameException {
|
||||
return controllers.get(tableId).submitDeck(sessionId, deckList);
|
||||
}
|
||||
|
||||
public void removeSession(UUID sessionId) {
|
||||
// TODO: search through tables and remove session
|
||||
}
|
||||
|
|
@ -100,8 +102,8 @@ public class TableManager {
|
|||
return controllers.get(tableId).getChatId();
|
||||
}
|
||||
|
||||
public void startGame(UUID sessionId, UUID roomId, UUID tableId) {
|
||||
controllers.get(tableId).startGame(sessionId);
|
||||
public void startMatch(UUID sessionId, UUID roomId, UUID tableId) {
|
||||
controllers.get(tableId).startMatch(sessionId);
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID sessionId, UUID tableId) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue