mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-11-16 07:15:14 +01:00
d61b93a1e7
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: 75af27ac Fix missing static on ChatColor.values d0fd673b Minecraft 1.16 support + RGB ChatColor preview
77 lines
2.9 KiB
Diff
77 lines
2.9 KiB
Diff
From d787491efd13f07ef27ced2319979b24b72847a0 Mon Sep 17 00:00:00 2001
|
|
From: kashike <kashike@vq.lc>
|
|
Date: Wed, 20 Mar 2019 21:39:12 -0700
|
|
Subject: [PATCH] Use proper max length for serverbound chat packet
|
|
|
|
|
|
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
|
|
index 57155c3b..9951c1f9 100644
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
|
|
@@ -37,6 +37,34 @@ public abstract class DefinedPacket
|
|
return new String( b, Charsets.UTF_8 );
|
|
}
|
|
|
|
+ // Waterfall start
|
|
+ public static void writeString(String s, final int maxLength, ByteBuf buf)
|
|
+ {
|
|
+ if ( s.length() > maxLength )
|
|
+ {
|
|
+ throw new OverflowPacketException( String.format( "Cannot send string longer than %s (got %s characters)", maxLength, s.length() ) );
|
|
+ }
|
|
+
|
|
+ byte[] b = s.getBytes( Charsets.UTF_8 );
|
|
+ writeVarInt( b.length, buf );
|
|
+ buf.writeBytes( b );
|
|
+ }
|
|
+
|
|
+ public static String readString(ByteBuf buf, final int maxLength)
|
|
+ {
|
|
+ int len = readVarInt( buf );
|
|
+ if ( len > maxLength )
|
|
+ {
|
|
+ throw new OverflowPacketException( String.format( "Cannot receive string longer than %s (got %s characters)", maxLength, len ) );
|
|
+ }
|
|
+
|
|
+ byte[] b = new byte[ len ];
|
|
+ buf.readBytes( b );
|
|
+
|
|
+ return new String( b, Charsets.UTF_8 );
|
|
+ }
|
|
+ // Waterfall end
|
|
+
|
|
public static void writeArray(byte[] b, ByteBuf buf)
|
|
{
|
|
if ( b.length > Short.MAX_VALUE )
|
|
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java
|
|
index b5615a9f..d2a4dea6 100644
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Chat.java
|
|
@@ -35,6 +35,11 @@ public class Chat extends DefinedPacket
|
|
@Override
|
|
public void read(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
|
{
|
|
+ // Waterfall start
|
|
+ if (direction == ProtocolConstants.Direction.TO_CLIENT) {
|
|
+ this.message = readString(buf, Short.MAX_VALUE * 8 + 8);
|
|
+ } else
|
|
+ // Waterfall end
|
|
message = readString( buf );
|
|
if ( direction == ProtocolConstants.Direction.TO_CLIENT )
|
|
{
|
|
@@ -49,6 +54,11 @@ public class Chat extends DefinedPacket
|
|
@Override
|
|
public void write(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion)
|
|
{
|
|
+ // Waterfall start
|
|
+ if (direction == ProtocolConstants.Direction.TO_CLIENT) {
|
|
+ writeString(this.message, Short.MAX_VALUE * 8 + 8, buf);
|
|
+ } else
|
|
+ // Waterfall end
|
|
writeString( message, buf );
|
|
if ( direction == ProtocolConstants.Direction.TO_CLIENT )
|
|
{
|
|
--
|
|
2.27.0
|
|
|