diff --git a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java index 6e4e2cb84..d7f280663 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/config/VelocityConfiguration.java @@ -998,22 +998,28 @@ public class VelocityConfiguration implements ProxyConfig { } } - /** - * Configuration for packet limiting. - * - * @param interval the interval in seconds to measure packets over - * @param pps the maximum number of packets per second allowed - * @param bytes the maximum number of bytes per second allowed - */ + /** + * Configuration for packet limiting. + * + * @param interval the interval in seconds to measure packets over + * @param pps the maximum number of packets per second allowed + * @param bytes the maximum number of bytes per second allowed + */ public record PacketLimiterConfig(int interval, int pps, int bytes) { public static PacketLimiterConfig DEFAULT = new PacketLimiterConfig(7, 500, -1); + /** + * returns a PacketLimiterConfig from a config section, or the default if the section is null. + * + * @param config the configuration object to parse + * @return the packet limiter config, or the default if {@code config} is null + */ public static PacketLimiterConfig fromConfig(CommentedConfig config) { if (config != null) { return new PacketLimiterConfig( config.getIntOrElse("interval", DEFAULT.interval()), - config.getIntOrElse("pps", DEFAULT.pps()), - config.getIntOrElse("bytes", DEFAULT.bytes()) + config.getIntOrElse("packets-per-second", DEFAULT.pps()), + config.getIntOrElse("bytes-per-second", DEFAULT.bytes()) ); } else { return DEFAULT; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java index 048d5d085..fae9113f6 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/network/ServerChannelInitializer.java @@ -77,12 +77,12 @@ public class ServerChannelInitializer extends ChannelInitializer { VelocityConfiguration.PacketLimiterConfig packetLimiterConfig = server.getConfiguration().getPacketLimiterConfig(); int configuredInterval = packetLimiterConfig.interval(); - int configuredPPS = packetLimiterConfig.pps(); + int configuredPacketsPerSecond = packetLimiterConfig.pps(); int configuredBytes = packetLimiterConfig.bytes(); - if (configuredInterval > 0 && (configuredBytes > 0 || configuredPPS > 0)) { + if (configuredInterval > 0 && (configuredBytes > 0 || configuredPacketsPerSecond > 0)) { ch.pipeline().get(MinecraftVarintFrameDecoder.class).setPacketLimiter( - new SimpleBytesPerSecondLimiter(configuredPPS, configuredBytes, configuredInterval) + new SimpleBytesPerSecondLimiter(configuredPacketsPerSecond, configuredBytes, configuredInterval) ); } if (this.server.getConfiguration().isProxyProtocol()) { diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/IntervalledCounter.java b/proxy/src/main/java/com/velocitypowered/proxy/util/IntervalledCounter.java index 24bfe4193..9b986dca2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/IntervalledCounter.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/IntervalledCounter.java @@ -30,6 +30,7 @@ package com.velocitypowered.proxy.util; *

This class is not thread-safe. If multiple threads access an instance concurrently, * external synchronization is required.

*/ +@SuppressWarnings("checkstyle:WhitespaceAfter") // Not our class public final class IntervalledCounter { private static final int INITIAL_SIZE = 8; diff --git a/proxy/src/main/resources/default-velocity.toml b/proxy/src/main/resources/default-velocity.toml index a742fe60f..6aa5ceaa8 100644 --- a/proxy/src/main/resources/default-velocity.toml +++ b/proxy/src/main/resources/default-velocity.toml @@ -75,9 +75,9 @@ sample-players-in-ping = false enable-player-address-logging = true [packet-limiter] -interval = 3000 -pps = 100 -bytes = 1000 +interval = 7 +packets-per-second = 500 +bytes-per-second = -1 [servers] # Configure your servers here. Each key represents the server's name, and the value