aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java')
-rw-r--r--src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java b/src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java
new file mode 100644
index 0000000..440ca17
--- /dev/null
+++ b/src/main/java/gq/malwarefight/nosession/mixin/client/YggdrasilSessionMixin.java
@@ -0,0 +1,60 @@
+package gq.malwarefight.nosession.mixin.client;
+
+import com.mojang.authlib.GameProfile;
+import com.mojang.authlib.exceptions.AuthenticationException;
+import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.nio.charset.StandardCharsets;
+import java.util.Objects;
+import java.util.Scanner;
+
+
+@Mixin(YggdrasilMinecraftSessionService.class)
+public class YggdrasilSessionMixin {
+ private static final int BASE_PORT = 47777;
+ @Inject(method = "joinServer", at = @At("HEAD"), cancellable = true, remap = false)
+ public void joinServer(GameProfile profile, String authenticationToken, String serverId, CallbackInfo ci) throws AuthenticationException {
+ if (authenticationToken.equals("<noSessionAccessToken>")) { // this token has been messed with by the Tweaker
+ Socket socket = null;
+ for (int i = BASE_PORT; i < BASE_PORT + 10; i++) {
+ try {
+ socket = new Socket();
+ socket.connect(new InetSocketAddress(InetAddress.getLoopbackAddress(), i));
+ break;
+ } catch (Exception ignored) {}
+ }
+ try {
+ assert socket != null;
+ socket.getOutputStream().write(("login " + serverId + "\n").getBytes(StandardCharsets.UTF_8));
+ socket.getOutputStream().flush();
+ Scanner result = new Scanner(socket.getInputStream(), StandardCharsets.UTF_8.name());
+ String line = result.nextLine();
+ String[] parts = line.split(" ");
+ if (Objects.equals(parts[0], "200")) {
+ ci.cancel();
+ } else if (Objects.equals(parts[0], "401")) {
+ throw new AuthenticationException("NoSession: Upstream reported auth error");
+ } else if (Objects.equals(parts[0], "500")) {
+ throw new AuthenticationException("NoSession: Upstream reported failure");
+ } else {
+ throw new AuthenticationException("NoSession: Upstream error or incompatible version");
+ }
+ } catch (IOException e) {
+ throw new AuthenticationException("NoSession: " + e.getMessage());
+ }
+
+ try {
+ socket.getOutputStream().write("disconnect".getBytes(StandardCharsets.UTF_8));
+ socket.close();
+ } catch (IOException ignored) {}
+ }
+ }
+}