Validate packet limiter system properties

Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
Joshua Castle 2024-03-31 10:50:56 -07:00
parent 307acc3163
commit 97c29e2493
No known key found for this signature in database
GPG Key ID: 7ECA1A2FC38ABA9F
1 changed files with 24 additions and 7 deletions

View File

@ -213,19 +213,15 @@ public final class GeyserServer {
playerGroup = serverInitializer.getEventLoopGroup();
this.geyser.getLogger().debug("Setting MTU to " + this.geyser.getConfig().getMtu());
String geyserRakPacketLimit = System.getProperty("Geyser.RakPacketLimit");
int rakPacketLimit = geyserRakPacketLimit != null ? Integer.parseInt(geyserRakPacketLimit) : DEFAULT_PACKET_LIMIT;
int rakPacketLimit = positivePropOrDefault("Geyser.RakPacketLimit", DEFAULT_PACKET_LIMIT);
this.geyser.getLogger().debug("Setting RakNet packet limit to " + rakPacketLimit);
String geyserRakOfflinePacketLimit = System.getProperty("Geyser.RakOfflinePacketLimit");
boolean isWhitelistedProxyProtocol = this.geyser.getConfig().getBedrock().isEnableProxyProtocol()
&& !this.geyser.getConfig().getBedrock().getProxyProtocolWhitelistedIPs().isEmpty();
int rakOfflinePacketLimit = geyserRakOfflinePacketLimit != null ? Integer.parseInt(geyserRakOfflinePacketLimit)
: isWhitelistedProxyProtocol ? Integer.MAX_VALUE : DEFAULT_OFFLINE_PACKET_LIMIT;
int rakOfflinePacketLimit = positivePropOrDefault("Geyser.RakOfflinePacketLimit", isWhitelistedProxyProtocol ? Integer.MAX_VALUE : DEFAULT_OFFLINE_PACKET_LIMIT);
this.geyser.getLogger().debug("Setting RakNet offline packet limit to " + rakOfflinePacketLimit);
String geyserRakGlobalPacketLimit = System.getProperty("Geyser.RakGlobalPacketLimit");
int rakGlobalPacketLimit = geyserRakGlobalPacketLimit != null ? Integer.parseInt(geyserRakGlobalPacketLimit) : DEFAULT_GLOBAL_PACKET_LIMIT;
int rakGlobalPacketLimit = positivePropOrDefault("Geyser.RakGlobalPacketLimit", DEFAULT_GLOBAL_PACKET_LIMIT);
this.geyser.getLogger().debug("Setting RakNet global packet limit to " + rakGlobalPacketLimit);
return new ServerBootstrap()
@ -384,6 +380,27 @@ public final class GeyserServer {
}
}
private static int positivePropOrDefault(String property, int defaultValue) {
String value = System.getProperty(property);
try {
int parsed = value != null ? Integer.parseInt(value) : defaultValue;
if (parsed < 1) {
GeyserImpl.getInstance().getLogger().warning(
"Non-postive integer value for " + property + ": " + value + ". Using default value: " + defaultValue
);
return defaultValue;
}
return parsed;
} catch (NumberFormatException e) {
GeyserImpl.getInstance().getLogger().warning(
"Invalid integer value for " + property + ": " + value + ". Using default value: " + defaultValue
);
return defaultValue;
}
}
private static Transport compatibleTransport() {
TransportHelper.TransportMethod transportMethod = TransportHelper.determineTransportMethod();
if (transportMethod == TransportHelper.TransportMethod.EPOLL) {