refactor client

This commit is contained in:
1e99 2024-11-17 18:29:19 +01:00
parent 1aabd0f3cf
commit 004ab1e220
7 changed files with 62 additions and 17 deletions

View file

@ -13,6 +13,14 @@ dependencies {
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
implementation "dev.onvoid.webrtc:webrtc-java:0.8.0"
implementation group: "dev.onvoid.webrtc", name: "webrtc-java", version: "0.8.0", classifier: "windows-x86_64"
implementation group: "dev.onvoid.webrtc", name: "webrtc-java", version: "0.8.0", classifier: "macos-x86_64"
implementation group: "dev.onvoid.webrtc", name: "webrtc-java", version: "0.8.0", classifier: "macos-aarch64"
implementation group: "dev.onvoid.webrtc", name: "webrtc-java", version: "0.8.0", classifier: "linux-x86_64"
implementation group: "dev.onvoid.webrtc", name: "webrtc-java", version: "0.8.0", classifier: "linux-aarch64"
implementation group: "dev.onvoid.webrtc", name: "webrtc-java", version: "0.8.0", classifier: "linux-aarch32"
implementation project(':common')
}
@ -43,3 +51,9 @@ jar {
rename { "${it}_${project.base.archivesName.get()}" }
}
}
runClient {
// I need to do it here, IntelliJ doesn't recognize the mod and I couldn't figure out how to set env variables
systemProperty "devauth.enabled", System.getenv("DEVAUTH_ENABLED")
systemProperty "devauth.account", System.getenv("DEVAUTH_ACCOUNT")
}

View file

@ -3,6 +3,7 @@
"package": "eu.e99.svc.client.fabric.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"PlayerEntityMixin"
],
"injectors": {
"defaultRequire": 1

View file

@ -3,13 +3,10 @@ package eu.e99.svc.client.fabric;
import net.fabricmc.api.ClientModInitializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.session.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLSocketFactory;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
public class FabricSimplerVoiceChat implements ClientModInitializer {
@ -31,13 +28,10 @@ public class FabricSimplerVoiceChat implements ClientModInitializer {
MinecraftClient client = MinecraftClient.getInstance();
Session session = client.getSession();
SVCClient voiceChat = new SVCClient(
"localhost",
6969,
session.getAccessToken(),
session.getUsername(),
session.getUuidOrNull(),
client,
socketFactory
);
Thread.ofPlatform().start(voiceChat::start);

View file

@ -6,6 +6,8 @@ import eu.e99.svc.SimplerVoiceChat;
import eu.e99.svc.auth.MojangAPI;
import eu.e99.svc.io.BinaryMessage;
import eu.e99.svc.packet.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.session.Session;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
@ -33,17 +35,13 @@ public class SVCClient {
private final String host;
private final int port;
private final String accessToken;
private final String username;
private final UUID uuid;
private final MinecraftClient client;
private final SSLSocketFactory socketFactory;
public SVCClient(String host, int port, String accessToken, String username, UUID uuid, SSLSocketFactory socketFactory) {
public SVCClient(String host, int port, MinecraftClient client, SSLSocketFactory socketFactory) {
this.host = host;
this.port = port;
this.accessToken = accessToken;
this.username = username;
this.uuid = uuid;
this.client = client;
this.socketFactory = socketFactory;
}
@ -64,6 +62,8 @@ public class SVCClient {
}
System.out.printf("Successfully authenticated.%n");
while (true) {}
} catch (IOException e) {
System.out.printf("Failed to connect.%n");
e.printStackTrace(System.out);
@ -91,9 +91,15 @@ public class SVCClient {
case AuthRequestPacket authRequest -> {
System.out.printf("Joining server to authenticate...%n");
Session session = this.client.getSession();
boolean ok;
try {
ok = MojangAPI.joinServer(this.accessToken, this.uuid, authRequest.serverId);
ok = MojangAPI.joinServer(
session.getAccessToken(),
session.getUuidOrNull(),
authRequest.serverId
);
} catch (Exception e) {
System.out.printf("Failed to join server:%n");
e.printStackTrace(System.out);
@ -106,7 +112,7 @@ public class SVCClient {
}
AuthResponsePacket authResponse = new AuthResponsePacket();
authResponse.username = this.username;
authResponse.username = session.getUsername();
conn.writePacket(authResponse);
}
case AuthSuccessPacket authComplete -> {

View file

@ -0,0 +1,30 @@
package eu.e99.svc.client.fabric.mixin;
import com.mojang.authlib.GameProfile;
import dev.onvoid.webrtc.RTCPeerConnection;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PlayerEntity.class)
public class PlayerEntityMixin {
@Shadow @Final private GameProfile gameProfile;
@Inject(method = "<init>", at = @At("RETURN"))
private void svc$init(World world, BlockPos pos, float yaw, GameProfile gameProfile, CallbackInfo ci) {
System.out.printf("Added %s.%n", gameProfile.getName());
}
@Inject(method = "remove", at = @At("HEAD"))
private void svc$remove(Entity.RemovalReason reason, CallbackInfo ci) {
System.out.printf("Removed %s.%n", this.gameProfile.getName());
}
}

View file

@ -5,6 +5,7 @@ import eu.e99.svc.io.Reader;
import eu.e99.svc.io.Writer;
import java.io.IOException;
import java.util.UUID;
public class AuthResponsePacket implements BinaryMessage {

View file

@ -7,7 +7,6 @@ import eu.e99.svc.auth.PlayerProfile;
import eu.e99.svc.io.BinaryMessage;
import eu.e99.svc.packet.*;
import java.io.EOFException;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;