mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 04:22:01 -08:00
fixed some merge issues + added additional connection properties
This commit is contained in:
parent
38da157f8c
commit
864a318b3f
21 changed files with 241 additions and 1630 deletions
|
|
@ -738,7 +738,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
|
||||
public boolean connect(Connection connection) {
|
||||
client = new Client(instance);
|
||||
boolean result = client.connect(connection.getUsername(), connection.getHost(), connection.getPort(), true, version);
|
||||
boolean result = client.connect(connection, version);
|
||||
if (result) {
|
||||
updateDatabase(connection.isForceDBComparison(), serverState);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -328,6 +328,7 @@ public class ConnectDialog extends MageDialog {
|
|||
connection = new Connection();
|
||||
connection.setHost(this.txtServer.getText().trim());
|
||||
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
||||
connection.setSSL(true);
|
||||
connection.setUsername(this.txtUserName.getText().trim());
|
||||
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected());
|
||||
MageFrame.getPreferences().put(KEY_CONNECT_FLAG, ((CountryItemEditor)cbFlag.getEditor()).getImageItem());
|
||||
|
|
|
|||
|
|
@ -178,8 +178,8 @@ public class UserRequestDialog extends MageDialog {
|
|||
|
||||
private void sendUserReplay(PlayerAction playerAction) {
|
||||
Client client = MageFrame.getClient();
|
||||
if (session != null && playerAction != null) {
|
||||
session.sendPlayerAction(playerAction, userRequestMessage.getGameId(), userRequestMessage.getRelatedUserId());
|
||||
if (client != null && playerAction != null) {
|
||||
client.sendPlayerAction(playerAction, userRequestMessage.getGameId(), userRequestMessage.getRelatedUserId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,23 +152,23 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
break;
|
||||
}
|
||||
case "F3": {
|
||||
gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId, null);
|
||||
gamePanel.getClient().sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId, null);
|
||||
break;
|
||||
}
|
||||
case "F4": {
|
||||
gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId, null);
|
||||
gamePanel.getClient().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId, null);
|
||||
break;
|
||||
}
|
||||
case "F5": {
|
||||
gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_TURN_END_STEP, gameId, null);
|
||||
gamePanel.getClient().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_TURN_END_STEP, gameId, null);
|
||||
break;
|
||||
}
|
||||
case "F7": {
|
||||
gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE, gameId, null);
|
||||
gamePanel.getClient().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE, gameId, null);
|
||||
break;
|
||||
}
|
||||
case "F9": {
|
||||
gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId, null);
|
||||
gamePanel.getClient().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId, null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -241,7 +241,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
boolean manaPoolAutomatic = ((JCheckBoxMenuItem)e.getSource()).getState();
|
||||
PreferencesDialog.saveValue(KEY_GAME_MANA_AUTOPAYMENT, manaPoolAutomatic ? "true": "false");
|
||||
gamePanel.setMenuStates(manaPoolAutomatic, manaPoolMenuItem2.getState());
|
||||
gamePanel.getSession().sendPlayerAction(manaPoolAutomatic ? PlayerAction.MANA_AUTO_PAYMENT_ON: PlayerAction.MANA_AUTO_PAYMENT_OFF, gameId, null);
|
||||
gamePanel.getClient().sendPlayerAction(manaPoolAutomatic ? PlayerAction.MANA_AUTO_PAYMENT_ON: PlayerAction.MANA_AUTO_PAYMENT_OFF, gameId, null);
|
||||
}
|
||||
});
|
||||
manaPoolMenuItem2 = new JCheckBoxMenuItem("No automatic usage for mana already in the pool", true);
|
||||
|
|
@ -258,7 +258,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
boolean manaPoolAutomaticRestricted = ((JCheckBoxMenuItem)e.getSource()).getState();
|
||||
PreferencesDialog.saveValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, manaPoolAutomaticRestricted ? "true": "false");
|
||||
gamePanel.setMenuStates(manaPoolMenuItem1.getState(), manaPoolAutomaticRestricted);
|
||||
gamePanel.getSession().sendPlayerAction(manaPoolAutomaticRestricted ? PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_ON: PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_OFF, gameId, null);
|
||||
gamePanel.getClient().sendPlayerAction(manaPoolAutomaticRestricted ? PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_ON: PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_OFF, gameId, null);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -329,7 +329,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int turnsToRollBack = Integer.parseInt(e.getActionCommand());
|
||||
gamePanel.getSession().sendPlayerAction(PlayerAction.ROLLBACK_TURNS, gameId, turnsToRollBack);
|
||||
gamePanel.getClient().sendPlayerAction(PlayerAction.ROLLBACK_TURNS, gameId, turnsToRollBack);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -376,13 +376,13 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
switch (e.getActionCommand()) {
|
||||
case "Game": {
|
||||
if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to concede the game?", "Confirm concede game", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
MageFrame.getSession().sendPlayerAction(PlayerAction.CONCEDE, gameId, null);
|
||||
MageFrame.getClient().sendPlayerAction(PlayerAction.CONCEDE, gameId, null);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "Match": {
|
||||
if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to concede the complete match?", "Confirm concede match", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
MageFrame.getSession().quitMatch(gameId);
|
||||
MageFrame.getClient().quitMatch(gameId);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,9 +59,10 @@ public class MultiConnectTest {
|
|||
connection.setUsername(username);
|
||||
connection.setHost("localhost");
|
||||
connection.setPort(17171);
|
||||
connection.setSSL(true);
|
||||
connection.setProxyType(Connection.ProxyType.NONE);
|
||||
|
||||
client.connect(username, "localhost", 17171, true, version);
|
||||
client.connect(connection, version);
|
||||
}
|
||||
|
||||
public MageVersion getVersion() {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
package mage.remote;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InterfaceAddress;
|
||||
|
|
@ -40,10 +41,11 @@ import mage.players.net.UserSkipPrioritySteps;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Connection {
|
||||
public class Connection implements Serializable {
|
||||
|
||||
private String host;
|
||||
private int port;
|
||||
private boolean ssl;
|
||||
private String username;
|
||||
private String password;
|
||||
private ProxyType proxyType;
|
||||
|
|
@ -61,51 +63,51 @@ public class Connection {
|
|||
private String flagName;
|
||||
private UserSkipPrioritySteps userSkipPrioritySteps;
|
||||
|
||||
private static final String serialization = "?serializationtype=jboss";
|
||||
private static final String transport = "bisocket";
|
||||
// private static final String serialization = "?serializationtype=jboss";
|
||||
// private static final String transport = "bisocket";
|
||||
|
||||
private final String parameter;
|
||||
// private final String parameter;
|
||||
|
||||
public Connection() {
|
||||
this("");
|
||||
}
|
||||
// public Connection() {
|
||||
// this("");
|
||||
// }
|
||||
//
|
||||
// public Connection(String parameter) {
|
||||
// this.parameter = parameter;
|
||||
// }
|
||||
|
||||
public Connection(String parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (transport + host + Integer.toString(port) + proxyType.toString()).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (! (object instanceof Connection)) {
|
||||
return false;
|
||||
}
|
||||
Connection otherConnection = (Connection) object;
|
||||
return hashCode() == otherConnection.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return host + ":" + Integer.toString(port) + "/" + serialization + parameter;
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
if (host.equals("localhost")) {
|
||||
try {
|
||||
InetAddress inet = getLocalAddress();
|
||||
if (inet != null) {
|
||||
return transport + "://" + inet.getHostAddress() + ":" + port + "/" + serialization + parameter;
|
||||
}
|
||||
} catch (SocketException ex) {
|
||||
// just use localhost if can't find local ip
|
||||
}
|
||||
}
|
||||
return transport + "://" + host + ":" + port + "/" + serialization + parameter;
|
||||
}
|
||||
// @Override
|
||||
// public int hashCode() {
|
||||
// return (transport + host + Integer.toString(port) + proxyType.toString()).hashCode();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean equals(Object object) {
|
||||
// if (! (object instanceof Connection)) {
|
||||
// return false;
|
||||
// }
|
||||
// Connection otherConnection = (Connection) object;
|
||||
// return hashCode() == otherConnection.hashCode();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return host + ":" + Integer.toString(port) + "/" + serialization + parameter;
|
||||
// }
|
||||
//
|
||||
// public String getURI() {
|
||||
// if (host.equals("localhost")) {
|
||||
// try {
|
||||
// InetAddress inet = getLocalAddress();
|
||||
// if (inet != null) {
|
||||
// return transport + "://" + inet.getHostAddress() + ":" + port + "/" + serialization + parameter;
|
||||
// }
|
||||
// } catch (SocketException ex) {
|
||||
// // just use localhost if can't find local ip
|
||||
// }
|
||||
// }
|
||||
// return transport + "://" + host + ":" + port + "/" + serialization + parameter;
|
||||
// }
|
||||
|
||||
public ProxyType getProxyType() {
|
||||
return proxyType;
|
||||
|
|
@ -155,6 +157,14 @@ public class Connection {
|
|||
this.port = port;
|
||||
}
|
||||
|
||||
public boolean isSSL() {
|
||||
return this.ssl;
|
||||
}
|
||||
|
||||
public void setSSL(boolean ssl) {
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -24,6 +24,7 @@ import mage.game.match.MatchOptions;
|
|||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.players.net.UserSkipPrioritySteps;
|
||||
import mage.remote.Connection;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.DraftPickView;
|
||||
import mage.view.RoomView;
|
||||
|
|
@ -103,15 +104,15 @@ public class Client {
|
|||
exceptionHandler = new ExceptionHandler();
|
||||
}
|
||||
|
||||
public boolean connect(String userName, String host, int port, boolean ssl, MageVersion version) {
|
||||
public boolean connect(Connection connection, MageVersion version) {
|
||||
|
||||
this.username = userName;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.username = connection.getUsername();
|
||||
this.host = connection.getHost();
|
||||
this.port = connection.getPort();
|
||||
|
||||
group = new NioEventLoopGroup();
|
||||
try {
|
||||
if (ssl) {
|
||||
if (connection.isSSL()) {
|
||||
sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
|
||||
} else {
|
||||
sslCtx = null;
|
||||
|
|
@ -121,13 +122,13 @@ public class Client {
|
|||
.channel(NioSocketChannel.class)
|
||||
.handler(new ClientInitializer());
|
||||
|
||||
clientRegisteredMessageHandler.setUserName(userName);
|
||||
clientRegisteredMessageHandler.setConnection(connection);
|
||||
clientRegisteredMessageHandler.setVersion(version);
|
||||
channel = b.connect(host, port).sync().channel();
|
||||
ServerState state = clientRegisteredMessageHandler.registerClient();
|
||||
if (state.isValid()) {
|
||||
client.clientRegistered(state);
|
||||
client.connected(userName + "@" + host + ":" + port + " ");
|
||||
client.connected(connection.getUsername() + "@" + host + ":" + port + " ");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
|
@ -270,17 +271,17 @@ public class Client {
|
|||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public void updatePreferencesForServer(int selectedAvatar, boolean selected, boolean selected0, UserSkipPrioritySteps userSkipPrioritySteps) {
|
||||
public void updatePreferencesForServer(int avatarId, boolean showAbilityPickerForced, boolean allowRequestShowHandCards, boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps, String flagName) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
public boolean isTableOwner(UUID roomId, UUID tableId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
// public boolean isTableOwner(UUID roomId, UUID tableId) {
|
||||
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
// }
|
||||
|
||||
public UUID getTableChatId(UUID tableId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
// public UUID getTableChatId(UUID tableId) {
|
||||
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
// }
|
||||
|
||||
public boolean startMatch(UUID roomId, UUID tableId) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
|
|
@ -307,7 +308,7 @@ public class Client {
|
|||
}
|
||||
}
|
||||
|
||||
public void sendPlayerAction(PlayerAction playerAction, UUID gameId, UUID relatedUserId) {
|
||||
public void sendPlayerAction(PlayerAction passPriorityAction, UUID gameId, Object data) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.UUID;
|
|||
import mage.view.ChatMessage;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.network.handlers.ExceptionHandler;
|
||||
import org.mage.network.handlers.MessageHandler;
|
||||
import org.mage.network.handlers.server.HeartbeatHandler;
|
||||
import org.mage.network.handlers.PingMessageHandler;
|
||||
import org.mage.network.handlers.server.ChatMessageHandler;
|
||||
|
|
@ -56,6 +57,7 @@ public class Server {
|
|||
private SslContext sslCtx;
|
||||
|
||||
private final MageServer server;
|
||||
// private final MessageHandler h;
|
||||
private final PingMessageHandler pingMessageHandler = new PingMessageHandler();
|
||||
private final EventExecutorGroup handlersExecutor = new DefaultEventExecutorGroup(Runtime.getRuntime().availableProcessors() * 2);
|
||||
private final RegisterClientMessageHandler registerClientMessageHandler;
|
||||
|
|
@ -69,6 +71,7 @@ public class Server {
|
|||
|
||||
public Server(MageServer server) {
|
||||
this.server = server;
|
||||
// h = new MessageHandler();
|
||||
registerClientMessageHandler = new RegisterClientMessageHandler(server);
|
||||
chatMessageHandler = new ChatMessageHandler(server);
|
||||
serverMessageHandler = new ServerMessageHandler(server);
|
||||
|
|
@ -118,6 +121,7 @@ public class Server {
|
|||
ch.pipeline().addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
|
||||
ch.pipeline().addLast(new ObjectEncoder());
|
||||
|
||||
// ch.pipeline().addLast("h", h);
|
||||
ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(IDLE_TIMEOUT, IDLE_PING_TIME, 0));
|
||||
ch.pipeline().addLast(handlersExecutor, "heartbeatHandler", new HeartbeatHandler(server));
|
||||
ch.pipeline().addLast("pingMessageHandler", pingMessageHandler);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
package org.mage.network.handlers.client;
|
||||
package org.mage.network.handlers;
|
||||
|
||||
import io.netty.channel.ChannelHandler.Sharable;
|
||||
import io.netty.channel.ChannelHandlerAdapter;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
@Sharable
|
||||
public class MessageHandler extends ChannelHandlerAdapter {
|
||||
|
||||
@Override
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.mage.network.handlers;
|
||||
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class WriteListener implements ChannelFutureListener {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(WriteListener.class);
|
||||
|
||||
private static final WriteListener instance = new WriteListener();
|
||||
|
||||
public static WriteListener getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private WriteListener() { }
|
||||
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
if (!future.isSuccess()) {
|
||||
logger.error("Communication error", future.cause());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
package org.mage.network.handlers.client;
|
||||
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.remote.Connection;
|
||||
import mage.utils.MageVersion;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.network.model.ClientRegisteredMessage;
|
||||
import org.mage.network.model.RegisterClientMessage;
|
||||
import org.mage.network.model.RegisterClientRequest;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -15,13 +19,15 @@ import org.mage.network.model.RegisterClientMessage;
|
|||
*/
|
||||
public class ClientRegisteredMessageHandler extends SimpleChannelInboundHandler<ClientRegisteredMessage> {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ClientRegisteredMessageHandler.class);
|
||||
|
||||
private final BlockingQueue<ServerState> queue = new LinkedBlockingQueue<>();
|
||||
private String userName;
|
||||
private Connection connection;
|
||||
private MageVersion version;
|
||||
|
||||
@Override
|
||||
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||
ctx.writeAndFlush(new RegisterClientMessage(userName, version));
|
||||
ctx.writeAndFlush(new RegisterClientRequest(connection, version)).addListener(new ListenerImpl());
|
||||
super.channelActive(ctx);
|
||||
}
|
||||
|
||||
|
|
@ -30,8 +36,8 @@ public class ClientRegisteredMessageHandler extends SimpleChannelInboundHandler<
|
|||
queue.offer(msg.getServerState());
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
public void setConnection(Connection connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public void setVersion(MageVersion version) {
|
||||
|
|
@ -42,4 +48,16 @@ public class ClientRegisteredMessageHandler extends SimpleChannelInboundHandler<
|
|||
return queue.take();
|
||||
}
|
||||
|
||||
private final class ListenerImpl implements ChannelFutureListener {
|
||||
|
||||
private final ServerState POISON_PILL = new ServerState();
|
||||
|
||||
@Override
|
||||
public void operationComplete(ChannelFuture future) throws Exception {
|
||||
if (!future.isSuccess()) {
|
||||
logger.error("Communication error", future.cause());
|
||||
queue.offer(POISON_PILL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ public class ConnectionHandler extends ChannelHandlerAdapter {
|
|||
this.client = client;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
logger.error("Connection error", cause);
|
||||
client.disconnected(true);
|
||||
}
|
||||
// @Override
|
||||
// public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
// logger.error("Connection error", cause);
|
||||
// client.disconnected(true);
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ import java.net.InetSocketAddress;
|
|||
import mage.interfaces.ServerState;
|
||||
import mage.remote.DisconnectReason;
|
||||
import org.mage.network.interfaces.MageServer;
|
||||
import org.mage.network.model.RegisterClientMessage;
|
||||
import org.mage.network.model.RegisterClientRequest;
|
||||
import org.mage.network.model.ClientRegisteredMessage;
|
||||
|
||||
/**
|
||||
|
|
@ -15,7 +15,7 @@ import org.mage.network.model.ClientRegisteredMessage;
|
|||
* @author BetaSteward
|
||||
*/
|
||||
@Sharable
|
||||
public class RegisterClientMessageHandler extends SimpleChannelInboundHandler<RegisterClientMessage> {
|
||||
public class RegisterClientMessageHandler extends SimpleChannelInboundHandler<RegisterClientRequest> {
|
||||
|
||||
private final MageServer server;
|
||||
|
||||
|
|
@ -24,9 +24,9 @@ public class RegisterClientMessageHandler extends SimpleChannelInboundHandler<Re
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void messageReceived(ChannelHandlerContext ctx, RegisterClientMessage msg) throws Exception {
|
||||
protected void messageReceived(ChannelHandlerContext ctx, RegisterClientRequest msg) throws Exception {
|
||||
String host = ((InetSocketAddress)ctx.channel().remoteAddress()).getAddress().getHostAddress();
|
||||
boolean result = server.registerClient(msg.getUserName(), ctx.channel().id().asLongText(), msg.getMageVersion(), host);
|
||||
boolean result = server.registerClient(msg.getConnection(), ctx.channel().id().asLongText(), msg.getMageVersion(), host);
|
||||
if (result) {
|
||||
ctx.writeAndFlush(new ClientRegisteredMessage(server.getServerState()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import java.util.UUID;
|
|||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.DisconnectReason;
|
||||
import mage.utils.MageVersion;
|
||||
import mage.view.RoomView;
|
||||
|
|
@ -16,7 +17,7 @@ import mage.view.TableView;
|
|||
*/
|
||||
public interface MageServer {
|
||||
|
||||
boolean registerClient(String userName, String sessionId, MageVersion version, String host);
|
||||
boolean registerClient(Connection connection, String sessionId, MageVersion version, String host);
|
||||
void disconnect(String sessionId, DisconnectReason reason);
|
||||
|
||||
void receiveChatMessage(UUID chatId, String sessionId, String message);
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.utils.MageVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class RegisterClientMessage implements Serializable {
|
||||
private String userName;
|
||||
private MageVersion version;
|
||||
|
||||
public RegisterClientMessage(String userName, MageVersion version) {
|
||||
this.userName = userName;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public MageVersion getMageVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.mage.network.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import mage.remote.Connection;
|
||||
import mage.utils.MageVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class RegisterClientRequest implements Serializable {
|
||||
private Connection connection;
|
||||
private MageVersion version;
|
||||
|
||||
public RegisterClientRequest(Connection connection, MageVersion version) {
|
||||
this.connection = connection;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public MageVersion getMageVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -60,6 +60,7 @@ import mage.interfaces.ActionWithResult;
|
|||
import org.mage.network.interfaces.MageServer;
|
||||
import mage.interfaces.ServerState;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.DisconnectReason;
|
||||
import mage.remote.MageVersionException;
|
||||
import mage.server.draft.CubeFactory;
|
||||
|
|
@ -242,16 +243,16 @@ public class Main implements MageServer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean registerClient(String userName, String sessionId, MageVersion version, String host) {
|
||||
public boolean registerClient(Connection connection, String sessionId, MageVersion version, String host) {
|
||||
try {
|
||||
if (version.compareTo(Main.getVersion()) != 0) {
|
||||
logger.info("MageVersionException: userName=" + userName + ", version=" + version);
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_WRONG_VERSION, userName, version.toString(), Main.getVersion().toString(), sessionId);
|
||||
logger.info("MageVersionException: userName=" + connection.getUsername() + ", version=" + version);
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_WRONG_VERSION, connection.getUsername(), version.toString(), Main.getVersion().toString(), sessionId);
|
||||
String message = "Wrong client version " + version + ", expecting version " + Main.getVersion() + ". \r\n\r\nPlease download needed version from http://XMage.de or http://www.slightlymagic.net/forum/viewforum.php?f=70";
|
||||
server.informClient(sessionId, "Wrong version", message, MessageType.ERROR);
|
||||
return false;
|
||||
}
|
||||
return SessionManager.getInstance().registerUser(sessionId, userName, host);
|
||||
return SessionManager.getInstance().registerUser(sessionId, connection, host);
|
||||
} catch (MageException ex) {
|
||||
// if (ex instanceof MageVersionException) {
|
||||
// throw (MageVersionException)ex;
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import mage.MageException;
|
|||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.players.net.UserData;
|
||||
import mage.players.net.UserGroup;
|
||||
import mage.remote.Connection;
|
||||
import mage.server.game.GamesRoomManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.view.UserDataView;
|
||||
|
|
@ -83,7 +84,7 @@ public class Session {
|
|||
this.lock = new ReentrantLock();
|
||||
}
|
||||
|
||||
public String registerUser(String userName) throws MageException {
|
||||
public String registerUser(Connection connection) throws MageException {
|
||||
// String returnMessage = registerUserHandling(userName);
|
||||
// if (returnMessage != null) {
|
||||
// sendErrorMessageToClient(returnMessage);
|
||||
|
|
@ -95,15 +96,16 @@ public class Session {
|
|||
Main.getInstance().pingClient(sessionId);
|
||||
}
|
||||
}, 10, 60, TimeUnit.SECONDS);
|
||||
return registerUserHandling(userName);
|
||||
return registerUserHandling(connection);
|
||||
}
|
||||
|
||||
public boolean isLocked() {
|
||||
return lock.isLocked();
|
||||
}
|
||||
|
||||
public String registerUserHandling(String userName) throws MageException {
|
||||
public String registerUserHandling(Connection connection) throws MageException {
|
||||
this.isAdmin = false;
|
||||
String userName = connection.getUsername();
|
||||
if (userName.equals("Admin")) {
|
||||
return "User name Admin already in use";
|
||||
}
|
||||
|
|
@ -141,6 +143,9 @@ public class Session {
|
|||
return new StringBuilder("Error connecting ").append(userName).toString();
|
||||
}
|
||||
this.userId = user.getId();
|
||||
|
||||
setUserData(user, connection);
|
||||
|
||||
if (reconnect) { // must be connected to receive the message
|
||||
UUID chatId = GamesRoomManager.getInstance().getRoom(GamesRoomManager.getInstance().getMainRoomId()).getChatId();
|
||||
if (chatId != null) {
|
||||
|
|
@ -164,25 +169,25 @@ public class Session {
|
|||
this.userId = user.getId();
|
||||
}
|
||||
|
||||
public boolean setUserData(String userName, UserDataView userDataView) {
|
||||
User user = UserManager.getInstance().findUser(userName);
|
||||
public boolean setUserData(User user, Connection connection) {
|
||||
// User user = UserManager.getInstance().findUser(userName);
|
||||
if (user != null) {
|
||||
UserData userData = user.getUserData();
|
||||
if (userData == null) {
|
||||
userData = new UserData(UserGroup.PLAYER, userDataView.getAvatarId(),
|
||||
userDataView.isShowAbilityPickerForced(), userDataView.allowRequestShowHandCards(),
|
||||
userDataView.confirmEmptyManaPool(), userDataView.getUserSkipPrioritySteps(),
|
||||
userDataView.getFlagName());
|
||||
userData = new UserData(UserGroup.PLAYER, connection.getAvatarId(),
|
||||
connection.isShowAbilityPickerForced(), connection.allowRequestShowHandCards(),
|
||||
connection.confirmEmptyManaPool(), connection.getUserSkipPrioritySteps(),
|
||||
connection.getFlagName());
|
||||
user.setUserData(userData);
|
||||
} else {
|
||||
if (userDataView.getAvatarId() == 51) { // Update special avatar if first avatar is selected
|
||||
updateAvatar(userName, userData);
|
||||
if (connection.getAvatarId() == 51) { // Update special avatar if first avatar is selected
|
||||
updateAvatar(connection.getUsername(), userData);
|
||||
}
|
||||
userData.setAvatarId(userDataView.getAvatarId());
|
||||
userData.setShowAbilityPickerForced(userDataView.isShowAbilityPickerForced());
|
||||
userData.setAllowRequestShowHandCards(userDataView.allowRequestShowHandCards());
|
||||
userData.setUserSkipPrioritySteps(userDataView.getUserSkipPrioritySteps());
|
||||
userData.setConfirmEmptyManaPool(userDataView.confirmEmptyManaPool());
|
||||
userData.setAvatarId(connection.getAvatarId());
|
||||
userData.setShowAbilityPickerForced(connection.isShowAbilityPickerForced());
|
||||
userData.setAllowRequestShowHandCards(connection.allowRequestShowHandCards());
|
||||
userData.setUserSkipPrioritySteps(connection.getUserSkipPrioritySteps());
|
||||
userData.setConfirmEmptyManaPool(connection.confirmEmptyManaPool());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import mage.MageException;
|
||||
import mage.remote.Connection;
|
||||
import mage.server.services.LogKeys;
|
||||
import mage.server.services.impl.LogServiceImpl;
|
||||
import mage.view.UserDataView;
|
||||
|
|
@ -73,23 +74,23 @@ public class SessionManager {
|
|||
// sessions.put(sessionId, session);
|
||||
// }
|
||||
|
||||
public boolean registerUser(String sessionId, String userName, String host) throws MageException {
|
||||
public boolean registerUser(String sessionId, Connection connection, String host) throws MageException {
|
||||
Session session = new Session(sessionId);
|
||||
sessions.put(sessionId, session);
|
||||
session.setHost(host);
|
||||
// Session session = sessions.get(sessionId);
|
||||
// if (session != null) {
|
||||
String returnMessage = session.registerUser(userName);
|
||||
String returnMessage = session.registerUser(connection);
|
||||
if (returnMessage == null) {
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, userName, session.getHost(), sessionId);
|
||||
LogServiceImpl.instance.log(LogKeys.KEY_USER_CONNECTED, connection.getUsername(), session.getHost(), sessionId);
|
||||
|
||||
logger.info(userName + " joined server");
|
||||
logger.info(connection.getUsername() + " joined server");
|
||||
logger.debug("- userId: " + session.getUserId());
|
||||
logger.debug("- sessionId: " + sessionId);
|
||||
logger.debug("- host: " + session.getHost());
|
||||
return true;
|
||||
}
|
||||
logger.debug(userName + " not registered: " + returnMessage);
|
||||
logger.debug(connection.getUsername() + " not registered: " + returnMessage);
|
||||
Main.getInstance().informClient(sessionId, "Connection Error", returnMessage, MessageType.ERROR);
|
||||
// Server.informClient(sessionId, returnMessage, MessageType.ERROR);
|
||||
|
||||
|
|
@ -110,14 +111,14 @@ public class SessionManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean setUserData(String userName, String sessionId, UserDataView userDataView) throws MageException {
|
||||
Session session = sessions.get(sessionId);
|
||||
if (session != null) {
|
||||
session.setUserData(userName, userDataView);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// public boolean setUserData(String userName, String sessionId, UserDataView userDataView) throws MageException {
|
||||
// Session session = sessions.get(sessionId);
|
||||
// if (session != null) {
|
||||
// session.setUserData(userName, userDataView);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public void disconnect(String sessionId, DisconnectReason reason) {
|
||||
Session session = sessions.get(sessionId);
|
||||
|
|
|
|||
|
|
@ -123,17 +123,10 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
for (User user : UserManager.getInstance().getUsers()) {
|
||||
Session session = SessionManager.getInstance().getSession(user.getSessionId());
|
||||
try {
|
||||
<<<<<<< HEAD
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), user.getGameInfo(), session.getPingInfo()));
|
||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getInfo(), user.getGameInfo(), session.getPingInfo()));
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
|
||||
users.add(new UsersView(user.getName(), user.getInfo(), "[exception]", session.getPingInfo()));
|
||||
=======
|
||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getInfo(), user.getGameInfo(), user.getPingInfo()));
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
|
||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getInfo(), "[exception]", user.getPingInfo()));
|
||||
>>>>>>> master
|
||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getInfo(), "[exception]", session.getPingInfo()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue