added HTTP proxy - fixes issues 77 & 78

This commit is contained in:
BetaSteward 2011-05-16 22:58:58 -04:00
parent dce5595337
commit 21b7ad8808
4 changed files with 430 additions and 195 deletions

View file

@ -80,6 +80,8 @@ import mage.client.tournament.TournamentPane;
import mage.game.match.MatchOptions;
import mage.utils.MageVersion;
import mage.sets.Sets;
import mage.utils.Connection;
import mage.utils.Connection.ProxyType;
import mage.view.TableView;
import org.apache.log4j.Logger;
@ -460,12 +462,8 @@ public class MageFrame extends javax.swing.JFrame {
}
}
public static boolean connect(String userName, String serverName, int port) {
return session.connect(userName, serverName, port);
}
public static boolean connect(String userName, String serverName, int port, String proxyServer, int proxyPort) {
return session.connect(userName, serverName, port, proxyServer, proxyPort);
public static boolean connect(Connection connection) {
return session.connect(connection);
}
public boolean autoConnect() {
@ -476,10 +474,19 @@ public class MageFrame extends javax.swing.JFrame {
int port = Integer.parseInt(prefs.get("serverPort", ""));
String proxyServer = prefs.get("proxyAddress", "");
int proxyPort = Integer.parseInt(prefs.get("proxyPort", ""));
boolean useProxy = Boolean.parseBoolean(prefs.get("useProxy", "false"));
ProxyType proxyType = Connection.ProxyType.valueOf(prefs.get("proxyType", "None"));
String proxyUsername = prefs.get("proxyUsername", "");
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
if (MageFrame.connect(userName, server, port, useProxy?proxyServer:"", useProxy?proxyPort:0)) {
Connection connection = new Connection();
connection.setUsername(userName);
connection.setHost(server);
connection.setPort(port);
connection.setProxyType(proxyType);
connection.setProxyHost(proxyServer);
connection.setProxyPort(proxyPort);
connection.setProxyUsername(proxyUsername);
if (MageFrame.connect(connection)) {
return true;
} else {
JOptionPane.showMessageDialog(rootPane, "Unable to connect to server");

View file

@ -30,38 +30,35 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="btnConnect" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblServer" min="-2" max="-2" attributes="0"/>
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="txtPort" min="-2" pref="71" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="131" max="-2" attributes="0"/>
</Group>
<Component id="txtUserName" alignment="0" pref="270" max="32767" attributes="0"/>
<Component id="chkAutoConnect" alignment="0" pref="270" max="32767" attributes="0"/>
<Component id="chkUseProxy" alignment="0" pref="270" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="txtServer" pref="199" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<Component id="lblProxyType" min="-2" max="-2" attributes="0"/>
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblServer" min="-2" max="-2" attributes="0"/>
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="txtPort" min="-2" pref="71" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="131" max="-2" attributes="0"/>
</Group>
<Component id="txtUserName" alignment="0" pref="382" max="32767" attributes="0"/>
<Component id="chkAutoConnect" alignment="0" pref="382" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="txtServer" pref="311" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="cbProxyType" alignment="0" min="-2" pref="126" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="pnlProxy" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="btnConnect" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="pnlProxySettings" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -87,9 +84,12 @@
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="chkAutoConnect" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="chkUseProxy" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cbProxyType" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyType" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="pnlProxy" pref="51" max="32767" attributes="0"/>
<Component id="pnlProxySettings" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
@ -158,76 +158,6 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkAutoConnectActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="chkUseProxy">
<Properties>
<Property name="text" type="java.lang.String" value="Use Proxy"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkUseProxyActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JPanel" name="pnlProxy">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="30" max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lblProxyPort" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyServer" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtProxyPort" min="-2" pref="71" max="-2" attributes="0"/>
<Component id="txtProxyServer" alignment="0" pref="260" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblProxyServer">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtServer"/>
</Property>
<Property name="text" type="java.lang.String" value="Server:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyServer">
</Component>
<Component class="javax.swing.JLabel" name="lblProxyPort">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtPort"/>
</Property>
<Property name="text" type="java.lang.String" value="Port:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyPort">
<Events>
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtProxyPortkeyTyped"/>
</Events>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JButton" name="jButton1">
<Properties>
<Property name="text" type="java.lang.String" value="Find..."/>
@ -235,8 +165,189 @@
<Property name="name" type="java.lang.String" value="findServerBtn" noResource="true"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="findPublicServerActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JComboBox" name="cbProxyType">
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbProxyTypeActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblProxyType">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="cbProxyType"/>
</Property>
<Property name="text" type="java.lang.String" value="Proxy:"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="pnlProxySettings">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder/>
</Border>
</Property>
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 0]"/>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="pnlProxy" alignment="0" max="32767" attributes="0"/>
<Component id="pnlProxyAuth" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="pnlProxy" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="pnlProxyAuth" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JPanel" name="pnlProxy">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Group type="102" alignment="1" attributes="1">
<EmptySpace max="32767" attributes="0"/>
<Component id="lblProxyPort" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="28" max="-2" attributes="0"/>
<Component id="lblProxyServer" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtProxyServer" pref="360" max="32767" attributes="0"/>
<Component id="txtProxyPort" min="-2" pref="71" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyServer" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyPort" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblProxyServer">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtProxyServer"/>
</Property>
<Property name="text" type="java.lang.String" value="Server:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyServer">
</Component>
<Component class="javax.swing.JLabel" name="lblProxyPort">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtProxyPort"/>
</Property>
<Property name="text" type="java.lang.String" value="Port:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyPort">
<Events>
<EventHandler event="keyTyped" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="txtProxyPortkeyTyped"/>
</Events>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JPanel" name="pnlProxyAuth">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="438" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lblProxyUserName" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyPassword" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="txtProxyPassword" alignment="0" pref="358" max="32767" attributes="0"/>
<Component id="txtProxyUserName" alignment="0" pref="358" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="59" max="32767" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblProxyUserName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyUserName" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtProxyPassword" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblProxyPassword" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="lblProxyUserName">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtProxyUserName"/>
</Property>
<Property name="text" type="java.lang.String" value="User Name:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyUserName">
</Component>
<Component class="javax.swing.JTextField" name="txtProxyPassword">
</Component>
<Component class="javax.swing.JLabel" name="lblProxyPassword">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtProxyPassword"/>
</Property>
<Property name="text" type="java.lang.String" value="Password:"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -40,6 +40,7 @@ import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
@ -50,6 +51,8 @@ import javax.swing.event.ListSelectionListener;
import mage.client.MageFrame;
import mage.client.util.Config;
import mage.utils.Connection;
import mage.utils.Connection.ProxyType;
import org.apache.log4j.Logger;
@ -65,6 +68,7 @@ public class ConnectDialog extends MageDialog {
/** Creates new form ConnectDialog */
public ConnectDialog() {
initComponents();
cbProxyType.setModel(new DefaultComboBoxModel(Connection.ProxyType.values()));
}
public void showDialog() {
@ -74,7 +78,7 @@ public class ConnectDialog extends MageDialog {
this.chkAutoConnect.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get("autoConnect", "false")));
this.txtProxyServer.setText(MageFrame.getPreferences().get("proxyAddress", Config.serverName));
this.txtProxyPort.setText(MageFrame.getPreferences().get("proxyPort", Integer.toString(Config.port)));
this.chkUseProxy.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get("useProxy", "false")));
this.cbProxyType.setSelectedItem(MageFrame.getPreferences().get("proxyType", Connection.ProxyType.NONE.toString()));
this.showProxySettings();
this.setModal(true);
this.setLocation(50, 50);
@ -82,11 +86,20 @@ public class ConnectDialog extends MageDialog {
}
private void showProxySettings() {
if (chkUseProxy.isSelected()) {
if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
this.pnlProxy.setVisible(true);
this.pnlProxyAuth.setVisible(false);
this.pnlProxySettings.setVisible(true);
}
else {
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.HTTP) {
this.pnlProxy.setVisible(true);
this.pnlProxyAuth.setVisible(true);
this.pnlProxySettings.setVisible(true);
}
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.NONE) {
this.pnlProxy.setVisible(false);
this.pnlProxyAuth.setVisible(false);
this.pnlProxySettings.setVisible(false);
}
this.pack();
this.revalidate();
@ -100,7 +113,7 @@ public class ConnectDialog extends MageDialog {
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
MageFrame.getPreferences().put("proxyAddress", txtProxyServer.getText());
MageFrame.getPreferences().put("proxyPort", txtProxyPort.getText());
MageFrame.getPreferences().put("useProxy", Boolean.toString(chkUseProxy.isSelected()));
MageFrame.getPreferences().put("proxyType", cbProxyType.getSelectedItem().toString());
}
/** This method is called from within the constructor to
@ -121,13 +134,20 @@ public class ConnectDialog extends MageDialog {
btnConnect = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
chkAutoConnect = new javax.swing.JCheckBox();
chkUseProxy = new javax.swing.JCheckBox();
jButton1 = new javax.swing.JButton();
cbProxyType = new javax.swing.JComboBox();
lblProxyType = new javax.swing.JLabel();
pnlProxySettings = new javax.swing.JPanel();
pnlProxy = new javax.swing.JPanel();
lblProxyServer = new javax.swing.JLabel();
txtProxyServer = new javax.swing.JTextField();
lblProxyPort = new javax.swing.JLabel();
txtProxyPort = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
pnlProxyAuth = new javax.swing.JPanel();
lblProxyUserName = new javax.swing.JLabel();
txtProxyUserName = new javax.swing.JTextField();
txtProxyPassword = new javax.swing.JTextField();
lblProxyPassword = new javax.swing.JLabel();
setTitle("Connect");
setNormalBounds(new java.awt.Rectangle(100, 100, 410, 307));
@ -168,17 +188,31 @@ public class ConnectDialog extends MageDialog {
}
});
chkUseProxy.setText("Use Proxy");
chkUseProxy.addActionListener(new java.awt.event.ActionListener() {
jButton1.setText("Find...");
jButton1.setToolTipText("Find public server");
jButton1.setName("findServerBtn"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
chkUseProxyActionPerformed(evt);
findPublicServerActionPerformed(evt);
}
});
lblProxyServer.setLabelFor(txtServer);
cbProxyType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbProxyTypeActionPerformed(evt);
}
});
lblProxyType.setLabelFor(cbProxyType);
lblProxyType.setText("Proxy:");
pnlProxySettings.setBorder(javax.swing.BorderFactory.createEtchedBorder());
pnlProxySettings.setMinimumSize(new java.awt.Dimension(0, 0));
lblProxyServer.setLabelFor(txtProxyServer);
lblProxyServer.setText("Server:");
lblProxyPort.setLabelFor(txtPort);
lblProxyPort.setLabelFor(txtProxyPort);
lblProxyPort.setText("Port:");
txtProxyPort.addKeyListener(new java.awt.event.KeyAdapter() {
@ -191,37 +225,87 @@ public class ConnectDialog extends MageDialog {
pnlProxy.setLayout(pnlProxyLayout);
pnlProxyLayout.setHorizontalGroup(
pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlProxyLayout.createSequentialGroup()
.addGap(30, 30, 30)
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblProxyPort)
.addComponent(lblProxyServer))
.addGroup(pnlProxyLayout.createSequentialGroup()
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(pnlProxyLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lblProxyPort))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlProxyLayout.createSequentialGroup()
.addGap(28, 28, 28)
.addComponent(lblProxyServer)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtProxyServer, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
.addComponent(txtProxyServer, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pnlProxyLayout.setVerticalGroup(
pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlProxyLayout.createSequentialGroup()
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblProxyServer)
.addComponent(txtProxyServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(txtProxyServer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblProxyServer))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlProxyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblProxyPort)
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jButton1.setText("Find...");
jButton1.setToolTipText("Find public server");
jButton1.setName("findServerBtn"); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
findPublicServerActionPerformed(evt);
}
});
lblProxyUserName.setLabelFor(txtProxyUserName);
lblProxyUserName.setText("User Name:");
lblProxyPassword.setLabelFor(txtProxyPassword);
lblProxyPassword.setText("Password:");
javax.swing.GroupLayout pnlProxyAuthLayout = new javax.swing.GroupLayout(pnlProxyAuth);
pnlProxyAuth.setLayout(pnlProxyAuthLayout);
pnlProxyAuthLayout.setHorizontalGroup(
pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 438, Short.MAX_VALUE)
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlProxyAuthLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblProxyUserName)
.addComponent(lblProxyPassword))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtProxyPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE)
.addComponent(txtProxyUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 358, Short.MAX_VALUE))
.addContainerGap()))
);
pnlProxyAuthLayout.setVerticalGroup(
pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 59, Short.MAX_VALUE)
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlProxyAuthLayout.createSequentialGroup()
.addGap(2, 2, 2)
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblProxyUserName)
.addComponent(txtProxyUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlProxyAuthLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtProxyPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblProxyPassword))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
);
javax.swing.GroupLayout pnlProxySettingsLayout = new javax.swing.GroupLayout(pnlProxySettings);
pnlProxySettings.setLayout(pnlProxySettingsLayout);
pnlProxySettingsLayout.setHorizontalGroup(
pnlProxySettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlProxy, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlProxyAuth, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pnlProxySettingsLayout.setVerticalGroup(
pnlProxySettingsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlProxySettingsLayout.createSequentialGroup()
.addComponent(pnlProxy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlProxyAuth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
@ -232,29 +316,28 @@ public class ConnectDialog extends MageDialog {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblProxyType)
.addComponent(lblPort)
.addComponent(lblServer)
.addComponent(lblUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(btnConnect)
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(131, 131, 131))
.addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 382, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblPort)
.addComponent(lblServer)
.addComponent(lblUserName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(131, 131, 131))
.addComponent(txtUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
.addComponent(chkAutoConnect, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
.addComponent(chkUseProxy, javax.swing.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(txtServer, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))))
.addContainerGap())
.addComponent(pnlProxy, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addComponent(jButton1))
.addComponent(cbProxyType, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnConnect)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addComponent(pnlProxySettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -275,9 +358,11 @@ public class ConnectDialog extends MageDialog {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkAutoConnect)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkUseProxy)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbProxyType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblProxyType))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlProxy, javax.swing.GroupLayout.DEFAULT_SIZE, 51, Short.MAX_VALUE)
.addComponent(pnlProxySettings, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel)
@ -315,17 +400,18 @@ public class ConnectDialog extends MageDialog {
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
if (chkUseProxy.isSelected()) {
if (MageFrame.connect(txtUserName.getText(), txtServer.getText().trim(), Integer.valueOf(txtPort.getText()), txtProxyServer.getText().trim(), Integer.valueOf(txtProxyPort.getText()))) {
this.saveSettings();
this.setVisible(false);
}
}
else {
if (MageFrame.connect(txtUserName.getText(), txtServer.getText().trim(), Integer.valueOf(txtPort.getText()))) {
this.saveSettings();
this.setVisible(false);
}
Connection connection = new Connection();
connection.setHost(this.txtServer.getText());
connection.setPort(Integer.valueOf(this.txtPort.getText()));
connection.setUsername(this.txtUserName.getText());
connection.setProxyType((ProxyType) this.cbProxyType.getSelectedItem());
connection.setProxyHost(this.txtProxyServer.getText());
connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText()));
connection.setProxyUsername(this.txtProxyUserName.getText());
connection.setProxyPassword(this.txtProxyPassword.getText());
if (MageFrame.connect(connection)) {
this.saveSettings();
this.setVisible(false);
}
}
finally {
@ -349,10 +435,6 @@ public class ConnectDialog extends MageDialog {
// TODO add your handling code here:
}//GEN-LAST:event_txtProxyPortkeyTyped
private void chkUseProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkUseProxyActionPerformed
this.showProxySettings();
}//GEN-LAST:event_chkUseProxyActionPerformed
private void findPublicServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
BufferedReader in = null;
try {
@ -393,22 +475,33 @@ public class ConnectDialog extends MageDialog {
}
}//GEN-LAST:event_jButton1ActionPerformed
private void cbProxyTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbProxyTypeActionPerformed
this.showProxySettings();
}//GEN-LAST:event_cbProxyTypeActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnConnect;
private javax.swing.JComboBox cbProxyType;
private javax.swing.JCheckBox chkAutoConnect;
private javax.swing.JCheckBox chkUseProxy;
private javax.swing.JButton jButton1;
private javax.swing.JLabel lblPort;
private javax.swing.JLabel lblProxyPassword;
private javax.swing.JLabel lblProxyPort;
private javax.swing.JLabel lblProxyServer;
private javax.swing.JLabel lblProxyType;
private javax.swing.JLabel lblProxyUserName;
private javax.swing.JLabel lblServer;
private javax.swing.JLabel lblUserName;
private javax.swing.JPanel pnlProxy;
private javax.swing.JPanel pnlProxyAuth;
private javax.swing.JPanel pnlProxySettings;
private javax.swing.JTextField txtPort;
private javax.swing.JTextField txtProxyPassword;
private javax.swing.JTextField txtProxyPort;
private javax.swing.JTextField txtProxyServer;
private javax.swing.JTextField txtProxyUserName;
private javax.swing.JTextField txtServer;
private javax.swing.JTextField txtUserName;
// End of variables declaration//GEN-END:variables

View file

@ -28,6 +28,8 @@
package mage.client.remote;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
@ -57,7 +59,7 @@ import mage.game.tournament.TournamentOptions;
import mage.interfaces.Server;
import mage.interfaces.ServerState;
import mage.interfaces.callback.CallbackClientDaemon;
import mage.util.Logging;
import mage.utils.Connection;
import mage.view.DraftPickView;
import mage.view.GameTypeView;
import mage.view.TableView;
@ -91,35 +93,41 @@ public class Session {
public Session(MageFrame frame) {
this.frame = frame;
}
public boolean connect(String userName, String serverName, int port) {
return connect(userName, serverName, port, "", 0);
}
public boolean connect(String userName, String serverName, int port, String proxyServer, int proxyPort) {
public boolean connect(Connection connection) {
if (isConnected()) {
disconnect();
}
try {
System.setSecurityManager(null);
if (proxyServer.length() > 0) {
System.setProperty("socksProxyHost", proxyServer);
System.setProperty("socksProxyPort", Integer.toString(proxyPort));
switch (connection.getProxyType()) {
case SOCKS:
System.setProperty("socksProxyHost", connection.getProxyHost());
System.setProperty("socksProxyPort", Integer.toString(connection.getProxyPort()));
break;
case HTTP:
System.setProperty("http.proxyHost", connection.getProxyHost());
System.setProperty("http.proxyPort", Integer.toString(connection.getProxyPort()));
Authenticator.setDefault(new MageAuthenticator(connection.getProxyUsername(), connection.getProxyPassword()));
break;
default:
System.clearProperty("socksProxyHost");
System.clearProperty("socksProxyPort");
System.clearProperty("http.proxyHost");
System.clearProperty("http.proxyPort");
break;
}
else {
System.clearProperty("socksProxyHost");
System.clearProperty("socksProxyPort");
}
Registry reg = LocateRegistry.getRegistry(serverName, port);
Registry reg = LocateRegistry.getRegistry(connection.getHost(), connection.getPort());
this.server = (Server) reg.lookup(Config.remoteServer);
this.userName = userName;
this.userName = connection.getUsername();
if (client == null)
client = new Client(this, frame);
sessionId = server.registerClient(userName, client.getId(), frame.getVersion());
callbackDaemon = new CallbackClientDaemon(sessionId, client, server);
serverState = server.getServerState();
future = sessionExecutor.scheduleWithFixedDelay(new ServerPinger(), 5, 5, TimeUnit.SECONDS);
logger.info("Connected to RMI server at " + serverName + ":" + port);
frame.setStatusText("Connected to " + serverName + ":" + port + " ");
logger.info("Connected to RMI server at " + connection.getHost() + ":" + connection.getPort());
frame.setStatusText("Connected to " + connection.getHost() + ":" + connection.getPort() + " ");
frame.enableButtons();
return true;
} catch (MageException ex) {
@ -742,14 +750,14 @@ public class Session {
private void handleRemoteException(RemoteException ex) {
logger.fatal("Communication error", ex);
removeServer();
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Critical server error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);
disconnect();
}
private void handleMageException(MageException ex) {
logger.fatal("Server error", ex);
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Critical server error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);
disconnect();
frame.disableButtons();
}
private void handleGameException(GameException ex) {
@ -789,4 +797,20 @@ public class Session {
}
}
}
class MageAuthenticator extends Authenticator {
private String username;
private String password;
public MageAuthenticator(String username, String password) {
this.username = username;
this.password = password;
}
@Override
public PasswordAuthentication getPasswordAuthentication () {
return new PasswordAuthentication (username, password.toCharArray());
}
}