use of mage.server.managers.ManagerFactory 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);
}
}
Aggregations