Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/src/main/java/dev/ryanhcode/sable/SableConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public final class SableConfig {
public static final ModConfigSpec.IntValue SUB_LEVEL_PUNCH_COOLDOWN_TICKS;
public static final ModConfigSpec.BooleanValue DISABLE_UDP_PIPELINE;
public static final ModConfigSpec.BooleanValue ATTEMPT_UDP_NETWORKING;
public static final ModConfigSpec.IntValue UDP_LISTEN_PORT;


static {
final ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
Expand Down Expand Up @@ -56,6 +58,9 @@ public final class SableConfig {
ATTEMPT_UDP_NETWORKING = builder
.comment("If Sable should attempt to authenticate with clients and send them sub-level data over UDP")
.define("attempt_udp_networking", true);
UDP_LISTEN_PORT = builder
.comment("The port Sable will use when sending data over UDP (-1 = The Minecraft Server Instance Port)")
.defineInRange("udp_listen_port", -1, -1, 65535);

SPEC = builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.ryanhcode.sable.SableClient;
import dev.ryanhcode.sable.mixinterface.udp.ConnectionExtension;
import dev.ryanhcode.sable.network.udp.SableUDPPacket;
import dev.ryanhcode.sable.network.udp.SableUDPServer;
import dev.ryanhcode.sable.network.udp.handler.SableUDPChannelHandlerClient;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
Expand Down Expand Up @@ -83,7 +84,7 @@ protected void initChannel(final Channel channel) {
}
})
.channel(channelClass)
.connect(inetSocketAddress.getAddress(), inetSocketAddress.getPort());
.connect(inetSocketAddress.getAddress(), SableUDPServer.getUDPPort(inetSocketAddress.getPort()));

channelFuture.syncUninterruptibly();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollChannelOption;
import io.netty.channel.epoll.EpollDatagramChannel;
import io.netty.channel.local.LocalAddress;
import io.netty.channel.local.LocalServerChannel;
Expand Down Expand Up @@ -75,7 +76,7 @@ protected void initChannel(final Channel channel) {
}
})
.group(eventLoopGroup)
.localAddress(inetAddress, port)
.localAddress(inetAddress, SableUDPServer.getUDPPort(port))
.bind()
.syncUninterruptibly());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.ryanhcode.sable.network.packets.udp.SableUDPAuthenticationPacket;
import dev.ryanhcode.sable.network.tcp.SableTCPPacket;
import dev.ryanhcode.sable.network.udp.AddressedSableUDPPacket;
import dev.ryanhcode.sable.network.udp.SableUDPServer;
import foundry.veil.api.network.handler.PacketContext;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
Expand Down Expand Up @@ -44,7 +45,10 @@ public void handle(final PacketContext context) {
final Channel channel = connectionExtension.sable$getUDPChannel();

final InetSocketAddress baseAddress = ((InetSocketAddress) connection.getRemoteAddress());
final InetSocketAddress remoteAddress = new InetSocketAddress(baseAddress.getAddress(), baseAddress.getPort());
final InetSocketAddress remoteAddress = new InetSocketAddress(
baseAddress.getAddress(),
SableUDPServer.getUDPPort(baseAddress.getPort())
);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.ryanhcode.sable.network.udp.AddressedSableUDPPacket;
import dev.ryanhcode.sable.network.udp.SableUDPPacket;
import dev.ryanhcode.sable.network.udp.SableUDPPacketType;
import dev.ryanhcode.sable.network.udp.SableUDPServer;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
Expand All @@ -30,7 +31,9 @@ public void handleClient(final Level level) {
final Channel channel = connectionExtension.sable$getUDPChannel();

final InetSocketAddress baseAddress = ((InetSocketAddress) connection.getRemoteAddress());
final InetSocketAddress remoteAddress = new InetSocketAddress(baseAddress.getAddress(), baseAddress.getPort());
final InetSocketAddress remoteAddress = new InetSocketAddress(
baseAddress.getAddress(),
SableUDPServer.getUDPPort(baseAddress.getPort()));

channel.eventLoop().execute(() -> {
final SableUDPServerboundAlivePacket packet = new SableUDPServerboundAlivePacket();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.neoforge.common.ModConfigSpec;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -52,6 +53,20 @@ public static SableUDPServer getServer(final MinecraftServer server) {
return (((ServerConnectionListenerExtension) server.getConnection())).sable$getServer();
}

/**
* Returns the port that will be used by the UDP server
*
* @param _default the socket that will be used in the case where the port in config is set to -1
* @return the port that will be used by the UDP server
*/
public static Integer getUDPPort(final int _default) {
final int fromConfig = SableConfig.UDP_LISTEN_PORT.getAsInt();

if(fromConfig == -1) return _default;

return fromConfig;
}

/*@Override
public void flushUDP() {
if (this.udpChannel.eventLoop().inEventLoop())
Expand Down