Documentation
¶
Overview ¶
Package anticheat is the per-class check harness for server-authoritative games: pure-function checks register under a Class enum, are dispatched with InputMode-aware thresholds, and route results (info / flag / hard) to audit + metrics sinks.
The 20-class catalogue (Speed / Teleport / FireRate / RootStunBypass etc.) is game-specific and lives in the consumer; the harness here owns registration, dispatch, severity routing, and metric/audit emission so each consumer doesn't re-invent that scaffold.
Checks must be pure: no I/O, no goroutines, no time.Now() — pass the simulation tick + clock through the input struct.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrClassUnregistered = errors.New("anticheat: class has no registered check") ErrCheckTypeMismatch = errors.New("anticheat: input type does not match registered check") )
Errors surfaced by the registry.
Functions ¶
Types ¶
type AuditSinkFunc ¶
AuditSinkFunc adapts a function to AuditSink.
type Config ¶
type Config struct {
Audit AuditSink
Metrics MetricsSink
}
Config configures a Registry.
type InputMode ¶
type InputMode uint8
InputMode caps thresholds per device family. Consumers register one threshold value per (Class, InputMode); the dispatcher picks the right value automatically.
type MetricsSink ¶
MetricsSink is invoked for SevFlag and SevHard results.
type MetricsSinkFunc ¶
MetricsSinkFunc adapts a function to MetricsSink.
func (MetricsSinkFunc) Inc ¶
func (f MetricsSinkFunc) Inc(class Class, reason string)
Inc implements MetricsSink.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the consumer's checks and dispatches Run calls.
type Result ¶
type Result struct {
Pass bool
Severity Severity
Reason string // short tag for metric labels — keep cardinality bounded
Detail map[string]any // free-form payload for the audit row
}
Result is what a Check returns.
func Run ¶
func Run[T any](r *Registry, ctx context.Context, class Class, mode InputMode, in T) (Result, error)
Run dispatches the registered check for class with the supplied input + InputMode. The result's severity drives audit + metrics routing; the result itself is also returned so the caller can act on SevHard.
type Severity ¶
type Severity uint8
Severity classifies a Result.
const ( // SevInfo — single-event anomaly. Logged via the audit sink; no // metric counter, no hard reject. SevInfo Severity = iota // SevFlag — recurring anomaly. Audit + metric counter. SevFlag // SevHard — outright violation. Audit + metric + the dispatcher // returns the result so the caller can reject the action. SevHard )
type Thresholds ¶
type Thresholds[V any] struct { // contains filtered or unexported fields }
Thresholds is a per-(Class, InputMode) value map. Lookups are O(1) after construction with no allocations on the hot path.
func NewThresholds ¶
func NewThresholds[V any]() *Thresholds[V]
NewThresholds constructs an empty Thresholds.
func (*Thresholds[V]) Get ¶
func (t *Thresholds[V]) Get(class Class, mode InputMode) (V, bool)
Get returns the value at (class, mode). Returns the zero value when the pair is unregistered (does not allocate).
func (*Thresholds[V]) Set ¶
func (t *Thresholds[V]) Set(class Class, mode InputMode, v V)
Set installs a value at (class, mode).