mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-11-04 20:38:02 +00:00
new config options: handle-motd, reconnect to last server
This commit is contained in:
parent
f96c5759a2
commit
16576ab4c2
@ -51,7 +51,7 @@ public interface ConfigLoader {
|
||||
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);
|
||||
final boolean restoreOldKickBehavior = node.getNode("disable-kick-when-online").getBoolean(false);
|
||||
final boolean kickWhenOnline = node.getNode("kick-when-online").getBoolean(false);
|
||||
String redisPassword = node.getNode("redis-password").getString("");
|
||||
String redisUsername = node.getNode("redis-username").getString("");
|
||||
String proxyId = node.getNode("proxy-id").getString("test-1");
|
||||
@ -86,7 +86,10 @@ public interface ConfigLoader {
|
||||
} else {
|
||||
plugin.logInfo("Loaded proxy id " + proxyId);
|
||||
}
|
||||
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, getMessagesFromPath(createMessagesFile(dataFolder)), restoreOldKickBehavior);
|
||||
boolean reconnectToLastServer = node.getNode("reconnect-to-last-server").getBoolean();
|
||||
boolean handleMotd = node.getNode("handle-motd").getBoolean(true);
|
||||
|
||||
RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands, getMessagesFromPath(createMessagesFile(dataFolder)), kickWhenOnline, reconnectToLastServer, handleMotd);
|
||||
Summoner<?> summoner;
|
||||
RedisBungeeMode redisBungeeMode;
|
||||
if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
|
||||
|
@ -25,15 +25,18 @@ public class RedisBungeeConfiguration {
|
||||
}
|
||||
|
||||
private final ImmutableMap<MessageType, String> messages;
|
||||
public static final int CONFIG_VERSION = 1;
|
||||
public static final int CONFIG_VERSION = 2;
|
||||
private final String proxyId;
|
||||
private final List<InetAddress> exemptAddresses;
|
||||
private final boolean registerLegacyCommands;
|
||||
private final boolean overrideBungeeCommands;
|
||||
private final boolean kickWhenOnline;
|
||||
|
||||
private final boolean restoreOldKickBehavior;
|
||||
private final boolean handleReconnectToLastServer;
|
||||
private final boolean handleMotd;
|
||||
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, ImmutableMap<MessageType, String> messages, boolean restoreOldKickBehavior) {
|
||||
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands, ImmutableMap<MessageType, String> messages, boolean kickWhenOnline, boolean handleReconnectToLastServer, boolean handleMotd) {
|
||||
this.proxyId = proxyId;
|
||||
this.messages = messages;
|
||||
ImmutableList.Builder<InetAddress> addressBuilder = ImmutableList.builder();
|
||||
@ -43,7 +46,9 @@ public class RedisBungeeConfiguration {
|
||||
this.exemptAddresses = addressBuilder.build();
|
||||
this.registerLegacyCommands = registerLegacyCommands;
|
||||
this.overrideBungeeCommands = overrideBungeeCommands;
|
||||
this.restoreOldKickBehavior = restoreOldKickBehavior;
|
||||
this.kickWhenOnline = kickWhenOnline;
|
||||
this.handleReconnectToLastServer = handleReconnectToLastServer;
|
||||
this.handleMotd = handleMotd;
|
||||
}
|
||||
|
||||
public String getProxyId() {
|
||||
@ -66,7 +71,17 @@ public class RedisBungeeConfiguration {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public boolean restoreOldKickBehavior() {
|
||||
return restoreOldKickBehavior;
|
||||
public boolean kickWhenOnline() {
|
||||
return kickWhenOnline;
|
||||
}
|
||||
|
||||
public boolean handleMotd() {
|
||||
return this.handleMotd;
|
||||
}
|
||||
|
||||
public boolean handleReconnectToLastServer() {
|
||||
return this.handleReconnectToLastServer;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -74,8 +74,20 @@ override-bungee-commands: false
|
||||
# restart scripts.
|
||||
exempt-ip-addresses: []
|
||||
|
||||
# restore old login when online behavior before 0.9.0 update
|
||||
disable-kick-when-online: false
|
||||
# restore old login behavior before 0.9.0 update
|
||||
# enabled by default
|
||||
# when true: when player login and there is old player with same uuid it will get disconnected as result and new player will login
|
||||
# when false: when a player login but login will fail because old player is still connected.
|
||||
kick-when-online: true
|
||||
|
||||
# enabled by default
|
||||
# this option tells redis-bungee handle motd and set online count, when motd is requested
|
||||
# you can disable this when you want to handle motd yourself, use RedisBungee api to get total players when needed :)
|
||||
handle-motd: true
|
||||
|
||||
# disabled by default
|
||||
# Redis-bungee will attempt to connect player to last server that was stored.
|
||||
reconnect-to-last-server: false
|
||||
|
||||
# Config version DO NOT CHANGE!!!!
|
||||
config-version: 1
|
||||
config-version: 2
|
||||
|
@ -1,2 +1,5 @@
|
||||
# this config file is for messages for players and command messages
|
||||
# Note this uses legacy formating which § for color codes
|
||||
# this might get replaced soon with mini message for both, velocity and bungeecord
|
||||
logged-in-other-location: "§cYou logged in from another location!"
|
||||
already-logged-in: "§cYou are already logged in!"
|
@ -67,7 +67,7 @@ public class BungeePlayerDataManager extends PlayerDataManager<ProxiedPlayer, Po
|
||||
event.registerIntent((Plugin) plugin);
|
||||
// check if online
|
||||
if (getLastOnline(event.getConnection().getUniqueId()) == 0) {
|
||||
if (!plugin.configuration().restoreOldKickBehavior()) {
|
||||
if (!plugin.configuration().kickWhenOnline()) {
|
||||
kickPlayer(event.getConnection().getUniqueId(), plugin.configuration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION));
|
||||
// wait 3 seconds before releasing the event
|
||||
plugin.executeAsyncAfter(() -> event.completeIntent((Plugin) plugin), TimeUnit.SECONDS, 3);
|
||||
|
@ -28,8 +28,7 @@ import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.MultiMapSerialization.serializeMultimap;
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.MultiMapSerialization.serializeMultiset;
|
||||
import static com.imaginarycode.minecraft.redisbungee.api.util.serialize.MultiMapSerialization.*;
|
||||
|
||||
public class RedisBungeeListener implements Listener {
|
||||
|
||||
@ -41,14 +40,11 @@ public class RedisBungeeListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPing(ProxyPingEvent event) {
|
||||
if (plugin.configuration().getExemptAddresses().contains(event.getConnection().getAddress().getAddress())) {
|
||||
return;
|
||||
}
|
||||
if (!plugin.configuration().handleMotd()) return;
|
||||
if (plugin.configuration().getExemptAddresses().contains(event.getConnection().getAddress().getAddress())) return;
|
||||
ServerInfo forced = AbstractReconnectHandler.getForcedHost(event.getConnection());
|
||||
|
||||
if (forced != null && event.getConnection().getListener().isPingPassthrough()) {
|
||||
return;
|
||||
}
|
||||
if (forced != null && event.getConnection().getListener().isPingPassthrough()) return;
|
||||
event.getResponse().getPlayers().setOnline(plugin.proxyDataManager().totalNetworkPlayers());
|
||||
}
|
||||
|
||||
|
@ -41,9 +41,9 @@ public class RedisBungeeListener {
|
||||
|
||||
@Subscribe(order = PostOrder.LAST) // some plugins changes it online players so we need to be executed as last
|
||||
public void onPing(ProxyPingEvent event) {
|
||||
if (plugin.configuration().getExemptAddresses().contains(event.getConnection().getRemoteAddress().getAddress())) {
|
||||
return;
|
||||
}
|
||||
if (!plugin.configuration().handleMotd()) return;
|
||||
if (plugin.configuration().getExemptAddresses().contains(event.getConnection().getRemoteAddress().getAddress())) return;
|
||||
|
||||
ServerPing.Builder ping = event.getPing().asBuilder();
|
||||
ping.onlinePlayers(plugin.proxyDataManager().totalNetworkPlayers());
|
||||
event.setPing(ping.build());
|
||||
|
@ -71,7 +71,7 @@ public class VelocityPlayerDataManager extends PlayerDataManager<Player, PostLog
|
||||
public void onLoginEvent(LoginEvent event, Continuation continuation) {
|
||||
// check if online
|
||||
if (getLastOnline(event.getPlayer().getUniqueId()) == 0) {
|
||||
if (!plugin.configuration().restoreOldKickBehavior()) {
|
||||
if (!plugin.configuration().kickWhenOnline()) {
|
||||
kickPlayer(event.getPlayer().getUniqueId(), plugin.configuration().getMessages().get(RedisBungeeConfiguration.MessageType.LOGGED_IN_OTHER_LOCATION));
|
||||
// wait 3 seconds before releasing the event
|
||||
plugin.executeAsyncAfter(continuation::resume, TimeUnit.SECONDS, 3);
|
||||
|
Loading…
Reference in New Issue
Block a user