mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Initial skin support
This commit is contained in:
parent
d37113388b
commit
ec87344a77
8 changed files with 129 additions and 16 deletions
|
@ -51,19 +51,21 @@ public final class BedrockData {
|
|||
private final LinkedPlayer linkedPlayer;
|
||||
private final int dataLength;
|
||||
|
||||
private RawSkin skin;
|
||||
|
||||
public BedrockData(String version, String username, String xuid, int deviceOs,
|
||||
String languageCode, int uiProfile, int inputMode, String ip,
|
||||
LinkedPlayer linkedPlayer) {
|
||||
LinkedPlayer linkedPlayer, RawSkin skin) {
|
||||
this(version, username, xuid, deviceOs, languageCode,
|
||||
inputMode, uiProfile, ip, linkedPlayer, EXPECTED_LENGTH);
|
||||
inputMode, uiProfile, ip, linkedPlayer, EXPECTED_LENGTH, skin);
|
||||
}
|
||||
|
||||
public BedrockData(String version, String username, String xuid, int deviceOs,
|
||||
String languageCode, int uiProfile, int inputMode, String ip) {
|
||||
this(version, username, xuid, deviceOs, languageCode, uiProfile, inputMode, ip, null);
|
||||
String languageCode, int uiProfile, int inputMode, String ip, RawSkin skin) {
|
||||
this(version, username, xuid, deviceOs, languageCode, uiProfile, inputMode, ip, null, skin);
|
||||
}
|
||||
|
||||
public static BedrockData fromString(String data) {
|
||||
public static BedrockData fromString(String data, String skin) {
|
||||
String[] split = data.split("\0");
|
||||
if (split.length != EXPECTED_LENGTH) return emptyData(split.length);
|
||||
|
||||
|
@ -72,12 +74,12 @@ 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, split.length
|
||||
linkedPlayer, split.length, RawSkin.parse(skin)
|
||||
);
|
||||
}
|
||||
|
||||
public static BedrockData fromRawData(byte[] data) {
|
||||
return fromString(new String(data));
|
||||
public static BedrockData fromRawData(byte[] data, String skin) {
|
||||
return fromString(new String(data), skin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,6 +95,6 @@ public final class BedrockData {
|
|||
}
|
||||
|
||||
private static BedrockData emptyData(int dataLength) {
|
||||
return new BedrockData(null, null, null, -1, null, -1, -1, null, null, dataLength);
|
||||
return new BedrockData(null, null, null, -1, null, -1, -1, null, null, dataLength, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,9 +58,14 @@ public final class EncryptionUtil {
|
|||
Base64.getEncoder().encodeToString(encryptedText);
|
||||
}
|
||||
|
||||
public static String encryptBedrockData(Key key, BedrockData data, boolean includeSkin) throws IllegalBlockSizeException,
|
||||
InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
return encrypt(key, data.toString()) + (includeSkin ? data.getSkin() : "");
|
||||
}
|
||||
|
||||
public static String encryptBedrockData(Key key, BedrockData data) throws IllegalBlockSizeException,
|
||||
InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
return encrypt(key, data.toString());
|
||||
return encryptBedrockData(key, data, true);
|
||||
}
|
||||
|
||||
public static byte[] decrypt(Key key, String encryptedData) throws IllegalBlockSizeException,
|
||||
|
@ -80,9 +85,9 @@ public final class EncryptionUtil {
|
|||
return cipher.doFinal(Base64.getDecoder().decode(split[1]));
|
||||
}
|
||||
|
||||
public static BedrockData decryptBedrockData(Key key, String encryptedData) throws IllegalBlockSizeException,
|
||||
public static BedrockData decryptBedrockData(Key key, String encryptedData, String skin) throws IllegalBlockSizeException,
|
||||
InvalidKeyException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
return BedrockData.fromRawData(decrypt(key, encryptedData));
|
||||
return BedrockData.fromRawData(decrypt(key, encryptedData), skin);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* 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.charset.StandardCharsets;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class RawSkin {
|
||||
public int width;
|
||||
public int height;
|
||||
public byte[] data;
|
||||
|
||||
private RawSkin() {}
|
||||
|
||||
public static RawSkin parse(String data) {
|
||||
if (data == null) return null;
|
||||
String[] split = data.split(":");
|
||||
if (split.length != 3) return null;
|
||||
|
||||
RawSkin skin = new RawSkin();
|
||||
skin.width = Integer.parseInt(split[0]);
|
||||
skin.height = Integer.parseInt(split[1]);
|
||||
skin.data = split[2].getBytes(StandardCharsets.UTF_8);
|
||||
return skin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Integer.toString(width) + ':' + height + ':' + new String(data);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue