diff options
Diffstat (limited to 'go/game/playerControl.go')
| -rw-r--r-- | go/game/playerControl.go | 20 |
1 files changed, 20 insertions, 0 deletions
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 } |
