Skip to content

Commit 0cf5c7c

Browse files
committed
Add a client config for attempt_udp_networking
1 parent f8f20a6 commit 0cf5c7c

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

common/src/main/java/dev/ryanhcode/sable/SableClientConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public final class SableClientConfig {
2121

2222
public static final ModConfigSpec SPEC;
2323

24+
public static final ModConfigSpec.BooleanValue ATTEMPT_UDP_NETWORKING;
2425
public static final ModConfigSpec.BooleanValue SUB_LEVEL_DYNAMIC_SHADING;
2526
public static final ModConfigSpec.BooleanValue SUB_LEVEL_WATER_OCCLUSION;
2627
public static final ModConfigSpec.BooleanValue SUB_LEVEL_SKYLIGHT_SHADOWS;
@@ -31,6 +32,7 @@ public final class SableClientConfig {
3132
static {
3233
final ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
3334

35+
3436
SUB_LEVEL_DYNAMIC_SHADING = builder
3537
.comment("Whether sub-levels should apply block shading dynamically")
3638
.define("sub_level_dynamic_shading", true);
@@ -51,7 +53,9 @@ public final class SableClientConfig {
5153
ZOOM_SENSITIVITY = builder
5254
.comment("The zoom sensitivity for sub-level camera types")
5355
.defineInRange("sub_level_zoom_sensitivity", 0.2, 0.0, 100.0);
54-
56+
ATTEMPT_UDP_NETWORKING = builder
57+
.comment("If Sable should attempt to establish a UDP connection with the server, to receive sub-level movement data over a UDP channel")
58+
.define("attempt_udp_networking", true);
5559

5660
SPEC = builder.build();
5761
}

common/src/main/java/dev/ryanhcode/sable/SableConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public final class SableConfig {
5656
.comment("If the entire Sable UDP Networking pipeline should be disabled. This can improve compatibility with certain mods like Replay mod and certain networking setups, but will have worse performance and latency for networking sub-levels.")
5757
.define("disable_udp_pipeline", false);
5858
ATTEMPT_UDP_NETWORKING = builder
59-
.comment("If Sable should attempt to authenticate with clients and send them sub-level data over UDP")
59+
.comment("If Sable should attempt to authenticate with clients and send them sub-level movement data over UDP")
6060
.define("attempt_udp_networking", true);
6161
SUB_LEVEL_SAVING_LOG_MESSAGE = builder
6262
.comment("If Sable should log when saving sub-levels for a dimension.")

common/src/main/java/dev/ryanhcode/sable/network/packets/tcp/ClientboundSableUDPActivationPacket.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.ryanhcode.sable.network.packets.tcp;
22

33
import dev.ryanhcode.sable.Sable;
4+
import dev.ryanhcode.sable.SableClientConfig;
45
import dev.ryanhcode.sable.mixinterface.udp.ConnectionExtension;
56
import dev.ryanhcode.sable.network.packets.udp.SableUDPAuthenticationPacket;
67
import dev.ryanhcode.sable.network.tcp.SableTCPPacket;
@@ -39,14 +40,19 @@ public Type<? extends CustomPacketPayload> type() {
3940

4041
@Override
4142
public void handle(final PacketContext context) {
43+
if (!SableClientConfig.ATTEMPT_UDP_NETWORKING.get()) {
44+
Sable.LOGGER.info("Received UDP authentication request, ignoring due to disabled attempt_udp_networking config");
45+
return;
46+
}
47+
4248
final Connection connection = Minecraft.getInstance().getConnection().getConnection();
4349
final ConnectionExtension connectionExtension = (ConnectionExtension) connection;
4450
final Channel channel = connectionExtension.sable$getUDPChannel();
4551

4652
final InetSocketAddress baseAddress = ((InetSocketAddress) connection.getRemoteAddress());
4753
final InetSocketAddress remoteAddress = new InetSocketAddress(baseAddress.getAddress(), baseAddress.getPort());
4854

49-
Sable.LOGGER.info("Received authentication request, sending response over UDP to {}", remoteAddress);
55+
Sable.LOGGER.info("Received UDP authentication request, sending response over UDP to {}", remoteAddress);
5056

5157
channel.eventLoop().execute(() -> {
5258
final SableUDPAuthenticationPacket packet = new SableUDPAuthenticationPacket(this.uuid.toString());

0 commit comments

Comments
 (0)