3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-28 00:50:20 +01:00

Centeralised message length checking and added TODO for localization

Dieser Commit ist enthalten in:
rtm516 2020-04-13 17:49:29 +01:00
Ursprung 79a7258fd1
Commit 55608a2a48
3 geänderte Dateien mit 16 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -34,6 +34,7 @@ import org.geysermc.connector.network.translators.Translator;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket; import com.nukkitx.protocol.bedrock.packet.CommandRequestPacket;
import org.geysermc.connector.utils.MessageUtils;
@Translator(packet = CommandRequestPacket.class) @Translator(packet = CommandRequestPacket.class)
public class BedrockCommandRequestTranslator extends PacketTranslator<CommandRequestPacket> { public class BedrockCommandRequestTranslator extends PacketTranslator<CommandRequestPacket> {
@ -47,10 +48,7 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
} else { } else {
String message = packet.getCommand().trim(); String message = packet.getCommand().trim();
if (message.length() > 256) { if (MessageUtils.isTooLong(message, session)) { return; }
session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent.");
return;
}
ClientChatPacket chatPacket = new ClientChatPacket(message); ClientChatPacket chatPacket = new ClientChatPacket(message);
session.getDownstream().getSession().send(chatPacket); session.getDownstream().getSession().send(chatPacket);

Datei anzeigen

@ -31,6 +31,7 @@ import org.geysermc.connector.network.translators.Translator;
import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.client.ClientChatPacket;
import com.nukkitx.protocol.bedrock.packet.TextPacket; import com.nukkitx.protocol.bedrock.packet.TextPacket;
import org.geysermc.connector.utils.MessageUtils;
@Translator(packet = TextPacket.class) @Translator(packet = TextPacket.class)
public class BedrockTextTranslator extends PacketTranslator<TextPacket> { public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
@ -40,10 +41,7 @@ public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
if (packet.getMessage().charAt(0) == '.') { if (packet.getMessage().charAt(0) == '.') {
String message = packet.getMessage().replace(".", "/").trim(); String message = packet.getMessage().replace(".", "/").trim();
if (message.length() > 256) { if (MessageUtils.isTooLong(message, session)) { return; }
session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent.");
return;
}
ClientChatPacket chatPacket = new ClientChatPacket(message); ClientChatPacket chatPacket = new ClientChatPacket(message);
session.getDownstream().getSession().send(chatPacket); session.getDownstream().getSession().send(chatPacket);
@ -52,10 +50,7 @@ public class BedrockTextTranslator extends PacketTranslator<TextPacket> {
String message = packet.getMessage().trim(); String message = packet.getMessage().trim();
if (message.length() > 256) { if (MessageUtils.isTooLong(message, session)) { return; }
session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent.");
return;
}
ClientChatPacket chatPacket = new ClientChatPacket(message); ClientChatPacket chatPacket = new ClientChatPacket(message);
session.getDownstream().getSession().send(chatPacket); session.getDownstream().getSession().send(chatPacket);

Datei anzeigen

@ -32,6 +32,7 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive; import com.google.gson.JsonPrimitive;
import org.geysermc.connector.network.session.GeyserSession;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -290,4 +291,14 @@ public class MessageUtils {
} }
return ""; return "";
} }
public static boolean isTooLong(String message, GeyserSession session) {
if (message.length() > 256) {
// TODO: Add Geyser localization and translate this based on language
session.sendMessage("Your message is bigger than 256 characters (" + message.length() + ") so it has not been sent.");
return false;
}
return true;
}
} }