The game kit: the shared infrastructure of Wiz-War and Waving Hands as a template

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0141G6xqLeNRYEtviLWSB5Up
This commit is contained in:
Eric Wagoner
2026-09-23 11:00:05 -04:00
co-authored by Claude Fable 5.1
commit 1cd24e3ddd
59 changed files with 7420 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// A sliding-window count per key, for the doors a stranger can knock on.
export class RateLimit {
private hits = new Map<string, number[]>();
constructor(
private limit: number,
private windowMs: number
) {}
/** True if the key may act now; the act is recorded when it is allowed. */
allow(key: string, now = Date.now()): boolean {
const since = now - this.windowMs;
const recent = (this.hits.get(key) ?? []).filter((t) => t > since);
if (recent.length >= this.limit) {
this.hits.set(key, recent);
return false;
}
recent.push(now);
this.hits.set(key, recent);
if (this.hits.size > 10000) this.prune(now);
return true;
}
prune(now = Date.now()): void {
const since = now - this.windowMs;
for (const [key, times] of this.hits) {
if (!times.some((t) => t > since)) this.hits.delete(key);
}
}
}