Moved skin uploading to the global api

This commit is contained in:
Tim203 2021-02-12 22:22:45 +01:00
parent cf149b58e0
commit 52ddf8c556
No known key found for this signature in database
GPG key ID: 064EE9F5BF7C3EE8
12 changed files with 363 additions and 200 deletions

View file

@ -37,7 +37,7 @@ import lombok.Getter;
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public final class BedrockData implements Cloneable {
public static final int EXPECTED_LENGTH = 10;
public static final int EXPECTED_LENGTH = 12;
private final String version;
private final String username;
@ -50,19 +50,24 @@ public final class BedrockData implements Cloneable {
private final LinkedPlayer linkedPlayer;
private final boolean fromProxy;
private final int subscribeId;
private final String verifyCode;
private final int dataLength;
public static BedrockData of(String version, String username, String xuid, int deviceOs,
String languageCode, int uiProfile, int inputMode, String ip,
LinkedPlayer linkedPlayer, boolean fromProxy) {
LinkedPlayer linkedPlayer, boolean fromProxy, int subscribeId,
String verifyCode) {
return new BedrockData(version, username, xuid, deviceOs, languageCode, inputMode,
uiProfile, ip, linkedPlayer, fromProxy, EXPECTED_LENGTH);
uiProfile, ip, linkedPlayer, fromProxy, subscribeId, verifyCode, EXPECTED_LENGTH);
}
public static BedrockData of(String version, String username, String xuid, int deviceOs,
String languageCode, int uiProfile, int inputMode, String ip) {
return of(version, username, xuid, deviceOs, languageCode,
uiProfile, inputMode, ip, null, false);
String languageCode, int uiProfile, int inputMode, String ip,
int subscribeId, String verifyCode) {
return of(version, username, xuid, deviceOs, languageCode, uiProfile, inputMode, ip, null,
false, subscribeId, verifyCode);
}
public static BedrockData fromString(String data) {
@ -75,13 +80,14 @@ public final class BedrockData implements Cloneable {
// The format is the same as the order of the fields in this class
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, "1".equals(split[8]), split.length
Integer.parseInt(split[5]), Integer.parseInt(split[6]), split[7], linkedPlayer,
"1".equals(split[9]), Integer.parseInt(split[10]), split[11], split.length
);
}
private static BedrockData emptyData(int dataLength) {
return new BedrockData(null, null, null, -1, null, -1, -1, null, null, false, dataLength);
return new BedrockData(null, null, null, -1, null, -1, -1, null, null, false, -1, null,
dataLength);
}
public boolean hasPlayerLink() {
@ -94,7 +100,8 @@ public final class BedrockData implements Cloneable {
return version + '\0' + username + '\0' + xuid + '\0' + deviceOs + '\0' +
languageCode + '\0' + uiProfile + '\0' + inputMode + '\0' + ip + '\0' +
(fromProxy ? 1 : 0) + '\0' +
(linkedPlayer != null ? linkedPlayer.toString() : "null");
(linkedPlayer != null ? linkedPlayer.toString() : "null") + '\0' +
subscribeId + '\0' + verifyCode;
}
@Override

View file

@ -1,106 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.floodgate.util;
import lombok.AllArgsConstructor;
import java.nio.ByteBuffer;
import java.util.Base64;
import static java.lang.String.format;
@AllArgsConstructor
public final class RawSkin {
public int width;
public int height;
public byte[] data;
public boolean alex;
private RawSkin() {
}
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) 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 > 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 < Base64Utils.getEncodedLength(9)) {
throw new InvalidFormatException("Encoded data must be at least 16 bytes long!");
}
data = Base64.getDecoder().decode(data);
ByteBuffer buffer = ByteBuffer.wrap(data);
RawSkin skin = new RawSkin();
skin.width = buffer.getInt();
skin.height = buffer.getInt();
if (buffer.remaining() - 1 != (skin.width * skin.height * 4)) {
throw new InvalidFormatException(format(
"Expected skin length to be %s, got %s",
(skin.width * skin.height * 4), buffer.remaining()
));
}
skin.data = new byte[buffer.remaining() - 1];
buffer.get(skin.data);
skin.alex = buffer.get() == 1;
return skin;
}
public byte[] encode() {
// 2 x int + 1 = 9 bytes
ByteBuffer buffer = ByteBuffer.allocate(9 + data.length);
buffer.putInt(width);
buffer.putInt(height);
buffer.put(data);
buffer.put((byte) (alex ? 1 : 0));
return Base64.getEncoder().encode(buffer.array());
}
}

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.floodgate.util;
public enum WebsocketEventType {
SUBSCRIBER_CREATED,
SUBSCRIBERS_COUNT,
ADDED_TO_QUEUE,
SKIN_UPLOADED,
CREATOR_DISCONNECTED;
public static final WebsocketEventType[] VALUES = values();
public static WebsocketEventType getById(int id) {
return VALUES.length > id ? VALUES[id] : null;
}
}