Skip to content

Commit

Permalink
Merge branch 'floodgate-2.0' of https://github.com/Tim203/Geyser into…
Browse files Browse the repository at this point in the history
… floodgate-2.0
  • Loading branch information
Camotoy committed Dec 20, 2020
2 parents c937a8a + d6c2507 commit b0aceef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static BedrockData fromString(String data) {
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
);
}

Expand All @@ -93,6 +93,7 @@ public String toString() {
// 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");
}
}
21 changes: 14 additions & 7 deletions common/src/main/java/org/geysermc/floodgate/util/RawSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
package org.geysermc.floodgate.util;

import lombok.AllArgsConstructor;
import lombok.ToString;

import java.nio.ByteBuffer;
import java.util.Base64;

import static java.lang.String.format;

@AllArgsConstructor
@ToString
public final class RawSkin {
public int width;
public int height;
Expand All @@ -44,27 +42,36 @@ 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;
}

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
));
}

// 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!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit b0aceef

Please sign in to comment.