diff --git a/group.go b/group.go index a954190..a45bce9 100644 --- a/group.go +++ b/group.go @@ -64,7 +64,9 @@ type connectionFailedAction struct { type permissionsChangedAction struct{} -type kickAction struct{} +type kickAction struct{ + message string +} var groups struct { mu sync.Mutex diff --git a/static/protocol.js b/static/protocol.js index 46bec13..27af3b8 100644 --- a/static/protocol.js +++ b/static/protocol.js @@ -437,12 +437,14 @@ ServerConnection.prototype.groupAction = function(kind) { * * @param {string} kind - One of "op", "unop", "kick", "present", "unpresent". * @param {string} id + * @param {string} [message] */ -ServerConnection.prototype.userAction = function(kind, id) { +ServerConnection.prototype.userAction = function(kind, id, message) { this.send({ type: 'useraction', kind: kind, id: id, + value: message, }); } diff --git a/static/sfu.js b/static/sfu.js index d99e6aa..75d627d 100644 --- a/static/sfu.js +++ b/static/sfu.js @@ -955,14 +955,14 @@ function handleInput() { message = data.substring(1); me = false; } else { - let space, cmd, rest; - space = data.indexOf(' '); + let cmd, rest; + let space = data.indexOf(' '); if(space < 0) { cmd = data; rest = ''; } else { cmd = data.slice(0, space); - rest = data.slice(space + 1).trim(); + rest = data.slice(space + 1); } switch(cmd) { @@ -1005,22 +1005,31 @@ function handleInput() { displayError("You're not an operator"); return; } + let username, message; + let space = rest.indexOf(' '); + if(space < 0) { + username = rest; + message = null; + } else { + username = rest.slice(0, space); + message = rest.slice(space + 1).trim(); + } let id; - if(rest in users) { + if(username in users) { id = rest; } else { for(let i in users) { - if(users[i] === rest) { + if(users[i] === username) { id = i; break; } } } if(!id) { - displayError('Unknown user ' + rest); + displayError('Unknown user ' + username); return; } - serverConnection.userAction(cmd.slice(1), id) + serverConnection.userAction(cmd.slice(1), id, message); return; } default: diff --git a/webclient.go b/webclient.go index 8af2019..4a5beaa 100644 --- a/webclient.go +++ b/webclient.go @@ -870,7 +870,7 @@ func clientLoop(c *webClient, conn *websocket.Conn) error { } } case kickAction: - return userError("you have been kicked") + return userError(a.message) default: log.Printf("unexpected action %T", a) return errors.New("unexpected action") @@ -943,7 +943,7 @@ func setPermissions(g *group, id string, perm string) error { return c.action(permissionsChangedAction{}) } -func kickClient(g *group, id string) error { +func kickClient(g *group, id string, message string) error { g.mu.Lock() defer g.mu.Unlock() @@ -957,7 +957,7 @@ func kickClient(g *group, id string) error { return userError("this is not a real user") } - return c.action(kickAction{}) + return c.action(kickAction{message}) } func handleClientMessage(c *webClient, m clientMessage) error { @@ -1094,7 +1094,11 @@ func handleClientMessage(c *webClient, m clientMessage) error { if !c.permissions.Op { return c.error(userError("not authorised")) } - err := kickClient(c.group, m.Id) + message := m.Value + if message == "" { + message = "you have been kicked" + } + err := kickClient(c.group, m.Id, message) if err != nil { return c.error(err) }