diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index ac995a57..a696c718 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -93,6 +93,8 @@ public static final class Config extends ConfigObject { public final int authRateLimitMilis; + public final ListConfigEntry authLimitExclusions; + public final String authRejectString; public final String projectName; @@ -122,6 +124,7 @@ private Config(BlockConfigEntry block, Path coredir, LaunchServer server) { VerifyHelper.range(0, 1000000), "Illegal authRateLimit"); authRateLimitMilis = VerifyHelper.verifyInt(block.getEntryValue("authRateLimitMilis", IntegerConfigEntry.class), VerifyHelper.range(10, 10000000), "Illegal authRateLimitMillis"); + authLimitExclusions = block.hasEntry("authLimitExclusions") ? block.getEntry("authLimitExclusions", ListConfigEntry.class) : null; bindAddress = block.hasEntry("bindAddress") ? block.getEntryValue("bindAddress", StringConfigEntry.class) : getAddress(); authRejectString = block.hasEntry("authRejectString") ? @@ -129,7 +132,6 @@ private Config(BlockConfigEntry block, Path coredir, LaunchServer server) { whitelistRejectString = block.hasEntry("whitelistRejectString") ? block.getEntryValue("whitelistRejectString", StringConfigEntry.class) : "Вас нет в белом списке"; - // Set handlers & providers authHandler = new AuthHandler[1]; authHandler[0] = AuthHandler.newHandler(block.getEntryValue("authHandler", StringConfigEntry.class), diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java index a66bbff3..faef83be 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/AuthLimiter.java @@ -1,8 +1,11 @@ package ru.gravit.launchserver.auth; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import ru.gravit.launcher.NeedGarbageCollection; +import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launchserver.LaunchServer; public class AuthLimiter implements NeedGarbageCollection { @@ -50,10 +53,13 @@ public String toString() { public final int rateLimit; public final int rateLimitMilis; - private HashMap map; + private final HashMap map; + private final List excludeIps; public AuthLimiter(LaunchServer srv) { map = new HashMap<>(); + excludeIps = new ArrayList<>(); + if (srv.config.authLimitExclusions != null) srv.config.authLimitExclusions.stream(StringConfigEntry.class).forEach(excludeIps::add); rateLimit = srv.config.authRateLimit; rateLimitMilis = srv.config.authRateLimitMilis; } @@ -66,6 +72,7 @@ public void garbageCollection() { } public boolean isLimit(String ip) { + if (excludeIps.contains(ip)) return false; if (map.containsKey(ip)) { AuthEntry rate = map.get(ip); long currenttime = System.currentTimeMillis(); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 5e7afc76..248a802c 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -53,10 +53,8 @@ protected AuthHandler(BlockConfigEntry block) { super(block); } - public abstract UUID auth(AuthProviderResult authResult) throws IOException; - public abstract UUID checkServer(String username, String serverID) throws IOException; @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java index cd71e474..ae7cf3ff 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/MySQLAuthProvider.java @@ -20,6 +20,7 @@ public final class MySQLAuthProvider extends AuthProvider { private final MySQLSourceConfig mySQLHolder; private final String query; + private final String message; private final String[] queryParams; private final boolean usePermission; @@ -31,6 +32,7 @@ public MySQLAuthProvider(BlockConfigEntry block, LaunchServer server) { query = VerifyHelper.verify(block.getEntryValue("query", StringConfigEntry.class), VerifyHelper.NOT_EMPTY, "MySQL query can't be empty"); usePermission = block.hasEntry("usePermission") ? block.getEntryValue("usePermission", BooleanConfigEntry.class) : false; + message = block.hasEntry("message") ? block.getEntryValue("message", StringConfigEntry.class) : "Incorrect username or password"; queryParams = block.getEntry("queryParams", ListConfigEntry.class). stream(StringConfigEntry.class).toArray(String[]::new); } @@ -46,7 +48,7 @@ public AuthProviderResult auth(String login, String password, String ip) throws // Execute SQL query s.setQueryTimeout(MySQLSourceConfig.TIMEOUT); try (ResultSet set = s.executeQuery()) { - return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : new ClientPermissions()) : authError("Incorrect username or password"); + return set.next() ? new AuthProviderResult(set.getString(1), SecurityHelper.randomStringToken(), usePermission ? new ClientPermissions(set.getLong(2)) : new ClientPermissions()) : authError(message); } } diff --git a/Launcher/runtime/dialog/dialog.js b/Launcher/runtime/dialog/dialog.js index 63be8402..8b35fad4 100644 --- a/Launcher/runtime/dialog/dialog.js +++ b/Launcher/runtime/dialog/dialog.js @@ -276,19 +276,25 @@ function updateProfilesList(profiles) { profilesList = []; // Set profiles items serverList.getChildren().clear(); + var index = 0; profiles.forEach(function (profile, i, arr) { pingers[profile.object] = new ServerPinger(profile.object.getServerSocketAddress(), profile.object.getVersion()); var serverBtn = new javafx.scene.control.ToggleButton(profile); (function () { profilesList[serverBtn] = profile; var hold = serverBtn; + var hIndex = index; serverBtn.setOnAction(function (event) { serverHolder.set(hold); + settings.profile = hIndex; }); })(); serverList.getChildren().add(serverBtn); + index++; }); - serverHolder.set(serverList.getChildren().get(0)); + LogHelper.debug("Load selected %d profile",settings.profile); + if(profiles.length > 0) + serverHolder.set(serverList.getChildren().get(settings.profile)); } function pingServer(btn) { @@ -417,4 +423,4 @@ launcher.loadScript("dialog/overlay/debug/debug.js"); launcher.loadScript("dialog/overlay/processing/processing.js"); launcher.loadScript("dialog/overlay/settings/settings.js"); launcher.loadScript("dialog/overlay/options/options.js"); -launcher.loadScript("dialog/overlay/update/update.js"); \ No newline at end of file +launcher.loadScript("dialog/overlay/update/update.js"); diff --git a/Launcher/runtime/dialog/overlay/options/options.js b/Launcher/runtime/dialog/overlay/options/options.js index 02ece64f..22949c05 100644 --- a/Launcher/runtime/dialog/overlay/options/options.js +++ b/Launcher/runtime/dialog/overlay/options/options.js @@ -79,7 +79,7 @@ var options = { initOverlay: function() { options.overlay = loadFXML("dialog/overlay/options/options.fxml"); - var holder = options.overlay.lookup("#holder"); + var holder = options.overlay.lookup("#holder"); holder.lookup("#apply").setOnAction(function(event) overlay.hide(0, null)); }, update: function() { @@ -188,8 +188,10 @@ var options = { modIDs.forEach(function(key, id) { if(modList[key] != null && modList[key].subTreeLevel != null) { if( modList[key].subTreeLevel > modInfo.subTreeLevel && modIDs.indexOf(key) > modIDs.indexOf(ImodFile) && enable == false && stop == false) { - profile.unmarkOptional(key); - LogHelper.debug("Unselected subMod %s", key); + if(options.modExists(key)){ + profile.unmarkOptional(key); + LogHelper.debug("Unselected subMod %s", key); + } } else if(modIDs.indexOf(key) > modIDs.indexOf(ImodFile) && modList[key].subTreeLevel <= modInfo.subTreeLevel && stop == false) { //LogHelper.debug("STOP disable!! " + key); stop = true; @@ -202,8 +204,10 @@ var options = { modIDs.forEach(function(key, id) { if(modList[key] != null && modList[key].onlyOneGroup != null) { if(modList[key].onlyOneGroup == modInfo.onlyOneGroup && modList[key].onlyOne == true && enable == true && key != ImodFile) { - profile.unmarkOptional(key); - LogHelper.debug("Unselected Mod (onlyOne toggle) %s", key); + if(options.modExists(key)) { + profile.unmarkOptional(key); + LogHelper.debug("Unselected Mod (onlyOne toggle) %s", key); + } options.treeToggle(false, key); //И все его подмодификации канут в Лету.. } } @@ -216,8 +220,10 @@ var options = { reverseModList.forEach(function(key, id) { if(modList[key] != null && modList[key].subTreeLevel != null) { if(modList[key].subTreeLevel == tsl && modIDs.indexOf(key) < modIDs.indexOf(ImodFile) && enable == true) { - profile.markOptional(key); - LogHelper.debug("Selected coreMod %s", key); + if(options.modExists(key)) { + profile.markOptional(key); + LogHelper.debug("Selected coreMod %s", key); + } options.treeToggle(true, key); //Для срабатывания onlyOne-модификаций. tsl--; } @@ -227,6 +233,17 @@ var options = { } } + }, + modExists: function(key){ + var profile = profilesList[serverHolder.old].object; + var list = profile.getOptional(); + var result = false; + list.forEach(function(modFile) { + if(modFile.string === key) { + result = true; + } + }); + return result; } }; diff --git a/Launcher/runtime/dialog/overlay/settings/settings.css b/Launcher/runtime/dialog/overlay/settings/settings.css index 3e99b724..1e001ca0 100644 --- a/Launcher/runtime/dialog/overlay/settings/settings.css +++ b/Launcher/runtime/dialog/overlay/settings/settings.css @@ -1,6 +1,9 @@ #holder { -fx-background-color: #fff; } +#holder > #transferDialog { + -fx-background-color: RGBA(0, 0, 0, 0.9); +} /* Labels */ #holder > #settingsTitle { -fx-font-size: 14pt; @@ -37,14 +40,14 @@ #holder > #ramSlider:pressed > .thumb { } /* Dir options */ -#holder > #deleteDir { +#holder > #deleteDir, #cancelTransfer { -fx-background-color: #CE5757; -fx-text-fill: white; -fx-background-radius: 0; } -#holder > #deleteDir:hover, -#holder > #deleteDir:focused { +#holder > #deleteDir:hover,#cancelTransfer:hover, +#holder > #deleteDir:focused,#cancelTransfer:focused { -fx-opacity: 0.8; } @@ -63,13 +66,13 @@ #holder > #changeDir:pressed { -fx-opacity: 0.8; } -#holder > #apply{ +#holder > #apply,#applyTransfer{ -fx-background-color: #61B373; -fx-text-fill: #fff; -fx-background-radius: 0; } -#holder > #apply:hover, -#holder > #apply:focused{ +#holder > #apply:hover,#applyTransfer:hover, +#holder > #apply:focused,#applyTransfer:focused{ -fx-background-color: #74C085; } diff --git a/Launcher/runtime/dialog/overlay/settings/settings.fxml b/Launcher/runtime/dialog/overlay/settings/settings.fxml index 1bc40df3..3602b5d7 100644 --- a/Launcher/runtime/dialog/overlay/settings/settings.fxml +++ b/Launcher/runtime/dialog/overlay/settings/settings.fxml @@ -47,6 +47,17 @@