-
Notifications
You must be signed in to change notification settings - Fork 27
Feat/check reloading #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Axionize
wants to merge
9
commits into
GrimAnticheat:master
Choose a base branch
from
Axionize:feat/check-reloading
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f6bf485
Add unloaded check behaviour
959e9e7
Document code and UnloadedBehaviour
e152ebf
Add support to get dependency information for checks
3500c6a
Address code review changes in AbstractCheck
aaea770
Add new function to API for checking if a check supports being run ag…
97505bb
Apply minor style changes from code review
Axionize d140895
Remove bitPosition; use ordinal() instead
8d082da
Use 4 line indents on DefaultUnloadedBehaviour
e05a14c
New None CheckType and basic checktype documentation
Axionize File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,21 +1,112 @@ | ||
| package ac.grim.grimac.api; | ||
|
|
||
| import ac.grim.grimac.api.common.BasicStatus; | ||
| import ac.grim.grimac.api.dynamic.UnloadedBehavior; | ||
| import java.util.Collections; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.Stream; | ||
|
|
||
| /** | ||
| * Base interface for all anti-cheat checks. Checks are modular components that detect specific | ||
| * types of cheating behavior. This interface defines the very core functionality that all checks | ||
| * must implement. | ||
| */ | ||
| public interface AbstractCheck extends AbstractProcessor, BasicStatus { | ||
|
|
||
| /** | ||
| * Gets the name of this check, used for identification and permissions. | ||
| * @return The check's name | ||
| */ | ||
| String getCheckName(); | ||
|
|
||
| /** | ||
| * Gets an alternative name for this check, defaults to the check name. | ||
| * Useful for checks that may have multiple names or variants (IE AntiKB and AntiKnockback) | ||
| * @return The alternative check name | ||
| */ | ||
| default String getAlternativeName() { | ||
| return getCheckName(); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the current violation level for this check. | ||
| * @return Number of violations accumulated | ||
| */ | ||
| double getViolations(); | ||
|
|
||
| /** | ||
| * Gets the rate at which violations decay over time. | ||
| * @return The violation decay rate | ||
| */ | ||
| double getDecay(); | ||
|
|
||
| /** | ||
| * Gets the violation level at which a setback/punishment should occur. | ||
| * @return The setback threshold | ||
| */ | ||
| double getSetbackVL(); | ||
|
|
||
| /** | ||
| * Whether this check is experimental/in testing. | ||
| * @return true if experimental, false if stable | ||
| */ | ||
| boolean isExperimental(); | ||
|
|
||
| /** | ||
| * Defines how this check should behave when unloaded. | ||
| * This allows checks to specify custom behavior when they are disabled | ||
| * rather than using the default no-op behavior. | ||
| * | ||
| * @return The UnloadedBehavior implementation for this check | ||
| */ | ||
| UnloadedBehavior getUnloadedBehavior(); | ||
|
|
||
| /** | ||
| * @return Set of check classes that must be loaded along with this check to run | ||
| */ | ||
| default Set<Class<? extends AbstractCheck>> getDependencies() { | ||
| return Stream.concat(getLoadAfter().stream(), getLoadBefore().stream()) | ||
| .collect(Collectors.toSet()); | ||
| } | ||
|
|
||
| /** | ||
| * @return Set of check classes that must run after this check | ||
| */ | ||
| default Set<Class<? extends AbstractCheck>> getLoadAfter() { | ||
| return Collections.emptySet(); | ||
| } | ||
|
|
||
| /** | ||
| * @return Set of check classes that must run before this check | ||
| */ | ||
| default Set<Class<? extends AbstractCheck>> getLoadBefore() { | ||
| return Collections.emptySet(); | ||
| } | ||
|
|
||
| /** | ||
| * Called when check is being loaded | ||
| * @return true if loaded successfully | ||
| */ | ||
| default boolean onLoad() { | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Called when check is being unloaded | ||
| */ | ||
| default void onUnload() {} | ||
|
|
||
| /** | ||
| * @return Bit mask representing all check types this check implements | ||
| */ | ||
| int getCheckMask(); | ||
Axionize marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Test if this check is of a specific type | ||
| * @param type The check type to test for | ||
| * @return true if this check handles the given type | ||
| */ | ||
| default boolean isCheckType(CheckType type) { | ||
Axionize marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return (getCheckMask() & type.getMask()) != 0; | ||
| } | ||
| } | ||
This file contains hidden or 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,30 @@ | ||||||||
| package ac.grim.grimac.api; | ||||||||
|
|
||||||||
| /** | ||||||||
| * Represents different types of checks that can be performed | ||||||||
| */ | ||||||||
| public enum CheckType { | ||||||||
| PACKET(0), | ||||||||
| POSITION(1), | ||||||||
| ROTATION(2), | ||||||||
| VEHICLE(3), | ||||||||
| PRE_PREDICTION(4), | ||||||||
| BLOCK_BREAK(5), | ||||||||
| BLOCK_PLACE(6), | ||||||||
| POST_PREDICTION(7); | ||||||||
|
|
||||||||
| private final int bitPosition; | ||||||||
Axionize marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| private final int mask; | ||||||||
|
|
||||||||
| CheckType(int bitPosition) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could get |
||||||||
| if (bitPosition >= 32) { | ||||||||
| throw new IllegalArgumentException("Cannot have more than 32 check types"); | ||||||||
| } | ||||||||
| this.bitPosition = bitPosition; | ||||||||
| this.mask = 1 << bitPosition; | ||||||||
| } | ||||||||
|
|
||||||||
| public int getMask() { | ||||||||
| return mask; | ||||||||
| } | ||||||||
| } | ||||||||
Axionize marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
23 changes: 23 additions & 0 deletions
23
src/main/java/ac/grim/grimac/api/dynamic/DefaultUnloadedBehavior.java
Axionize marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,23 @@ | ||
| package ac.grim.grimac.api.dynamic; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| /** | ||
| * Default implementation that returns safe "no-op" values for unloaded checks. | ||
| * - boolean methods return false | ||
| * - numeric methods return 0 | ||
| * - void methods do nothing | ||
| * - object methods return null | ||
| */ | ||
| public class DefaultUnloadedBehavior implements UnloadedBehavior { | ||
Axionize marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public static final UnloadedBehavior INSTANCE = new DefaultUnloadedBehavior(); | ||
|
|
||
| @Override | ||
| public Object handleUnloadedCall(Method method, Object[] args) { | ||
| Class<?> returnType = method.getReturnType(); | ||
| if (returnType == boolean.class) return false; | ||
| if (returnType == int.class) return 0; | ||
| if (returnType == void.class) return null; | ||
| return null; | ||
| } | ||
| } | ||
Axionize marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
19 changes: 19 additions & 0 deletions
19
src/main/java/ac/grim/grimac/api/dynamic/UnloadedBehavior.java
This file contains hidden or 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,19 @@ | ||
| package ac.grim.grimac.api.dynamic; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| /** | ||
| * Defines how an unloaded check should behave when its methods are called. | ||
| * This allows for graceful degradation when checks are disabled/unloaded. | ||
| * | ||
Axionize marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public interface UnloadedBehavior { | ||
| /** | ||
| * Handle a method call on an unloaded check | ||
| * | ||
| * @param method The method being called | ||
| * @param args The arguments passed to the method | ||
| * @return The value to return from the method call | ||
| */ | ||
| Object handleUnloadedCall(Method method, Object[] args); | ||
| } | ||
Axionize marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.