/
docNemo
/
tactic-hack-server
Обзор
Документация
Войти
/
docNemo
/
tactic-hack-server
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/matchmaking/queue.ts
39 строк
1 KB
neo
Implement matchmaking lobby, authoritative GameRoom with timers and reconnect, integration tests
19 июл 2026, 00:10
19 июл 2026, 00:10
bed576b
Код
Авторство
О чём код?
/** * Очередь матчмейкинга за интерфейсом: in-memory реализация ниже заменяема * на внешнюю (например, Redis) без изменения потребителей. */ export interface MatchQueue { /** Поставить в очередь; false, если игрок уже стоит в ней. */ enqueue(id: string): boolean; /** Убрать из очереди (отмена поиска или дисконнект). */ remove(id: string): boolean; /** Извлечь двух наиболее давних, если есть пара. */ takePair(): [string, string] | null; readonly size: number; } export class InMemoryFifoQueue implements MatchQueue { private entries: string[] = []; enqueue(id: string): boolean { if (this.entries.includes(id)) return false; this.entries.push(id); return true; } remove(id: string): boolean { const index = this.entries.indexOf(id); if (index === -1) return false; this.entries.splice(index, 1); return true; } takePair(): [string, string] | null { if (this.entries.length < 2) return null; return [this.entries.shift()!, this.entries.shift()!]; } get size(): number { return this.entries.length; } }