2021-01-29 11:35:23 +01:00
|
|
|
From 4de2289a69e998b32e548dc57e4819cd138e1611 Mon Sep 17 00:00:00 2001
|
2019-03-21 05:41:13 +01:00
|
|
|
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
|
2021-01-29 11:35:23 +01:00
|
|
|
index 0cef9430..d51a3142 100644
|
2019-03-21 05:41:13 +01:00
|
|
|
--- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
|
|
|
|
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
|
2021-01-29 11:35:23 +01:00
|
|
|
@@ -56,6 +56,20 @@ public abstract class DefinedPacket
|
|
|
|
return s;
|
2019-03-21 05:41:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // 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 );
|
|
|
|
+ }
|
|
|
|
+ // 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
|
2020-10-23 04:01:15 +02:00
|
|
|
index 7a0a1ce7..828a5dbe 100644
|
2019-03-21 05:41:13 +01:00
|
|
|
--- 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
|
2020-10-23 04:01:15 +02:00
|
|
|
@@ -40,6 +40,11 @@ public class Chat extends DefinedPacket
|
2019-03-21 05:41:13 +01:00
|
|
|
@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 )
|
|
|
|
{
|
2020-10-23 04:01:15 +02:00
|
|
|
@@ -54,6 +59,11 @@ public class Chat extends DefinedPacket
|
2019-03-21 05:41:13 +01:00
|
|
|
@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 )
|
|
|
|
{
|
|
|
|
--
|
2021-01-29 11:35:23 +01:00
|
|
|
2.30.0
|
2019-03-21 05:41:13 +01:00
|
|
|
|