Search in sources :

Example 1 with InvalidControlCapture

use of com.ichorpowered.guardian.common.capture.player.InvalidControlCapture 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());
}
Also used : GuardianSequenceBuilder(com.ichorpowered.guardian.sequence.GuardianSequenceBuilder) Summary(com.ichorpowered.guardianapi.detection.report.Summary) ContentKeys(com.ichorpowered.guardianapi.content.ContentKeys) Keys(org.spongepowered.api.data.key.Keys) StringUtils(org.apache.commons.lang3.StringUtils) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) Origin(com.ichorpowered.guardianapi.event.origin.Origin) GuardianCaptureRegistry(com.ichorpowered.guardian.sequence.capture.GuardianCaptureRegistry) SequenceReport(com.ichorpowered.guardian.sequence.SequenceReport) Nonnull(javax.annotation.Nonnull) ConditionType(com.abilityapi.sequenceapi.action.condition.ConditionType) Location(org.spongepowered.api.world.Location) GuardianSequence(com.ichorpowered.guardian.sequence.GuardianSequence) Event(org.spongepowered.api.event.Event) InvalidControlCapture(com.ichorpowered.guardian.common.capture.player.InvalidControlCapture) Set(java.util.Set) SequenceContext(com.abilityapi.sequenceapi.SequenceContext) Sets(com.google.common.collect.Sets) Check(com.ichorpowered.guardianapi.detection.check.Check) GuardianPlayerEntry(com.ichorpowered.guardian.entry.GuardianPlayerEntry) Detection(com.ichorpowered.guardianapi.detection.Detection) CommonContextKeys(com.ichorpowered.guardian.sequence.context.CommonContextKeys) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) SequenceBlueprint(com.abilityapi.sequenceapi.SequenceBlueprint) Collections(java.util.Collections) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) Set(java.util.Set) InvalidControlCapture(com.ichorpowered.guardian.common.capture.player.InvalidControlCapture) Optional(java.util.Optional) SequenceReport(com.ichorpowered.guardian.sequence.SequenceReport) GuardianPlayerEntry(com.ichorpowered.guardian.entry.GuardianPlayerEntry) CaptureContainer(com.ichorpowered.guardianapi.detection.capture.CaptureContainer) Summary(com.ichorpowered.guardianapi.detection.report.Summary) GuardianSequenceBuilder(com.ichorpowered.guardian.sequence.GuardianSequenceBuilder) GuardianCaptureRegistry(com.ichorpowered.guardian.sequence.capture.GuardianCaptureRegistry) Nonnull(javax.annotation.Nonnull)

Aggregations

SequenceBlueprint (com.abilityapi.sequenceapi.SequenceBlueprint)1 SequenceContext (com.abilityapi.sequenceapi.SequenceContext)1 ConditionType (com.abilityapi.sequenceapi.action.condition.ConditionType)1 Sets (com.google.common.collect.Sets)1 InvalidControlCapture (com.ichorpowered.guardian.common.capture.player.InvalidControlCapture)1 GuardianPlayerEntry (com.ichorpowered.guardian.entry.GuardianPlayerEntry)1 GuardianSequence (com.ichorpowered.guardian.sequence.GuardianSequence)1 GuardianSequenceBuilder (com.ichorpowered.guardian.sequence.GuardianSequenceBuilder)1 SequenceReport (com.ichorpowered.guardian.sequence.SequenceReport)1 GuardianCaptureRegistry (com.ichorpowered.guardian.sequence.capture.GuardianCaptureRegistry)1 CommonContextKeys (com.ichorpowered.guardian.sequence.context.CommonContextKeys)1 GuardianValue (com.ichorpowered.guardian.util.item.mutable.GuardianValue)1 ContentKeys (com.ichorpowered.guardianapi.content.ContentKeys)1 Detection (com.ichorpowered.guardianapi.detection.Detection)1 CaptureContainer (com.ichorpowered.guardianapi.detection.capture.CaptureContainer)1 Check (com.ichorpowered.guardianapi.detection.check.Check)1 Summary (com.ichorpowered.guardianapi.detection.report.Summary)1 Origin (com.ichorpowered.guardianapi.event.origin.Origin)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1