aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gq/malwarefight/tokenapp/Main.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gq/malwarefight/tokenapp/Main.java')
-rw-r--r--src/main/java/gq/malwarefight/tokenapp/Main.java21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/main/java/gq/malwarefight/tokenapp/Main.java b/src/main/java/gq/malwarefight/tokenapp/Main.java
index 66afad1..f86711b 100644
--- a/src/main/java/gq/malwarefight/tokenapp/Main.java
+++ b/src/main/java/gq/malwarefight/tokenapp/Main.java
@@ -5,7 +5,7 @@ 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 gq.malwarefight.nosession.utils.Utils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import javax.net.ssl.HttpsURLConnection;
@@ -14,25 +14,25 @@ import java.net.*;
import java.util.UUID;
public class Main {
+
public static final int BASE_PORT = 47777;
- public static long ID;
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);
+ 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 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"
- )
+ Utils.normalizeUUID(jsonObject.get("id").getAsString())
);
String name = jsonObject.get("name").getAsString();
gameProfile = new GameProfile(id, name);
@@ -40,7 +40,6 @@ public class Main {
}
public static void main(String[] args) {
- ID = Long.parseLong(args[0]);
try {
setup();
} catch (Exception e) {
@@ -53,7 +52,9 @@ public class Main {
//noinspection resource
sock = new ServerSocket(i, 50, InetAddress.getLoopbackAddress());
break;
- } catch (Exception ignored) {}
+ } catch (Exception ignored) {
+ // we couldn't bind to the port, try the next one
+ }
}
if (sock == null) {
System.err.println("Could not bind to any valid port");
@@ -64,7 +65,7 @@ public class Main {
Socket connection = sock.accept();
Thread t = new SocketThread(connection);
t.start();
- } catch (IOException ignored) {
+ } catch (IOException exception) {
System.exit(0);
}
}