Waterfall/BungeeCord-Patches/0025-Improve-ServerKickEvent.patch
Shane Freeder 25ecd402f3
Updated Upstream (BungeeCord)
Upstream has released updates that appear 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:
1a807731 #3567: Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.2 to 3.6.3
772ad995 #3566: Bump actions/setup-java from 3 to 4
2431c40a #3562: Bump io.netty:netty-bom from 4.1.100.Final to 4.1.101.Final
8144ae8d #3555: Bump com.mysql:mysql-connector-j from 8.1.0 to 8.2.0
0757c39a Attempt upgrade of resolver libraries
2023-12-13 15:18:04 +00:00

152 lines
6.9 KiB
Diff

From 3955eb202eed2e2b2b49b8c403b0a72ad40f8f97 Mon Sep 17 00:00:00 2001
From: Nathan Poirier <nathan@poirier.io>
Date: Tue, 28 Jun 2016 23:00:49 -0500
Subject: [PATCH] Improve ServerKickEvent
ServerKickEvent traditionally will only fire if the server sends a kick packet. During a server shutdown, or server crash this event would not fire for most players. While ServerDisconnectEvent is fired it does not tell us if it was a kick/shutdown/server crash. This improvement fires the ServerKickEvent for server caused disconnections, and adds a Cause to the kick event.
diff --git a/api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java b/api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java
index 3f9efaa8..5d2597ad 100644
--- a/api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java
+++ b/api/src/main/java/net/md_5/bungee/api/event/ServerKickEvent.java
@@ -44,6 +44,12 @@ public class ServerKickEvent extends Event implements Cancellable
* State in which the kick occured.
*/
private State state;
+ // Waterfall start
+ /**
+ * Circumstances which led to the kick.
+ */
+ private Cause cause;
+ // Waterfall end
public enum State
{
@@ -51,6 +57,13 @@ public class ServerKickEvent extends Event implements Cancellable
CONNECTING, CONNECTED, UNKNOWN;
}
+ // Waterfall start
+ public enum Cause
+ {
+ SERVER, LOST_CONNECTION, EXCEPTION, UNKNOWN;
+ }
+ // Waterfall end
+
@Deprecated
public ServerKickEvent(ProxiedPlayer player, BaseComponent[] kickReasonComponent, ServerInfo cancelServer)
{
@@ -69,14 +82,29 @@ public class ServerKickEvent extends Event implements Cancellable
this( player, kickedFrom, TextComponent.fromArray( kickReasonComponent ), cancelServer, state );
}
- public ServerKickEvent(ProxiedPlayer player, ServerInfo kickedFrom, BaseComponent reason, ServerInfo cancelServer, State state)
+ // Waterfall start
+
+ @Deprecated
+ public ServerKickEvent(ProxiedPlayer player, ServerInfo kickedFrom, BaseComponent kickReasonComponent, ServerInfo cancelServer, State state)
+ {
+ this(player, kickedFrom, kickReasonComponent, cancelServer, state, Cause.UNKNOWN);
+ }
+
+ public ServerKickEvent(ProxiedPlayer player, ServerInfo kickedFrom, BaseComponent[] reason, ServerInfo cancelServer, State state, Cause cause)
+ {
+ this(player, kickedFrom, TextComponent.fromArray(reason), cancelServer, state, cause);
+ }
+
+ public ServerKickEvent(ProxiedPlayer player, ServerInfo kickedFrom, BaseComponent reason, ServerInfo cancelServer, State state, Cause cause)
{
this.player = player;
this.kickedFrom = kickedFrom;
this.reason = reason;
this.cancelServer = cancelServer;
this.state = state;
+ this.cause = cause;
}
+ // Waterfall end
/**
* @return the kick reason
diff --git a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
index a8e938be..43af8888 100644
--- a/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
+++ b/proxy/src/main/java/net/md_5/bungee/ServerConnector.java
@@ -431,7 +431,7 @@ public class ServerConnector extends PacketHandler
ServerKickEvent event = new ServerKickEvent( user, target, new BaseComponent[]
{
kick.getMessage()
- }, def, ServerKickEvent.State.CONNECTING );
+ }, def, ServerKickEvent.State.CONNECTING, ServerKickEvent.Cause.SERVER ); // Waterfall );
if ( event.getKickReason().toLowerCase( Locale.ROOT ).contains( "outdated" ) && def != null )
{
// Pre cancel the event if we are going to try another server
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
index 976c8e26..7e416a6d 100644
--- a/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
+++ b/proxy/src/main/java/net/md_5/bungee/connection/DownstreamBridge.java
@@ -98,16 +98,19 @@ public class DownstreamBridge extends PacketHandler
return;
}
+ // Waterfall start
ServerInfo def = con.updateAndGetNextServer( server.getInfo() );
- if ( def != null )
+ ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, server.getInfo(), TextComponent.fromLegacyText( bungee.getTranslation( "server_went_down" ) ), def, ServerKickEvent.State.CONNECTED, ServerKickEvent.Cause.EXCEPTION ) );
+ if ( event.isCancelled() && event.getCancelServer() != null )
{
server.setObsolete( true );
- con.connectNow( def, ServerConnectEvent.Reason.SERVER_DOWN_REDIRECT );
- con.sendMessage( bungee.getTranslation( "server_went_down" ) );
- } else
+ con.connectNow( event.getCancelServer(), ServerConnectEvent.Reason.SERVER_DOWN_REDIRECT );
+ }
+ else
{
- con.disconnect( Util.exception( t ) );
+ con.disconnect0( event.getReason() );
}
+ // Waterfall end
}
@Override
@@ -122,7 +125,19 @@ public class DownstreamBridge extends PacketHandler
if ( !server.isObsolete() )
{
- con.disconnect( bungee.getTranslation( "lost_connection" ) );
+ // Waterfall start
+ ServerInfo def = con.updateAndGetNextServer( server.getInfo() );
+ ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, server.getInfo(), TextComponent.fromLegacyText( bungee.getTranslation( "lost_connection" ) ), def, ServerKickEvent.State.CONNECTED, ServerKickEvent.Cause.LOST_CONNECTION ) );
+ if ( event.isCancelled() && event.getCancelServer() != null )
+ {
+ server.setObsolete( true );
+ con.connectNow( event.getCancelServer() );
+ }
+ else
+ {
+ con.disconnect0( event.getReason() );
+ }
+ // Waterfall end
}
ServerDisconnectEvent serverDisconnectEvent = new ServerDisconnectEvent( con, server.getInfo() );
@@ -633,10 +648,14 @@ public class DownstreamBridge extends PacketHandler
public void handle(Kick kick) throws Exception
{
ServerInfo def = con.updateAndGetNextServer( server.getInfo() );
+ if ( java.util.Objects.equals( server.getInfo(), def ) )
+ {
+ def = null;
+ }
ServerKickEvent event = bungee.getPluginManager().callEvent( new ServerKickEvent( con, server.getInfo(), new BaseComponent[]
{
kick.getMessage()
- }, def, ServerKickEvent.State.CONNECTED ) );
+ }, def, ServerKickEvent.State.CONNECTED, ServerKickEvent.Cause.SERVER ) ); // Waterfall
if ( event.isCancelled() && event.getCancelServer() != null )
{
con.connectNow( event.getCancelServer(), ServerConnectEvent.Reason.KICK_REDIRECT );
--
2.43.0