mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 12:31:59 -08:00
added watch game methods
This commit is contained in:
parent
8225a4080c
commit
4bb7ffd452
22 changed files with 235 additions and 114 deletions
|
|
@ -665,7 +665,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
});
|
||||
}
|
||||
|
||||
public void watchGame(final UUID gameId) {
|
||||
@Override
|
||||
public void watchGame(final UUID gameId, final UUID chatId, final GameView game) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -681,7 +682,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
desktopPane.add(gamePane, JLayeredPane.DEFAULT_LAYER);
|
||||
gamePane.setMaximum(true);
|
||||
gamePane.setVisible(true);
|
||||
gamePane.watchGame(gameId);
|
||||
gamePane.watchGame(gameId, chatId, game);
|
||||
setActive(gamePane);
|
||||
} catch (PropertyVetoException ex) {
|
||||
}
|
||||
|
|
@ -1524,13 +1525,9 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
@Override
|
||||
public void gameStarted(UUID gameId, UUID playerId) {
|
||||
// try {
|
||||
GameManager.getInstance().setCurrentPlayerUUID(playerId);
|
||||
showGame(gameId, playerId);
|
||||
logger.info("Game " + gameId + " started for player " + playerId);
|
||||
// } catch (Exception ex) {
|
||||
// handleException(ex);
|
||||
// }
|
||||
GameManager.getInstance().setCurrentPlayerUUID(playerId);
|
||||
showGame(gameId, playerId);
|
||||
logger.info("Game " + gameId + " started for player " + playerId);
|
||||
|
||||
if (Plugins.getInstance().isCounterPluginLoaded()) {
|
||||
Plugins.getInstance().addGamesPlayed();
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import java.util.UUID;
|
|||
import javax.swing.SwingUtilities;
|
||||
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
|
||||
import mage.client.MagePane;
|
||||
import mage.view.GameView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -74,10 +75,10 @@ public class GamePane extends MagePane {
|
|||
this.removeFrame();
|
||||
}
|
||||
|
||||
public void watchGame(UUID gameId) {
|
||||
public void watchGame(UUID gameId, UUID chatId, GameView game) {
|
||||
this.setTitle("Watching " + gameId);
|
||||
this.gameId = gameId;
|
||||
gamePanel.watchGame(gameId, this);
|
||||
gamePanel.watchGame(gameId, chatId, game, this);
|
||||
}
|
||||
|
||||
public void replayGame(UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -400,7 +400,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void watchGame(UUID gameId, GamePane gamePane) {
|
||||
public synchronized void watchGame(UUID gameId, UUID chatId, GameView game, GamePane gamePane) {
|
||||
this.gameId = gameId;
|
||||
this.gamePane = gamePane;
|
||||
this.playerId = null;
|
||||
|
|
@ -423,13 +423,13 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
this.pnlReplay.setVisible(false);
|
||||
this.gameChatPanel.clear();
|
||||
UUID chatId = client.watchGame(gameId);
|
||||
if (chatId == null) {
|
||||
removeGame();
|
||||
}
|
||||
else {
|
||||
this.gameChatPanel.connect(chatId);
|
||||
}
|
||||
this.init(game);
|
||||
for (PlayAreaPanel panel : getPlayers().values()) {
|
||||
panel.setPlayingMode(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,6 +271,11 @@ public class MultiConnectTest {
|
|||
public void tournamentStarted(UUID tournamentId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watchGame(UUID gameId, UUID chatId, GameView game) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
|
|
|
|||
|
|
@ -330,7 +330,11 @@ public class Client {
|
|||
}
|
||||
|
||||
public void watchTournamentTable(UUID tableId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
try {
|
||||
clientMessageHandler.watchTournamentTable(tableId);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error watching tournament table", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getTournamentChatId(UUID tournamentId) {
|
||||
|
|
@ -369,7 +373,11 @@ public class Client {
|
|||
}
|
||||
|
||||
public void watchTable(UUID roomId, UUID tableId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
try {
|
||||
clientMessageHandler.watchTable(roomId, tableId);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error watching table", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void replayGame(UUID gameId) {
|
||||
|
|
@ -416,16 +424,16 @@ public class Client {
|
|||
return null;
|
||||
}
|
||||
|
||||
public UUID watchGame(UUID gameId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public boolean startReplay(UUID gameId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public void stopWatching(UUID gameId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
try {
|
||||
clientMessageHandler.stopWatching(gameId);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error stopping watching game", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopReplay(UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -75,6 +75,7 @@ import org.mage.network.messages.callback.SideboardCallback;
|
|||
import org.mage.network.messages.callback.StartDraftCallback;
|
||||
import org.mage.network.messages.callback.TournamentStartedCallback;
|
||||
import org.mage.network.messages.callback.UserRequestDialogCallback;
|
||||
import org.mage.network.messages.callback.WatchGameCallback;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -364,8 +365,10 @@ public class Server {
|
|||
ch.writeAndFlush(new ShowTournamentCallback(tournamentId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
public void watchGame(String sessionId, UUID gameId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
public void watchGame(String sessionId, UUID gameId, UUID chatId, GameView game) {
|
||||
Channel ch = findChannel(sessionId);
|
||||
if (ch != null)
|
||||
ch.writeAndFlush(new WatchGameCallback(gameId, chatId, game)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
public void replayGame(String sessionId, UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,5 @@
|
|||
package org.mage.network.handlers.client;
|
||||
|
||||
import org.mage.network.messages.requests.GetTournamentChatIdRequest;
|
||||
import org.mage.network.messages.requests.GetTournamentRequest;
|
||||
import org.mage.network.messages.requests.JoinTournamentRequest;
|
||||
import org.mage.network.messages.requests.StartTournamentRequest;
|
||||
import org.mage.network.messages.requests.CreateTournamentRequest;
|
||||
import org.mage.network.messages.requests.QuitTournamentRequest;
|
||||
import org.mage.network.messages.requests.QuitMatchRequest;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import java.io.Serializable;
|
||||
|
|
@ -31,11 +24,15 @@ import org.mage.network.messages.ClientMessage;
|
|||
import org.mage.network.messages.requests.ChatMessageRequest;
|
||||
import org.mage.network.messages.requests.ChatRoomIdRequest;
|
||||
import org.mage.network.messages.requests.CreateTableRequest;
|
||||
import org.mage.network.messages.requests.CreateTournamentRequest;
|
||||
import org.mage.network.messages.requests.GetRoomRequest;
|
||||
import org.mage.network.messages.requests.GetTournamentChatIdRequest;
|
||||
import org.mage.network.messages.requests.GetTournamentRequest;
|
||||
import org.mage.network.messages.requests.JoinChatRequest;
|
||||
import org.mage.network.messages.requests.JoinDraftRequest;
|
||||
import org.mage.network.messages.requests.JoinGameRequest;
|
||||
import org.mage.network.messages.requests.JoinTableRequest;
|
||||
import org.mage.network.messages.requests.JoinTournamentRequest;
|
||||
import org.mage.network.messages.requests.JoinTournamentTableRequest;
|
||||
import org.mage.network.messages.requests.LeaveChatRequest;
|
||||
import org.mage.network.messages.requests.LeaveTableRequest;
|
||||
|
|
@ -43,6 +40,8 @@ import org.mage.network.messages.requests.MarkCardRequest;
|
|||
import org.mage.network.messages.requests.PickCardRequest;
|
||||
import org.mage.network.messages.requests.PlayerActionRequest;
|
||||
import org.mage.network.messages.requests.QuitDraftRequest;
|
||||
import org.mage.network.messages.requests.QuitMatchRequest;
|
||||
import org.mage.network.messages.requests.QuitTournamentRequest;
|
||||
import org.mage.network.messages.requests.RemoveTableRequest;
|
||||
import org.mage.network.messages.requests.SendFeedbackRequest;
|
||||
import org.mage.network.messages.requests.SendPlayerBooleanRequest;
|
||||
|
|
@ -53,10 +52,14 @@ import org.mage.network.messages.requests.SendPlayerUUIDRequest;
|
|||
import org.mage.network.messages.requests.ServerMessagesRequest;
|
||||
import org.mage.network.messages.requests.SetPreferencesRequest;
|
||||
import org.mage.network.messages.requests.StartMatchRequest;
|
||||
import org.mage.network.messages.requests.StartTournamentRequest;
|
||||
import org.mage.network.messages.requests.StopWatchingRequest;
|
||||
import org.mage.network.messages.requests.SubmitDeckRequest;
|
||||
import org.mage.network.messages.requests.SwapSeatRequest;
|
||||
import org.mage.network.messages.requests.TableWaitingRequest;
|
||||
import org.mage.network.messages.requests.UpdateDeckRequest;
|
||||
import org.mage.network.messages.requests.WatchTableRequest;
|
||||
import org.mage.network.messages.requests.WatchTournamentTableRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -301,4 +304,16 @@ public class ClientMessageHandler extends SimpleChannelInboundHandler<ClientMess
|
|||
return tournamentViewQueue.take();
|
||||
}
|
||||
|
||||
public void watchTournamentTable(UUID tableId) {
|
||||
ctx.writeAndFlush(new WatchTournamentTableRequest(tableId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
public void watchTable(UUID roomId, UUID tableId) {
|
||||
ctx.writeAndFlush(new WatchTableRequest(roomId, tableId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
public void stopWatching(UUID gameId) {
|
||||
ctx.writeAndFlush(new StopWatchingRequest(gameId)).addListener(WriteListener.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,4 +71,5 @@ public interface MageClient {
|
|||
void showTournament(UUID tournamentId);
|
||||
void tournamentStarted(UUID tournamentId);
|
||||
|
||||
void watchGame(UUID gameId, UUID chatId, GameView game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,6 +73,10 @@ public interface MageServer {
|
|||
boolean joinTournament(UUID tournamentId, String sessionId);
|
||||
void quitTournament(UUID tournamentId, String sessionId);
|
||||
|
||||
void watchTable(String sessionId, UUID roomId, UUID tableId);
|
||||
void watchTournamentTable(String sessionId, UUID tableId);
|
||||
void stopWatching(UUID gameId, String sessionId);
|
||||
|
||||
void pingTime(long milliSeconds, String sessionId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
package org.mage.network.messages.callback;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.view.GameView;
|
||||
import org.mage.network.handlers.client.ClientMessageHandler;
|
||||
import org.mage.network.messages.ClientMessage;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class WatchGameCallback extends ClientMessage {
|
||||
private final UUID gameId;
|
||||
private final UUID chatId;
|
||||
private final GameView game;
|
||||
|
||||
public WatchGameCallback(UUID gameId, UUID chatId, GameView game) {
|
||||
this.gameId = gameId;
|
||||
this.chatId = chatId;
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(ClientMessageHandler handler) {
|
||||
handler.getClient().watchGame(gameId, chatId, game);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.mage.network.messages.requests;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.UUID;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class StopWatchingRequest extends ServerRequest {
|
||||
private final UUID gameId;
|
||||
|
||||
public StopWatchingRequest(UUID gameId) {
|
||||
this.gameId = gameId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
server.stopWatching(gameId, getSessionId(ctx));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
//package org.mage.network.messages.requests;
|
||||
//
|
||||
//import io.netty.channel.ChannelHandlerContext;
|
||||
//import java.util.UUID;
|
||||
//import org.mage.network.handlers.WriteListener;
|
||||
//import org.mage.network.interfaces.MageServer;
|
||||
//import org.mage.network.messages.responses.UUIDResponse;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author BetaSteward
|
||||
// */
|
||||
//public class WatchGameRequest extends ServerRequest {
|
||||
// private final UUID gameId;
|
||||
//
|
||||
// public WatchGameRequest(UUID gameId) {
|
||||
// this.gameId = gameId;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
// ctx.writeAndFlush(new UUIDResponse(server.watchGame(gameId, getSessionId(ctx)))).addListener(WriteListener.getInstance());
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package org.mage.network.messages.requests;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.UUID;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class WatchTableRequest extends ServerRequest {
|
||||
private final UUID roomId;
|
||||
private final UUID tableId;
|
||||
|
||||
public WatchTableRequest(UUID roomId, UUID tableId) {
|
||||
this.roomId = roomId;
|
||||
this.tableId = tableId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
server.watchTable(getSessionId(ctx), roomId, tableId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.mage.network.messages.requests;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import java.util.UUID;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class WatchTournamentTableRequest extends ServerRequest {
|
||||
private final UUID tableId;
|
||||
|
||||
public WatchTournamentTableRequest(UUID tableId) {
|
||||
this.tableId = tableId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(MageServer server, ChannelHandlerContext ctx) {
|
||||
server.watchTournamentTable(getSessionId(ctx), tableId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -703,55 +703,30 @@ public class ServerMain implements MageServer {
|
|||
GameManager.getInstance().sendPlayerAction(playerAction, gameId, session.getUserId(), data);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean watchTable(final String sessionId, final UUID roomId, final UUID tableId) throws MageException {
|
||||
// return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
// @Override
|
||||
// public Boolean execute() throws MageException {
|
||||
// UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
// return GamesRoomManager.getInstance().getRoom(roomId).watchTable(userId, tableId);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean watchTournamentTable(final String sessionId, final UUID tableId) throws MageException {
|
||||
// return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
|
||||
// @Override
|
||||
// public Boolean execute() throws MageException {
|
||||
// UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
// return TableManager.getInstance().watchTable(userId, tableId);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void watchGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
// execute("watchGame", sessionId, new Action() {
|
||||
// @Override
|
||||
// public void execute() {
|
||||
// UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
// GameManager.getInstance().watchGame(gameId, userId);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void stopWatching(final UUID gameId, final String sessionId) throws MageException {
|
||||
// execute("stopWatching", sessionId, new Action() {
|
||||
// @Override
|
||||
// public void execute() {
|
||||
// UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
// User user = UserManager.getInstance().getUser(userId);
|
||||
// if (user != null) {
|
||||
// GameManager.getInstance().stopWatching(gameId, userId);
|
||||
// user.removeGameWatchInfo(gameId);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//
|
||||
@Override
|
||||
public void watchTable(final String sessionId, final UUID roomId, final UUID tableId) {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
GamesRoomManager.getInstance().getRoom(roomId).watchTable(userId, tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watchTournamentTable(final String sessionId, final UUID tableId) {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
TableManager.getInstance().watchTable(userId, tableId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void stopWatching(final UUID gameId, final String sessionId) {
|
||||
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
GameManager.getInstance().stopWatching(gameId, userId);
|
||||
user.removeGameWatchInfo(gameId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void replayGame(final UUID gameId, final String sessionId) throws MageException {
|
||||
// execute("replayGame", sessionId, new Action() {
|
||||
|
|
@ -1244,24 +1219,12 @@ public class ServerMain implements MageServer {
|
|||
server.showTournament(sessionId, tournamentId);
|
||||
}
|
||||
|
||||
// public void tournamentInit(String sessionId, UUID tournamentId, TournamentView tournamentView) {
|
||||
// server.tournamentInit(sessionId, tournamentId, tournamentView);
|
||||
// }
|
||||
|
||||
// public void tournamentUpdate(String sessionId, UUID tournamentId, TournamentView tournamentView) {
|
||||
// server.tournamentUpdate(sessionId, tournamentId, tournamentView);
|
||||
// }
|
||||
//
|
||||
// public void tournamentOver(String sessionId, UUID tournamentId) {
|
||||
// server.tournamentOver(sessionId, tournamentId);
|
||||
// }
|
||||
|
||||
public void showGameEndDialog(String sessionId, UUID gameId) {
|
||||
server.showGameEndDialog(sessionId, gameId);
|
||||
}
|
||||
|
||||
public void watchGame(String sessionId, UUID gameId) {
|
||||
server.watchGame(sessionId, gameId);
|
||||
public void watchGame(String sessionId, UUID gameId, UUID chatId, GameView game) {
|
||||
server.watchGame(sessionId, gameId, chatId, game);
|
||||
}
|
||||
|
||||
public void replayGame(String sessionId, UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -434,22 +434,21 @@ public class TableController {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID userId) {
|
||||
public void watchTable(UUID userId) {
|
||||
if (table.isTournament()) {
|
||||
UserManager.getInstance().getUser(userId).showTournament(table.getTournament().getId());
|
||||
return true;
|
||||
} else {
|
||||
if (table.isTournamentSubTable() && !table.getTournament().getOptions().isWatchingAllowed()) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (table.getState() != TableState.DUELING) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
// you can't watch your own game
|
||||
if (userPlayerMap.get(userId) != null) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
return UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
|
||||
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId(), getChatId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -270,11 +270,10 @@ public class TableManager {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean watchTable(UUID userId, UUID tableId) {
|
||||
public void watchTable(UUID userId, UUID tableId) {
|
||||
if (controllers.containsKey(tableId)) {
|
||||
return controllers.get(tableId).watchTable(userId);
|
||||
controllers.get(tableId).watchTable(userId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// public boolean replayTable(UUID userId, UUID tableId) {
|
||||
|
|
|
|||
|
|
@ -330,9 +330,10 @@ public class User {
|
|||
ServerMain.getInstance().informClient(sessionId, title, message, MessageType.ERROR);
|
||||
}
|
||||
|
||||
public boolean watchGame(final UUID gameId) {
|
||||
ServerMain.getInstance().watchGame(sessionId, gameId);
|
||||
return true;
|
||||
public void watchGame(final UUID gameId, UUID chatId) {
|
||||
GameView game = GameManager.getInstance().watchGame(gameId, userId);
|
||||
if (game != null)
|
||||
ServerMain.getInstance().watchGame(sessionId, gameId, chatId, game);
|
||||
}
|
||||
|
||||
public void replayGame(final UUID gameId) {
|
||||
|
|
|
|||
|
|
@ -433,14 +433,14 @@ public class GameController implements GameCallback {
|
|||
return true;
|
||||
}
|
||||
|
||||
public void watch(UUID userId) {
|
||||
public GameView watch(UUID userId) {
|
||||
if (userPlayerMap.get(userId) != null) {
|
||||
// You can't watch a game if you already a player in it
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
if (watchers.get(userId) != null) {
|
||||
// You can't watch a game if you already watch it
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
|
|
@ -449,7 +449,9 @@ public class GameController implements GameCallback {
|
|||
gameWatcher.init();
|
||||
user.addGameWatchInfo(game.getId());
|
||||
ChatManager.getInstance().broadcast(chatId, user, " has started watching", MessageColor.BLUE, true, ChatMessage.MessageType.STATUS);
|
||||
return watchers.get(userId).getGameView();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void stopWatching(UUID userId) {
|
||||
|
|
|
|||
|
|
@ -122,11 +122,12 @@ public class GameManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void watchGame(UUID gameId, UUID userId) {
|
||||
public GameView watchGame(UUID gameId, UUID userId) {
|
||||
GameController gameController = gameControllers.get(gameId);
|
||||
if (gameController != null) {
|
||||
gameController.watch(userId);
|
||||
return gameController.watch(userId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void stopWatching(UUID gameId, UUID userId) {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@
|
|||
package mage.server.game;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
|
|
@ -51,7 +50,7 @@ public interface GamesRoom extends Room {
|
|||
void removeTable(UUID tableId);
|
||||
TableView getTable(UUID tableId);
|
||||
void leaveTable(UUID userId, UUID tableId);
|
||||
boolean watchTable(UUID userId, UUID tableId) throws MageException;
|
||||
void watchTable(UUID userId, UUID tableId);
|
||||
|
||||
public RoomView getRoomView();
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import mage.MageException;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.constants.TableState;
|
||||
import mage.game.Table;
|
||||
|
|
@ -200,8 +199,8 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean watchTable(UUID userId, UUID tableId) throws MageException {
|
||||
return TableManager.getInstance().watchTable(userId, tableId);
|
||||
public void watchTable(UUID userId, UUID tableId) {
|
||||
TableManager.getInstance().watchTable(userId, tableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue