mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 04:22:01 -08:00
completed Room handling
This commit is contained in:
parent
e7bb3a0dbf
commit
bc51a8fc79
13 changed files with 357 additions and 147 deletions
|
|
@ -370,8 +370,8 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
private final String[] columnNames = new String[]{"Players", "Info", "Games", "Connection"};
|
||||
private UsersView[] players = new UsersView[0];
|
||||
|
||||
public void loadData(Collection<RoomUsersView> roomUserInfoList) throws MageRemoteException {
|
||||
RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
|
||||
public void loadData(RoomUsersView roomUserInfo) throws MageRemoteException {
|
||||
// RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
|
||||
this.players = roomUserInfo.getUsersView().toArray(new UsersView[0]);
|
||||
JTableHeader th = jTablePlayers.getTableHeader();
|
||||
TableColumnModel tcm = th.getColumnModel();
|
||||
|
|
@ -535,9 +535,9 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
}
|
||||
}//GEN-LAST:event_txtMessageKeyTyped
|
||||
|
||||
public void setRoomUserInfo(List<Collection<RoomUsersView>> view) {
|
||||
public void setRoomUserInfo(RoomUsersView view) {
|
||||
try {
|
||||
tableModel.loadData(view.get(0));
|
||||
tableModel.loadData(view);
|
||||
} catch (Exception ex) {
|
||||
this.players.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ import mage.remote.MageRemoteException;
|
|||
//import mage.remote.Session;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.RoomView;
|
||||
import mage.view.TableView;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.card.arcane.Util;
|
||||
|
|
@ -107,9 +108,9 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
private TableTableModel tableModel;
|
||||
private MatchesTableModel matchesModel;
|
||||
private UUID roomId;
|
||||
private UpdateTablesTask updateTablesTask;
|
||||
private UpdatePlayersTask updatePlayersTask;
|
||||
private UpdateMatchesTask updateMatchesTask;
|
||||
private UpdateRoomTask updateRoomTask;
|
||||
// private UpdatePlayersTask updatePlayersTask;
|
||||
// private UpdateMatchesTask updateMatchesTask;
|
||||
private JoinTableDialog joinTableDialog;
|
||||
private NewTableDialog newTableDialog;
|
||||
private NewTournamentDialog newTournamentDialog;
|
||||
|
|
@ -389,38 +390,38 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
|
||||
public void startTasks() {
|
||||
if (client != null) {
|
||||
if (updateTablesTask == null || updateTablesTask.isDone()) {
|
||||
updateTablesTask = new UpdateTablesTask(client, roomId, this);
|
||||
updateTablesTask.execute();
|
||||
}
|
||||
if (updatePlayersTask == null || updatePlayersTask.isDone()) {
|
||||
updatePlayersTask = new UpdatePlayersTask(client, roomId, this.chatPanel);
|
||||
updatePlayersTask.execute();
|
||||
}
|
||||
if (this.btnStateFinished.isSelected()) {
|
||||
if (updateMatchesTask == null || updateMatchesTask.isDone()) {
|
||||
updateMatchesTask = new UpdateMatchesTask(client, roomId, this);
|
||||
updateMatchesTask.execute();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (updateMatchesTask != null) {
|
||||
updateMatchesTask.cancel(true);
|
||||
}
|
||||
if (updateRoomTask == null || updateRoomTask.isDone()) {
|
||||
updateRoomTask = new UpdateRoomTask(client, roomId, this, this.chatPanel);
|
||||
updateRoomTask.execute();
|
||||
}
|
||||
// if (updatePlayersTask == null || updatePlayersTask.isDone()) {
|
||||
// updatePlayersTask = new UpdatePlayersTask(client, roomId, this.chatPanel);
|
||||
// updatePlayersTask.execute();
|
||||
// }
|
||||
// if (this.btnStateFinished.isSelected()) {
|
||||
// if (updateMatchesTask == null || updateMatchesTask.isDone()) {
|
||||
// updateMatchesTask = new UpdateMatchesTask(client, roomId, this);
|
||||
// updateMatchesTask.execute();
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (updateMatchesTask != null) {
|
||||
// updateMatchesTask.cancel(true);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTasks() {
|
||||
if (updateTablesTask != null) {
|
||||
updateTablesTask.cancel(true);
|
||||
}
|
||||
if (updatePlayersTask != null) {
|
||||
updatePlayersTask.cancel(true);
|
||||
}
|
||||
if (updateMatchesTask != null) {
|
||||
updateMatchesTask.cancel(true);
|
||||
if (updateRoomTask != null) {
|
||||
updateRoomTask.cancel(true);
|
||||
}
|
||||
// if (updatePlayersTask != null) {
|
||||
// updatePlayersTask.cancel(true);
|
||||
// }
|
||||
// if (updateMatchesTask != null) {
|
||||
// updateMatchesTask.cancel(true);
|
||||
// }
|
||||
}
|
||||
|
||||
public void showTables(UUID roomId) {
|
||||
|
|
@ -1402,28 +1403,30 @@ class TableTableModel extends AbstractTableModel {
|
|||
|
||||
}
|
||||
|
||||
class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
||||
class UpdateRoomTask extends SwingWorker<Void, RoomView> {
|
||||
|
||||
private final Client client;
|
||||
private final UUID roomId;
|
||||
private final TablesPanel panel;
|
||||
private final ChatPanel chat;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||
private static final Logger logger = Logger.getLogger(UpdateRoomTask.class);
|
||||
|
||||
private int count = 0;
|
||||
|
||||
UpdateTablesTask(Client client, UUID roomId, TablesPanel panel) {
|
||||
UpdateRoomTask(Client client, UUID roomId, TablesPanel panel, ChatPanel chat) {
|
||||
this.client = client;
|
||||
this.roomId = roomId;
|
||||
this.panel = panel;
|
||||
this.chat = chat;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
Collection<TableView> tables = client.getTables(roomId);
|
||||
if (tables != null) {
|
||||
this.publish(tables);
|
||||
RoomView room = client.getRoom(roomId);
|
||||
if (room != null) {
|
||||
this.publish(room);
|
||||
}
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
|
|
@ -1431,8 +1434,10 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<Collection<TableView>> view) {
|
||||
panel.updateTables(view.get(0));
|
||||
protected void process(List<RoomView> view) {
|
||||
panel.updateTables(view.get(0).getTableViews());
|
||||
panel.updateMatches(view.get(0).getMatchViews());
|
||||
chat.setRoomUserInfo(view.get(0).getRoomUsersView());
|
||||
count++;
|
||||
if (count > 60) {
|
||||
count = 0;
|
||||
|
|
@ -1451,44 +1456,44 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
|||
|
||||
}
|
||||
|
||||
class UpdatePlayersTask extends SwingWorker<Void, Collection<RoomUsersView>> {
|
||||
|
||||
private final Client client;
|
||||
private final UUID roomId;
|
||||
private final ChatPanel chat;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdatePlayersTask.class);
|
||||
|
||||
UpdatePlayersTask(Client client, UUID roomId, ChatPanel chat) {
|
||||
this.client = client;
|
||||
this.roomId = roomId;
|
||||
this.chat = chat;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
this.publish(client.getRoomUsers(roomId));
|
||||
Thread.sleep(3000);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<Collection<RoomUsersView>> roomUserInfo) {
|
||||
chat.setRoomUserInfo(roomUserInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
logger.fatal("Update Players Task error", ex);
|
||||
} catch (CancellationException ex) {}
|
||||
}
|
||||
|
||||
}
|
||||
//class UpdatePlayersTask extends SwingWorker<Void, Collection<RoomUsersView>> {
|
||||
//
|
||||
// private final Client client;
|
||||
// private final UUID roomId;
|
||||
// private final ChatPanel chat;
|
||||
//
|
||||
// private static final Logger logger = Logger.getLogger(UpdatePlayersTask.class);
|
||||
//
|
||||
// UpdatePlayersTask(Client client, UUID roomId, ChatPanel chat) {
|
||||
// this.client = client;
|
||||
// this.roomId = roomId;
|
||||
// this.chat = chat;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground() throws Exception {
|
||||
// while (!isCancelled()) {
|
||||
// this.publish(client.getRoomUsers(roomId));
|
||||
// Thread.sleep(3000);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void process(List<Collection<RoomUsersView>> roomUserInfo) {
|
||||
// chat.setRoomUserInfo(roomUserInfo);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void done() {
|
||||
// try {
|
||||
// get();
|
||||
// } catch (InterruptedException | ExecutionException ex) {
|
||||
// logger.fatal("Update Players Task error", ex);
|
||||
// } catch (CancellationException ex) {}
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
class MatchesTableModel extends AbstractTableModel {
|
||||
|
||||
|
|
@ -1592,47 +1597,47 @@ class MatchesTableModel extends AbstractTableModel {
|
|||
|
||||
}
|
||||
|
||||
class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||
|
||||
private final Client client;
|
||||
private final UUID roomId;
|
||||
private final TablesPanel panel;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||
|
||||
UpdateMatchesTask(Client client, UUID roomId, TablesPanel panel) {
|
||||
this.client = client;
|
||||
this.roomId = roomId;
|
||||
this.panel = panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
while (!isCancelled()) {
|
||||
Collection<MatchView> matches = client.getFinishedMatches(roomId);
|
||||
if (matches != null) {
|
||||
this.publish(matches);
|
||||
}
|
||||
Thread.sleep(10000);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<Collection<MatchView>> view) {
|
||||
panel.updateMatches(view.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
get();
|
||||
} catch (InterruptedException | ExecutionException ex) {
|
||||
logger.fatal("Update Matches Task error", ex);
|
||||
} catch (CancellationException ex) {}
|
||||
}
|
||||
|
||||
}
|
||||
//class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||
//
|
||||
// private final Client client;
|
||||
// private final UUID roomId;
|
||||
// private final TablesPanel panel;
|
||||
//
|
||||
// private static final Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||
//
|
||||
// UpdateMatchesTask(Client client, UUID roomId, TablesPanel panel) {
|
||||
// this.client = client;
|
||||
// this.roomId = roomId;
|
||||
// this.panel = panel;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Void doInBackground() throws Exception {
|
||||
// while (!isCancelled()) {
|
||||
// Collection<MatchView> matches = client.getFinishedMatches(roomId);
|
||||
// if (matches != null) {
|
||||
// this.publish(matches);
|
||||
// }
|
||||
// Thread.sleep(10000);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void process(List<Collection<MatchView>> view) {
|
||||
// panel.updateMatches(view.get(0));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void done() {
|
||||
// try {
|
||||
// get();
|
||||
// } catch (InterruptedException | ExecutionException ex) {
|
||||
// logger.fatal("Update Matches Task error", ex);
|
||||
// } catch (CancellationException ex) {}
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
class GameChooser extends JPopupMenu {
|
||||
|
||||
|
|
|
|||
65
Mage.Common/src/mage/view/RoomView.java
Normal file
65
Mage.Common/src/mage/view/RoomView.java
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.view;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class RoomView implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final RoomUsersView roomUsersView;
|
||||
private final List<MatchView> matchViews;
|
||||
private final List<TableView> tableViews;
|
||||
|
||||
public RoomView(RoomUsersView roomUsersView, List<TableView> tableViews, List<MatchView> matchViews) {
|
||||
|
||||
this.roomUsersView = roomUsersView;
|
||||
this.matchViews = matchViews;
|
||||
this.tableViews = tableViews;
|
||||
|
||||
}
|
||||
|
||||
public RoomUsersView getRoomUsersView() {
|
||||
return roomUsersView;
|
||||
}
|
||||
|
||||
public List<MatchView> getMatchViews() {
|
||||
return matchViews;
|
||||
}
|
||||
|
||||
public List<TableView> getTableViews() {
|
||||
return tableViews;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ import mage.utils.MageVersion;
|
|||
import mage.view.DraftPickView;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.RoomView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserView;
|
||||
|
|
@ -40,6 +41,7 @@ import org.mage.network.handlers.client.ChatRoomHandler;
|
|||
import org.mage.network.handlers.client.ClientRegisteredMessageHandler;
|
||||
import org.mage.network.handlers.client.InformClientMessageHandler;
|
||||
import org.mage.network.handlers.client.ServerMessageHandler;
|
||||
import org.mage.network.handlers.client.RoomMessageHandler;
|
||||
import org.mage.network.interfaces.MageClient;
|
||||
import org.mage.network.model.MessageType;
|
||||
|
||||
|
|
@ -61,6 +63,7 @@ public class Client {
|
|||
private final InformClientMessageHandler informClientMessageHandler;
|
||||
private final ClientRegisteredMessageHandler clientRegisteredMessageHandler;
|
||||
private final ServerMessageHandler serverMessageHandler;
|
||||
private final RoomMessageHandler roomMessageHandler;
|
||||
|
||||
private SslContext sslCtx;
|
||||
private Channel channel;
|
||||
|
|
@ -77,6 +80,7 @@ public class Client {
|
|||
informClientMessageHandler = new InformClientMessageHandler(client);
|
||||
clientRegisteredMessageHandler = new ClientRegisteredMessageHandler(client);
|
||||
serverMessageHandler = new ServerMessageHandler();
|
||||
roomMessageHandler = new RoomMessageHandler();
|
||||
}
|
||||
|
||||
public boolean connect(String userName, String host, int port, boolean ssl, MageVersion version) {
|
||||
|
|
@ -132,6 +136,7 @@ public class Client {
|
|||
ch.pipeline().addLast("clientRegisteredMessageHandler", clientRegisteredMessageHandler);
|
||||
ch.pipeline().addLast("chatRoomHandler", chatRoomHandler);
|
||||
ch.pipeline().addLast("serverMessageHandler", serverMessageHandler);
|
||||
ch.pipeline().addLast("tablesMessageHandler", roomMessageHandler);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -304,17 +309,22 @@ public class Client {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Collection<TableView> getTables(UUID roomId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
public RoomView getRoom(UUID roomId) {
|
||||
try {
|
||||
return roomMessageHandler.getRoom(roomId);
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error getting tables", ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Collection<MatchView> getFinishedMatches(UUID roomId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public Collection<RoomUsersView> getRoomUsers(UUID roomId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
// public Collection<MatchView> getFinishedMatches(UUID roomId) {
|
||||
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
// }
|
||||
//
|
||||
// public Collection<RoomUsersView> getRoomUsers(UUID roomId) {
|
||||
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
// }
|
||||
|
||||
public void sendPlayerInteger(UUID gameId, int i) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import org.mage.network.handlers.server.ConnectionHandler;
|
|||
import org.mage.network.handlers.server.JoinChatMessageHandler;
|
||||
import org.mage.network.handlers.server.LeaveChatMessageHandler;
|
||||
import org.mage.network.handlers.server.RegisterClientMessageHandler;
|
||||
import org.mage.network.handlers.server.RoomMessageHandler;
|
||||
import org.mage.network.handlers.server.ServerMessageHandler;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
import org.mage.network.model.InformClientMessage;
|
||||
|
|
@ -62,6 +63,7 @@ public class Server {
|
|||
private final JoinChatMessageHandler joinChatMessageHandler;
|
||||
private final LeaveChatMessageHandler leaveChatMessageHandler;
|
||||
private final ServerMessageHandler serverMessageHandler;
|
||||
private final RoomMessageHandler roomMessageHandler;
|
||||
|
||||
public Server(MageServer server) {
|
||||
heartbeatHandler = new HeartbeatHandler(server);
|
||||
|
|
@ -71,6 +73,7 @@ public class Server {
|
|||
leaveChatMessageHandler = new LeaveChatMessageHandler(server);
|
||||
chatRoomIdHandler = new ChatRoomIdHandler(server);
|
||||
serverMessageHandler = new ServerMessageHandler(server);
|
||||
roomMessageHandler = new RoomMessageHandler(server);
|
||||
}
|
||||
|
||||
public void start(int port, boolean ssl) throws Exception {
|
||||
|
|
@ -125,6 +128,7 @@ public class Server {
|
|||
ch.pipeline().addLast(handlersExecutor, joinChatMessageHandler);
|
||||
ch.pipeline().addLast(handlersExecutor, leaveChatMessageHandler);
|
||||
ch.pipeline().addLast(handlersExecutor, serverMessageHandler);
|
||||
ch.pipeline().addLast(handlersExecutor, roomMessageHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package org.mage.network.handlers.client;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import mage.view.RoomView;
|
||||
import org.mage.network.model.RoomMessage;
|
||||
import org.mage.network.model.RoomRequest;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class RoomMessageHandler extends SimpleChannelInboundHandler<RoomMessage> {
|
||||
|
||||
private ChannelHandlerContext ctx;
|
||||
private final BlockingQueue<RoomView> queue = new LinkedBlockingQueue<>();
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
this.ctx = ctx;
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void messageReceived(ChannelHandlerContext ctx, RoomMessage msg) throws Exception {
|
||||
queue.offer(msg.getRoom());
|
||||
}
|
||||
|
||||
public RoomView getRoom(UUID roomId) throws Exception {
|
||||
ctx.writeAndFlush(new RoomRequest(roomId));
|
||||
return queue.take();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
package org.mage.network.handlers.server;
|
||||
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
import org.mage.network.model.ServerMessagesMessage;
|
||||
import org.mage.network.model.ServerMessagesRequest;
|
||||
import org.mage.network.model.RoomMessage;
|
||||
import org.mage.network.model.RoomRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
@Sharable
|
||||
public class RoomMessageHandler extends SimpleChannelInboundHandler<RoomRequest> {
|
||||
|
||||
private final MageServer server;
|
||||
|
||||
public RoomMessageHandler (MageServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageReceived(ChannelHandlerContext ctx, RoomRequest msg) {
|
||||
ctx.writeAndFlush(new RoomMessage(server.getRoom(msg.getRoomId())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelReadComplete(ChannelHandlerContext ctx) {
|
||||
ctx.flush();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
cause.printStackTrace();
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import java.util.UUID;
|
|||
import mage.interfaces.ServerState;
|
||||
import mage.remote.DisconnectReason;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.RoomView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -23,6 +24,7 @@ public interface MageServer {
|
|||
|
||||
ServerState getServerState();
|
||||
|
||||
public List<String> getServerMessages();
|
||||
List<String> getServerMessages();
|
||||
RoomView getRoom(UUID roomId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.view.RoomView;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class RoomMessage implements Serializable {
|
||||
|
||||
private RoomView room;
|
||||
|
||||
public RoomMessage(RoomView room) {
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
public RoomView getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class RoomRequest implements Serializable {
|
||||
|
||||
private UUID roomId;
|
||||
|
||||
public RoomRequest(UUID roomId) {
|
||||
this.roomId = roomId;
|
||||
}
|
||||
|
||||
public UUID getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -94,6 +94,7 @@ import mage.view.DraftPickView;
|
|||
import mage.view.GameView;
|
||||
import mage.view.MatchView;
|
||||
import mage.view.RoomUsersView;
|
||||
import mage.view.RoomView;
|
||||
import mage.view.TableView;
|
||||
import mage.view.TournamentView;
|
||||
import mage.view.UserDataView;
|
||||
|
|
@ -419,22 +420,22 @@ public class Main implements MageServer {
|
|||
// });
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// //FIXME: why no sessionId here???
|
||||
// public List<TableView> getTables(UUID roomId) throws MageException {
|
||||
@Override
|
||||
//FIXME: why no sessionId here???
|
||||
public RoomView getRoom(UUID roomId) {
|
||||
// try {
|
||||
// GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
// if (room != null) {
|
||||
// return room.getTables();
|
||||
// } else {
|
||||
// return null;
|
||||
// }
|
||||
GamesRoom room = GamesRoomManager.getInstance().getRoom(roomId);
|
||||
if (room != null) {
|
||||
return new RoomView(room.getRoomUsersInfo(), room.getTables(), room.getFinished());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
// }
|
||||
// catch (Exception ex) {
|
||||
// handleException(ex);
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
//
|
||||
// @Override
|
||||
// //FIXME: why no sessionId here???
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ public interface GamesRoom extends Room {
|
|||
|
||||
List<TableView> getTables();
|
||||
List<MatchView> getFinished();
|
||||
List<RoomUsersView> getRoomUsersInfo();
|
||||
RoomUsersView getRoomUsersInfo();
|
||||
boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws MageException;
|
||||
boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList, String password) throws GameException;
|
||||
TableView createTable(UUID userId, MatchOptions options);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
private static final ScheduledExecutorService updateExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||
private static List<TableView> tableView = new ArrayList<>();
|
||||
private static List<MatchView> matchView = new ArrayList<>();
|
||||
private static List<RoomUsersView> roomUsersView = new ArrayList<>();
|
||||
private static RoomUsersView roomUsersView;
|
||||
|
||||
private final ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<>();
|
||||
|
||||
|
|
@ -128,13 +128,13 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
Collections.sort(users, new UserNameSorter());
|
||||
List<RoomUsersView> roomUserInfo = new ArrayList<>();
|
||||
roomUserInfo.add(new RoomUsersView(users,
|
||||
// List<RoomUsersView> roomUserInfo = new ArrayList<>();
|
||||
roomUsersView = new RoomUsersView(users,
|
||||
GameManager.getInstance().getNumberActiveGames(),
|
||||
ThreadExecutor.getInstance().getActiveThreads(ThreadExecutor.getInstance().getGameExecutor()),
|
||||
ConfigSettings.getInstance().getMaxGameThreads()
|
||||
));
|
||||
roomUsersView = roomUserInfo;
|
||||
);
|
||||
// roomUsersView = roomUserInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -210,7 +210,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<RoomUsersView> getRoomUsersInfo() {
|
||||
public RoomUsersView getRoomUsersInfo() {
|
||||
return roomUsersView;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue