From d43a2b0104c3036d2eb3293eee435c09bf612045 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 23 Dec 2020 21:32:32 +0100 Subject: [PATCH] Implement WallOps to send a warning to all operators. --- group/group.go | 18 ++++++++++++++++++ rtpconn/webclient.go | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/group/group.go b/group/group.go index c52c1fb..42c3881 100644 --- a/group/group.go +++ b/group/group.go @@ -480,6 +480,24 @@ func (g *Group) Shutdown(message string) { }) } +type warner interface { + Warn(oponly bool, message string) error +} + +func (g *Group) WallOps(message string) { + clients := g.GetClients(nil) + for _, c := range clients { + w, ok := c.(warner) + if !ok { + continue + } + err := w.Warn(true, message) + if err != nil { + log.Printf("WallOps: %v", err) + } + } +} + func FromJSTime(tm int64) time.Time { if tm == 0 { return time.Time{} diff --git a/rtpconn/webclient.go b/rtpconn/webclient.go index 66dd260..263e378 100644 --- a/rtpconn/webclient.go +++ b/rtpconn/webclient.go @@ -1393,6 +1393,20 @@ func clientWriter(conn *websocket.Conn, ch <-chan interface{}, done chan<- struc } } +func (c *webClient) Warn(oponly bool, message string) error { + if oponly && !c.permissions.Op { + return nil + } + + return c.write(clientMessage{ + Type: "usermessage", + Kind: "warning", + Dest: c.id, + Privileged: true, + Value: &message, + }) +} + var ErrClientDead = errors.New("client is dead") func (c *webClient) action(m interface{}) error {