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