mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-02-05 22:31:26 +01:00
Add basic (mostly global) configuration for net checks.
Currently the parameters except for the "active" flag are not available per-world, but this can be added later.
This commit is contained in:
parent
02eea231b7
commit
289da86c35
@ -11,6 +11,9 @@ import com.comphenix.protocol.events.PacketEvent;
|
|||||||
|
|
||||||
import fr.neatmonster.nocheatplus.NCPAPIProvider;
|
import fr.neatmonster.nocheatplus.NCPAPIProvider;
|
||||||
import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
|
import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
|
||||||
|
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||||
|
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
||||||
|
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||||
import fr.neatmonster.nocheatplus.stats.Counters;
|
import fr.neatmonster.nocheatplus.stats.Counters;
|
||||||
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
||||||
import fr.neatmonster.nocheatplus.utilities.ds.LinkedHashMapCOW;
|
import fr.neatmonster.nocheatplus.utilities.ds.LinkedHashMapCOW;
|
||||||
@ -33,9 +36,15 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
|
|||||||
private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class);
|
private final Counters counters = NCPAPIProvider.getNoCheatPlusAPI().getGenericInstance(Counters.class);
|
||||||
private final int idSilent = counters.registerKey("packet.flying.silentcancel");
|
private final int idSilent = counters.registerKey("packet.flying.silentcancel");
|
||||||
|
|
||||||
|
private final int seconds;
|
||||||
|
private final float maxPackets;
|
||||||
|
|
||||||
public FlyingFrequency(Plugin plugin) {
|
public FlyingFrequency(Plugin plugin) {
|
||||||
// PacketPlayInFlying[3, legacy: 10]
|
// PacketPlayInFlying[3, legacy: 10]
|
||||||
super(plugin, PacketType.Play.Client.FLYING); // TODO: How does POS and POS_LOOK relate/translate?
|
super(plugin, PacketType.Play.Client.FLYING); // TODO: How does POS and POS_LOOK relate/translate?
|
||||||
|
ConfigFile config = ConfigManager.getConfigFile();
|
||||||
|
seconds = Math.max(1, config.getInt(ConfPaths.NET_FLYINGFREQUENCY_SECONDS));
|
||||||
|
maxPackets = Math.max(1, config.getInt(ConfPaths.NET_FLYINGFREQUENCY_MAXPACKETS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -53,10 +62,10 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
|
|||||||
if (freq != null) {
|
if (freq != null) {
|
||||||
return freq;
|
return freq;
|
||||||
} else {
|
} else {
|
||||||
final ActionFrequency newFreq = new ActionFrequency(5, 1000);
|
final ActionFrequency newFreq = new ActionFrequency(seconds, 1000);
|
||||||
this.freqMap.put(name, newFreq);
|
this.freqMap.put(name, newFreq);
|
||||||
return newFreq;
|
return newFreq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,7 +73,7 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
|
|||||||
// TODO: Add several (at least has look + has pos individually, maybe none/onground)
|
// TODO: Add several (at least has look + has pos individually, maybe none/onground)
|
||||||
final ActionFrequency freq = getFreq(event.getPlayer().getName());
|
final ActionFrequency freq = getFreq(event.getPlayer().getName());
|
||||||
freq.add(System.currentTimeMillis(), 1f);
|
freq.add(System.currentTimeMillis(), 1f);
|
||||||
if (freq.score(1f) > 300) {
|
if (freq.score(1f) > maxPackets) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
counters.add(idSilent, 1); // Until it is sure if we can get these async.
|
counters.add(idSilent, 1); // Until it is sure if we can get these async.
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,22 @@
|
|||||||
package fr.neatmonster.nocheatplus.net.protocollib;
|
package fr.neatmonster.nocheatplus.net.protocollib;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
import com.comphenix.protocol.events.PacketAdapter;
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
|
|
||||||
|
import fr.neatmonster.nocheatplus.NCPAPIProvider;
|
||||||
import fr.neatmonster.nocheatplus.components.DisableListener;
|
import fr.neatmonster.nocheatplus.components.DisableListener;
|
||||||
|
import fr.neatmonster.nocheatplus.components.INotifyReload;
|
||||||
|
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
|
||||||
|
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||||
|
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||||
import fr.neatmonster.nocheatplus.logging.LogUtil;
|
import fr.neatmonster.nocheatplus.logging.LogUtil;
|
||||||
import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
||||||
|
|
||||||
@ -20,46 +25,64 @@ import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
|||||||
* @author dev1mc
|
* @author dev1mc
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ProtocolLibComponent implements DisableListener{
|
public class ProtocolLibComponent implements DisableListener, INotifyReload{
|
||||||
|
|
||||||
private final List<PacketAdapter> registeredPacketAdapters = new LinkedList<PacketAdapter>();
|
private final List<PacketAdapter> registeredPacketAdapters = new LinkedList<PacketAdapter>();
|
||||||
|
|
||||||
public ProtocolLibComponent(Plugin plugin) {
|
public ProtocolLibComponent(Plugin plugin) {
|
||||||
// Register with ProtocolLib
|
LogUtil.logInfo("Adding packet level hooks for ProtocolLib (MC " + ProtocolLibrary.getProtocolManager().getMinecraftVersion().getVersion() + ")...");
|
||||||
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
register(plugin);
|
||||||
LogUtil.logInfo("[NoCheatPlus] ProtocolLib seems to be available, attempt to add packet level hooks...");
|
}
|
||||||
// Classes having a constructor with Plugin as argument.
|
|
||||||
List<Class<? extends PacketAdapter>> adapterClasses = Arrays.asList(
|
private void register(Plugin plugin) {
|
||||||
FlyingFrequency.class,
|
// REgister Classes having a constructor with Plugin as argument.
|
||||||
SoundDistance.class // Need too: SPAWN_ENTITY_WEATHER, wither/dragon: WORLD_EVENT
|
// TODO: Config paths for activation flags ...
|
||||||
);
|
// TODO: @GlobalConfig simple setup at first.
|
||||||
// TODO: Configurability (INotifyConfig, method to set up hooks).
|
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE)) {
|
||||||
for (Class<? extends PacketAdapter> clazz : adapterClasses) {
|
register(FlyingFrequency.class, plugin);
|
||||||
try {
|
}
|
||||||
// Construct a new instance using reflection.
|
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_SOUNDDISTANCE_ACTIVE)) {
|
||||||
PacketAdapter adapter = clazz.getDeclaredConstructor(Plugin.class).newInstance(plugin);
|
register(SoundDistance.class, plugin);
|
||||||
protocolManager.addPacketListener(adapter);
|
|
||||||
registeredPacketAdapters.add(adapter);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
LogUtil.logWarning("[NoCheatPlus] Could not register packet level hook: " + clazz.getSimpleName());
|
|
||||||
LogUtil.logWarning(t); // TODO: Maybe temporary.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!registeredPacketAdapters.isEmpty()) {
|
if (!registeredPacketAdapters.isEmpty()) {
|
||||||
List<String> names = new ArrayList<String>(registeredPacketAdapters.size());
|
List<String> names = new ArrayList<String>(registeredPacketAdapters.size());
|
||||||
for (PacketAdapter adapter : registeredPacketAdapters) {
|
for (PacketAdapter adapter : registeredPacketAdapters) {
|
||||||
names.add(adapter.getClass().getSimpleName());
|
names.add(adapter.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
LogUtil.logInfo("[NoCheatPlus] Available packet level hooks: " + StringUtil.join(names, " | "));
|
LogUtil.logInfo("[NoCheatPlus] Available (and activated) packet level hooks: " + StringUtil.join(names, " | "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void register(Class<? extends PacketAdapter> clazz, Plugin plugin) {
|
||||||
|
try {
|
||||||
|
// Construct a new instance using reflection.
|
||||||
|
PacketAdapter adapter = clazz.getDeclaredConstructor(Plugin.class).newInstance(plugin);
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(adapter);
|
||||||
|
registeredPacketAdapters.add(adapter);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
LogUtil.logWarning("[NoCheatPlus] Could not register packet level hook: " + clazz.getSimpleName());
|
||||||
|
LogUtil.logWarning(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
unregister();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReload() {
|
||||||
|
unregister();
|
||||||
|
register(Bukkit.getPluginManager().getPlugin("NoCheatPlus")); // Store instead ?
|
||||||
|
}
|
||||||
|
|
||||||
|
private void unregister() {
|
||||||
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
|
||||||
for (PacketAdapter adapter : registeredPacketAdapters) {
|
for (PacketAdapter adapter : registeredPacketAdapters) {
|
||||||
try {
|
try {
|
||||||
protocolManager.removePacketListener(adapter);
|
protocolManager.removePacketListener(adapter);
|
||||||
|
api.removeComponent(adapter); // Bit heavy, but consistent.
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
LogUtil.logWarning("[NoCheatPlus] Failed to unregister packet level hook: " + adapter.getClass().getName());
|
LogUtil.logWarning("[NoCheatPlus] Failed to unregister packet level hook: " + adapter.getClass().getName());
|
||||||
}
|
}
|
||||||
|
@ -10,15 +10,15 @@ import com.comphenix.protocol.events.PacketContainer;
|
|||||||
import com.comphenix.protocol.events.PacketEvent;
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
|
|
||||||
|
import fr.neatmonster.nocheatplus.config.ConfPaths;
|
||||||
|
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
||||||
|
import fr.neatmonster.nocheatplus.config.ConfigManager;
|
||||||
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
|
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
|
||||||
|
|
||||||
public class SoundDistance extends PacketAdapter {
|
public class SoundDistance extends PacketAdapter {
|
||||||
|
|
||||||
// TODO: Will not be effective with 512 radius, if they add the patch by @Amranth.
|
// TODO: Will not be effective with 512 radius, if they add the patch by @Amranth.
|
||||||
// TODO: For lower distances more packets might need to be intercepted.
|
// TODO: For lower distances more packets might need to be intercepted.
|
||||||
|
|
||||||
/** Maximum distance for thunder effects (squared). */
|
|
||||||
private static final double distSq = 320.0 * 320.0; // TODO:configurable.
|
|
||||||
|
|
||||||
private static final String[] effectNames = new String[] { // Prefix tree?
|
private static final String[] effectNames = new String[] { // Prefix tree?
|
||||||
"ambient.weather.thunder",
|
"ambient.weather.thunder",
|
||||||
@ -35,9 +35,15 @@ public class SoundDistance extends PacketAdapter {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Maximum distance for thunder effects (squared). */
|
||||||
|
private final double distSq;
|
||||||
|
|
||||||
public SoundDistance(Plugin plugin) {
|
public SoundDistance(Plugin plugin) {
|
||||||
super(plugin, PacketType.Play.Server.NAMED_SOUND_EFFECT);
|
super(plugin, PacketType.Play.Server.NAMED_SOUND_EFFECT);
|
||||||
|
ConfigFile config = ConfigManager.getConfigFile();
|
||||||
|
double dist = config.getDouble(ConfPaths.NET_SOUNDDISTANCE_MAXDISTANCE);
|
||||||
|
distSq = dist * dist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -585,6 +585,20 @@ public abstract class ConfPaths {
|
|||||||
public static final String MOVING_TRACE_SIZE = MOVING_TRACE + "size";
|
public static final String MOVING_TRACE_SIZE = MOVING_TRACE + "size";
|
||||||
public static final String MOVING_TRACE_MERGEDIST = MOVING_TRACE + "mergedist";
|
public static final String MOVING_TRACE_MERGEDIST = MOVING_TRACE + "mergedist";
|
||||||
|
|
||||||
|
private static final String NET = CHECKS + "net.";
|
||||||
|
|
||||||
|
private static final String NET_SOUNDDISTANCE = NET + "sounddistance.";
|
||||||
|
public static final String NET_SOUNDDISTANCE_ACTIVE = NET_SOUNDDISTANCE + "active";
|
||||||
|
@GlobalConfig
|
||||||
|
public static final String NET_SOUNDDISTANCE_MAXDISTANCE = NET_SOUNDDISTANCE + "maxdistance";
|
||||||
|
|
||||||
|
private static final String NET_FLYINGFREQUENCY = NET + "flyingfrequency.";
|
||||||
|
public static final String NET_FLYINGFREQUENCY_ACTIVE = NET_FLYINGFREQUENCY + "active";
|
||||||
|
@GlobalConfig
|
||||||
|
public static final String NET_FLYINGFREQUENCY_SECONDS = NET_FLYINGFREQUENCY + "seconds";
|
||||||
|
@GlobalConfig
|
||||||
|
public static final String NET_FLYINGFREQUENCY_MAXPACKETS = NET_FLYINGFREQUENCY + "maxpackets";
|
||||||
|
|
||||||
|
|
||||||
public static final String STRINGS = "strings";
|
public static final String STRINGS = "strings";
|
||||||
|
|
||||||
|
@ -423,6 +423,18 @@ public class DefaultConfig extends ConfigFile {
|
|||||||
set(ConfPaths.MOVING_SPEEDGRACE, 4.0);
|
set(ConfPaths.MOVING_SPEEDGRACE, 4.0);
|
||||||
set(ConfPaths.MOVING_ENFORCELOCATION, true);
|
set(ConfPaths.MOVING_ENFORCELOCATION, true);
|
||||||
|
|
||||||
|
// NET
|
||||||
|
|
||||||
|
// FlyingFrequency
|
||||||
|
set(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE, true);
|
||||||
|
set(ConfPaths.NET_FLYINGFREQUENCY_SECONDS, 5);
|
||||||
|
set(ConfPaths.NET_FLYINGFREQUENCY_MAXPACKETS, 300);
|
||||||
|
|
||||||
|
// SoundDistance
|
||||||
|
set(ConfPaths.NET_SOUNDDISTANCE_ACTIVE, true);
|
||||||
|
set(ConfPaths.NET_SOUNDDISTANCE_MAXDISTANCE, 320);
|
||||||
|
|
||||||
|
|
||||||
// TODO: An extra file might suit these.
|
// TODO: An extra file might suit these.
|
||||||
final String start = "[player] failed [check]: ";
|
final String start = "[player] failed [check]: ";
|
||||||
final String end = ". VL [violations].";
|
final String end = ". VL [violations].";
|
||||||
|
Loading…
Reference in New Issue
Block a user