Skip to content

Commit 4268c53

Browse files
committed
get client address
1 parent 3abfe29 commit 4268c53

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private ServerBootstrap createBootstrap() {
233233
.childHandler(serverInitializer);
234234
}
235235

236-
public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
236+
public boolean onConnectionRequest(InetSocketAddress inetSocketAddress, InetSocketAddress clientAddress) {
237237
List<String> allowedProxyIPs = geyser.config().advanced().bedrock().haproxyProtocolWhitelistedIps();
238238
if (geyser.config().advanced().bedrock().useHaproxyProtocol() && !allowedProxyIPs.isEmpty()) {
239239
boolean isWhitelistedIP = false;
@@ -250,11 +250,11 @@ public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
250250
}
251251
}
252252

253-
String ip = geyser.config().logPlayerIpAddresses() ? inetSocketAddress.toString() : "<IP address withheld>";
253+
String ip = geyser.config().logPlayerIpAddresses() ? clientAddress.toString() : "<IP address withheld>";
254254

255255
ConnectionRequestEvent requestEvent = new ConnectionRequestEvent(
256-
inetSocketAddress,
257-
null // TODO
256+
clientAddress,
257+
geyser.config().advanced().bedrock().useHaproxyProtocol() ? inetSocketAddress : null
258258
);
259259
geyser.eventBus().fire(requestEvent);
260260
if (requestEvent.isCancelled()) {
@@ -268,9 +268,9 @@ public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
268268
return true;
269269
}
270270

271-
public BedrockPong onQuery(Channel channel, InetSocketAddress inetSocketAddress) {
271+
public BedrockPong onQuery(Channel channel, InetSocketAddress inetSocketAddress, InetSocketAddress clientAddress) {
272272
if (geyser.config().debugMode() && PRINT_DEBUG_PINGS) {
273-
String ip = geyser.config().logPlayerIpAddresses() ? inetSocketAddress.toString() : "<IP address withheld>";
273+
String ip = geyser.config().logPlayerIpAddresses() ? clientAddress.toString() : "<IP address withheld>";
274274
geyser.getLogger().debug(GeyserLocale.getLocaleStringLog("geyser.network.pinged", ip));
275275
}
276276

core/src/main/java/org/geysermc/geyser/network/netty/handler/RakConnectionRequestHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import io.netty.channel.socket.DatagramPacket;
3434
import lombok.RequiredArgsConstructor;
3535
import org.checkerframework.checker.nullness.qual.NonNull;
36+
import org.cloudburstmc.netty.channel.raknet.RakServerChannel;
3637
import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption;
3738
import org.geysermc.geyser.network.netty.GeyserServer;
3839

@@ -84,8 +85,10 @@ public void channelRead(@NonNull ChannelHandlerContext ctx, @NonNull Object msg)
8485
ByteBuf magicBuf = ctx.channel().config().getOption(RakChannelOption.RAK_UNCONNECTED_MAGIC);
8586
long guid = ctx.channel().config().getOption(RakChannelOption.RAK_GUID);
8687

87-
if (!this.server.onConnectionRequest(packet.sender())) {
88-
this.sendConnectionBanned(ctx, packet.sender(), magicBuf, guid);
88+
InetSocketAddress address = packet.sender();
89+
InetSocketAddress clientAddress = ((RakServerChannel) ctx.channel()).getClientAddress(address);
90+
if (!this.server.onConnectionRequest(address, clientAddress)) {
91+
this.sendConnectionBanned(ctx, address, magicBuf, guid);
8992
} else {
9093
ctx.fireChannelRead(msg);
9194
}

core/src/main/java/org/geysermc/geyser/network/netty/handler/RakPingHandler.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
import lombok.RequiredArgsConstructor;
3232
import org.cloudburstmc.netty.channel.raknet.RakPing;
3333
import org.cloudburstmc.netty.channel.raknet.RakPong;
34+
import org.cloudburstmc.netty.channel.raknet.RakServerChannel;
3435
import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption;
3536
import org.geysermc.geyser.network.netty.GeyserServer;
3637

38+
import java.net.InetSocketAddress;
39+
3740
@ChannelHandler.Sharable
3841
@RequiredArgsConstructor
3942
public class RakPingHandler extends SimpleChannelInboundHandler<RakPing> {
@@ -45,7 +48,9 @@ public class RakPingHandler extends SimpleChannelInboundHandler<RakPing> {
4548
protected void channelRead0(ChannelHandlerContext ctx, RakPing msg) {
4649
long guid = ctx.channel().config().getOption(RakChannelOption.RAK_GUID);
4750

48-
RakPong pong = msg.reply(guid, this.server.onQuery(ctx.channel(), msg.getSender()).toByteBuf());
51+
InetSocketAddress address = msg.getSender();
52+
InetSocketAddress clientAddress = ((RakServerChannel) ctx.channel()).getClientAddress(address);
53+
RakPong pong = msg.reply(guid, this.server.onQuery(ctx.channel(), address, clientAddress).toByteBuf());
4954
ctx.writeAndFlush(pong);
5055
}
5156
}

0 commit comments

Comments
 (0)