From 6719858de1afd34aeb2db211d38e5bc35f4a438c Mon Sep 17 00:00:00 2001 From: William Date: Fri, 21 Jan 2022 00:57:16 +0000 Subject: [PATCH] Add SSL connection option for Redis --- .../husksync/bukkit/config/ConfigLoader.java | 1 + bukkit/src/main/resources/config.yml | 1 + .../husksync/bungeecord/config/ConfigLoader.java | 1 + .../src/main/java/me/william278/husksync/Settings.java | 1 + .../me/william278/husksync/redis/RedisListener.java | 6 ++++-- common/src/main/resources/proxy-config.yml | 1 + .../husksync/velocity/config/ConfigLoader.java | 10 +++++----- 7 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bukkit/src/main/java/me/william278/husksync/bukkit/config/ConfigLoader.java b/bukkit/src/main/java/me/william278/husksync/bukkit/config/ConfigLoader.java index 21d0b7df..609613cb 100644 --- a/bukkit/src/main/java/me/william278/husksync/bukkit/config/ConfigLoader.java +++ b/bukkit/src/main/java/me/william278/husksync/bukkit/config/ConfigLoader.java @@ -12,6 +12,7 @@ public class ConfigLoader { Settings.redisHost = config.getString("redis_settings.host", "localhost"); Settings.redisPort = config.getInt("redis_settings.port", 6379); Settings.redisPassword = config.getString("redis_settings.password", ""); + Settings.redisSSL = config.getBoolean("redis_settings.use_ssl", false); Settings.syncInventories = config.getBoolean("synchronisation_settings.inventories", true); Settings.syncEnderChests = config.getBoolean("synchronisation_settings.ender_chests", true); diff --git a/bukkit/src/main/resources/config.yml b/bukkit/src/main/resources/config.yml index f42bd593..a4b1da83 100644 --- a/bukkit/src/main/resources/config.yml +++ b/bukkit/src/main/resources/config.yml @@ -2,6 +2,7 @@ redis_settings: host: 'localhost' port: 6379 password: '' + use_ssl: false synchronisation_settings: inventories: true ender_chests: true diff --git a/bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigLoader.java b/bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigLoader.java index 5880f3b2..d088356a 100644 --- a/bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigLoader.java +++ b/bungeecord/src/main/java/me/william278/husksync/bungeecord/config/ConfigLoader.java @@ -42,6 +42,7 @@ public class ConfigLoader { Settings.redisHost = config.getString("redis_settings.host", "localhost"); Settings.redisPort = config.getInt("redis_settings.port", 6379); Settings.redisPassword = config.getString("redis_settings.password", ""); + Settings.redisSSL = config.getBoolean("redis_settings.use_ssl", false); Settings.dataStorageType = Settings.DataStorageType.valueOf(config.getString("data_storage_settings.database_type", "sqlite").toUpperCase()); if (Settings.dataStorageType == Settings.DataStorageType.MYSQL) { diff --git a/common/src/main/java/me/william278/husksync/Settings.java b/common/src/main/java/me/william278/husksync/Settings.java index 39fa73b0..ab5e0590 100644 --- a/common/src/main/java/me/william278/husksync/Settings.java +++ b/common/src/main/java/me/william278/husksync/Settings.java @@ -21,6 +21,7 @@ public class Settings { public static String redisHost; public static int redisPort; public static String redisPassword; + public static boolean redisSSL; /* * Bungee / Proxy server-only settings diff --git a/common/src/main/java/me/william278/husksync/redis/RedisListener.java b/common/src/main/java/me/william278/husksync/redis/RedisListener.java index e12a82c4..6288476f 100644 --- a/common/src/main/java/me/william278/husksync/redis/RedisListener.java +++ b/common/src/main/java/me/william278/husksync/redis/RedisListener.java @@ -27,13 +27,15 @@ public abstract class RedisListener { jedisPool = new JedisPool(new JedisPoolConfig(), Settings.redisHost, Settings.redisPort, - 0); + 0, + Settings.redisSSL); } else { jedisPool = new JedisPool(new JedisPoolConfig(), Settings.redisHost, Settings.redisPort, 0, - Settings.redisPassword); + Settings.redisPassword, + Settings.redisSSL); } } diff --git a/common/src/main/resources/proxy-config.yml b/common/src/main/resources/proxy-config.yml index 0da450ad..9f35fb7f 100644 --- a/common/src/main/resources/proxy-config.yml +++ b/common/src/main/resources/proxy-config.yml @@ -3,6 +3,7 @@ redis_settings: host: 'localhost' port: 6379 password: '' + use_ssl: false data_storage_settings: database_type: 'sqlite' mysql_settings: diff --git a/velocity/src/main/java/me/william278/husksync/velocity/config/ConfigLoader.java b/velocity/src/main/java/me/william278/husksync/velocity/config/ConfigLoader.java index a6fc6d83..9e98d716 100644 --- a/velocity/src/main/java/me/william278/husksync/velocity/config/ConfigLoader.java +++ b/velocity/src/main/java/me/william278/husksync/velocity/config/ConfigLoader.java @@ -31,25 +31,24 @@ public class ConfigLoader { } private static String getConfigString(ConfigurationNode rootNode, String defaultValue, String... nodePath) { - return !rootNode.getNode((Object[]) nodePath).isVirtual() ? rootNode.getNode((Object[])nodePath).getString() : defaultValue; + return !rootNode.getNode((Object[]) nodePath).isVirtual() ? rootNode.getNode((Object[]) nodePath).getString() : defaultValue; } @SuppressWarnings("SameParameterValue") private static boolean getConfigBoolean(ConfigurationNode rootNode, boolean defaultValue, String... nodePath) { - return !rootNode.getNode((Object[]) nodePath).isVirtual() ? rootNode.getNode((Object[])nodePath).getBoolean() : defaultValue; + return !rootNode.getNode((Object[]) nodePath).isVirtual() ? rootNode.getNode((Object[]) nodePath).getBoolean() : defaultValue; } private static int getConfigInt(ConfigurationNode rootNode, int defaultValue, String... nodePath) { - return !rootNode.getNode((Object[]) nodePath).isVirtual() ? rootNode.getNode((Object[])nodePath).getInt() : defaultValue; + return !rootNode.getNode((Object[]) nodePath).isVirtual() ? rootNode.getNode((Object[]) nodePath).getInt() : defaultValue; } private static long getConfigLong(ConfigurationNode rootNode, long defaultValue, String... nodePath) { - return !rootNode.getNode((Object[])nodePath).isVirtual() ? rootNode.getNode((Object[])nodePath).getLong() : defaultValue; + return !rootNode.getNode((Object[]) nodePath).isVirtual() ? rootNode.getNode((Object[]) nodePath).getLong() : defaultValue; } public static void loadSettings(ConfigurationNode loadedConfig) throws IllegalArgumentException { ConfigurationNode config = copyDefaults(loadedConfig); - //ConfigurationNode config = copyDefaults(loadedConfig); Settings.language = getConfigString(config, "en-gb", "language"); @@ -58,6 +57,7 @@ public class ConfigLoader { Settings.redisHost = getConfigString(config, "localhost", "redis_settings", "host"); Settings.redisPort = getConfigInt(config, 6379, "redis_settings", "port"); Settings.redisPassword = getConfigString(config, "", "redis_settings", "password"); + Settings.redisSSL = getConfigBoolean(config, false, "redis_settings", "use_ssl"); Settings.dataStorageType = Settings.DataStorageType.valueOf(getConfigString(config, "sqlite", "data_storage_settings", "database_type").toUpperCase()); if (Settings.dataStorageType == Settings.DataStorageType.MYSQL) {