use of mage.remote.Connection in project mage by magefree.
the class Main method main.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
logger.info("Starting MAGE server version " + version);
logger.info("Logging level: " + logger.getEffectiveLevel());
logger.info("Default charset: " + Charset.defaultCharset());
String adminPassword = "";
for (String arg : args) {
if (arg.startsWith(testModeArg)) {
testMode = Boolean.valueOf(arg.replace(testModeArg, ""));
} else if (arg.startsWith(adminPasswordArg)) {
adminPassword = arg.replace(adminPasswordArg, "");
adminPassword = SystemUtil.sanitize(adminPassword);
} else if (arg.startsWith(fastDBModeArg)) {
fastDbMode = Boolean.valueOf(arg.replace(fastDBModeArg, ""));
}
}
final String configPath = Optional.ofNullable(System.getProperty(configPathProp)).orElse(defaultConfigPath);
logger.info(String.format("Reading configuration from path=%s", configPath));
final ConfigWrapper config = new ConfigWrapper(ConfigFactory.loadFromFile(configPath));
if (config.isAuthenticationActivated()) {
logger.info("Check authorized user DB version ...");
if (!AuthorizedUserRepository.getInstance().checkAlterAndMigrateAuthorizedUser()) {
logger.fatal("Failed to start server.");
return;
}
logger.info("Done.");
}
// db init and updates checks (e.g. cleanup cards db on new version)
RepositoryUtil.bootstrapLocalDb();
logger.info("Done.");
logger.info("Loading extension packages...");
if (!extensionFolder.exists()) {
if (!extensionFolder.mkdirs()) {
logger.error("Could not create extensions directory.");
}
}
File[] extensionDirectories = extensionFolder.listFiles();
List<ExtensionPackage> extensions = new ArrayList<>();
if (extensionDirectories != null) {
for (File f : extensionDirectories) {
if (f.isDirectory()) {
try {
logger.info(" - Loading extension from " + f);
extensions.add(ExtensionPackageLoader.loadExtension(f));
} catch (IOException e) {
logger.error("Could not load extension in " + f + '!', e);
}
}
}
}
logger.info("Done.");
if (!extensions.isEmpty()) {
logger.info("Registering custom sets...");
for (ExtensionPackage pkg : extensions) {
for (ExpansionSet set : pkg.getSets()) {
logger.info("- Loading " + set.getName() + " (" + set.getCode() + ')');
Sets.getInstance().addSet(set);
}
PluginClassloaderRegistery.registerPluginClassloader(pkg.getClassLoader());
}
logger.info("Done.");
}
logger.info("Loading cards...");
if (fastDbMode) {
CardScanner.scanned = true;
} else {
CardScanner.scan();
}
logger.info("Done.");
// cards preload with ratings
if (RateCard.PRELOAD_CARD_RATINGS_ON_STARTUP) {
RateCard.bootstrapCardsAndRatings();
logger.info("Done.");
}
logger.info("Updating user stats DB...");
UserStatsRepository.instance.updateUserStats();
logger.info("Done.");
deleteSavedGames();
int gameTypes = 0;
for (GamePlugin plugin : config.getGameTypes()) {
gameTypes++;
GameFactory.instance.addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
}
int tourneyTypes = 0;
for (GamePlugin plugin : config.getTournamentTypes()) {
tourneyTypes++;
TournamentFactory.instance.addTournamentType(plugin.getName(), loadTournamentType(plugin), loadPlugin(plugin));
}
int playerTypes = 0;
for (Plugin plugin : config.getPlayerTypes()) {
playerTypes++;
PlayerFactory.instance.addPlayerType(plugin.getName(), loadPlugin(plugin));
}
int cubeTypes = 0;
for (Plugin plugin : config.getDraftCubes()) {
cubeTypes++;
CubeFactory.instance.addDraftCube(plugin.getName(), loadPlugin(plugin));
}
int deckTypes = 0;
for (Plugin plugin : config.getDeckTypes()) {
deckTypes++;
DeckValidatorFactory.instance.addDeckType(plugin.getName(), loadPlugin(plugin));
}
for (ExtensionPackage pkg : extensions) {
for (Map.Entry<String, Class> entry : pkg.getDraftCubes().entrySet()) {
logger.info("Loading extension: [" + entry.getKey() + "] " + entry.getValue().toString());
cubeTypes++;
CubeFactory.instance.addDraftCube(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Class> entry : pkg.getDeckTypes().entrySet()) {
logger.info("Loading extension: [" + entry.getKey() + "] " + entry.getValue().toString());
deckTypes++;
DeckValidatorFactory.instance.addDeckType(entry.getKey(), entry.getValue());
}
}
logger.info("Config - max seconds idle: " + config.getMaxSecondsIdle());
logger.info("Config - max game threads: " + config.getMaxGameThreads());
logger.info("Config - max AI opponents: " + config.getMaxAiOpponents());
logger.info("Config - min usr name le.: " + config.getMinUserNameLength());
logger.info("Config - max usr name le.: " + config.getMaxUserNameLength());
logger.info("Config - min pswrd length: " + config.getMinPasswordLength());
logger.info("Config - max pswrd length: " + config.getMaxPasswordLength());
logger.info("Config - inv.usr name pat: " + config.getInvalidUserNamePattern());
logger.info("Config - save game active: " + (config.isSaveGameActivated() ? "true" : "false"));
logger.info("Config - backlog size : " + config.getBacklogSize());
logger.info("Config - lease period : " + config.getLeasePeriod());
logger.info("Config - sock wrt timeout: " + config.getSocketWriteTimeout());
logger.info("Config - max pool size : " + config.getMaxPoolSize());
logger.info("Config - num accp.threads: " + config.getNumAcceptThreads());
logger.info("Config - second.bind port: " + config.getSecondaryBindPort());
logger.info("Config - auth. activated : " + (config.isAuthenticationActivated() ? "true" : "false"));
logger.info("Config - mailgun api key : " + config.getMailgunApiKey());
logger.info("Config - mailgun domain : " + config.getMailgunDomain());
logger.info("Config - mail smtp Host : " + config.getMailSmtpHost());
logger.info("Config - mail smtpPort : " + config.getMailSmtpPort());
logger.info("Config - mail user : " + config.getMailUser());
logger.info("Config - mail passw. len.: " + config.getMailPassword().length());
logger.info("Config - mail from addre.: " + config.getMailFromAddress());
logger.info("Config - google account : " + config.getGoogleAccount());
logger.info("Loaded game types: " + gameTypes + ", tourneys: " + tourneyTypes + ", players: " + playerTypes + ", cubes: " + cubeTypes + ", decks: " + deckTypes);
if (gameTypes == 0) {
logger.error("ERROR, can't load any game types. Check your config.xml in server's config folder (example: old jar versions after update).");
}
Connection connection = new Connection("&maxPoolSize=" + config.getMaxPoolSize());
connection.setHost(config.getServerAddress());
connection.setPort(config.getPort());
final ManagerFactory managerFactory = new MainManagerFactory(config);
try {
// Parameter: serializationtype => jboss
InvokerLocator serverLocator = new InvokerLocator(connection.getURI());
if (!isAlreadyRunning(config, serverLocator)) {
server = new MageTransporterServer(managerFactory, serverLocator, new MageServerImpl(managerFactory, adminPassword, testMode), MageServer.class.getName(), new MageServerInvocationHandler(managerFactory));
server.start();
logger.info("Started MAGE server - listening on " + connection.toString());
if (testMode) {
logger.info("MAGE server running in test mode");
}
initStatistics();
} else {
logger.fatal("Unable to start MAGE server - another server is already started");
}
} catch (Exception ex) {
logger.fatal("Failed to start server - " + connection.toString(), ex);
}
}
use of mage.remote.Connection 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 in project mage by magefree.
the class RegisterUserDialog method btnRegisterActionPerformed.
// GEN-LAST:event_btnCancelActionPerformed
private void btnRegisterActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_btnRegisterActionPerformed
if (!Arrays.equals(this.txtPassword.getPassword(), this.txtPasswordConfirmation.getPassword())) {
MageFrame.getInstance().showError("Passwords don't match.");
return;
}
connection = new Connection();
connection.setHost(this.txtServer.getText().trim());
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
connection.setUsername(this.txtUserName.getText().trim());
connection.setPassword(String.valueOf(this.txtPassword.getPassword()).trim());
connection.setEmail(this.txtEmail.getText().trim());
PreferencesDialog.setProxyInformation(connection);
task = new ConnectTask();
task.execute();
}
use of mage.remote.Connection in project mage by magefree.
the class ConnectDialog method btnConnectActionPerformed.
// GEN-LAST:event_btnCancelActionPerformed
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {
if (txtServer.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a server address");
return;
}
if (txtPort.getText().trim().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a port number");
return;
}
if (txtUserName.getText().isEmpty()) {
JOptionPane.showMessageDialog(rootPane, "Please provide a user name");
return;
}
// txtPassword is not checked here, because authentication might be disabled by the server config.
if (Integer.parseInt(txtPort.getText()) < 1 || Integer.parseInt(txtPort.getText()) > 65535) {
JOptionPane.showMessageDialog(rootPane, "Invalid port number");
txtPort.setText(Integer.toString(MagePreferences.getServerPortWithDefault(ClientDefaultSettings.port)));
return;
}
char[] input = new char[0];
try {
connection = new Connection();
connection.setHost(this.txtServer.getText().trim());
connection.setPort(Integer.parseInt(this.txtPort.getText().trim()));
connection.setUsername(this.txtUserName.getText().trim());
connection.setPassword(String.valueOf(this.txtPassword.getPassword()).trim());
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected() || RepositoryUtil.isDatabaseEmpty());
String allMAC = "";
try {
allMAC = Connection.getMAC();
} catch (SocketException ex) {
}
connection.setUserIdStr(System.getProperty("user.name") + ":" + System.getProperty("os.name") + ":" + MagePreferences.getUserNames() + ":" + allMAC);
MageFrame.getPreferences().put(KEY_CONNECT_FLAG, ((CountryItemEditor) cbFlag.getEditor()).getImageItem());
PreferencesDialog.setProxyInformation(connection);
// pref settings
MageFrame.getInstance().setUserPrefsToConnection(connection);
logger.debug("connecting: " + connection.getProxyType() + ' ' + connection.getProxyHost() + ' ' + connection.getProxyPort());
task = new ConnectTask();
task.execute();
} finally {
Arrays.fill(input, '0');
}
}
use of mage.remote.Connection in project mage by magefree.
the class ResetPasswordDialog method btnGetAuthTokenActionPerformed.
// </editor-fold>//GEN-END:initComponents
private void btnGetAuthTokenActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_btnGetAuthTokenActionPerformed
if (this.txtEmail.getText().isEmpty()) {
MageFrame.getInstance().showError("Please enter an email address.");
return;
}
connection = new Connection();
connection.setHost(this.txtServer.getText().trim());
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
PreferencesDialog.setProxyInformation(connection);
connection.setEmail(this.txtEmail.getText().trim());
getAuthTokenTask = new GetAuthTokenTask();
getAuthTokenTask.execute();
}
Aggregations