Skip to content

Commit

Permalink
Correct usage of NetherNet ID
Browse files Browse the repository at this point in the history
Turns out the client can use numbers bigger than long can store so use BigInteger
  • Loading branch information
rtm516 committed Dec 15, 2024
1 parent 87194d8 commit 673b1b0
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rtm516.mcxboxbroadcast.core;

import java.math.BigInteger;
import java.util.Random;
import java.util.UUID;

Expand All @@ -12,7 +13,7 @@ public class ExpandedSessionInfo extends SessionInfo {
private String sessionId;
private String handleId;

private long webrtcNetworkId;
private BigInteger netherNetId;
private String deviceId;

ExpandedSessionInfo(String connectionId, String xuid, SessionInfo sessionInfo) {
Expand All @@ -21,7 +22,7 @@ public class ExpandedSessionInfo extends SessionInfo {
this.rakNetGUID = "";

this.sessionId = UUID.randomUUID().toString();
this.webrtcNetworkId = Math.abs(RANDOM.nextLong());
this.netherNetId = BigInteger.valueOf(Math.abs(RANDOM.nextLong()));
this.deviceId = UUID.randomUUID().toString();

setHostName(sessionInfo.getHostName());
Expand Down Expand Up @@ -77,8 +78,8 @@ public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}

public long getWebrtcNetworkId() {
return webrtcNetworkId;
public BigInteger getNetherNetId() {
return netherNetId;
}

public String getDeviceId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ protected String setupSession() {

HttpRequest request = HttpRequest.newBuilder(Constants.START_SESSION)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(SessionStartBody.create(sessionInfo, playfabTicket)))
.POST(HttpRequest.BodyPublishers.ofString(SessionStartBody.create(sessionInfo.getDeviceId(), playfabTicket)))
.build();

HttpResponse<String> response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import java.util.HashMap;

public final class SessionStartBody {
public static String create(ExpandedSessionInfo info, String playfabSessionTicket) {
public static String create(String deviceId, String playfabSessionTicket) {
return Constants.GSON_NULLS.toJson(new HashMap<>() {{
put("device", new HashMap<>() {{
put("applicationType", "MinecraftPE");
put("capabilities", new String[0]); // it's RayTracing for me
put("gameVersion", "1.21.20");
put("id", info.getDeviceId());
put("id", deviceId);
put("memory", "8589934592"); // exactly 8GiB
put("platform", "Windows10"); // idk if it matters but the auth was with Android
put("playFabTitleId", "20CA2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import com.rtm516.mcxboxbroadcast.core.Constants;

import java.math.BigInteger;

public record Connection(
int ConnectionType,
String HostIpAddress,
int HostPort,
long NetherNetId,
long WebRTCNetworkId
BigInteger NetherNetId
) {
public Connection(long webrtcNetworkId) {
this(Constants.ConnectionTypeWebRTC, "", 0, webrtcNetworkId, webrtcNetworkId);
public Connection(BigInteger netherNetId) {
this(Constants.ConnectionTypeWebRTC, "", 0, netherNetId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ public CreateSessionRequest(ExpandedSessionInfo sessionInfo) {
sessionInfo.getMaxPlayers(),
sessionInfo.getPlayers(),
true,
Collections.singletonList(new Connection(sessionInfo.getWebrtcNetworkId())),
Collections.singletonList(new Connection(sessionInfo.getNetherNetId())),
0,
2,
"level",
sessionInfo.getHostName(),
sessionInfo.getXuid(),
"",
sessionInfo.getWebrtcNetworkId(),
sessionInfo.getWorldName(),
"Survival",
sessionInfo.getProtocol(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public record SessionCustomProperties(
String hostName,
String ownerId,
String rakNetGUID,
long WebRTCNetworkId,
String worldName,
String worldType,
int protocol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class RtcWebsocketClient extends WebSocketClient {
* @param scheduledExecutorService The executor service to use for scheduling tasks
*/
public RtcWebsocketClient(String authenticationToken, ExpandedSessionInfo sessionInfo, Logger logger, ScheduledExecutorService scheduledExecutorService) {
super(URI.create(Constants.RTC_WEBSOCKET_FORMAT.formatted(sessionInfo.getWebrtcNetworkId())));
super(URI.create(Constants.RTC_WEBSOCKET_FORMAT.formatted(sessionInfo.getNetherNetId())));
addHeader("Authorization", authenticationToken);
// both seem random
addHeader("Session-Id", UUID.randomUUID().toString());
Expand Down

0 comments on commit 673b1b0

Please sign in to comment.