2019-11-30 20:30:25 +00:00
|
|
|
package org.geysermc.floodgate.util;
|
|
|
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
import lombok.Getter;
|
|
|
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
@Getter
|
|
|
|
public class BedrockData {
|
2019-12-17 22:27:29 +00:00
|
|
|
public static final int EXPECTED_LENGTH = 7;
|
|
|
|
public static final String FLOODGATE_IDENTIFIER = "Geyser-Floodgate";
|
|
|
|
|
2019-11-30 20:30:25 +00:00
|
|
|
private String version;
|
|
|
|
private String username;
|
|
|
|
private String xuid;
|
|
|
|
private int deviceId;
|
|
|
|
private String languageCode;
|
|
|
|
private int inputMode;
|
2019-12-17 22:27:29 +00:00
|
|
|
private String ip;
|
2019-11-30 20:30:25 +00:00
|
|
|
private int dataLength;
|
|
|
|
|
2019-12-17 22:27:29 +00:00
|
|
|
public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode, String ip) {
|
|
|
|
this(version, username, xuid, deviceId, languageCode, inputMode, ip, EXPECTED_LENGTH);
|
2019-11-30 20:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static BedrockData fromString(String data) {
|
|
|
|
String[] split = data.split("\0");
|
|
|
|
if (split.length != EXPECTED_LENGTH) return null;
|
2019-12-17 22:27:29 +00:00
|
|
|
|
|
|
|
return new BedrockData(
|
|
|
|
split[0], split[1], split[2], Integer.parseInt(split[3]),
|
|
|
|
split[4], Integer.parseInt(split[5]), split[6], split.length
|
|
|
|
);
|
2019-11-30 20:30:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static BedrockData fromRawData(byte[] data) {
|
|
|
|
return fromString(new String(data));
|
|
|
|
}
|
|
|
|
|
2019-12-17 22:27:29 +00:00
|
|
|
@Override
|
2019-11-30 20:30:25 +00:00
|
|
|
public String toString() {
|
2019-12-17 22:27:29 +00:00
|
|
|
return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+
|
|
|
|
inputMode +'\0'+ ip;
|
2019-11-30 20:30:25 +00:00
|
|
|
}
|
|
|
|
}
|