3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Implement PPS for Sponge

Dieser Commit ist enthalten in:
Matsv 2016-09-26 11:16:20 +02:00
Ursprung 4840db095c
Commit 9a8a6e5b16
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 97CEC2A2EA31350F
4 geänderte Dateien mit 38 neuen und 36 gelöschten Zeilen

Datei anzeigen

@ -137,36 +137,6 @@ public class ViaVersionPlugin extends JavaPlugin implements ViaPlatform {
return protocolSupport; return protocolSupport;
} }
public boolean handlePPS(UserConnection info) {
// Max PPS Checker
if (conf.getMaxPPS() > 0) {
if (info.getPacketsPerSecond() >= conf.getMaxPPS()) {
info.disconnect(conf.getMaxPPSKickMessage().replace("%pps", ((Long) info.getPacketsPerSecond()).intValue() + ""));
return true; // don't send current packet
}
}
// Tracking PPS Checker
if (conf.getMaxWarnings() > 0 && conf.getTrackingPeriod() > 0) {
if (info.getSecondsObserved() > conf.getTrackingPeriod()) {
// Reset
info.setWarnings(0);
info.setSecondsObserved(1);
} else {
info.setSecondsObserved(info.getSecondsObserved() + 1);
if (info.getPacketsPerSecond() >= conf.getWarningPPS()) {
info.setWarnings(info.getWarnings() + 1);
}
if (info.getWarnings() >= conf.getMaxWarnings()) {
info.disconnect(conf.getMaxWarningsKickMessage().replace("%pps", ((Long) info.getPacketsPerSecond()).intValue() + ""));
return true; // don't send current packet
}
}
}
return false;
}
@Override @Override
public String getPlatformName() { public String getPlatformName() {
return "Bukkit"; return "Bukkit";

Datei anzeigen

@ -39,7 +39,7 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
boolean second = info.incrementReceived(); boolean second = info.incrementReceived();
// Check PPS // Check PPS
if (second) { if (second) {
if (((ViaVersionPlugin) Via.getPlatform()).handlePPS(info)) if (info.handlePPS())
return; return;
} }

Datei anzeigen

@ -7,6 +7,7 @@ import io.netty.channel.socket.SocketChannel;
import lombok.Data; import lombok.Data;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.ViaVersionConfig;
import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import java.util.Map; import java.util.Map;
@ -133,6 +134,37 @@ public class UserConnection {
return false; return false;
} }
public boolean handlePPS() {
ViaVersionConfig conf = Via.getConfig();
// Max PPS Checker
if (conf.getMaxPPS() > 0) {
if (getPacketsPerSecond() >= conf.getMaxPPS()) {
disconnect(conf.getMaxPPSKickMessage().replace("%pps", ((Long) getPacketsPerSecond()).intValue() + ""));
return true; // don't send current packet
}
}
// Tracking PPS Checker
if (conf.getMaxWarnings() > 0 && conf.getTrackingPeriod() > 0) {
if (getSecondsObserved() > conf.getTrackingPeriod()) {
// Reset
setWarnings(0);
setSecondsObserved(1);
} else {
setSecondsObserved(getSecondsObserved() + 1);
if (getPacketsPerSecond() >= conf.getWarningPPS()) {
setWarnings(getWarnings() + 1);
}
if (getWarnings() >= conf.getMaxWarnings()) {
disconnect(conf.getMaxWarningsKickMessage().replace("%pps", ((Long) getPacketsPerSecond()).intValue() + ""));
return true; // don't send current packet
}
}
}
return false;
}
/** /**
* Disconnect a connection * Disconnect a connection
* *

Datei anzeigen

@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.exception.CancelException; import us.myles.ViaVersion.exception.CancelException;
@ -35,11 +36,10 @@ public class ViaDecodeHandler extends ByteToMessageDecoder {
// Increment received // Increment received
boolean second = info.incrementReceived(); boolean second = info.incrementReceived();
// Check PPS // Check PPS
// TODO implement pps if (second) {
// if (second) { if (info.handlePPS())
// if (((ViaVersionPlugin) Via.getPlatform()).handlePPS(info)) return;
// return; }
// }
if (info.isActive()) { if (info.isActive()) {
// Handle ID // Handle ID