From 12858e1f365d2febffc9f017628ba493ceffd3c3 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Mon, 18 May 2020 15:24:04 +0200 Subject: [PATCH] Implement commands /lock and /unlock. --- client.go | 10 ++++++++++ group.go | 5 +++++ static/sfu.js | 10 ++++++++++ 3 files changed, 25 insertions(+) diff --git a/client.go b/client.go index ce8d8ee..10dd469 100644 --- a/client.go +++ b/client.go @@ -1248,6 +1248,16 @@ func handleClientMessage(c *client, m clientMessage) error { if err != nil { return c.error(err) } + case "lock", "unlock": + if !c.permissions.Op { + c.error(userError("not authorised")) + return nil + } + var locked uint32 + if m.Type == "lock" { + locked = 1 + } + atomic.StoreUint32(&c.group.locked, locked) case "kick": if !c.permissions.Op { c.error(userError("not authorised")) diff --git a/group.go b/group.go index 70d568f..41ded51 100644 --- a/group.go +++ b/group.go @@ -199,6 +199,7 @@ type group struct { dead bool description *groupDescription videoCount uint32 + locked uint32 mu sync.Mutex clients map[string]*client @@ -366,6 +367,10 @@ func addClient(name string, client *client, user, pass string) (*group, []userid } client.permissions = perms + if !perms.Op && atomic.LoadUint32(&g.locked) != 0 { + return nil, nil, userError("group is locked") + } + g.mu.Lock() defer g.mu.Unlock() diff --git a/static/sfu.js b/static/sfu.js index 12fe2ea..fa610b9 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -888,6 +888,16 @@ function handleInput() { type: 'clearchat', }); return; + case '/lock': + case '/unlock': + if(!permissions.op) { + displayError("You're not an operator"); + return; + } + send({ + type: cmd === '/lock' ? 'lock' : 'unlock', + }); + return; case '/op': case '/unop': case '/kick':