From 79a7258fd1df227d3cba040f0568bc6fb2b88883 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Mon, 13 Apr 2020 11:10:53 +0100 Subject: [PATCH] Added warning message if chat message is longer than 256 characters. --- .../BedrockCommandRequestTranslator.java | 9 ++++++++- .../bedrock/BedrockTextTranslator.java | 18 ++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java index 28cbf4c41..47895666c 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockCommandRequestTranslator.java @@ -45,7 +45,14 @@ public class BedrockCommandRequestTranslator extends PacketTranslator 256) { + session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent."); + return; + } + + ClientChatPacket chatPacket = new ClientChatPacket(message); session.getDownstream().getSession().send(chatPacket); } } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java index 1c8416310..89766be3b 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/bedrock/BedrockTextTranslator.java @@ -38,12 +38,26 @@ public class BedrockTextTranslator extends PacketTranslator { @Override public void translate(TextPacket packet, GeyserSession session) { if (packet.getMessage().charAt(0) == '.') { - ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage().replace(".", "/")); + String message = packet.getMessage().replace(".", "/").trim(); + + if (message.length() > 256) { + session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent."); + return; + } + + ClientChatPacket chatPacket = new ClientChatPacket(message); session.getDownstream().getSession().send(chatPacket); return; } - ClientChatPacket chatPacket = new ClientChatPacket(packet.getMessage()); + String message = packet.getMessage().trim(); + + if (message.length() > 256) { + session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent."); + return; + } + + ClientChatPacket chatPacket = new ClientChatPacket(message); session.getDownstream().getSession().send(chatPacket); } }