aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-22 11:18:06 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-22 11:18:32 +0200
commit157a8601c10b06ab14a216372b0c06fc47f4de31 (patch)
tree51a9e22535e5e553b331fc95015f8f25cd3b61dd
parentd3df9009625708bd847e6b7b00c7401b29c8bada (diff)
downloadmuhqs-game-157a8601c10b06ab14a216372b0c06fc47f4de31.tar.gz
muhqs-game-157a8601c10b06ab14a216372b0c06fc47f4de31.zip
notify players about concessions
-rw-r--r--go/game/player.go3
-rw-r--r--go/game/playerControl.go20
2 files changed, 21 insertions, 2 deletions
diff --git a/go/game/player.go b/go/game/player.go
index cd5a4b5a..a3b5c44b 100644
--- a/go/game/player.go
+++ b/go/game/player.go
@@ -1,7 +1,6 @@
package game
import (
- "fmt"
"muhq.space/muhqs-game/go/log"
"muhq.space/muhqs-game/go/utils"
)
@@ -290,5 +289,5 @@ func (p *Player) clearKnownStore() {
func (p *Player) concede() {
p.Conceded = true
- log.Info(fmt.Sprintf("%s concedes", p.Name))
+ p.gameState.broadcastNotification(newConcededNotification(p))
}
diff --git a/go/game/playerControl.go b/go/game/playerControl.go
index 3972cc8e..5f446106 100644
--- a/go/game/playerControl.go
+++ b/go/game/playerControl.go
@@ -18,6 +18,7 @@ const (
DraftPickPrompt
JoinedPlayerNotification
ReadyPlayerNotification
+ ConcededNotification
)
func (n PlayerNotificationType) String() string {
@@ -40,6 +41,8 @@ func (n PlayerNotificationType) String() string {
return "JoinedPlayerNotification"
case ReadyPlayerNotification:
return "ReadyPlayerNotification"
+ case ConcededNotification:
+ return "ConcededNotification"
default:
log.Panicf("Unhandled notification %d", n)
return ""
@@ -128,6 +131,11 @@ func NewReadyPlayerNotification(p *Player) PlayerNotification {
return PlayerNotification{ReadyPlayerNotification, p.Name, nil}
}
+// newConcededNotification creates a notification about a player's concession.
+func newConcededNotification(p *Player) PlayerNotification {
+ return PlayerNotification{ConcededNotification, p, nil}
+}
+
// Marshal marshals a PlayerNotification to plain text.
//
// The marshaled PlayerNotification has the form `!TYPE{CONTEXT}`.
@@ -154,6 +162,9 @@ func (n PlayerNotification) Marshal(s State) []byte {
case ReadyPlayerNotification:
out = append(out, []byte("ready")...)
ctx = []byte(n.Context.(string))
+ case ConcededNotification:
+ out = append(out, []byte("ready")...)
+ ctx = []byte(n.Context.(*Player).Name)
default:
log.Fatalf("Marshal(%s) not implement\n", n)
}
@@ -215,6 +226,15 @@ func UnmarshalPlayerNotification(s State, in []byte) (n PlayerNotification, err
case "ready":
n = PlayerNotification{ReadyPlayerNotification, string(ctx), nil}
+
+ case "conceded":
+ p := s.PlayerByName(string(ctx))
+ if p == nil {
+ err = ErrUnknownPlayer
+ return
+ }
+ n = newConcededNotification(p)
+
default:
return n, ErrUnknownNotification
}