From d6c2507bb5480d29ab8ca37358f96bd22a7f74df Mon Sep 17 00:00:00 2001 From: Tim203 Date: Sun, 20 Dec 2020 17:34:46 +0100 Subject: [PATCH] Fixed some bugs --- .../geysermc/floodgate/util/BedrockData.java | 5 +++-- .../org/geysermc/floodgate/util/RawSkin.java | 21 ++++++++++++------- .../connector/utils/PluginMessageUtils.java | 7 +------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java index 08c1e28d3..cc8f9eeea 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java +++ b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java @@ -76,7 +76,7 @@ public final class BedrockData { return new BedrockData( split[0], split[1], split[2], Integer.parseInt(split[3]), split[4], Integer.parseInt(split[5]), Integer.parseInt(split[6]), split[7], - linkedPlayer, Boolean.parseBoolean(split[9]), split.length + linkedPlayer, "1".equals(split[8]), split.length ); } @@ -93,6 +93,7 @@ public final class BedrockData { // The format is the same as the order of the fields in this class return version + '\0' + username + '\0' + xuid + '\0' + deviceOs + '\0' + languageCode + '\0' + uiProfile + '\0' + inputMode + '\0' + ip + '\0' + - fromProxy + '\0' + (linkedPlayer != null ? linkedPlayer.toString() : "null"); + (fromProxy ? 1 : 0) + '\0' + + (linkedPlayer != null ? linkedPlayer.toString() : "null"); } } diff --git a/common/src/main/java/org/geysermc/floodgate/util/RawSkin.java b/common/src/main/java/org/geysermc/floodgate/util/RawSkin.java index 6759ffa3c..470b7e24a 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/RawSkin.java +++ b/common/src/main/java/org/geysermc/floodgate/util/RawSkin.java @@ -26,7 +26,6 @@ package org.geysermc.floodgate.util; import lombok.AllArgsConstructor; -import lombok.ToString; import java.nio.ByteBuffer; import java.util.Base64; @@ -34,7 +33,6 @@ import java.util.Base64; import static java.lang.String.format; @AllArgsConstructor -@ToString public final class RawSkin { public int width; public int height; @@ -44,11 +42,20 @@ public final class RawSkin { private RawSkin() { } - public static RawSkin decode(byte[] data) throws InvalidFormatException { - return decode(data, 0); + public static RawSkin decode(byte[] data, int offset) throws InvalidFormatException { + if (data == null || offset < 0 || data.length <= offset) { + return null; + } + if (offset == 0) { + return decode(data); + } + + byte[] rawSkin = new byte[data.length - offset]; + System.arraycopy(data, offset, rawSkin, 0, rawSkin.length); + return decode(rawSkin); } - public static RawSkin decode(byte[] data, int offset) throws InvalidFormatException { + public static RawSkin decode(byte[] data) throws InvalidFormatException { // offset is an amount of bytes before the Base64 starts if (data == null) { return null; @@ -56,7 +63,7 @@ public final class RawSkin { int maxEncodedLength = Base64Utils.getEncodedLength(64 * 64 * 4 + 9); // if the RawSkin is longer then the max Java Edition skin length - if ((data.length - offset) > maxEncodedLength) { + if (data.length > maxEncodedLength) { throw new InvalidFormatException(format( "Encoded data cannot be longer then %s bytes! Got %s", maxEncodedLength, data.length @@ -64,7 +71,7 @@ public final class RawSkin { } // if the encoded data doesn't even contain the width, height (8 bytes, 2 ints) and isAlex - if ((data.length - offset) < Base64Utils.getEncodedLength(9)) { + if (data.length < Base64Utils.getEncodedLength(9)) { throw new InvalidFormatException("Encoded data must be at least 16 bytes long!"); } diff --git a/connector/src/main/java/org/geysermc/connector/utils/PluginMessageUtils.java b/connector/src/main/java/org/geysermc/connector/utils/PluginMessageUtils.java index 4c7547d3a..475380ab3 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/PluginMessageUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/PluginMessageUtils.java @@ -42,12 +42,7 @@ public class PluginMessageUtils { .put(data) .array(); - data = "floodgate:skin\0floodgate:form".getBytes(Charsets.UTF_8); - FLOODGATE_REGISTER_DATA = - ByteBuffer.allocate(data.length + getVarIntLength(data.length)) - .put(writeVarInt(data.length)) - .put(data) - .array(); + FLOODGATE_REGISTER_DATA = "floodgate:skin\0floodgate:form".getBytes(Charsets.UTF_8); } /**