Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add KeepAliveFrequency check, add missing @GlobalConfig.
Limit the number of keep-alive packets to one per second.
- Loading branch information
Showing
11 changed files
with
162 additions
and
32 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...tocolLib/src/main/java/fr/neatmonster/nocheatplus/checks/net/protocollib/BaseAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package fr.neatmonster.nocheatplus.checks.net.protocollib; | ||
|
||
import org.bukkit.plugin.Plugin; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.events.ListenerOptions; | ||
import com.comphenix.protocol.events.ListenerPriority; | ||
import com.comphenix.protocol.events.PacketAdapter; | ||
|
||
import fr.neatmonster.nocheatplus.NCPAPIProvider; | ||
import fr.neatmonster.nocheatplus.checks.CheckType; | ||
import fr.neatmonster.nocheatplus.checks.net.NetConfigCache; | ||
import fr.neatmonster.nocheatplus.checks.net.NetDataFactory; | ||
import fr.neatmonster.nocheatplus.stats.Counters; | ||
|
||
/** | ||
* Convenience base class for PacketAdapter creation with using config, data, counters. | ||
* @author asofold | ||
* | ||
*/ | ||
public abstract class BaseAdapter extends PacketAdapter { | ||
|
||
protected final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class); | ||
protected final NetConfigCache configFactory = (NetConfigCache) CheckType.NET.getConfigFactory(); | ||
protected final NetDataFactory dataFactory = (NetDataFactory) CheckType.NET.getDataFactory(); | ||
|
||
public BaseAdapter(AdapterParameteters params) { | ||
super(params); | ||
} | ||
|
||
public BaseAdapter(Plugin plugin, Iterable<? extends PacketType> types) { | ||
super(plugin, types); | ||
} | ||
|
||
public BaseAdapter(Plugin plugin, ListenerPriority listenerPriority, Iterable<? extends PacketType> types, ListenerOptions... options) { | ||
super(plugin, listenerPriority, types, options); | ||
} | ||
|
||
public BaseAdapter(Plugin plugin, ListenerPriority listenerPriority, Iterable<? extends PacketType> types) { | ||
super(plugin, listenerPriority, types); | ||
} | ||
|
||
public BaseAdapter(Plugin plugin, ListenerPriority listenerPriority, PacketType... types) { | ||
super(plugin, listenerPriority, types); | ||
} | ||
|
||
public BaseAdapter(Plugin plugin, PacketType... types) { | ||
super(plugin, types); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...b/src/main/java/fr/neatmonster/nocheatplus/checks/net/protocollib/KeepAliveFrequency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package fr.neatmonster.nocheatplus.checks.net.protocollib; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import com.comphenix.protocol.PacketType; | ||
import com.comphenix.protocol.events.ListenerPriority; | ||
import com.comphenix.protocol.events.PacketEvent; | ||
|
||
import fr.neatmonster.nocheatplus.checks.Check; | ||
import fr.neatmonster.nocheatplus.checks.CheckType; | ||
import fr.neatmonster.nocheatplus.checks.net.NetConfig; | ||
import fr.neatmonster.nocheatplus.checks.net.NetData; | ||
|
||
public class KeepAliveFrequency extends BaseAdapter { | ||
|
||
/** Dummy check for bypass checking and actions execution. */ | ||
private final Check check = new Check(CheckType.NET_KEEPALIVEFREQUENCY) {}; | ||
|
||
public KeepAliveFrequency(Plugin plugin) { | ||
super(plugin, ListenerPriority.LOW, PacketType.Play.Client.KEEP_ALIVE); | ||
} | ||
|
||
@Override | ||
public void onPacketReceiving(final PacketEvent event) { | ||
final long time = System.currentTimeMillis(); | ||
final Player player = event.getPlayer(); | ||
if (player == null) { | ||
counters.add(ProtocolLibComponent.idNullPlayer, 1); | ||
event.setCancelled(true); | ||
return; | ||
} | ||
final NetConfig cc = configFactory.getConfig(player); | ||
if (!cc.keepAliveFrequencyActive) { | ||
return; | ||
} | ||
final NetData data = dataFactory.getData(player); | ||
// TODO: Better modeling of actual packet sequences (flying vs. keep alive vs. request/ping). | ||
// TODO: Better integration wih god-mode check / trigger reset ndt. | ||
data.keepAliveFreq.add(time, 1f); | ||
// Use last time accepted as a hard reference. | ||
final float first = data.keepAliveFreq.bucketScore(0); | ||
if (first > 1f && !check.hasBypass(player)) { | ||
// Trigger a violation. | ||
final double vl = Math.max(first - 1f, data.keepAliveFreq.score(1f) - data.keepAliveFreq.numberOfBuckets()); | ||
if (check.executeActions(player, vl, 1.0, cc.keepAliveFrequencyActions)) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onPacketSending(PacketEvent event) { | ||
// TODO: Maybe detect if keep alive wasn't asked for + allow cancel. | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters