Skip to content

Commit

Permalink
Lots more code tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Aug 24, 2024
1 parent ed948d7 commit f86ef9f
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.geysermc.geyser.api.extension.ExtensionLogger;

public class ExtensionLoggerImpl implements Logger {
private ExtensionLogger logger;
private final ExtensionLogger logger;
private final String prefixString;

public ExtensionLoggerImpl(ExtensionLogger logger) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void initialise() {
}
}

private String fetchPlayfabSessionTicket(HttpClient httpClient) throws IOException, InterruptedException {
private String fetchPlayfabSessionTicket(HttpClient httpClient) throws IOException {
// TODO Use minecraftauth library using StepPlayFabToken
StepInitialXblSession.InitialXblSession initialSession = xboxToken.getInitialXblSession();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class Constants {
/**
* Gathered from scraped web requests
*/
public static int ConnectionTypeWebRTC = 3;
public static final int ConnectionTypeWebRTC = 3;

/**
* Used to be 1000, but the limit was increased in Aug 2024
*/
public static int MAX_FRIENDS = 2000;
public static final int MAX_FRIENDS = 2000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class FriendManager {
private final Map<String, String> toRemove;

private List<FollowerResponse.Person> lastFriendCache;
private Future internalScheduledFuture;
private Future<Void> internalScheduledFuture;

public FriendManager(HttpClient httpClient, Logger logger, SessionManagerCore sessionManager) {
this.httpClient = httpClient;
Expand Down Expand Up @@ -281,9 +281,7 @@ private void internalProcess() {

// Update the user in the cache
Optional<FollowerResponse.Person> friend = lastFriendCache.stream().filter(p -> p.xuid.equals(entry.getKey())).findFirst();
if (friend.isPresent()) {
friend.get().isFollowedByCaller = true;
}
friend.ifPresent(person -> person.isFollowedByCaller = true);
} else if (response.statusCode() == 429) {
// The friend wasn't added successfully so get the retry after header
Optional<String> header = response.headers().firstValue("Retry-After");
Expand Down Expand Up @@ -358,9 +356,7 @@ private void internalProcess() {

// Update the user in the cache
Optional<FollowerResponse.Person> friend = lastFriendCache.stream().filter(p -> p.xuid.equals(entry.getKey())).findFirst();
if (friend.isPresent()) {
friend.get().isFollowedByCaller = false;
}
friend.ifPresent(person -> person.isFollowedByCaller = false);
} else if (response.statusCode() == 429) {
// The friend wasn't removed successfully so get the retry after header
Optional<String> header = response.headers().firstValue("Retry-After");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static String create(ExpandedSessionInfo info, String playfabSessionTicke
put("storePlatform", "uwp.store");
put("treatmentOverrides", null);
put("type", "Windows10");
}});;
}});
put("user", new HashMap<>() {{
put("language", "en");
put("languageCode", "en-US");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.rtm516.mcxboxbroadcast.core.models.session;

public class CreateHandleRequest {
public int version;
public String type;
public SessionRef sessionRef;
public final int version;
public final String type;
public final SessionRef sessionRef;

public CreateHandleRequest(int version, String type, SessionRef sessionRef) {
this.version = version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Collections;

public class CreateSessionRequest extends JoinSessionRequest {
public SessionProperties properties;
public final SessionProperties properties;

public CreateSessionRequest(ExpandedSessionInfo sessionInfo) {
super(sessionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Map;

public class JoinSessionRequest {
public Map<String, SessionMember> members;
public final Map<String, SessionMember> members;

public JoinSessionRequest(ExpandedSessionInfo sessionInfo) {
Map<String, MemberConstantsSystem> constants = new HashMap<>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void onTimeout(Channel channel) {
}

@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
public void handlerAdded(ChannelHandlerContext ctx) {
this.timeoutFuture = ctx.channel().eventLoop().schedule(() -> this.onTimeout(ctx.channel()), this.timeout, this.timeUnit);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.concurrent.TimeUnit;

public class PingUtil {
private static EventLoopGroup workerEventLoopGroup;
private static final EventLoopGroup workerEventLoopGroup;
private static boolean webPingEnabled = false;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@
import java.io.IOException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -137,4 +135,4 @@ private String fingerprintFor(byte[] input) {
public String getClientFingerprint() throws CertificateEncodingException {
return fingerprintFor(cert.getEncoded());
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class RtcWebsocketClient extends WebSocketClient {
}

private final Logger logger;
private SessionInfo sessionInfo;
private final SessionInfo sessionInfo;
private final ScheduledExecutorService scheduledExecutorService;
private final Map<String, PeerSession> activeSessions;
private final List<CandidateHarvester> candidateHarvesters;
Expand All @@ -50,7 +50,9 @@ public class RtcWebsocketClient extends WebSocketClient {
* Create a new websocket and add the Authorization header
*
* @param authenticationToken The token to use for authentication
* @param scheduledExecutorService
* @param sessionInfo The session info to use for the connection
* @param logger The logger to use for outputting messages
* @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())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void onDisAssociated(Association association) {
}

@Override
public void onDCEPStream(SCTPStream sctpStream, String label, int i) throws Exception {
public void onDCEPStream(SCTPStream sctpStream, String label, int i) {
if (label == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

public class NoneCompressionCodec implements CompressionCodec {
@Override
public ByteBuf encode(ByteBuf msg) throws Exception {
public ByteBuf encode(ByteBuf msg) {
return Unpooled.buffer(msg.readableBytes() + 1)
.writeByte(compressionIdentifier())
.writeBytes(msg);
}

@Override
public ByteBuf decode(ByteBuf msg) throws Exception {
public ByteBuf decode(ByteBuf msg) {
if (msg.readUnsignedByte() != compressionIdentifier()) {
throw new IllegalArgumentException("Unexpected compression identifier");
}
Expand Down

0 comments on commit f86ef9f

Please sign in to comment.