Auth
This commit is contained in:
+1
-1
@@ -20,7 +20,7 @@ dependencies {
|
||||
modApi "dev.felnull:special-model-loader:1.4.0+pre.1"
|
||||
include "dev.felnull:special-model-loader:1.4.0+pre.1"
|
||||
|
||||
implementation 'com.github.selimaj-dev:session-java:0.1.3'
|
||||
implementation 'com.github.selimaj-dev:session-java:0.1.4'
|
||||
|
||||
include modImplementation("dev.kosmx.player-anim:player-animation-lib-fabric:${project.player_anim}")
|
||||
//You might want bendy-lib. playerAnimator will wrap it.
|
||||
|
||||
@@ -9,6 +9,9 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.saturnclient.saturnclient.SaturnClient;
|
||||
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
||||
import org.saturnclient.saturnclient.cosmetics.Hats;
|
||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||
|
||||
import dev.selimaj.session.Session;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||
@@ -18,25 +21,11 @@ public class ServiceClient {
|
||||
public static UUID uuid;
|
||||
|
||||
public static boolean connectTimeout() {
|
||||
ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
Callable<Session> task = () -> Session.connect("ws://localhost:3000");
|
||||
|
||||
Future<Session> future = executor.submit(task);
|
||||
|
||||
try {
|
||||
session = future.get(10, TimeUnit.SECONDS);
|
||||
System.out.println("Connected!");
|
||||
session = Session.connect("ws://localhost:3000", 0, null);
|
||||
return true;
|
||||
} catch (TimeoutException e) {
|
||||
System.out.println("Connection timed out!");
|
||||
future.cancel(true);
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
executor.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,23 +53,23 @@ public class ServiceClient {
|
||||
SaturnClient.LOGGER.info("Authenticating with UUID: " + accessToken);
|
||||
|
||||
if (!connectTimeout()) {
|
||||
SaturnClient.LOGGER.error("Unable to authenticate: Session Server Timeout");
|
||||
return false;
|
||||
}
|
||||
|
||||
// String cloak = parser.getString("cloak");
|
||||
// String hat = parser.getString("hat");
|
||||
ServiceMethods.AuthResponse response = session.request(ServiceMethods.Authenticate, accessToken).get();
|
||||
|
||||
// for (String availableCloak : parser.getArray("cloaks")) {
|
||||
// Cloaks.availableCloaks.add(availableCloak);
|
||||
// }
|
||||
for (String availableCloak : response.cloaks()) {
|
||||
Cloaks.availableCloaks.add(availableCloak);
|
||||
}
|
||||
|
||||
// for (String availableHat : parser.getArray("hats")) {
|
||||
// Hats.availableHats.add(availableHat);
|
||||
// }
|
||||
for (String availableHat : response.hats()) {
|
||||
Hats.availableHats.add(availableHat);
|
||||
}
|
||||
|
||||
// players.put(uuid, new SaturnPlayer(cloak, hat));
|
||||
SaturnPlayer.set(uuid, new SaturnPlayer(response.cloak(), response.hat()));
|
||||
|
||||
// Cloaks.loadCloak(uuid);
|
||||
Cloaks.loadCloak(uuid);
|
||||
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package org.saturnclient.saturnclient.client;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.TextNode;
|
||||
|
||||
import dev.selimaj.session.types.Method;
|
||||
|
||||
public class ServiceMethods {
|
||||
public record AuthResponse(
|
||||
String username,
|
||||
String password) {
|
||||
}
|
||||
public record AuthResponse(String cloak, String hat, String[] cloaks, String[] hats) {
|
||||
}
|
||||
|
||||
public static final Method<TextNode, AuthResponse, TextNode> Authenticate = new Method<>("auth",
|
||||
TextNode.class, AuthResponse.class, TextNode.class);
|
||||
public static final Method<String, AuthResponse, String> Authenticate = new Method<>("auth",
|
||||
String.class, AuthResponse.class, String.class);
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
package org.saturnclient.saturnclient.client.player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SaturnPlayer {
|
||||
private static Map<UUID, SaturnPlayer> PLAYERS = new HashMap<>();
|
||||
|
||||
public String cloak = "";
|
||||
public String hat = "";
|
||||
|
||||
@@ -8,4 +14,22 @@ public class SaturnPlayer {
|
||||
this.cloak = cloak;
|
||||
this.hat = hat;
|
||||
}
|
||||
|
||||
public static SaturnPlayer get(UUID uuid) {
|
||||
return PLAYERS.get(uuid);
|
||||
}
|
||||
|
||||
public static void set(UUID uuid, SaturnPlayer player) {
|
||||
PLAYERS.put(uuid, player);
|
||||
}
|
||||
|
||||
public static void player(UUID uuid, SaturnPlayer player) {
|
||||
if (PLAYERS.containsKey(uuid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If offline then leave
|
||||
|
||||
PLAYERS.put(uuid, player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.saturnclient.saturnclient.cosmetics;
|
||||
|
||||
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||
import org.saturnclient.saturnclient.auth.Auth;
|
||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Cloaks {
|
||||
private static final String CLOAKS_RESOURCE_PATH = "assets/saturnclient/textures/cloaks/";
|
||||
public static final List<String> availableCloaks = new ArrayList<>();
|
||||
public static Identifier cloakCacheIdentifier = null;
|
||||
public static final Map<String, List<AnimatedCloakData>> animatedCloaks = new ConcurrentHashMap<>();
|
||||
public static final Map<UUID, List<AnimatedCloakData>> animatedCloaks = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Long> lastFrameTime = new ConcurrentHashMap<>();
|
||||
|
||||
private static final ExecutorService CLOAK_LOADER_EXECUTOR = Executors.newFixedThreadPool(
|
||||
@@ -99,8 +99,9 @@ public class Cloaks {
|
||||
*
|
||||
* @param cloakName Name of the cloak file to load
|
||||
*/
|
||||
public static void loadCloak(String uuid) {
|
||||
SaturnPlayer player = Auth.players.get(uuid);
|
||||
public static void loadCloak(UUID uuid) {
|
||||
SaturnPlayer player = SaturnPlayer.get(uuid);
|
||||
|
||||
if (player != null && player.cloak != null) {
|
||||
if (!player.cloak.isEmpty()) {
|
||||
if (Arrays.asList(ANIMATED_CLOAKS).contains(player.cloak)) {
|
||||
@@ -146,7 +147,7 @@ public class Cloaks {
|
||||
}
|
||||
}
|
||||
|
||||
public static CompletableFuture<Void> loadAnimatedCloakAsync(String uuid, String cloakName) {
|
||||
public static CompletableFuture<Void> loadAnimatedCloakAsync(UUID uuid, String cloakName) {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
String fileName = cloakName + ".gif";
|
||||
|
||||
@@ -196,7 +197,7 @@ public class Cloaks {
|
||||
} else {
|
||||
// Queue for main thread execution
|
||||
// SaturnClient.client.execute(
|
||||
// () -> IdentifierUtils.registerBufferedImageTexture(frameIdentifier, frame));
|
||||
// () -> IdentifierUtils.registerBufferedImageTexture(frameIdentifier, frame));
|
||||
}
|
||||
|
||||
animatedFrames.add(new AnimatedCloakData(frameIdentifier, delay));
|
||||
|
||||
Reference in New Issue
Block a user