From bd6b4db71f1e07a845d922dc30cefcc64afa6294 Mon Sep 17 00:00:00 2001 From: PandaNinjas Date: Fri, 23 Dec 2022 17:29:28 -0800 Subject: Initial commit --- src/main/java/gq/malwarefight/tokenapp/Main.java | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/gq/malwarefight/tokenapp/Main.java (limited to 'src/main/java/gq/malwarefight/tokenapp/Main.java') diff --git a/src/main/java/gq/malwarefight/tokenapp/Main.java b/src/main/java/gq/malwarefight/tokenapp/Main.java new file mode 100644 index 0000000..750ae83 --- /dev/null +++ b/src/main/java/gq/malwarefight/tokenapp/Main.java @@ -0,0 +1,75 @@ +package gq.malwarefight.tokenapp; + +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService; +import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService; +import gq.malwarefight.nosession.mixin.Utils; +import org.apache.commons.lang3.exception.ExceptionUtils; + +import javax.net.ssl.HttpsURLConnection; +import java.io.IOException; +import java.net.*; +import java.util.UUID; + +public class Main { + public static final int BASE_PORT = 47777; + public static volatile boolean running = true; + public static YggdrasilMinecraftSessionService sessionService = null; + public static YggdrasilAuthenticationService authenticationService = null; + public static GameProfile gameProfile = null; + + public static void setup() throws IOException { + String token = Utils.readString(System.in, '\n'); + YggdrasilAuthenticationService yas = new YggdrasilAuthenticationService(Proxy.NO_PROXY, token); + authenticationService = yas; + sessionService = (YggdrasilMinecraftSessionService) yas.createMinecraftSessionService(); + HttpsURLConnection httpsURLConnection = (HttpsURLConnection) (new URL("https://api.minecraftservices.com/minecraft/profile").openConnection()); + httpsURLConnection.setRequestProperty("Authorization", "Bearer " + token); + String response = Utils.readString(httpsURLConnection.getInputStream(), null); + JsonObject jsonObject = new JsonParser().parse(response).getAsJsonObject(); + UUID id = UUID.fromString( + jsonObject.get("id").getAsString().replaceFirst( + "(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5" + ) + ); + String name = jsonObject.get("name").getAsString(); + gameProfile = new GameProfile(id, name); + System.setProperty("java.net.preferIPv4Stack", "true"); + } + + public static void main(String[] args) { + try { + setup(); + } catch (Exception e) { + System.err.println("Could not setup the server\n" + ExceptionUtils.getStackTrace(e)); + System.exit(1); + } + ServerSocket sock = null; + for (int i = BASE_PORT; i < BASE_PORT + 10; i++) { + try { + System.out.println(i); + //noinspection resource + sock = new ServerSocket(i, 50, InetAddress.getLoopbackAddress()); + System.out.println(i); + break; + } catch (Exception ignored) { + } + } + if (sock == null) { + System.err.println("Could not bind to any valid port"); + System.exit(1); + } + while (running) { + try { + Socket connection = sock.accept(); + Thread t = new SocketThread(connection); + t.start(); + } catch (IOException ignored) { + running = false; + } + } + } +} + \ No newline at end of file -- cgit