mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-08-13 22:37:28 +00:00
fix(games): reject duplicate queue entries
This commit is contained in:
parent
97ce177dd3
commit
a64e4dc1b8
3 changed files with 16 additions and 2 deletions
|
|
@ -70,6 +70,9 @@ func (a *app) handleGame(s ssh.Session) {
|
|||
case errors.Is(err, games.ErrNoOpponent):
|
||||
_ = conn.Send(errEnvelope("no opponent found — try again later"))
|
||||
_ = s.Exit(1)
|
||||
case errors.Is(err, games.ErrAlreadyQueued):
|
||||
_ = conn.Send(errEnvelope("this account is already queued for that game"))
|
||||
_ = s.Exit(1)
|
||||
case err != nil && !errors.Is(err, games.ErrUnknownGame):
|
||||
// Unknown-game is already handled above; anything else is a wait abort
|
||||
// (e.g. the agent disconnected) and needs no message.
|
||||
|
|
|
|||
|
|
@ -77,9 +77,13 @@ func (a *app) handleGameWS(w http.ResponseWriter, r *http.Request) {
|
|||
defer func() { _ = a.st.EndSession(sessID) }()
|
||||
|
||||
_ = p.Send(map[string]any{"type": "queued", "game": gameID})
|
||||
if err := a.mm.Play(context.Background(), gameID, p); errors.Is(err, games.ErrNoOpponent) {
|
||||
err = a.mm.Play(context.Background(), gameID, p)
|
||||
if errors.Is(err, games.ErrNoOpponent) {
|
||||
_ = p.Send(errEnvelope("no opponent found — try again later"))
|
||||
}
|
||||
if errors.Is(err, games.ErrAlreadyQueued) {
|
||||
_ = p.Send(errEnvelope("this account is already queued for that game"))
|
||||
}
|
||||
}
|
||||
|
||||
// wsPlayer adapts a gorilla WebSocket connection to games.PlayerIO. The match
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue