use of mage.remote.Connection.ProxyType in project mage by magefree.
the class CardImageUtils method getProxyFromPreferences.
public static Proxy getProxyFromPreferences() {
Preferences prefs = MageFrame.getPreferences();
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
if (proxyType != ProxyType.NONE) {
String proxyServer = prefs.get("proxyAddress", "");
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
}
return null;
}
use of mage.remote.Connection.ProxyType in project mage by magefree.
the class MagePaneMenuItem method performConnect.
private boolean performConnect(boolean reconnect) {
if (currentConnection == null || !reconnect) {
String server = MagePreferences.getLastServerAddress();
int port = MagePreferences.getLastServerPort();
String userName = MagePreferences.getLastServerUser();
String password = MagePreferences.getLastServerPassword();
String proxyServer = PREFS.get("proxyAddress", "");
int proxyPort = Integer.parseInt(PREFS.get("proxyPort", "0"));
ProxyType proxyType = ProxyType.valueByText(PREFS.get("proxyType", "None"));
String proxyUsername = PREFS.get("proxyUsername", "");
String proxyPassword = PREFS.get("proxyPassword", "");
setCursor(new Cursor(Cursor.WAIT_CURSOR));
currentConnection = new Connection();
currentConnection.setUsername(userName);
currentConnection.setPassword(password);
currentConnection.setHost(server);
currentConnection.setPort(port);
// force to redownload db on updates
boolean redownloadDatabase = (ExpansionRepository.instance.getSetByCode("GRN") == null || CardRepository.instance.findCard("Island") == null);
currentConnection.setForceDBComparison(redownloadDatabase);
String allMAC = "";
try {
allMAC = Connection.getMAC();
} catch (SocketException ex) {
}
currentConnection.setUserIdStr(System.getProperty("user.name") + ":" + System.getProperty("os.name") + ":" + MagePreferences.getUserNames() + ":" + allMAC);
currentConnection.setProxyType(proxyType);
currentConnection.setProxyHost(proxyServer);
currentConnection.setProxyPort(proxyPort);
currentConnection.setProxyUsername(proxyUsername);
currentConnection.setProxyPassword(proxyPassword);
setUserPrefsToConnection(currentConnection);
}
try {
LOGGER.debug("connecting (auto): " + currentConnection.getProxyType().toString() + ' ' + currentConnection.getProxyHost() + ' ' + currentConnection.getProxyPort() + ' ' + currentConnection.getProxyUsername());
if (MageFrame.connect(currentConnection)) {
prepareAndShowTablesPane();
return true;
} else {
showMessage("Unable connect to server: " + SessionHandler.getLastConnectError());
}
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
return false;
}
use of mage.remote.Connection.ProxyType in project mage by magefree.
the class CardImageUtils method downloadHtmlDocument.
public static Document downloadHtmlDocument(String urlString) throws NumberFormatException, IOException {
Preferences prefs = MageFrame.getPreferences();
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
Document doc;
if (proxyType == ProxyType.NONE) {
doc = Jsoup.connect(urlString).timeout(60 * 1000).get();
} else {
String proxyServer = prefs.get("proxyAddress", "");
int proxyPort = Integer.parseInt(prefs.get("proxyPort", "0"));
URL url = new URL(urlString);
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort));
HttpURLConnection uc = (HttpURLConnection) url.openConnection(proxy);
uc.setConnectTimeout(10000);
uc.setReadTimeout(60000);
uc.connect();
String line;
StringBuffer tmp = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
while ((line = in.readLine()) != null) {
tmp.append(line);
}
doc = Jsoup.parse(String.valueOf(tmp));
}
return doc;
}
use of mage.remote.Connection.ProxyType in project mage by magefree.
the class PreferencesDialog method showProxySettings.
// GEN-LAST:event_cbUseSameSettingsForReplacementEffectActionPerformed
private void showProxySettings() {
Connection.ProxyType proxyType = (Connection.ProxyType) cbProxyType.getSelectedItem();
switch(proxyType) {
case SOCKS:
this.pnlProxy.setVisible(true);
this.pnlProxySettings.setVisible(true);
break;
case HTTP:
this.pnlProxy.setVisible(true);
this.pnlProxySettings.setVisible(true);
break;
case NONE:
this.pnlProxy.setVisible(false);
this.pnlProxySettings.setVisible(false);
break;
default:
break;
}
this.pack();
this.repaint();
}
use of mage.remote.Connection.ProxyType in project mage by magefree.
the class PreferencesDialog method setProxyInformation.
public static void setProxyInformation(Connection connection) {
ProxyType configProxyType = Connection.ProxyType.valueByText(getCachedValue(KEY_PROXY_TYPE, "None"));
if (configProxyType == null) {
return;
}
connection.setProxyType(configProxyType);
if (configProxyType != ProxyType.NONE) {
String host = getCachedValue(KEY_PROXY_ADDRESS, "");
String port = getCachedValue(KEY_PROXY_PORT, "");
if (!host.isEmpty() && !port.isEmpty()) {
connection.setProxyHost(host);
connection.setProxyPort(Integer.valueOf(port));
String username = getCachedValue(KEY_PROXY_USERNAME, "");
connection.setProxyUsername(username);
if (getCachedValue(KEY_PROXY_REMEMBER, "false").equals("true")) {
String password = getCachedValue(KEY_PROXY_PSWD, "");
connection.setProxyPassword(password);
}
} else {
logger.warn("host or\\and port are empty: host=" + host + ", port=" + port);
}
}
}
Aggregations