Skip to content

Commit

Permalink
Make session service static
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Apr 8, 2022
1 parent 9d70c21 commit ba214f3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.github.steveice10.mc.auth.exception.profile.ProfileException;
import com.github.steveice10.mc.auth.service.ProfileService;
import com.github.steveice10.mc.auth.service.SessionService;
import pl.js6pak.mojangfix.mixin.client.MinecraftAccessor;
import pl.js6pak.mojangfix.mixinterface.SessionAccessor;

import java.util.concurrent.CompletableFuture;
Expand All @@ -32,10 +31,9 @@ public class MojangProfileProvider implements ProfileProvider {
public Future<GameProfile> get(String username) {
CompletableFuture<GameProfile> future = new CompletableFuture<>();

final SessionAccessor session = (SessionAccessor) MinecraftAccessor.getInstance().session;
profileService.findProfilesByName(new String[]{username}, new ProfileService.ProfileLookupCallback() {
public void onProfileLookupSucceeded(GameProfile profile) {
SessionService sessionService = session.getSessionService();
SessionService sessionService = SessionAccessor.SESSION_SERVICE;

try {
sessionService.fillProfileProperties(profile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void onJoinServer(HandshakePacket packet, CallbackInfo ci) {
this.connection.disconnect("disconnect.loginFailedInfo", "Invalid access token!");
}

session.getSessionService().joinServer(session.getGameProfile(), session.getAccessToken(), packet.name);
SessionAccessor.SESSION_SERVICE.joinServer(session.getGameProfile(), session.getAccessToken(), packet.name);
this.sendPacket(new LoginHelloPacket(this.minecraft.session.username, 14));
} catch (RequestException e) {
this.connection.disconnect("disconnect.loginFailedInfo", e.getClass().getSimpleName() + "\n" + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package pl.js6pak.mojangfix.mixin.client.auth;

import com.github.steveice10.mc.auth.data.GameProfile;
import com.github.steveice10.mc.auth.service.SessionService;
import lombok.Getter;
import net.minecraft.client.util.Session;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -41,17 +40,11 @@ public class SessionMixin implements SessionAccessor {
@Getter
private String accessToken;

@Unique
@Getter
private SessionService sessionService;

@Unique
private static final Pattern UUID_PATTERN = Pattern.compile("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})");

@Inject(method = "<init>", at = @At("RETURN"))
private void onInit(String username, String sessionId, CallbackInfo ci) {
this.sessionService = new SessionService();

String[] split = sessionId.split(":");
if (split.length == 3 && split[0].equalsIgnoreCase("token")) {
accessToken = split[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public interface SessionAccessor {

String getAccessToken();

SessionService getSessionService();
SessionService SESSION_SERVICE = new SessionService();
}

0 comments on commit ba214f3

Please sign in to comment.