mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-06 10:45:37 +01:00
d75d7d1edc
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by 2LStudios and as with ANY update, please do your own testing Waterfall Changes:a5c78a9
(Maybe) Fix javadoc searcheb920b8
Updated Upstream (BungeeCord)8e9b90a
fix compile-native not working on linuxee819df
Updated Upstream (BungeeCord)66601f7
[ci skip] link to javadocs page instead of attempting direct
178 lines
7.2 KiB
Diff
178 lines
7.2 KiB
Diff
From cf8b96298bc7e02d04b30aa1dca04968bda068d8 Mon Sep 17 00:00:00 2001
|
|
From: foss-mc <69294560+foss-mc@users.noreply.github.com>
|
|
Date: Wed, 16 Dec 2020 18:06:17 +0800
|
|
Subject: [PATCH] Close connections & Don't flush if not necessary
|
|
|
|
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
|
|
index 0647a774..37784acd 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/connection/InitialHandler.java
|
|
@@ -192,6 +192,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|
}
|
|
|
|
ServerPing legacy = result.getResponse();
|
|
+
|
|
+ // FlameCord - Close and return if legacy == null
|
|
+ if (legacy == null) {
|
|
+ ch.close();
|
|
+ return;
|
|
+ }
|
|
+
|
|
String kickMessage;
|
|
|
|
if ( v1_5 )
|
|
@@ -257,6 +264,15 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|
@Override
|
|
public void done(ProxyPingEvent pingResult, Throwable error)
|
|
{
|
|
+ // FlameCord - Close if response is null
|
|
+ // FlameCord - Return if connection is closed
|
|
+ if (pingResult.getResponse() == null) {
|
|
+ ch.close();
|
|
+ return;
|
|
+ } else if (ch.isClosed()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
Gson gson = BungeeCord.getInstance().gson;
|
|
unsafe.sendPacket( new StatusResponse( gson.toJson( pingResult.getResponse() ) ) );
|
|
if ( bungee.getConnectionThrottle() != null )
|
|
@@ -286,11 +302,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|
@Override
|
|
public void handle(PingPacket ping) throws Exception
|
|
{
|
|
- if (!ACCEPT_INVALID_PACKETS) {
|
|
- Preconditions.checkState(thisState == State.PING, "Not expecting PING");
|
|
- }
|
|
+ // FlameCord - Never accept invalid packets
|
|
+ Preconditions.checkState( thisState == State.PING, "Not expecting PING" );
|
|
+
|
|
unsafe.sendPacket( ping );
|
|
- disconnect( "" );
|
|
+
|
|
+ // FlameCord - Close instead of disconnect
|
|
+ ch.close();
|
|
}
|
|
|
|
@Override
|
|
@@ -600,7 +618,8 @@ public class InitialHandler extends PacketHandler implements PendingConnection
|
|
{
|
|
if ( canSendKickMessage() )
|
|
{
|
|
- ch.delayedClose( new Kick( ComponentSerializer.toString( reason ) ) );
|
|
+ // FlameCord - Changed delayedClose to close
|
|
+ ch.close( new Kick( ComponentSerializer.toString( reason ) ) );
|
|
} else
|
|
{
|
|
ch.close();
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
|
|
index 6dc5633f..5c05f2b9 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/netty/ChannelWrapper.java
|
|
@@ -80,40 +80,27 @@ public class ChannelWrapper
|
|
|
|
if ( packet != null && ch.isActive() )
|
|
{
|
|
- ch.writeAndFlush( packet ).addListeners( ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, ChannelFutureListener.CLOSE );
|
|
+ // FlameCord - Remove the firing of exceptions on failure
|
|
+ ch.writeAndFlush( packet ).addListeners( ChannelFutureListener.CLOSE );
|
|
} else
|
|
{
|
|
- ch.flush();
|
|
+ // FlameCord - Don't flush just close
|
|
ch.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
+ // FlameCord - Deprecate and "disable" delayedClose because it doesn't have a reason to exist
|
|
+ @Deprecated
|
|
public void delayedClose(final Kick kick)
|
|
{
|
|
- if ( !closing )
|
|
- {
|
|
- closing = true;
|
|
-
|
|
- // Minecraft client can take some time to switch protocols.
|
|
- // Sending the wrong disconnect packet whilst a protocol switch is in progress will crash it.
|
|
- // Delay 250ms to ensure that the protocol switch (if any) has definitely taken place.
|
|
- ch.eventLoop().schedule( new Runnable()
|
|
- {
|
|
-
|
|
- @Override
|
|
- public void run()
|
|
- {
|
|
- close( kick );
|
|
- }
|
|
- }, 250, TimeUnit.MILLISECONDS );
|
|
- }
|
|
+ close(kick);
|
|
}
|
|
|
|
public void addBefore(String baseName, String name, ChannelHandler handler)
|
|
{
|
|
Preconditions.checkState( ch.eventLoop().inEventLoop(), "cannot add handler outside of event loop" );
|
|
- ch.pipeline().flush();
|
|
+ // FlameCord - Don't flush if not necessary
|
|
ch.pipeline().addBefore( baseName, name, handler );
|
|
}
|
|
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
|
|
index 96704d5e..654203ab 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/netty/PipelineUtils.java
|
|
@@ -5,6 +5,7 @@ import io.github.waterfallmc.waterfall.event.ConnectionInitEvent;
|
|
import io.netty.buffer.PooledByteBufAllocator;
|
|
import io.netty.channel.Channel;
|
|
import io.netty.channel.ChannelException;
|
|
+import io.netty.channel.ChannelHandlerContext;
|
|
import io.netty.channel.ChannelInitializer;
|
|
import io.netty.channel.ChannelOption;
|
|
import io.netty.channel.EventLoopGroup;
|
|
@@ -102,6 +103,14 @@ public class PipelineUtils
|
|
|
|
BungeeCord.getInstance().getPluginManager().callEvent(connectionInitEvent);
|
|
}
|
|
+
|
|
+ // FlameCord - Close on exception caught
|
|
+ @Override
|
|
+ public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
|
|
+ cause.printStackTrace();
|
|
+
|
|
+ ctx.close();
|
|
+ }
|
|
};
|
|
public static final Base BASE = new Base();
|
|
private static final KickStringWriter legacyKicker = new KickStringWriter();
|
|
@@ -196,5 +205,13 @@ public class PipelineUtils
|
|
|
|
ch.pipeline().addLast( BOSS_HANDLER, new HandlerBoss() );
|
|
}
|
|
+
|
|
+ // FlameCord - Close on exception caught
|
|
+ @Override
|
|
+ public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
|
|
+ cause.printStackTrace();
|
|
+
|
|
+ ctx.close();
|
|
+ }
|
|
}
|
|
}
|
|
diff --git a/query/src/main/java/net/md_5/bungee/query/QueryHandler.java b/query/src/main/java/net/md_5/bungee/query/QueryHandler.java
|
|
index 0c1ecfb8..b3bdfd05 100644
|
|
--- a/query/src/main/java/net/md_5/bungee/query/QueryHandler.java
|
|
+++ b/query/src/main/java/net/md_5/bungee/query/QueryHandler.java
|
|
@@ -71,6 +71,8 @@ public class QueryHandler extends SimpleChannelInboundHandler<DatagramPacket>
|
|
if ( in.readUnsignedByte() != 0xFE || in.readUnsignedByte() != 0xFD )
|
|
{
|
|
bungee.getLogger().log( Level.WARNING, "Query - Incorrect magic!: {0}", msg.sender() );
|
|
+ // FlameCord - Close on incorrect magic
|
|
+ ctx.close();
|
|
return;
|
|
}
|
|
|
|
--
|
|
2.32.0.windows.1
|
|
|