2020-07-19 15:26:04 +02:00
|
|
|
From d0addd4231eb0c95f4b8dcecce83a6d739667003 Mon Sep 17 00:00:00 2001
|
2019-01-17 04:26:52 +01:00
|
|
|
From: creeper123123321 <creeper123123321@gmail.com>
|
|
|
|
Date: Thu, 17 Jan 2019 03:25:59 +0000
|
|
|
|
Subject: [PATCH] Don't use a bytebuf for packet decoding
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
|
2020-07-19 15:26:04 +02:00
|
|
|
index f297620c..c0d37142 100644
|
2019-01-17 04:26:52 +01:00
|
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
|
|
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/Varint21FrameDecoder.java
|
2020-07-19 15:26:04 +02:00
|
|
|
@@ -27,8 +27,7 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
|
|
|
|
|
2019-01-17 04:26:52 +01:00
|
|
|
in.markReaderIndex();
|
|
|
|
|
|
|
|
- final byte[] buf = new byte[ 3 ];
|
|
|
|
- for ( int i = 0; i < buf.length; i++ )
|
|
|
|
+ for ( int i = 0; i < 3; i++ ) // Waterfall
|
|
|
|
{
|
|
|
|
if ( !in.isReadable() )
|
|
|
|
{
|
2020-07-19 15:26:04 +02:00
|
|
|
@@ -36,10 +35,13 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
|
2019-01-17 04:26:52 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
- buf[i] = in.readByte();
|
|
|
|
- if ( buf[i] >= 0 )
|
|
|
|
+ // Waterfall start
|
|
|
|
+ byte read = in.readByte();
|
|
|
|
+ if ( read >= 0 )
|
|
|
|
{
|
|
|
|
- int length = DefinedPacket.readVarInt( Unpooled.wrappedBuffer( buf ) );
|
|
|
|
+ in.resetReaderIndex();
|
|
|
|
+ int length = DefinedPacket.readVarInt( in );
|
|
|
|
+ // Waterfall end
|
2019-09-24 06:46:15 +02:00
|
|
|
if ( false && length == 0) // Waterfall - ignore
|
2019-01-17 04:26:52 +01:00
|
|
|
{
|
|
|
|
throw new CorruptedFrameException( "Empty Packet!" );
|
2020-07-19 15:26:04 +02:00
|
|
|
@@ -49,26 +51,11 @@ public class Varint21FrameDecoder extends ByteToMessageDecoder
|
2019-01-17 04:26:52 +01:00
|
|
|
{
|
|
|
|
in.resetReaderIndex();
|
|
|
|
return;
|
|
|
|
- } else
|
|
|
|
- {
|
|
|
|
- if ( in.hasMemoryAddress() )
|
|
|
|
- {
|
|
|
|
- out.add( in.slice( in.readerIndex(), length ).retain() );
|
|
|
|
- in.skipBytes( length );
|
|
|
|
- } else
|
|
|
|
- {
|
|
|
|
- if ( !DIRECT_WARNING )
|
|
|
|
- {
|
|
|
|
- DIRECT_WARNING = true;
|
|
|
|
- System.out.println( "Netty is not using direct IO buffers." );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // See https://github.com/SpigotMC/BungeeCord/issues/1717
|
|
|
|
- ByteBuf dst = ctx.alloc().directBuffer( length );
|
|
|
|
- in.readBytes( dst );
|
|
|
|
- out.add( dst );
|
|
|
|
- }
|
|
|
|
+ // Waterfall start
|
|
|
|
+ } else {
|
|
|
|
+ out.add(in.readRetainedSlice(length));
|
2019-01-17 05:50:19 +01:00
|
|
|
return;
|
2019-01-17 04:26:52 +01:00
|
|
|
+ // Waterfall end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--
|
2020-07-19 15:26:04 +02:00
|
|
|
2.25.1
|
2019-01-17 04:26:52 +01:00
|
|
|
|