Some minor changes for user registration.

This commit is contained in:
LevelX2 2016-01-10 20:56:09 +01:00
parent 0af945633c
commit bc822c9677
2 changed files with 64 additions and 68 deletions

View file

@ -18,11 +18,11 @@ import com.google.api.services.gmail.model.Message;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import javax.mail.Session;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.Collections; import java.util.Collections;
import java.util.Properties; import java.util.Properties;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.InternetAddress; import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import mage.server.util.ConfigSettings; import mage.server.util.ConfigSettings;
@ -50,9 +50,9 @@ public class GmailClient {
} }
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JSON_FACTORY, clientSecrets, httpTransport, JSON_FACTORY, clientSecrets,
Collections.singleton(GmailScopes.GMAIL_COMPOSE)).setDataStoreFactory( Collections.singleton(GmailScopes.GMAIL_COMPOSE)).setDataStoreFactory(
dataStoreFactory).build(); dataStoreFactory).build();
credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user"); credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
return true; return true;
@ -76,7 +76,8 @@ public class GmailClient {
Message message = new Message(); Message message = new Message();
message.setRaw(Base64.encodeBase64URLSafeString(baos.toByteArray())); message.setRaw(Base64.encodeBase64URLSafeString(baos.toByteArray()));
gmail.users().messages().send(ConfigSettings.getInstance().getGoogleAccount() + "@gmail.com", message).execute(); gmail.users().messages().send(ConfigSettings.getInstance().getGoogleAccount()
+ (ConfigSettings.getInstance().getGoogleAccount().endsWith("@gmail.com") ? "" : "@gmail.com"), message).execute();
return true; return true;
} catch (MessagingException | IOException ex) { } catch (MessagingException | IOException ex) {
logger.error("Error sending message", ex); logger.error("Error sending message", ex);

View file

@ -1,31 +1,30 @@
/* /*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without modification, are * Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met: * permitted provided that the following conditions are met:
* *
* 1. Redistributions of source code must retain the above copyright notice, this list of * 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer. * conditions and the following disclaimer.
* *
* 2. Redistributions in binary form must reproduce the above copyright notice, this list * 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials * of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution. * provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* The views and conclusions contained in the software and documentation are those of the * The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed * authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com. * or implied, of BetaSteward_at_googlemail.com.
*/ */
package mage.server; package mage.server;
import mage.cards.repository.CardScanner; import mage.cards.repository.CardScanner;
@ -58,14 +57,12 @@ import org.w3c.dom.Element;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.jboss.remoting.transport.bisocket.BisocketServerInvoker; import org.jboss.remoting.transport.bisocket.BisocketServerInvoker;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -73,14 +70,13 @@ import org.jboss.remoting.transport.bisocket.BisocketServerInvoker;
public class Main { public class Main {
private static final Logger logger = Logger.getLogger(Main.class); private static final Logger logger = Logger.getLogger(Main.class);
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO); private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO);
private static final String testModeArg = "-testMode="; private static final String testModeArg = "-testMode=";
private static final String fastDBModeArg = "-fastDbMode="; private static final String fastDBModeArg = "-fastDbMode=";
private static final String adminPasswordArg = "-adminPassword="; private static final String adminPasswordArg = "-adminPassword=";
private static final String pluginFolder = "plugins"; private static final String pluginFolder = "plugins";
public static PluginClassLoader classLoader = new PluginClassLoader(); public static PluginClassLoader classLoader = new PluginClassLoader();
public static TransporterServer server; public static TransporterServer server;
protected static boolean testMode; protected static boolean testMode;
@ -95,15 +91,13 @@ public class Main {
logger.info("Logging level: " + logger.getEffectiveLevel()); logger.info("Logging level: " + logger.getEffectiveLevel());
String adminPassword = ""; String adminPassword = "";
for (String arg: args) { for (String arg : args) {
if (arg.startsWith(testModeArg)) { if (arg.startsWith(testModeArg)) {
testMode = Boolean.valueOf(arg.replace(testModeArg, "")); testMode = Boolean.valueOf(arg.replace(testModeArg, ""));
} } else if (arg.startsWith(adminPasswordArg)) {
else if (arg.startsWith(adminPasswordArg)) {
adminPassword = arg.replace(adminPasswordArg, ""); adminPassword = arg.replace(adminPasswordArg, "");
adminPassword = SystemUtil.sanitize(adminPassword); adminPassword = SystemUtil.sanitize(adminPassword);
} } else if (arg.startsWith(fastDBModeArg)) {
else if (arg.startsWith(fastDBModeArg)) {
fastDbMode = Boolean.valueOf(arg.replace(fastDBModeArg, "")); fastDbMode = Boolean.valueOf(arg.replace(fastDBModeArg, ""));
} }
} }
@ -128,19 +122,19 @@ public class Main {
logger.info("Done."); logger.info("Done.");
deleteSavedGames(); deleteSavedGames();
for (GamePlugin plugin: config.getGameTypes()) { for (GamePlugin plugin : config.getGameTypes()) {
GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin)); GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
} }
for (GamePlugin plugin: config.getTournamentTypes()) { for (GamePlugin plugin : config.getTournamentTypes()) {
TournamentFactory.getInstance().addTournamentType(plugin.getName(), loadTournamentType(plugin), loadPlugin(plugin)); TournamentFactory.getInstance().addTournamentType(plugin.getName(), loadTournamentType(plugin), loadPlugin(plugin));
} }
for (Plugin plugin: config.getPlayerTypes()) { for (Plugin plugin : config.getPlayerTypes()) {
PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin)); PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin));
} }
for (Plugin plugin: config.getDraftCubes()) { for (Plugin plugin : config.getDraftCubes()) {
CubeFactory.getInstance().addDraftCube(plugin.getName(), loadPlugin(plugin)); CubeFactory.getInstance().addDraftCube(plugin.getName(), loadPlugin(plugin));
} }
for (Plugin plugin: config.getDeckTypes()) { for (Plugin plugin : config.getDeckTypes()) {
DeckValidatorFactory.getInstance().addDeckType(plugin.getName(), loadPlugin(plugin)); DeckValidatorFactory.getInstance().addDeckType(plugin.getName(), loadPlugin(plugin));
} }
@ -149,13 +143,15 @@ public class Main {
logger.info("Config - max AI opponents: " + config.getMaxAiOpponents()); logger.info("Config - max AI opponents: " + config.getMaxAiOpponents());
logger.info("Config - min user name l.: " + config.getMinUserNameLength()); logger.info("Config - min user name l.: " + config.getMinUserNameLength());
logger.info("Config - max user name l.: " + config.getMaxUserNameLength()); logger.info("Config - max user name l.: " + config.getMaxUserNameLength());
logger.info("Config - save game active: " + (config.isSaveGameActivated() ? "True":"false")); logger.info("Config - save game active: " + (config.isSaveGameActivated() ? "true" : "false"));
logger.info("Config - backlog size : " + config.getBacklogSize()); logger.info("Config - backlog size : " + config.getBacklogSize());
logger.info("Config - lease period : " + config.getLeasePeriod()); logger.info("Config - lease period : " + config.getLeasePeriod());
logger.info("Config - max pool size : " + config.getMaxPoolSize()); logger.info("Config - max pool size : " + config.getMaxPoolSize());
logger.info("Config - num accp.threads: " + config.getNumAcceptThreads()); logger.info("Config - num accp.threads: " + config.getNumAcceptThreads());
logger.info("Config - second.bind port: " + config.getSecondaryBindPort()); logger.info("Config - second.bind port: " + config.getSecondaryBindPort());
logger.info("Config - auth. activated : " + (config.isAuthenticationActivated() ? "true" : "false"));
logger.info("Config - google account : " + config.getGoogleAccount());
Connection connection = new Connection("&maxPoolSize=" + config.getMaxPoolSize()); Connection connection = new Connection("&maxPoolSize=" + config.getMaxPoolSize());
connection.setHost(config.getServerAddress()); connection.setHost(config.getServerAddress());
@ -172,8 +168,7 @@ public class Main {
logger.info("MAGE server running in test mode"); logger.info("MAGE server running in test mode");
} }
initStatistics(); initStatistics();
} } else {
else {
logger.fatal("Unable to start MAGE server - another server is already started"); logger.fatal("Unable to start MAGE server - another server is already started");
} }
} catch (Exception ex) { } catch (Exception ex) {
@ -202,6 +197,7 @@ public class Main {
} }
static class ClientConnectionListener implements ConnectionListener { static class ClientConnectionListener implements ConnectionListener {
@Override @Override
public void handleConnectionException(Throwable throwable, Client client) { public void handleConnectionException(Throwable throwable, Client client) {
Session session = SessionManager.getInstance().getSession(client.getSessionId()); Session session = SessionManager.getInstance().getSession(client.getSessionId());
@ -340,7 +336,7 @@ public class Main {
logger.debug("Loading tournament type: " + plugin.getClassName()); logger.debug("Loading tournament type: " + plugin.getClassName());
return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance(); return (TournamentType) Class.forName(plugin.getTypeName(), true, classLoader).newInstance();
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
logger.warn("Tournament type not found:" + plugin.getName() + " / "+ plugin.getJar() + " - check plugin folder", ex); logger.warn("Tournament type not found:" + plugin.getName() + " / " + plugin.getJar() + " - check plugin folder", ex);
} catch (Exception ex) { } catch (Exception ex) {
logger.fatal("Error loading game type " + plugin.getJar(), ex); logger.fatal("Error loading game type " + plugin.getJar(), ex);
} }
@ -353,15 +349,14 @@ public class Main {
directory.mkdirs(); directory.mkdirs();
} }
File[] files = directory.listFiles( File[] files = directory.listFiles(
new FilenameFilter() { new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
return name.endsWith(".game"); return name.endsWith(".game");
}
} }
}
); );
for (File file : files) for (File file : files) {
{
file.delete(); file.delete();
} }
} }