mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-22 20:28:00 +00:00
config changes
This commit is contained in:
parent
0408e2923b
commit
5c6cf405fa
@ -1,14 +1,41 @@
|
|||||||
package com.imaginarycode.minecraft.redisbungee.api.config;
|
package com.imaginarycode.minecraft.redisbungee.api.config;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface ConfigLoader {
|
public interface ConfigLoader {
|
||||||
void loadConfig() throws IOException;
|
void loadConfig() throws IOException;
|
||||||
|
|
||||||
Path createConfigFile() throws IOException;
|
default Path createConfigFile(Path dataFolder) throws IOException {
|
||||||
|
if (Files.notExists(dataFolder)) {
|
||||||
|
Files.createDirectory(dataFolder);
|
||||||
|
}
|
||||||
|
Path file = dataFolder.resolve("config.yml");
|
||||||
|
if (Files.notExists(file)) {
|
||||||
|
try (InputStream in = getClass().getClassLoader().getResourceAsStream("config.yml")) {
|
||||||
|
Files.createFile(file);
|
||||||
|
assert in != null;
|
||||||
|
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
default void handleOldConfig(Path dataFolder) throws IOException {
|
||||||
|
Path oldConfigFolder = dataFolder.resolve("old_config");
|
||||||
|
if (Files.notExists(oldConfigFolder)) {
|
||||||
|
Files.createDirectory(oldConfigFolder);
|
||||||
|
}
|
||||||
|
Path oldConfigPath = dataFolder.resolve("config.yml");
|
||||||
|
Files.move(oldConfigPath, oldConfigFolder.resolve(UUID.randomUUID() + "_config.yml"));
|
||||||
|
createConfigFile(dataFolder);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void handleOldConfig(Path path) throws IOException;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,43 +61,39 @@
|
|||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>redis.clients.jedis</pattern>
|
<pattern>redis.clients.jedis</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>redis.clients.util</pattern>
|
<pattern>redis.clients.util</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.apache.commons.pool</pattern>
|
<pattern>org.apache.commons.pool</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>com.squareup.okhttp</pattern>
|
<pattern>com.squareup.okhttp</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okhttp
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okhttp</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>okio</pattern>
|
<pattern>okio</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okio
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okio</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>com.google</pattern>
|
<pattern>com.google</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.google
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.google</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.json</pattern>
|
<pattern>org.json</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.json
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.json</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.checkerframework</pattern>
|
<pattern>org.checkerframework</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.checkframework
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.checkframework</shadedPattern>
|
||||||
</shadedPattern>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>ninja.leaping.configurate</pattern>
|
||||||
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.configurate</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -120,6 +116,11 @@
|
|||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.spongepowered</groupId>
|
||||||
|
<artifactId>configurate-yaml</artifactId>
|
||||||
|
<version>3.7.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -6,7 +6,8 @@ import com.google.common.collect.ImmutableList;
|
|||||||
import com.google.common.collect.ImmutableMultimap;
|
import com.google.common.collect.ImmutableMultimap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner;
|
import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner;
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
|
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.tasks.HeartbeatTask;
|
import com.imaginarycode.minecraft.redisbungee.api.tasks.HeartbeatTask;
|
||||||
@ -32,9 +33,9 @@ import net.md_5.bungee.api.ProxyServer;
|
|||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Event;
|
import net.md_5.bungee.api.plugin.Event;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
|
||||||
import redis.clients.jedis.*;
|
import redis.clients.jedis.*;
|
||||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
@ -43,7 +44,7 @@ import redis.clients.jedis.exceptions.JedisException;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Path;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -806,74 +807,6 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
return this.jedisSummoner;
|
return this.jedisSummoner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loadConfig() throws IOException {
|
|
||||||
if (!getDataFolder().exists() && getDataFolder().mkdir()) {
|
|
||||||
getLogger().info("data folder was created");
|
|
||||||
}
|
|
||||||
File file = new File(getDataFolder(), "config.yml");
|
|
||||||
if (!file.exists() && file.createNewFile()) {
|
|
||||||
try (InputStream in = getResourceAsStream("example_config.yml");
|
|
||||||
OutputStream out = Files.newOutputStream(file.toPath())) {
|
|
||||||
ByteStreams.copy(in, out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final Configuration yamlConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
|
||||||
final String redisServer = yamlConfiguration.getString("redis-server", "localhost");
|
|
||||||
final int redisPort = yamlConfiguration.getInt("redis-port", 6379);
|
|
||||||
final boolean useSSL = yamlConfiguration.getBoolean("useSSL", false);
|
|
||||||
String redisPassword = yamlConfiguration.getString("redis-password", "");
|
|
||||||
String serverId = yamlConfiguration.getString("server-id");
|
|
||||||
// check redis password
|
|
||||||
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
|
||||||
redisPassword = null;
|
|
||||||
getLogger().warning("INSECURE setup was detected Please set password for your redis instance.");
|
|
||||||
}
|
|
||||||
if (!useSSL) {
|
|
||||||
getLogger().warning("INSECURE setup was detected Please setup ssl for your redis instance.");
|
|
||||||
}
|
|
||||||
// Configuration sanity checks.
|
|
||||||
if (serverId == null || serverId.isEmpty()) {
|
|
||||||
/*
|
|
||||||
* this check causes the config comments to disappear somehow
|
|
||||||
* I think due snake yaml limitations so as todo: write our own yaml parser?
|
|
||||||
*/
|
|
||||||
String genId = UUID.randomUUID().toString();
|
|
||||||
getLogger().info("Generated server id " + genId + " and saving it to config.");
|
|
||||||
yamlConfiguration.set("server-id", genId);
|
|
||||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(yamlConfiguration, new File(getDataFolder(), "config.yml"));
|
|
||||||
getLogger().info("Server id was generated: " + serverId);
|
|
||||||
} else {
|
|
||||||
getLogger().info("server id: " + serverId + '.');
|
|
||||||
}
|
|
||||||
this.configuration = new RedisBungeeConfiguration(serverId, yamlConfiguration.getStringList("exempt-ip-addresses"), yamlConfiguration.getBoolean("register-bungee-commands", true));
|
|
||||||
|
|
||||||
if (redisServer != null && !redisServer.isEmpty()) {
|
|
||||||
if (yamlConfiguration.getBoolean("cluster-mode-enabled", false)) {
|
|
||||||
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
|
||||||
poolConfig.setMaxTotal(yamlConfiguration.getInt("max-redis-connections", 8));
|
|
||||||
if (redisPassword != null) {
|
|
||||||
this.jedisSummoner = new ClusterJedisSummoner(new JedisCluster(new HostAndPort(redisServer, redisPort), 5000, 5000, 60, serverId, redisPassword, poolConfig, useSSL));
|
|
||||||
} else {
|
|
||||||
this.jedisSummoner = new ClusterJedisSummoner(new JedisCluster(new HostAndPort(redisServer, redisPort), 5000, 5000, 60, poolConfig));
|
|
||||||
getLogger().warning("SSL option is ignored in Cluster mode if no PASSWORD is set");
|
|
||||||
}
|
|
||||||
this.redisBungeeMode = RedisBungeeMode.CLUSTER;
|
|
||||||
getLogger().log(Level.INFO, "RedisBungee MODE: CLUSTER");
|
|
||||||
} else {
|
|
||||||
JedisPoolConfig config = new JedisPoolConfig();
|
|
||||||
config.setMaxTotal(yamlConfiguration.getInt("max-redis-connections", 8));
|
|
||||||
this.jedisSummoner = new JedisSummoner(new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL));
|
|
||||||
this.redisBungeeMode = RedisBungeeMode.SINGLE;
|
|
||||||
getLogger().log(Level.INFO, "RedisBungee MODE: SINGLE");
|
|
||||||
}
|
|
||||||
|
|
||||||
getLogger().log(Level.INFO, "Successfully connected to Redis.");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("No redis server specified!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kickPlayer(UUID playerUniqueId, String message) {
|
public void kickPlayer(UUID playerUniqueId, String message) {
|
||||||
@ -946,4 +879,86 @@ public class RedisBungeeBungeePlugin extends Plugin implements RedisBungeePlugin
|
|||||||
public Object createPubSubEvent(String channel, String message) {
|
public Object createPubSubEvent(String channel, String message) {
|
||||||
return new PubSubMessageEvent(channel, message);
|
return new PubSubMessageEvent(channel, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadConfig() throws IOException {
|
||||||
|
Path configFile = createConfigFile(getDataFolder().toPath());
|
||||||
|
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
||||||
|
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
||||||
|
if (node.getNode("config-version").getInt(0) != RedisBungeeConfiguration.CONFIG_VERSION) {
|
||||||
|
handleOldConfig(getDataFolder().toPath());
|
||||||
|
node = yamlConfigurationFileLoader.load();
|
||||||
|
}
|
||||||
|
final boolean useSSL = node.getNode("useSSL").getBoolean(false);
|
||||||
|
final boolean overrideBungeeCommands = node.getNode("override-bungee-commands").getBoolean(false);
|
||||||
|
final boolean registerLegacyCommands = node.getNode("register-legacy-commands").getBoolean(false);
|
||||||
|
String redisPassword = node.getNode("redis-password").getString(null);
|
||||||
|
String proxyId = node.getNode("proxy-id").getString("test-1");
|
||||||
|
final int maxConnections = node.getNode("max-redis-connections").getInt(8);
|
||||||
|
List<String> exemptAddresses;
|
||||||
|
try {
|
||||||
|
exemptAddresses = node.getNode("exempt-ip-addresses").getList(TypeToken.of(String.class));
|
||||||
|
} catch (ObjectMappingException e) {
|
||||||
|
exemptAddresses = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// check redis password
|
||||||
|
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
||||||
|
redisPassword = null;
|
||||||
|
getLogger().warning("INSECURE setup was detected Please set password for your redis instance.");
|
||||||
|
} else if (redisPassword == null) {
|
||||||
|
getLogger().warning("INSECURE setup was detected Please set password for your redis instance.");
|
||||||
|
}
|
||||||
|
if (!useSSL) {
|
||||||
|
getLogger().warning("INSECURE setup was detected Please setup ssl for your redis instance.");
|
||||||
|
}
|
||||||
|
// Configuration sanity checks.
|
||||||
|
if (proxyId == null || proxyId.isEmpty()) {
|
||||||
|
String genId = UUID.randomUUID().toString();
|
||||||
|
getLogger().info("Generated proxy id " + genId + " and saving it to config.");
|
||||||
|
node.getNode("proxy-id").setValue(genId);
|
||||||
|
yamlConfigurationFileLoader.save(node);
|
||||||
|
proxyId = genId;
|
||||||
|
getLogger().info("proxy id was generated: " + proxyId);
|
||||||
|
} else {
|
||||||
|
getLogger().info("Loaded proxy id " + proxyId);
|
||||||
|
}
|
||||||
|
this.configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands);
|
||||||
|
|
||||||
|
if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
|
||||||
|
getLogger().info("RedisBungee MODE: CLUSTER");
|
||||||
|
Set<HostAndPort> hostAndPortSet = new HashSet<>();
|
||||||
|
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
||||||
|
poolConfig.setMaxTotal(maxConnections);
|
||||||
|
node.getNode("redis-cluster-servers").getChildrenList().forEach((childNode) -> {
|
||||||
|
Map<Object, ? extends ConfigurationNode> hostAndPort = childNode.getChildrenMap();
|
||||||
|
String host = hostAndPort.get("host").getString();
|
||||||
|
int port = hostAndPort.get("port").getInt();
|
||||||
|
hostAndPortSet.add(new HostAndPort(host, port));
|
||||||
|
});
|
||||||
|
getLogger().info(hostAndPortSet.size() + " cluster nodes were specified");
|
||||||
|
if (hostAndPortSet.isEmpty()) {
|
||||||
|
throw new RuntimeException("No redis cluster servers specified");
|
||||||
|
}
|
||||||
|
if (redisPassword != null) {
|
||||||
|
this.jedisSummoner = new ClusterJedisSummoner(new JedisCluster(hostAndPortSet, 5000, 5000, 60, proxyId, redisPassword, poolConfig, useSSL));
|
||||||
|
} else {
|
||||||
|
getLogger().warning("SSL option is ignored in Cluster mode if no PASSWORD is set");
|
||||||
|
this.jedisSummoner = new ClusterJedisSummoner(new JedisCluster(hostAndPortSet, 5000, 5000, 60, poolConfig));
|
||||||
|
}
|
||||||
|
this.redisBungeeMode = RedisBungeeMode.CLUSTER;
|
||||||
|
} else {
|
||||||
|
getLogger().info("RedisBungee MODE: SINGLE");
|
||||||
|
final String redisServer = node.getNode("redis-server").getString("127.0.0.1");
|
||||||
|
final int redisPort = node.getNode("redis-port").getInt(6379);
|
||||||
|
if (redisServer != null && redisServer.isEmpty()) {
|
||||||
|
throw new RuntimeException("No redis server specified");
|
||||||
|
}
|
||||||
|
JedisPoolConfig config = new JedisPoolConfig();
|
||||||
|
config.setMaxTotal(maxConnections);
|
||||||
|
this.jedisSummoner = new JedisSummoner(new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL));
|
||||||
|
this.redisBungeeMode = RedisBungeeMode.SINGLE;
|
||||||
|
}
|
||||||
|
getLogger().info("Successfully connected to Redis.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,38 +74,31 @@
|
|||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>redis.clients.jedis</pattern>
|
<pattern>redis.clients.jedis</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedis</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>redis.clients.util</pattern>
|
<pattern>redis.clients.util</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.jedisutil</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.apache.commons.pool</pattern>
|
<pattern>org.apache.commons.pool</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.commonspool</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>com.squareup.okhttp</pattern>
|
<pattern>com.squareup.okhttp</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okhttp
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okhttp</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>okio</pattern>
|
<pattern>okio</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okio
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.okio</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.json</pattern>
|
<pattern>org.json</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.json
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.json</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.checkerframework</pattern>
|
<pattern>org.checkerframework</pattern>
|
||||||
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.checkframework
|
<shadedPattern>com.imaginarycode.minecraft.redisbungee.internal.checkframework</shadedPattern>
|
||||||
</shadedPattern>
|
|
||||||
</relocation>
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -9,6 +9,7 @@ import com.google.common.collect.Multimap;
|
|||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.*;
|
import com.imaginarycode.minecraft.redisbungee.api.*;
|
||||||
|
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner;
|
import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner;
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
|
import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
|
||||||
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
|
||||||
@ -54,7 +55,6 @@ import java.io.*;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
@ -831,87 +831,87 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadConfig() throws IOException {
|
public void loadConfig() throws IOException {
|
||||||
if (Files.notExists(getDataFolder())) {
|
Path configFile = createConfigFile(getDataFolder());
|
||||||
try {
|
final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
|
||||||
Files.createDirectory(getDataFolder());
|
ConfigurationNode node = yamlConfigurationFileLoader.load();
|
||||||
getLogger().info("data folder was created");
|
if (node.getNode("config-version").getInt(0) != RedisBungeeConfiguration.CONFIG_VERSION) {
|
||||||
} catch (IOException e) {
|
handleOldConfig(getDataFolder());
|
||||||
getLogger().error("Cannot create data folder", e);
|
node = yamlConfigurationFileLoader.load();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Path file = getDataFolder().resolve("config.yml");
|
|
||||||
if (Files.notExists(file)) {
|
|
||||||
try (InputStream in = getResourceAsStream("example_config.yml")) {
|
|
||||||
Files.createFile(file);
|
|
||||||
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
getLogger().info("config file was created");
|
|
||||||
} catch (IOException e) {
|
|
||||||
getLogger().error("Cannot create configuration", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final YAMLConfigurationLoader yamlConfiguration = YAMLConfigurationLoader.builder().setPath(file).build();
|
|
||||||
ConfigurationNode node = yamlConfiguration.load();
|
|
||||||
final String redisServer = node.getNode("redis-server").getString("127.0.0.1");
|
|
||||||
final int redisPort = node.getNode("redis-port").getInt(6379);
|
|
||||||
final boolean useSSL = node.getNode("useSSL").getBoolean(false);
|
final boolean useSSL = node.getNode("useSSL").getBoolean(false);
|
||||||
|
final boolean overrideBungeeCommands = node.getNode("override-bungee-commands").getBoolean(false);
|
||||||
|
final boolean registerLegacyCommands = node.getNode("register-legacy-commands").getBoolean(false);
|
||||||
String redisPassword = node.getNode("redis-password").getString(null);
|
String redisPassword = node.getNode("redis-password").getString(null);
|
||||||
String serverId = node.getNode("server-id").getString("test-1");
|
String proxyId = node.getNode("proxy-id").getString("test-1");
|
||||||
|
final int maxConnections = node.getNode("max-redis-connections").getInt(8);
|
||||||
|
List<String> exemptAddresses;
|
||||||
|
try {
|
||||||
|
exemptAddresses = node.getNode("exempt-ip-addresses").getList(TypeToken.of(String.class));
|
||||||
|
} catch (ObjectMappingException e) {
|
||||||
|
exemptAddresses = Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
// check redis password
|
// check redis password
|
||||||
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
|
||||||
redisPassword = null;
|
redisPassword = null;
|
||||||
getLogger().warn("INSECURE setup was detected Please set password for your redis instance.");
|
getLogger().warn("INSECURE setup was detected Please set password for your redis instance.");
|
||||||
|
} else if (redisPassword == null) {
|
||||||
|
getLogger().warn("INSECURE setup was detected Please set password for your redis instance.");
|
||||||
}
|
}
|
||||||
if (!useSSL) {
|
if (!useSSL) {
|
||||||
getLogger().warn("INSECURE setup was detected Please setup ssl for your redis instance.");
|
getLogger().warn("INSECURE setup was detected Please setup ssl for your redis instance.");
|
||||||
}
|
}
|
||||||
// Configuration sanity checks.
|
// Configuration sanity checks.
|
||||||
if (serverId == null || serverId.isEmpty()) {
|
if (proxyId == null || proxyId.isEmpty()) {
|
||||||
/*
|
|
||||||
* this check causes the config comments to disappear somehow
|
|
||||||
* I think due snake yaml limitations so as todo: write our own yaml parser?
|
|
||||||
*/
|
|
||||||
String genId = UUID.randomUUID().toString();
|
String genId = UUID.randomUUID().toString();
|
||||||
getLogger().info("Generated server id {} and saving it to config.", genId);
|
getLogger().info("Generated proxy id {} and saving it to config.", genId);
|
||||||
node.getNode("server-id").setValue(genId);
|
node.getNode("proxy-id").setValue(genId);
|
||||||
yamlConfiguration.save(node);
|
yamlConfigurationFileLoader.save(node);
|
||||||
getLogger().info("Server id was generated: {}", serverId);
|
proxyId = genId;
|
||||||
|
getLogger().info("proxy id was generated: {}", proxyId);
|
||||||
} else {
|
} else {
|
||||||
getLogger().info("Loaded server id {}.", serverId);
|
getLogger().info("Loaded proxy id {}.", proxyId);
|
||||||
}
|
|
||||||
try {
|
|
||||||
this.configuration = new RedisBungeeConfiguration(serverId, node.getNode("exempt-ip-addresses").getList(TypeToken.of(String.class)), node.getNode("register-bungee-commands").getBoolean(true));
|
|
||||||
} catch (ObjectMappingException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
|
this.configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands);
|
||||||
|
|
||||||
if (redisServer != null && !redisServer.isEmpty()) {
|
if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
|
||||||
if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
|
getLogger().info("RedisBungee MODE: CLUSTER");
|
||||||
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
Set<HostAndPort> hostAndPortSet = new HashSet<>();
|
||||||
poolConfig.setMaxTotal(node.getNode("max-redis-connections").getInt(8));
|
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
|
||||||
if (redisPassword != null) {
|
poolConfig.setMaxTotal(maxConnections);
|
||||||
this.jedisSummoner = new ClusterJedisSummoner(new JedisCluster(new HostAndPort(redisServer, redisPort), 5000, 5000, 60, serverId, redisPassword, poolConfig, useSSL));
|
node.getNode("redis-cluster-servers").getChildrenList().forEach((childNode) -> {
|
||||||
} else {
|
Map<Object, ? extends ConfigurationNode> hostAndPort = childNode.getChildrenMap();
|
||||||
getLogger().warn("SSL option is ignored in Cluster mode if no PASSWORD is set");
|
String host = hostAndPort.get("host").getString();
|
||||||
this.jedisSummoner = new ClusterJedisSummoner(new JedisCluster(new HostAndPort(redisServer, redisPort), 5000, 5000, 60, poolConfig));
|
int port = hostAndPort.get("port").getInt();
|
||||||
}
|
hostAndPortSet.add(new HostAndPort(host, port));
|
||||||
this.redisBungeeMode = RedisBungeeMode.CLUSTER;
|
});
|
||||||
getLogger().info("RedisBungee MODE: CLUSTER");
|
getLogger().info(hostAndPortSet.size() + " cluster nodes were specified");
|
||||||
} else {
|
if (hostAndPortSet.isEmpty()) {
|
||||||
JedisPoolConfig config = new JedisPoolConfig();
|
throw new RuntimeException("No redis cluster servers specified");
|
||||||
config.setMaxTotal(node.getNode("max-redis-connections").getInt(8));
|
|
||||||
this.jedisSummoner = new JedisSummoner(new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL));
|
|
||||||
this.redisBungeeMode = RedisBungeeMode.SINGLE;
|
|
||||||
getLogger().info("RedisBungee MODE: SINGLE");
|
|
||||||
}
|
}
|
||||||
getLogger().info("Successfully connected to Redis.");
|
if (redisPassword != null) {
|
||||||
|
this.jedisSummoner = new ClusterJedisSummoner(new JedisCluster(hostAndPortSet, 5000, 5000, 60, proxyId, redisPassword, poolConfig, useSSL));
|
||||||
|
} else {
|
||||||
|
getLogger().warn("SSL option is ignored in Cluster mode if no PASSWORD is set");
|
||||||
|
this.jedisSummoner = new ClusterJedisSummoner(new JedisCluster(hostAndPortSet, 5000, 5000, 60, poolConfig));
|
||||||
|
}
|
||||||
|
this.redisBungeeMode = RedisBungeeMode.CLUSTER;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("No redis server specified!");
|
getLogger().info("RedisBungee MODE: SINGLE");
|
||||||
|
final String redisServer = node.getNode("redis-server").getString("127.0.0.1");
|
||||||
|
final int redisPort = node.getNode("redis-port").getInt(6379);
|
||||||
|
if (redisServer != null && redisServer.isEmpty()) {
|
||||||
|
throw new RuntimeException("No redis server specified");
|
||||||
|
}
|
||||||
|
JedisPoolConfig config = new JedisPoolConfig();
|
||||||
|
config.setMaxTotal(maxConnections);
|
||||||
|
this.jedisSummoner = new JedisSummoner(new JedisPool(config, redisServer, redisPort, 0, redisPassword, useSSL));
|
||||||
|
this.redisBungeeMode = RedisBungeeMode.SINGLE;
|
||||||
}
|
}
|
||||||
|
getLogger().info("Successfully connected to Redis.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void kickPlayer(UUID playerUniqueId, String message) {
|
public void kickPlayer(UUID playerUniqueId, String message) {
|
||||||
// first handle on origin proxy if player not found publish the payload
|
// first handle on origin proxy if player not found publish the payload
|
||||||
@ -935,7 +935,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
@Override
|
@Override
|
||||||
public void kickPlayer(String playerName, String message) {
|
public void kickPlayer(String playerName, String message) {
|
||||||
// fetch the uuid
|
// fetch the uuid
|
||||||
UUID playerUUID = this.uuidTranslator.getTranslatedUuid(playerName,true);
|
UUID playerUUID = this.uuidTranslator.getTranslatedUuid(playerName, true);
|
||||||
kickPlayer(playerUUID, message);
|
kickPlayer(playerUUID, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -997,7 +997,7 @@ public class RedisBungeeVelocityPlugin implements RedisBungeePlugin<Player> {
|
|||||||
return this.dataFolder;
|
return this.dataFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final InputStream getResourceAsStream(String name) {
|
public InputStream getResourceAsStream(String name) {
|
||||||
return getClass().getClassLoader().getResourceAsStream(name);
|
return this.getClass().getClassLoader().getResourceAsStream(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user