use of com.abilityapi.sequenceapi.SequenceContext in project guardian by ichorpowered.
the class InvalidCheck method getSequence.
@Nonnull
@Override
public SequenceBlueprint<Event> getSequence(final Detection detection) {
final Double analysisTime = detection.getContentContainer().get(ContentKeys.ANALYSIS_TIME).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
final Double minimumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MINIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
final Double maximumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MAXIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
return new GuardianSequenceBuilder().capture(new InvalidControlCapture(detection.getPlugin(), detection)).observe(MoveEntityEvent.class).observe(MoveEntityEvent.class).delay(analysisTime.intValue()).expire(maximumTickRate.intValue()).condition(sequenceContext -> {
final GuardianPlayerEntry<Player> entityEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
final Summary summary = sequenceContext.get(CommonContextKeys.SUMMARY);
final GuardianCaptureRegistry captureRegistry = sequenceContext.get(CommonContextKeys.CAPTURE_REGISTRY);
final long lastActionTime = sequenceContext.get(CommonContextKeys.LAST_ACTION_TIME);
summary.set(SequenceReport.class, new SequenceReport(false, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build()));
if (!entityEntry.getEntity(Player.class).isPresent())
return false;
final Player player = entityEntry.getEntity(Player.class).get();
/*
* Capture Collection
*/
final CaptureContainer captureContainer = captureRegistry.getContainer();
Optional<Location> initial = captureContainer.get(GuardianSequence.INITIAL_LOCATION);
Optional<Set<String>> invalidControls = captureContainer.get(InvalidControlCapture.INVALID_CONTROLS);
if (!initial.isPresent() || !invalidControls.isPresent())
return false;
long current = System.currentTimeMillis();
// Finds the average between now and the last action.
double averageClockRate = ((current - lastActionTime) / 1000) / 0.05;
if (averageClockRate < minimumTickRate) {
detection.getLogger().warn("The server may be overloaded. A check could not be completed.");
return false;
} else if (averageClockRate > maximumTickRate) {
return false;
}
if (invalidControls.get().isEmpty() || player.get(Keys.VEHICLE).isPresent())
return false;
// ------------------------- DEBUG -----------------------------
System.out.println(player.getName() + " has been caught using invalid movement hacks.");
// -------------------------------------------------------------
SequenceReport report = new SequenceReport(true, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build());
report.put("type", "InvalidControlCapture Movement");
report.put("information", Collections.singletonList("Received invalid controls of " + StringUtils.join((Set<String>) invalidControls.get(), ", ") + "."));
report.put("initial_location", initial.get());
report.put("final_location", player.getLocation());
report.put("severity", 1d);
summary.set(SequenceReport.class, report);
return true;
}, ConditionType.NORMAL).build(SequenceContext.builder().owner(detection).root(this).build());
}
use of com.abilityapi.sequenceapi.SequenceContext in project guardian by ichorpowered.
the class VerticalSpeedCheck method getSequence.
@Nonnull
@Override
public SequenceBlueprint<Event> getSequence(final Detection detection) {
final Double analysisTime = detection.getContentContainer().get(ContentKeys.ANALYSIS_TIME).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
final Double minimumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MINIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
final Double maximumTickRate = detection.getContentContainer().get(ContentKeys.ANALYSIS_MAXIMUM_TICK).orElse(GuardianValue.empty()).getDirect().orElse(0d) / 0.05;
return new GuardianSequenceBuilder().capture(new ControlCapture(detection.getPlugin(), detection)).capture(new PotionEffectCapture(detection.getPlugin(), detection)).observe(MoveEntityEvent.class).after().delay(analysisTime.intValue()).condition(sequenceContext -> {
final GuardianPlayerEntry<Player> entityEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
final Summary summary = sequenceContext.get(CommonContextKeys.SUMMARY);
final GuardianCaptureRegistry captureRegistry = sequenceContext.get(CommonContextKeys.CAPTURE_REGISTRY);
final long lastActionTime = sequenceContext.get(CommonContextKeys.LAST_ACTION_TIME);
summary.set(SequenceReport.class, new SequenceReport(false, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build()));
if (!entityEntry.getEntity(Player.class).isPresent())
return false;
Player player = entityEntry.getEntity(Player.class).get();
/*
* Capture Collection
*/
final CaptureContainer captureContainer = captureRegistry.getContainer();
Optional<Location> initial = captureContainer.get(GuardianSequence.INITIAL_LOCATION);
Optional<Double> verticalOffset = captureContainer.get(ControlCapture.VERTICAL_DISTANCE);
if (!initial.isPresent() || !verticalOffset.isPresent())
return false;
long current = System.currentTimeMillis();
// Finds the average between now and the last action.
double averageClockRate = ((current - lastActionTime) / 1000) / 0.05;
if (averageClockRate < minimumTickRate) {
detection.getLogger().warn("The server may be overloaded. A check could not be completed.");
return false;
} else if (averageClockRate > maximumTickRate) {
return false;
}
if (player.get(Keys.VEHICLE).isPresent())
return false;
double verticalDisplacement = MathUtil.truncateDownTo(player.getLocation().getY() - initial.get().getY(), 4);
double verticalPlacement = MathUtil.truncateDownTo((verticalOffset.get() * (verticalOffset.get() / 0.2)) / averageClockRate + 0.1, 4);
if (verticalDisplacement < 1 || verticalOffset.get() < 1)
return false;
if (verticalDisplacement > verticalPlacement) {
// ------------------------- DEBUG -----------------------------
System.out.println(player.getName() + " has been caught using vertical speed hacks. (" + (verticalDisplacement - verticalPlacement) + ")");
// -------------------------------------------------------------
SequenceReport report = new SequenceReport(true, Origin.source(sequenceContext.getRoot()).owner(entityEntry).build());
report.put("type", "Vertical Speed");
report.put("information", Collections.singletonList("Overshot maximum movement by " + (verticalDisplacement - verticalPlacement) + "."));
report.put("initial_location", initial.get());
report.put("final_location", player.getLocation());
report.put("severity", (verticalDisplacement - verticalPlacement) / verticalDisplacement);
summary.set(SequenceReport.class, report);
return true;
}
return false;
}, ConditionType.NORMAL).build(SequenceContext.builder().owner(detection).root(this).build());
}
use of com.abilityapi.sequenceapi.SequenceContext in project guardian by ichorpowered.
the class GuardianSequence method applySchedule.
@Override
public final void applySchedule(final SequenceContext sequenceContext) {
final PlayerEntry playerEntry = sequenceContext.get(CommonContextKeys.ENTITY_ENTRY);
final Player player = playerEntry.getEntity(Player.class).orElse(Sponge.getServer().getPlayer(playerEntry.getUniqueId()).orElse(null));
if (player == null)
return;
final SequenceContext mergedContext = SequenceContext.from(sequenceContext).custom(CommonContextKeys.LAST_ACTION_TIME, super.getLastActionTime()).custom(CommonContextKeys.CAPTURE_REGISTRY, this.captureRegistry).custom(CommonContextKeys.SUMMARY, this.summary).build();
if (this.getState().equals(State.INACTIVE)) {
this.captureRegistry.getContainer().offerIfEmpty(GuardianValue.builder(GuardianSequence.INITIAL_LOCATION).defaultElement(player.getLocation()).element(player.getLocation()).create());
}
super.applySchedule(mergedContext);
}
Aggregations