mirror of
https://github.com/PaperMC/Waterfall.git
synced 2024-12-01 06:33:39 +01:00
59 lines
2.2 KiB
Diff
59 lines
2.2 KiB
Diff
From 68af736ef6664d9e53c126cc7e43fbc6ec60afa7 Mon Sep 17 00:00:00 2001
|
|
From: Tux <write@imaginarycode.com>
|
|
Date: Tue, 25 Oct 2016 12:34:41 -0400
|
|
Subject: [PATCH] Validate that chat messages are non-blank
|
|
|
|
|
|
diff --git a/proxy/src/main/java/io/github/waterfallmc/waterfall/StringUtil.java b/proxy/src/main/java/io/github/waterfallmc/waterfall/StringUtil.java
|
|
new file mode 100644
|
|
index 0000000..d294dda
|
|
--- /dev/null
|
|
+++ b/proxy/src/main/java/io/github/waterfallmc/waterfall/StringUtil.java
|
|
@@ -0,0 +1,22 @@
|
|
+package io.github.waterfallmc.waterfall;
|
|
+
|
|
+import lombok.AccessLevel;
|
|
+import lombok.NoArgsConstructor;
|
|
+
|
|
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
|
+public class StringUtil {
|
|
+ public static boolean isBlank(String str) {
|
|
+ if (str.isEmpty()) {
|
|
+ return true;
|
|
+ }
|
|
+
|
|
+ int l = str.length();
|
|
+ for (int i = 0; i < l; i++) {
|
|
+ if (!Character.isWhitespace(str.charAt(i))) {
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+}
|
|
\ No newline at end of file
|
|
diff --git a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
|
|
index 618e76e..9e753d5 100644
|
|
--- a/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
|
|
+++ b/proxy/src/main/java/net/md_5/bungee/connection/UpstreamBridge.java
|
|
@@ -1,6 +1,7 @@
|
|
package net.md_5.bungee.connection;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
+import io.github.waterfallmc.waterfall.StringUtil;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import net.md_5.bungee.BungeeCord;
|
|
@@ -114,6 +115,7 @@ public class UpstreamBridge extends PacketHandler
|
|
{
|
|
int maxLength = ( con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_11 ) ? 256 : 100;
|
|
Preconditions.checkArgument( chat.getMessage().length() <= maxLength, "Chat message too long" ); // Mojang limit, check on updates
|
|
+ Preconditions.checkArgument(!StringUtil.isBlank(chat.getMessage()), "Chat message is empty");
|
|
|
|
ChatEvent chatEvent = new ChatEvent( con, con.getServer(), chat.getMessage() );
|
|
if ( !bungee.getPluginManager().callEvent( chatEvent ).isCancelled() )
|
|
--
|
|
2.10.0
|
|
|