Skip to content

Commit

Permalink
new: port override on velocity
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Jan 22, 2025
1 parent 0fee59e commit dae046d
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@

public class VelocityRaknetifyServer {

private static final int portOverride = Integer.getInteger("raknetify.velocity.portOverride", -1);

private static final Method INIT_CHANNEL;

static {
Expand Down Expand Up @@ -133,9 +135,12 @@ private static void startServer(InetSocketAddress address) {
final EventLoopGroup bossGroup = (EventLoopGroup) accessible(ConnectionManager.class.getDeclaredField("bossGroup")).get(cm);
final EventLoopGroup workerGroup = (EventLoopGroup) accessible(ConnectionManager.class.getDeclaredField("workerGroup")).get(cm);

final boolean hasPortOverride = portOverride > 0 && portOverride < 65535;
InetSocketAddress actualAddress = hasPortOverride ? new InetSocketAddress(address.getAddress(), portOverride) : address;

synchronized (channels) {
for (ChannelFuture future : channels) {
if (future.channel().localAddress().equals(address)) return;
if (future.channel().localAddress().equals(actualAddress)) return;
}

ChannelFuture future = new ServerBootstrap()
Expand All @@ -154,7 +159,7 @@ protected void initChannel(Channel channel) throws Exception {
RakNetVelocityConnectionUtil.postInitChannel(channel, false);
}
})
.localAddress(address)
.localAddress(actualAddress)
.bind()
.syncUninterruptibly();

Expand Down

0 comments on commit dae046d

Please sign in to comment.