2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

update to config handling, fix null pointer in pubsub handler, config changes

rename config in jar, config api, fixed null pointer in pubsub listener, use map allow muiltable port and hosts for the cluster
This commit is contained in:
mohammed jasem alaajel 2022-07-22 12:29:39 +04:00
parent 5d1167c20f
commit 0408e2923b
5 changed files with 70 additions and 57 deletions

View File

@ -22,59 +22,31 @@ public class PubSubListener implements Runnable {
@Override @Override
public void run() { public void run() {
RedisTask<Void> subTask = new RedisTask<Void>(plugin.getApi()) { RedisTask<Void> subTask = new RedisTask<Void>(plugin) {
@Override @Override
public Void jedisTask(Jedis jedis) { public Void jedisTask(Jedis jedis) {
try {
jpsh = new JedisPubSubHandler(plugin); jpsh = new JedisPubSubHandler(plugin);
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId()); addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
addedChannels.add("redisbungee-allservers"); addedChannels.add("redisbungee-allservers");
addedChannels.add("redisbungee-data"); addedChannels.add("redisbungee-data");
jedis.subscribe(jpsh, addedChannels.toArray(new String[0])); jedis.subscribe(jpsh, addedChannels.toArray(new String[0]));
} catch (Exception e) {
// FIXME: Extremely ugly hack
// Attempt to unsubscribe this instance and try again.
plugin.logWarn("PubSub error, attempting to recover.");
try {
jpsh.unsubscribe();
} catch (Exception e1) {
/* This may fail with
- java.net.SocketException: Broken pipe
- redis.clients.jedis.exceptions.JedisConnectionException: JedisPubSub was not subscribed to a Jedis instance
*/
}
}
return null; return null;
} }
@Override @Override
public Void clusterJedisTask(JedisCluster jedisCluster) { public Void clusterJedisTask(JedisCluster jedisCluster) {
try {
jpsh = new JedisPubSubHandler(plugin); jpsh = new JedisPubSubHandler(plugin);
addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId()); addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId());
addedChannels.add("redisbungee-allservers"); addedChannels.add("redisbungee-allservers");
addedChannels.add("redisbungee-data"); addedChannels.add("redisbungee-data");
jedisCluster.subscribe(jpsh, addedChannels.toArray(new String[0])); jedisCluster.subscribe(jpsh, addedChannels.toArray(new String[0]));
} catch (Exception e) {
// FIXME: Extremely ugly hack
// Attempt to unsubscribe this instance and try again.
plugin.logWarn("PubSub error, attempting to recover.");
try {
jpsh.unsubscribe();
} catch (Exception e1) {
/* This may fail with
- java.net.SocketException: Broken pipe
- redis.clients.jedis.exceptions.JedisConnectionException: JedisPubSub was not subscribed to a Jedis instance
*/
}
}
return null; return null;
} }
}; };
try { try {
subTask.execute(); subTask.execute();
} catch (JedisConnectionException e) { } catch (Exception e) {
plugin.logWarn("PubSub error, attempting to recover in 5 secs."); plugin.logWarn("PubSub error, attempting to recover in 5 secs.");
plugin.executeAsyncAfter(this, TimeUnit.SECONDS, 5); plugin.executeAsyncAfter(this, TimeUnit.SECONDS, 5);
} }

View File

@ -2,6 +2,8 @@ package com.imaginarycode.minecraft.redisbungee.api;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI;
import com.imaginarycode.minecraft.redisbungee.api.config.ConfigLoader;
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator; import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator;
@ -18,7 +20,7 @@ import java.util.concurrent.TimeUnit;
* @author Ham1255 * @author Ham1255
* @since 0.7.0 * @since 0.7.0
*/ */
public interface RedisBungeePlugin<P> extends EventsPlatform { public interface RedisBungeePlugin<P> extends EventsPlatform, ConfigLoader {
default void initialize() { default void initialize() {
@ -92,8 +94,6 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
long getRedisTime(List<String> timeRes); long getRedisTime(List<String> timeRes);
void loadConfig() throws Exception;
void kickPlayer(UUID playerUniqueId, String message); void kickPlayer(UUID playerUniqueId, String message);
void kickPlayer(String playerName, String message); void kickPlayer(String playerName, String message);

View File

@ -0,0 +1,14 @@
package com.imaginarycode.minecraft.redisbungee.api.config;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
public interface ConfigLoader {
void loadConfig() throws IOException;
Path createConfigFile() throws IOException;
void handleOldConfig(Path path) throws IOException;
}

View File

@ -1,4 +1,4 @@
package com.imaginarycode.minecraft.redisbungee.api; package com.imaginarycode.minecraft.redisbungee.api.config;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
@ -7,12 +7,15 @@ import java.net.InetAddress;
import java.util.List; import java.util.List;
public class RedisBungeeConfiguration { public class RedisBungeeConfiguration {
public static final int CONFIG_VERSION = 1;
private final String proxyId; private final String proxyId;
private final List<InetAddress> exemptAddresses; private final List<InetAddress> exemptAddresses;
private final boolean overrideBungeeCommands;
private static RedisBungeeConfiguration config;
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean overrideBungeeCommands) { private final boolean registerLegacyCommands;
private final boolean overrideBungeeCommands;
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands) {
this.proxyId = proxyId; this.proxyId = proxyId;
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder(); ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
@ -20,7 +23,7 @@ public class RedisBungeeConfiguration {
addressBuilder.add(InetAddresses.forString(s)); addressBuilder.add(InetAddresses.forString(s));
} }
this.exemptAddresses = addressBuilder.build(); this.exemptAddresses = addressBuilder.build();
config = this; this.registerLegacyCommands = registerLegacyCommands;
this.overrideBungeeCommands = overrideBungeeCommands; this.overrideBungeeCommands = overrideBungeeCommands;
} }
@ -32,11 +35,11 @@ public class RedisBungeeConfiguration {
return exemptAddresses; return exemptAddresses;
} }
public boolean doRegisterLegacyCommands() {
return registerLegacyCommands;
}
public boolean doOverrideBungeeCommands() { public boolean doOverrideBungeeCommands() {
return overrideBungeeCommands; return overrideBungeeCommands;
} }
public static RedisBungeeConfiguration getConfig() {
return config;
}
} }

View File

@ -1,3 +1,6 @@
# Config version DO NOT CHANGE!!!!
config-version: 1
# RedisBungee configuration file. # RedisBungee configuration file.
# PLEASE READ THE WIKI: https://github.com/ProxioDev/RedisBungee/wiki # PLEASE READ THE WIKI: https://github.com/ProxioDev/RedisBungee/wiki
@ -5,10 +8,27 @@
# enabling this option will enable cluster mode. # enabling this option will enable cluster mode.
cluster-mode-enabled: false cluster-mode-enabled: false
# The Redis server you use. # FORMAT:
# redis-cluster-servers:
# - host: 127.0.0.1
# port: 2020
# - host: 127.0.0.1
# port: 2021
# - host: 127.0.0.1
# port: 2021
# you can set single server and Jedis will automatically discover cluster nodes,
# but might fail if this single redis node is down when Proxy startup, its recommended put the all the nodes
redis-cluster-servers:
- host: 127.0.0.1
port: 6379
# Get Redis from http://redis.io/ # Get Redis from http://redis.io/
# The Redis server you use.
# these settings are ignored when cluster mode is enabled.
redis-server: 127.0.0.1 redis-server: 127.0.0.1
redis-port: 6379 redis-port: 6379
# OPTIONAL but recommended: If your Redis server uses AUTH, set the password required. # OPTIONAL but recommended: If your Redis server uses AUTH, set the password required.
redis-password: "" redis-password: ""
# Maximum connections that will be maintained to the Redis server. # Maximum connections that will be maintained to the Redis server.
@ -21,8 +41,12 @@ max-redis-connections: 10
# in cluster mode using ssl without password is ignored due fact is not supported in Jedis lib # in cluster mode using ssl without password is ignored due fact is not supported in Jedis lib
useSSL: false useSSL: false
# An identifier for this BungeeCord instance. Will randomly generate if leaving it blank. # An identifier for this BungeeCord / Velocity instance. Will randomly generate if leaving it blank.
server-id: "test1" proxy-id: "test-1"
# Register redis bungee legacy commands
# if this disabled override-bungee-commands will be ignored
register-legacy-commands: false
# Whether or not RedisBungee should install its version of regular BungeeCord commands. # Whether or not RedisBungee should install its version of regular BungeeCord commands.
# Often, the RedisBungee commands are desired, but in some cases someone may wish to # Often, the RedisBungee commands are desired, but in some cases someone may wish to
@ -33,7 +57,7 @@ server-id: "test1"
# #
# Please note that with build 787+, most commands overridden by RedisBungee were moved to # Please note that with build 787+, most commands overridden by RedisBungee were moved to
# modules, and these must be disabled or overridden yourself. # modules, and these must be disabled or overridden yourself.
register-bungee-commands: true override-bungee-commands: false
# A list of IP addresses for which RedisBungee will not modify the response for, useful for automatic # A list of IP addresses for which RedisBungee will not modify the response for, useful for automatic
# restart scripts. # restart scripts.