Added the player his IP to the transferable data

This commit is contained in:
Tim203 2019-12-17 23:27:29 +01:00
parent 9527709c59
commit 64b04330c3
3 changed files with 18 additions and 8 deletions

View file

@ -6,30 +6,39 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
@Getter @Getter
public class BedrockData { public class BedrockData {
public static final int EXPECTED_LENGTH = 6; public static final int EXPECTED_LENGTH = 7;
public static final String FLOODGATE_IDENTIFIER = "Geyser-Floodgate";
private String version; private String version;
private String username; private String username;
private String xuid; private String xuid;
private int deviceId; private int deviceId;
private String languageCode; private String languageCode;
private int inputMode; private int inputMode;
private String ip;
private int dataLength; private int dataLength;
public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode) { public BedrockData(String version, String username, String xuid, int deviceId, String languageCode, int inputMode, String ip) {
this(version, username, xuid, deviceId, languageCode, inputMode, EXPECTED_LENGTH); this(version, username, xuid, deviceId, languageCode, inputMode, ip, EXPECTED_LENGTH);
} }
public static BedrockData fromString(String data) { public static BedrockData fromString(String data) {
String[] split = data.split("\0"); String[] split = data.split("\0");
if (split.length != EXPECTED_LENGTH) return null; if (split.length != EXPECTED_LENGTH) return null;
return new BedrockData(split[0], split[1], split[2], Integer.parseInt(split[3]), split[4], Integer.parseInt(split[5]), split.length);
return new BedrockData(
split[0], split[1], split[2], Integer.parseInt(split[3]),
split[4], Integer.parseInt(split[5]), split[6], split.length
);
} }
public static BedrockData fromRawData(byte[] data) { public static BedrockData fromRawData(byte[] data) {
return fromString(new String(data)); return fromString(new String(data));
} }
@Override
public String toString() { public String toString() {
return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+ inputMode; return version +'\0'+ username +'\0'+ xuid +'\0'+ deviceId +'\0'+ languageCode +'\0'+
inputMode +'\0'+ ip;
} }
} }

View file

@ -221,7 +221,8 @@ public class GeyserSession implements Player {
authenticationData.getXboxUUID(), authenticationData.getXboxUUID(),
clientData.getDeviceOS().ordinal(), clientData.getDeviceOS().ordinal(),
clientData.getLanguageCode(), clientData.getLanguageCode(),
clientData.getCurrentInputMode().ordinal() clientData.getCurrentInputMode().ordinal(),
upstream.getSession().getAddress().getAddress().getHostAddress()
)); ));
} catch (Exception e) { } catch (Exception e) {
connector.getLogger().error("Failed to encrypt message", e); connector.getLogger().error("Failed to encrypt message", e);
@ -230,7 +231,7 @@ public class GeyserSession implements Player {
HandshakePacket handshakePacket = event.getPacket(); HandshakePacket handshakePacket = event.getPacket();
event.setPacket(new HandshakePacket( event.setPacket(new HandshakePacket(
handshakePacket.getProtocolVersion(), handshakePacket.getProtocolVersion(),
handshakePacket.getHostname() + '\0' + "Geyser-Floodgate" + '\0' + encrypted, handshakePacket.getHostname() + '\0' + BedrockData.FLOODGATE_IDENTIFIER + '\0' + encrypted,
handshakePacket.getPort(), handshakePacket.getPort(),
handshakePacket.getIntent() handshakePacket.getIntent()
)); ));

View file

@ -92,7 +92,7 @@ public class BlockStorage {
} }
private int legacyIdFor(int index) { private int legacyIdFor(int index) {
int runtimeId = this.palette.get(index); int runtimeId = this.palette.getInt(index);
return GlobalBlockPalette.getLegacyId(runtimeId); return GlobalBlockPalette.getLegacyId(runtimeId);
} }