Initial Commit
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
# OpenSpec Change: enterprise-gaming-api-plugin-anticheat
|
||||
|
||||
- **Change ID**: enterprise-gaming-api-plugin-anticheat
|
||||
- **Package**: `@suaveplan/api-plugin-anticheat`
|
||||
- **Category**: gaming/server
|
||||
- **Target path**: `gaming/server/api-plugin-anticheat`
|
||||
- **Status**: PROPOSED
|
||||
- **Date**: 2026-04-24
|
||||
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-anticheat.md`
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Deliver `@suaveplan/api-plugin-anticheat` on the genesis branch from scratch at enterprise quality. The package provides server-side anti-cheat validation with speed, damage, action-rate, and teleport checks. A `ViolationTracker` records per-player violations with severity 1–10, decays accumulated violations over time, and computes a running trust score (starting at 100). When the trust score drops below the ban threshold, the tracker fires `anticheat:ban` event. HTTP routes expose reporting and admin endpoints. Genesis adds Zod violation schemas, structured errors, OTel violation counter, injectable clock, and 100% coverage.
|
||||
|
||||
---
|
||||
|
||||
## Current-state audit (genesis)
|
||||
|
||||
Package does not exist on genesis yet — fresh build.
|
||||
|
||||
---
|
||||
|
||||
## Available workspace deps on genesis
|
||||
|
||||
| Package | Role |
|
||||
|---|---|
|
||||
| `@suaveplan/error` (`workspace:^`) | `AntiCheatError`; `AC.*` codes |
|
||||
| `@suaveplan/types` (`workspace:^`) | `Clock` |
|
||||
| `@suaveplan/events` (`workspace:^`) | `anticheat:violation`, `anticheat:ban`, `anticheat:flag` events |
|
||||
| `zod` (`catalog:forms`) | `Violation`, `CheckConfig` schemas |
|
||||
| `@opentelemetry/api` (`catalog:observability`) | Violation counter, ban counter |
|
||||
|
||||
---
|
||||
|
||||
## Public API surface
|
||||
|
||||
```ts
|
||||
type ViolationType = 'speed' | 'damage' | 'action_rate' | 'teleport' | 'custom'
|
||||
|
||||
interface Violation {
|
||||
playerId: string
|
||||
type: ViolationType
|
||||
severity: number // 1–10
|
||||
data?: unknown
|
||||
timestamp: number
|
||||
}
|
||||
|
||||
interface CheckConfig {
|
||||
maxSpeed?: number // m/s
|
||||
maxDamagePerSecond?: number
|
||||
maxActionsPerSecond?: number
|
||||
maxTeleportDistance?: number // meters
|
||||
banThreshold?: number // trust score, default 30
|
||||
decayRatePerSecond?: number // violation decay, default 0.1
|
||||
}
|
||||
|
||||
function createViolationTracker(config: CheckConfig, options?: { clock?: Clock }): ViolationTracker
|
||||
|
||||
interface ViolationTracker {
|
||||
check(playerId: string, type: ViolationType, value: number): void
|
||||
addViolation(violation: Violation): void
|
||||
getTrustScore(playerId: string): number
|
||||
getViolations(playerId: string): Violation[]
|
||||
isBanned(playerId: string): boolean
|
||||
tick(dt: number): void // decay violations
|
||||
reset(playerId: string): void
|
||||
}
|
||||
```
|
||||
|
||||
### HTTP Routes
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `POST` | `/check` | Submit player action for validation |
|
||||
| `GET` | `/players/:id/score` | Get trust score |
|
||||
| `GET` | `/players/:id/violations` | List violations |
|
||||
| `DELETE` | `/players/:id/violations` | Reset violations (admin) |
|
||||
| `POST` | `/ban/:id` | Manual ban |
|
||||
|
||||
---
|
||||
|
||||
## File layout
|
||||
|
||||
```text
|
||||
gaming/server/api-plugin-anticheat/
|
||||
package.json
|
||||
tsconfig.json
|
||||
vitest.config.ts
|
||||
src/
|
||||
index.ts
|
||||
error-codes.ts
|
||||
types/common.ts
|
||||
types/common.md
|
||||
core/
|
||||
violation-tracker/
|
||||
violation-tracker.ts
|
||||
violation-tracker.md
|
||||
violation-tracker.types.ts
|
||||
violation-tracker.test.ts
|
||||
index.ts
|
||||
routes/
|
||||
anticheat.ts
|
||||
anticheat.md
|
||||
plugin.ts
|
||||
plugin.md
|
||||
tests/
|
||||
integration.test.ts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Impact
|
||||
|
||||
**Downstream**: `@suaveplan/api-plugin-game-server` hooks ban events to session kick. Prerequisites: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/events`.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Tasks: enterprise-gaming-api-plugin-anticheat
|
||||
|
||||
## 0. Pre-flight (non-negotiable)
|
||||
|
||||
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
|
||||
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
|
||||
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
|
||||
|
||||
## Phase 1 — Scaffold
|
||||
|
||||
- [ ] Create `gaming/server/api-plugin-anticheat/` (`@suaveplan/api-plugin-anticheat`, `0.1.0`, `sideEffects: false`)
|
||||
- [ ] `tsconfig.json`, `vitest.config.ts`
|
||||
|
||||
## Phase 2 — Error codes + types
|
||||
|
||||
- [ ] `src/error-codes.ts` + `src/types/common.ts` + `common.md`
|
||||
|
||||
## Phase 3 — Violation tracker
|
||||
|
||||
- [ ] `src/core/violation-tracker/violation-tracker.ts` — check/addViolation/getTrustScore/isBanned/tick/reset, OTel counters
|
||||
- [ ] Tests (decay, ban threshold, per-type thresholds)
|
||||
- [ ] Docs
|
||||
|
||||
## Phase 4 — Routes
|
||||
|
||||
- [ ] `src/routes/anticheat.ts` — all HTTP endpoints
|
||||
- [ ] `src/routes/anticheat.md`
|
||||
|
||||
## Phase 5 — Plugin factory
|
||||
|
||||
- [ ] `src/plugin.ts` — `antiCheatPlugin()` factory
|
||||
- [ ] `src/plugin.md`
|
||||
|
||||
## Phase 6 — Integration tests
|
||||
|
||||
- [ ] `tests/integration.test.ts` — POST /check → trust score → ban event
|
||||
|
||||
## Phase 7 — Pre-publish gate
|
||||
|
||||
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-anticheat` green
|
||||
- [ ] 100% coverage
|
||||
- [ ] Publish: `bun scripts/publish.ts --package @suaveplan/api-plugin-anticheat`
|
||||
Reference in New Issue
Block a user