Search in sources :

Example 1 with ViaVersionConfig

use of com.viaversion.viaversion.api.configuration.ViaVersionConfig in project ViaVersion by ViaVersion.

the class PacketTracker method exceedsMaxPPS.

/**
 * Checks for packet flood with the packets sent in the last second.
 * ALWAYS check for {@link #incrementReceived()} before using this method.
 *
 * @return true if the packet should be cancelled
 * @see #incrementReceived()
 */
public boolean exceedsMaxPPS() {
    // Don't apply PPS limiting for client-side
    if (connection.isClientSide())
        return false;
    ViaVersionConfig conf = Via.getConfig();
    // Max PPS Checker
    if (conf.getMaxPPS() > 0) {
        if (packetsPerSecond >= conf.getMaxPPS()) {
            connection.disconnect(conf.getMaxPPSKickMessage().replace("%pps", Long.toString(packetsPerSecond)));
            // don't send current packet
            return true;
        }
    }
    // Tracking PPS Checker
    if (conf.getMaxWarnings() > 0 && conf.getTrackingPeriod() > 0) {
        if (secondsObserved > conf.getTrackingPeriod()) {
            // Reset
            warnings = 0;
            secondsObserved = 1;
        } else {
            secondsObserved++;
            if (packetsPerSecond >= conf.getWarningPPS()) {
                warnings++;
            }
            if (warnings >= conf.getMaxWarnings()) {
                connection.disconnect(conf.getMaxWarningsKickMessage().replace("%pps", Long.toString(packetsPerSecond)));
                // don't send current packet
                return true;
            }
        }
    }
    return false;
}
Also used : ViaVersionConfig(com.viaversion.viaversion.api.configuration.ViaVersionConfig)

Aggregations

ViaVersionConfig (com.viaversion.viaversion.api.configuration.ViaVersionConfig)1