Waterfall/BungeeCord-Patches/0014-Allow-removing-servers-or-changing-addresses-on-relo.patch
Shane Freeder cca83dfaf6
Updated Upstream (BungeeCord)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

BungeeCord Changes:
a3ab2bf5 Update checkstyle
adee7bd2 Source jar does not need to fork build
7bd8a027 Always print remote IP in InitialHandler
0cf27a09 Update scriptus
bf673c5d Add pretty colours to console log levels
2235a323 Optimize ColouredWriter slightly
1dee0490 Don't send/construct redundant kick messages
e9ba95b9 Don't log full CorruptedFrameException
d3bd7852 #2762: Work correctly with disabled timeout
3ce4132c Switch keepalive queue to ArrayDeque
ce2dcaf7 #2763: Fix .DS_Store entry in .gitignore
cf72c3a7 Show slow event times in milliseconds
cd7a3ab2 #2758: Improve server list ping response where remote ping failed
0a4b9b49 #2752: Configurable connect and ping timeouts
2020-02-01 15:39:53 +00:00

84 lines
4.5 KiB
Diff

From 08bece5292489452ccba95c8847398db189d9a11 Mon Sep 17 00:00:00 2001
From: Techcable <Techcable@outlook.com>
Date: Thu, 28 Jan 2016 15:13:29 -0700
Subject: [PATCH] Allow removing servers or changing addresses on reload
Moves all players on the removed server to the default server.
Address changes also move the players to the default server.
Kicks players on failure to move.
Original Issue: https://github.com/WaterfallMC/Waterfall-Old/issues/17
diff --git a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java
index 56a0f29c..d640313a 100644
--- a/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java
+++ b/proxy/src/main/java/net/md_5/bungee/conf/Configuration.java
@@ -11,12 +11,15 @@ import java.util.UUID;
import java.util.logging.Level;
import javax.imageio.ImageIO;
import lombok.Getter;
+
+import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.Favicon;
import net.md_5.bungee.api.ProxyConfig;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ConfigurationAdapter;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.config.ServerInfo;
+import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.util.CaseInsensitiveMap;
import net.md_5.bungee.util.CaseInsensitiveSet;
@@ -111,20 +114,38 @@ public abstract class Configuration implements ProxyConfig
servers = new CaseInsensitiveMap<>( newServers );
} else
{
- for ( ServerInfo oldServer : servers.values() )
- {
- // Don't allow servers to be removed
- Preconditions.checkArgument( newServers.containsKey( oldServer.getName() ), "Server %s removed on reload!", oldServer.getName() );
- }
+ Map<String, ServerInfo> oldServers = this.servers;
- // Add new servers
- for ( Map.Entry<String, ServerInfo> newServer : newServers.entrySet() )
+ for ( ServerInfo oldServer : oldServers.values() )
{
- if ( !servers.containsValue( newServer.getValue() ) )
- {
- servers.put( newServer.getKey(), newServer.getValue() );
+ ServerInfo newServer = newServers.get(oldServer.getName());
+ if ((newServer == null || !oldServer.getAddress().equals(newServer.getAddress())) && !oldServer.getPlayers().isEmpty()) {
+ BungeeCord.getInstance().getLogger().info("Moving players off of server: " + oldServer.getName());
+ // The server is being removed, or having it's address changed
+ for (ProxiedPlayer player : oldServer.getPlayers()) {
+ ListenerInfo listener = player.getPendingConnection().getListener();
+ String destinationName = newServers.get(listener.getDefaultServer()) == null ? listener.getDefaultServer() : listener.getFallbackServer();
+ ServerInfo destination = newServers.get(destinationName);
+ if (destination == null) {
+ BungeeCord.getInstance().getLogger().severe("Couldn't find server " + listener.getDefaultServer() + " or " + listener.getFallbackServer() + " to put player " + player.getName() + " on");
+ player.disconnect(BungeeCord.getInstance().getTranslation("fallback_kick", "Not found on reload"));
+ continue;
+ }
+ player.connect(destination, (success, cause) -> {
+ if (!success) {
+ BungeeCord.getInstance().getLogger().log(Level.WARNING, "Failed to connect " + player.getName() + " to " + destination.getName(), cause);
+ player.disconnect(BungeeCord.getInstance().getTranslation("fallback_kick", cause.getCause().getClass().getName()));
+ }
+ });
+ }
+ } else {
+ // This server isn't new or removed, we'll use bungees behavior of just ignoring
+ // any changes to info outside of the address, this is not ideal, but the alternative
+ // requires resetting multiple objects of which have no proper identity
+ newServers.put(oldServer.getName(), oldServer);
}
}
+ this.servers = new CaseInsensitiveMap<>(newServers);
}
for ( ListenerInfo listener : listeners )
--
2.25.0