Add after-failure config flag checks for net/packet checks.

Obviously these have been forgotten, but are not marked with
@GlobalConfig. Using after-failure checking, because the raw config
getting and accessing might be slightly heavy-ish.
This commit is contained in:
asofold 2014-10-31 11:03:23 +01:00
parent 07bc7f6a90
commit 95763d35c8
3 changed files with 38 additions and 34 deletions

View File

@ -70,13 +70,16 @@ public class FlyingFrequency extends PacketAdapter implements JoinLeaveListener
@Override
public void onPacketReceiving(final PacketEvent event) {
// TODO: Add several (at least has look + has pos individually, maybe none/onground)
final ActionFrequency freq = getFreq(event.getPlayer().getName());
freq.add(System.currentTimeMillis(), 1f);
if (freq.score(1f) > maxPackets) {
event.setCancelled(true);
counters.add(idSilent, 1); // Until it is sure if we can get these async.
}
// TODO: Add several (at least has look + has pos individually, maybe none/onground)
final ActionFrequency freq = getFreq(event.getPlayer().getName());
freq.add(System.currentTimeMillis(), 1f);
if (freq.score(1f) > maxPackets) {
// TODO: Get from a NetConfig (optimized).
if (ConfigManager.getConfigFile(event.getPlayer().getWorld().getName()).getBoolean(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE)) {
event.setCancelled(true);
counters.add(idSilent, 1); // Until it is sure if we can get these async.
}
}
}
}

View File

@ -35,9 +35,7 @@ public class ProtocolLibComponent implements DisableListener, INotifyReload{
}
private void register(Plugin plugin) {
// REgister Classes having a constructor with Plugin as argument.
// TODO: Config paths for activation flags ...
// TODO: @GlobalConfig simple setup at first.
// Register Classes having a constructor with Plugin as argument.
if (ConfigManager.isTrueForAnyConfig(ConfPaths.NET_FLYINGFREQUENCY_ACTIVE)) {
register(FlyingFrequency.class, plugin);
}

View File

@ -16,30 +16,30 @@ import fr.neatmonster.nocheatplus.config.ConfigManager;
import fr.neatmonster.nocheatplus.utilities.TrigUtil;
public class SoundDistance extends PacketAdapter {
// 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: 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.
private static final String[] effectNames = new String[] { // Prefix tree?
"ambient.weather.thunder",
"wither-spawn-sound-radius",
"dragon-death-sound-radius"
// other ?
"ambient.weather.thunder",
"wither-spawn-sound-radius",
"dragon-death-sound-radius"
// other ?
};
private static final boolean contains(final String ref) {
for (int i = 0; i < effectNames.length; i++) {
if (effectNames[i].equals(ref)) {
return true;
}
}
return false;
for (int i = 0; i < effectNames.length; i++) {
if (effectNames[i].equals(ref)) {
return true;
}
}
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);
ConfigFile config = ConfigManager.getConfigFile();
double dist = config.getDouble(ConfPaths.NET_SOUNDDISTANCE_MAXDISTANCE);
@ -49,20 +49,23 @@ public class SoundDistance extends PacketAdapter {
@Override
public void onPacketSending(final PacketEvent event) {
final PacketContainer packetContainer = event.getPacket();
final Player player = event.getPlayer();
// Compare sound effect name.
if (!contains(packetContainer.getStrings().read(0))) {
return;
return;
}
final Player player = event.getPlayer();
final Location loc = player.getLocation(); // TODO: Use getLocation(useLoc) [synced if async].
// Compare distance of player to the weather location.
final StructureModifier<Integer> ints = packetContainer.getIntegers();
if (TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(2) / 8, loc.getX(), loc.getZ()) > distSq) {
event.setCancelled(true);
// TODO: Get from a NetConfig (optimized).
if (ConfigManager.getConfigFile(player.getWorld().getName()).getBoolean(ConfPaths.NET_SOUNDDISTANCE_ACTIVE)) {
event.setCancelled(true);
}
}
}
}