Commit 675035ab authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Restructure group and client management messages.

parent 88d2a968
...@@ -1058,7 +1058,8 @@ function handleInput() { ...@@ -1058,7 +1058,8 @@ function handleInput() {
return; return;
} }
send({ send({
type: 'clearchat', type: 'groupaction',
kind: 'clearchat',
}); });
return; return;
case '/lock': case '/lock':
...@@ -1068,7 +1069,8 @@ function handleInput() { ...@@ -1068,7 +1069,8 @@ function handleInput() {
return; return;
} }
send({ send({
type: cmd.slice(1), type: 'groupaction',
kind: cmd.slice(1),
}); });
return; return;
case '/record': case '/record':
...@@ -1078,7 +1080,8 @@ function handleInput() { ...@@ -1078,7 +1080,8 @@ function handleInput() {
return; return;
} }
send({ send({
type: cmd.slice(1), type: 'groupaction',
kind: cmd.slice(1),
}); });
return; return;
case '/op': case '/op':
...@@ -1106,7 +1109,8 @@ function handleInput() { ...@@ -1106,7 +1109,8 @@ function handleInput() {
return; return;
} }
send({ send({
type: cmd.slice(1), type: 'useraction',
kind: cmd.slice(1),
id: id, id: id,
}); });
return; return;
......
...@@ -1006,6 +1006,8 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1006,6 +1006,8 @@ func handleClientMessage(c *webClient, m clientMessage) error {
cc.write(m) cc.write(m)
} }
} }
case "groupaction":
switch m.Kind {
case "clearchat": case "clearchat":
c.group.clearChatHistory() c.group.clearChatHistory()
m := clientMessage{Type: "clearchat"} m := clientMessage{Type: "clearchat"}
...@@ -1016,20 +1018,12 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1016,20 +1018,12 @@ func handleClientMessage(c *webClient, m clientMessage) error {
cc.write(m) cc.write(m)
} }
} }
case "op", "unop", "present", "unpresent":
if !c.permissions.Op {
return c.error(userError("not authorised"))
}
err := setPermissions(c.group, m.Id, m.Type)
if err != nil {
return c.error(err)
}
case "lock", "unlock": case "lock", "unlock":
if !c.permissions.Op { if !c.permissions.Op {
return c.error(userError("not authorised")) return c.error(userError("not authorised"))
} }
var locked uint32 var locked uint32
if m.Type == "lock" { if m.Kind == "lock" {
locked = 1 locked = 1
} }
atomic.StoreUint32(&c.group.locked, locked) atomic.StoreUint32(&c.group.locked, locked)
...@@ -1064,6 +1058,19 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1064,6 +1058,19 @@ func handleClientMessage(c *webClient, m clientMessage) error {
delClient(disk) delClient(disk)
} }
} }
default:
return protocolError("unknown group action")
}
case "useraction":
switch m.Kind {
case "op", "unop", "present", "unpresent":
if !c.permissions.Op {
return c.error(userError("not authorised"))
}
err := setPermissions(c.group, m.Id, m.Kind)
if err != nil {
return c.error(err)
}
case "kick": case "kick":
if !c.permissions.Op { if !c.permissions.Op {
return c.error(userError("not authorised")) return c.error(userError("not authorised"))
...@@ -1072,6 +1079,9 @@ func handleClientMessage(c *webClient, m clientMessage) error { ...@@ -1072,6 +1079,9 @@ func handleClientMessage(c *webClient, m clientMessage) error {
if err != nil { if err != nil {
return c.error(err) return c.error(err)
} }
default:
return protocolError("unknown user action")
}
case "pong": case "pong":
// nothing // nothing
case "ping": case "ping":
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment