better ping handling
This commit is contained in:
parent
5df96a5c33
commit
d2e9d6cf01
8
game.go
8
game.go
@ -41,8 +41,6 @@ func applyAction(g *game.Match, a action) error {
|
|||||||
return g.Apply(a.Player, 6)
|
return g.Apply(a.Player, 6)
|
||||||
case "7":
|
case "7":
|
||||||
return g.Apply(a.Player, 7)
|
return g.Apply(a.Player, 7)
|
||||||
case "ping":
|
|
||||||
return errJustAPing
|
|
||||||
default:
|
default:
|
||||||
return errWeirdAction
|
return errWeirdAction
|
||||||
}
|
}
|
||||||
@ -101,7 +99,7 @@ func gameActor(ctx context.Context, g *game.Match, dealer, chall person, join <-
|
|||||||
broadcast(ctx, g, dealer, chall, obs)
|
broadcast(ctx, g, dealer, chall, obs)
|
||||||
g.NextGame()
|
g.NextGame()
|
||||||
broadcast(ctx, g, dealer, chall, obs)
|
broadcast(ctx, g, dealer, chall, obs)
|
||||||
case game.ErrWrongTurn, errJustAPing: // do nothing
|
case game.ErrWrongTurn: // do nothing
|
||||||
case errWeirdAction:
|
case errWeirdAction:
|
||||||
slog.WarnContext(ctx, "nonsense action", "from", a.Player, "action", a.Action)
|
slog.WarnContext(ctx, "nonsense action", "from", a.Player, "action", a.Action)
|
||||||
default:
|
default:
|
||||||
@ -131,6 +129,9 @@ func playerActor(ctx context.Context, p person, actions chan<- action) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if a.Action == "ping" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
@ -174,6 +175,5 @@ func gameOver(ctx context.Context, dealer, chall person, obs []observer) {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
errWeirdAction = errors.New("unknown action")
|
errWeirdAction = errors.New("unknown action")
|
||||||
errJustAPing = errors.New("just a ping")
|
|
||||||
errMatchExpired = errors.New("there is a time limit on matches please")
|
errMatchExpired = errors.New("there is a time limit on matches please")
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user