Skip to content

Commit

Permalink
feat: use kaleido
Browse files Browse the repository at this point in the history
  • Loading branch information
vgskye committed Jul 19, 2024
1 parent 84cb784 commit 5ce511b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 7 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ allprojects {
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url 'https://jitpack.io' }
maven { url 'https://repo.sleeping.town/' }
}

tasks.withType(JavaCompile) {
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dependencies {
implementation("com.github.vgskye.netty-incubator-codec-quic:netty-incubator-codec-classes-quic:${rootProject.quic_version}") {
exclude(group: "io.netty")
}
implementation 'folk.sisby:kaleido-config:0.3.1+1.3.1'
}

publishing {
Expand Down
7 changes: 7 additions & 0 deletions common/src/main/java/link/e4mc/Agnos.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

import dev.architectury.injectables.annotations.ExpectPlatform;

import java.nio.file.Path;

public class Agnos {
@ExpectPlatform
public static boolean isClient() {
return false;
}

@ExpectPlatform
public static Path configDir() {
return null;
}
}
16 changes: 16 additions & 0 deletions common/src/main/java/link/e4mc/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package link.e4mc;

import folk.sisby.kaleido.api.ReflectiveConfig;
import folk.sisby.kaleido.lib.quiltconfig.api.annotations.Comment;
import folk.sisby.kaleido.lib.quiltconfig.api.values.TrackedValue;

public class Config extends ReflectiveConfig {
public static final Config INSTANCE = Config.createToml(Agnos.configDir(), "e4mc", "e4mc", Config.class);

@Comment("Whether to use the broker to get the best relay based on location or use a hard-coded relay.")
public final TrackedValue<Boolean> useBroker = this.value(true);
public final TrackedValue<String> brokerUrl = this.value("https://broker.e4mc.link/getBestRelay");

public final TrackedValue<String> relayHost = this.value("test.e4mc.link");
public final TrackedValue<Integer> relayPort = this.value(25575);
}
20 changes: 16 additions & 4 deletions common/src/main/java/link/e4mc/QuiclimeSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ public void startAsync() {
thread.start();
}

public void start() {
try {
private static BrokerResponse getRelay() throws Exception {
if (Config.INSTANCE.useBroker.value()) {
var httpClient = HttpClient.newHttpClient();
var request = HttpRequest
.newBuilder(new URI("https://broker.e4mc.link/getBestRelay"))
.newBuilder(new URI(Config.INSTANCE.brokerUrl.value()))
.header("Accept", "application/json")
.build();
LOGGER.info("req: {}", request);
Expand All @@ -249,7 +249,19 @@ public void start() {
if (response.statusCode() != 200) {
throw new RuntimeException();
}
var relayInfo = gson.fromJson(response.body(), BrokerResponse.class);
return gson.fromJson(response.body(), BrokerResponse.class);
} else {
var resp = new BrokerResponse();
resp.id = "custom";
resp.host = Config.INSTANCE.relayHost.value();
resp.port = Config.INSTANCE.relayPort.value();
return resp;
}
}

public void start() {
try {
var relayInfo = getRelay();
LOGGER.info("using relay {}", relayInfo.id);
QuicSslContext context = QuicSslContextBuilder
.forClient()
Expand Down
1 change: 1 addition & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
shadowCommon(implementation("com.github.vgskye.netty-incubator-codec-quic:netty-incubator-codec-classes-quic:${rootProject.quic_version}") {
exclude(group: "io.netty")
})
include 'folk.sisby:kaleido-config:0.3.1+1.3.1'
}

processResources {
Expand Down
5 changes: 4 additions & 1 deletion fabric/src/main/java/link/e4mc/fabric/AgnosImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package link.e4mc.fabric;

import link.e4mc.Agnos;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;

Expand All @@ -10,4 +9,8 @@ public class AgnosImpl {
public static boolean isClient() {
return FabricLoader.getInstance().getEnvironmentType().equals(EnvType.CLIENT);
}

public static Path configDir() {
return FabricLoader.getInstance().getConfigDir();
}
}
4 changes: 4 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
shadowCommon(implementation("com.github.vgskye.netty-incubator-codec-quic:netty-incubator-codec-classes-quic:${rootProject.quic_version}") {
exclude(group: "io.netty")
})
shadowCommon('folk.sisby:kaleido-config:0.3.1+1.3.1')
}

processResources {
Expand All @@ -52,6 +53,9 @@ shadowJar {

configurations = [project.configurations.shadowCommon]
archiveClassifier = "dev-shadow"

relocate 'com.electronwill.nightconfig', 'link.e4mc.shadow.nightconfig'
relocate 'folk.sisby.kaleido', 'link.e4mc.shadow.kaleido'
}

remapJar {
Expand Down
5 changes: 4 additions & 1 deletion forge/src/main/java/link/e4mc/forge/AgnosImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package link.e4mc.forge;

import link.e4mc.Agnos;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.FMLPaths;
Expand All @@ -11,4 +10,8 @@ public class AgnosImpl {
public static boolean isClient() {
return FMLLoader.getDist().equals(Dist.CLIENT);
}

public static Path configDir() {
return FMLPaths.CONFIGDIR.get();
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.18.2
enabled_platforms=fabric,forge

archives_base_name=e4mc_minecraft
mod_version=5.0.0
mod_version=5.1.0
maven_group=link.e4mc

architectury_version=4.11.93
Expand Down

0 comments on commit 5ce511b

Please sign in to comment.