3737import io .netty .util .concurrent .DefaultThreadFactory ;
3838import io .netty .util .concurrent .Future ;
3939import lombok .Getter ;
40- import net .jodah .expiringmap .ExpirationPolicy ;
41- import net .jodah .expiringmap .ExpiringMap ;
4240import org .cloudburstmc .netty .channel .raknet .RakChannelFactory ;
41+ import org .cloudburstmc .netty .channel .raknet .config .DefaultRakServerThrottle ;
4342import org .cloudburstmc .netty .channel .raknet .config .RakChannelOption ;
4443import org .cloudburstmc .netty .channel .raknet .config .RakServerCookieMode ;
4544import org .cloudburstmc .netty .handler .codec .raknet .server .RakServerOfflineHandler ;
5453import org .geysermc .geyser .network .GameProtocol ;
5554import org .geysermc .geyser .network .GeyserServerInitializer ;
5655import org .geysermc .geyser .network .netty .handler .RakConnectionRequestHandler ;
57- import org .geysermc .geyser .network .netty .handler .RakGeyserRateLimiter ;
5856import org .geysermc .geyser .network .netty .handler .RakPingHandler ;
59- import org .geysermc .geyser .network .netty .proxy .ProxyServerHandler ;
6057import org .geysermc .geyser .ping .GeyserPingInfo ;
6158import org .geysermc .geyser .ping .IGeyserPingPassthrough ;
6259import org .geysermc .geyser .skin .SkinProvider ;
@@ -107,8 +104,6 @@ public final class GeyserServer {
107104 private final ServerBootstrap bootstrap ;
108105 private EventLoopGroup playerGroup ;
109106
110- @ Getter
111- private final ExpiringMap <InetSocketAddress , InetSocketAddress > proxiedAddresses ;
112107 private int listenCount ;
113108
114109 private ChannelFuture [] bootstrapFutures ;
@@ -136,14 +131,6 @@ public GeyserServer(GeyserImpl geyser, int threadCount) {
136131 this .listenCount = 1 ;
137132 }
138133
139- if (this .geyser .config ().advanced ().bedrock ().useHaproxyProtocol () || this .geyser .config ().advanced ().bedrock ().useWaterdogpeForwarding ()) {
140- this .proxiedAddresses = ExpiringMap .builder ()
141- .expiration (30 + 1 , TimeUnit .MINUTES )
142- .expirationPolicy (ExpirationPolicy .ACCESSED ).build ();
143- } else {
144- this .proxiedAddresses = null ;
145- }
146-
147134 this .broadcastPort = geyser .config ().advanced ().bedrock ().broadcastPort ();
148135 }
149136
@@ -170,21 +157,6 @@ private void modifyHandlers(ChannelFuture future) {
170157 channel .pipeline ()
171158 .addFirst (RakConnectionRequestHandler .NAME , new RakConnectionRequestHandler (this ))
172159 .addAfter (RakServerOfflineHandler .NAME , RakPingHandler .NAME , new RakPingHandler (this ));
173-
174- // Add proxy handler
175- boolean isProxyProtocol = this .geyser .config ().advanced ().bedrock ().useHaproxyProtocol ();
176- if (isProxyProtocol ) {
177- channel .pipeline ().addFirst ("proxy-protocol-decoder" , new ProxyServerHandler ());
178- }
179-
180- boolean isWhitelistedProxyProtocol = isProxyProtocol && !this .geyser .config ().advanced ().bedrock ().haproxyProtocolWhitelistedIps ().isEmpty ();
181- if (Boolean .parseBoolean (System .getProperty ("Geyser.RakRateLimitingDisabled" , "false" )) || isWhitelistedProxyProtocol ) {
182- // We would already block any non-whitelisted IP addresses in onConnectionRequest so we can remove the rate limiter
183- channel .pipeline ().remove (RakServerRateLimiter .NAME );
184- } else {
185- // Use our own rate limiter to allow multiple players from the same IP
186- channel .pipeline ().replace (RakServerRateLimiter .NAME , RakGeyserRateLimiter .NAME , new RakGeyserRateLimiter (channel ));
187- }
188160 });
189161 }
190162
@@ -237,6 +209,15 @@ private ServerBootstrap createBootstrap() {
237209 boolean rakSendCookie = Boolean .parseBoolean (System .getProperty ("Geyser.RakSendCookie" , "true" ));
238210 this .geyser .getLogger ().debug ("Setting RakNet send cookie to " + rakSendCookie );
239211
212+ int maxConnectionsPerAddress = positivePropOrDefault ("Geyser.MaxConnectionsPerAddress" , 10 );
213+ this .geyser .getLogger ().debug ("Setting max connections per address to " + maxConnectionsPerAddress );
214+
215+ boolean rakRateLimitingDisabled = Boolean .parseBoolean (System .getProperty (
216+ "Geyser.RakRateLimitingDisabled" ,
217+ Boolean .toString (this .geyser .config ().advanced ().bedrock ().useWaterdogpeForwarding ())
218+ ));
219+ this .geyser .getLogger ().debug ("Disabling RakNet rate limiting " + rakRateLimitingDisabled );
220+
240221 GeyserServerInitializer serverInitializer = new GeyserServerInitializer (this .geyser , rakSendCookie );
241222 playerGroup = serverInitializer .getEventLoopGroup ();
242223
@@ -245,13 +226,15 @@ private ServerBootstrap createBootstrap() {
245226 .group (group , childGroup )
246227 .option (RakChannelOption .RAK_HANDLE_PING , true )
247228 .option (RakChannelOption .RAK_MAX_MTU , this .geyser .config ().advanced ().bedrock ().mtu ())
248- .option (RakChannelOption .RAK_PACKET_LIMIT , rakPacketLimit )
229+ .option (RakChannelOption .RAK_PACKET_LIMIT , rakRateLimitingDisabled ? 0 : rakPacketLimit )
249230 .option (RakChannelOption .RAK_GLOBAL_PACKET_LIMIT , rakGlobalPacketLimit )
250231 .option (RakChannelOption .RAK_SERVER_COOKIE_MODE , rakSendCookie ? RakServerCookieMode .ACTIVE : RakServerCookieMode .INVALID )
232+ .option (RakChannelOption .RAK_PROXY_PROTOCOL , this .geyser .config ().advanced ().bedrock ().useHaproxyProtocol ())
233+ .option (RakChannelOption .RAK_THROTTLE , rakRateLimitingDisabled ? null : new DefaultRakServerThrottle (maxConnectionsPerAddress , 4_000 , 3 ))
251234 .childHandler (serverInitializer );
252235 }
253236
254- public boolean onConnectionRequest (InetSocketAddress inetSocketAddress ) {
237+ public boolean onConnectionRequest (InetSocketAddress inetSocketAddress , InetSocketAddress clientAddress ) {
255238 List <String > allowedProxyIPs = geyser .config ().advanced ().bedrock ().haproxyProtocolWhitelistedIps ();
256239 if (geyser .config ().advanced ().bedrock ().useHaproxyProtocol () && !allowedProxyIPs .isEmpty ()) {
257240 boolean isWhitelistedIP = false ;
@@ -268,20 +251,11 @@ public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
268251 }
269252 }
270253
271- String ip ;
272- if (geyser .config ().logPlayerIpAddresses ()) {
273- if (this .proxiedAddresses != null ) {
274- ip = this .proxiedAddresses .getOrDefault (inetSocketAddress , inetSocketAddress ).toString ();
275- } else {
276- ip = inetSocketAddress .toString ();
277- }
278- } else {
279- ip = "<IP address withheld>" ;
280- }
254+ String ip = geyser .config ().logPlayerIpAddresses () ? clientAddress .toString () : "<IP address withheld>" ;
281255
282256 ConnectionRequestEvent requestEvent = new ConnectionRequestEvent (
283- inetSocketAddress ,
284- this . proxiedAddresses != null ? this . proxiedAddresses . get ( inetSocketAddress ) : null
257+ clientAddress ,
258+ geyser . config (). advanced (). bedrock (). useHaproxyProtocol () ? inetSocketAddress : null
285259 );
286260 geyser .eventBus ().fire (requestEvent );
287261 if (requestEvent .isCancelled ()) {
@@ -297,16 +271,7 @@ public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
297271
298272 public BedrockPong onQuery (Channel channel , InetSocketAddress inetSocketAddress ) {
299273 if (geyser .config ().debugMode () && PRINT_DEBUG_PINGS ) {
300- String ip ;
301- if (geyser .config ().logPlayerIpAddresses ()) {
302- if (this .proxiedAddresses != null ) {
303- ip = this .proxiedAddresses .getOrDefault (inetSocketAddress , inetSocketAddress ).toString ();
304- } else {
305- ip = inetSocketAddress .toString ();
306- }
307- } else {
308- ip = "<IP address withheld>" ;
309- }
274+ String ip = geyser .config ().logPlayerIpAddresses () ? inetSocketAddress .toString () : "<IP address withheld>" ;
310275 geyser .getLogger ().debug (GeyserLocale .getLocaleStringLog ("geyser.network.pinged" , ip ));
311276 }
312277
0 commit comments