1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-25 01:55:57 +01:00

Add autokick option.

This commit is contained in:
Juliusz Chroboczek 2021-01-17 21:29:07 +01:00
parent 7d216f650c
commit c769a4aad4
2 changed files with 45 additions and 16 deletions

2
README
View file

@ -242,6 +242,8 @@ the group.
are automatically created when first accessed; are automatically created when first accessed;
- `autolock`: if true, the group will start locked and become locked - `autolock`: if true, the group will start locked and become locked
whenever there are no clients with operator privileges; whenever there are no clients with operator privileges;
- `autokick`: if true, all clients will be kicked out whenever there are
no clients with operator privileges.
- `redirect`: if set, then attempts to join the group will be redirected - `redirect`: if set, then attempts to join the group will be redirected
to the given URL; most other fields are ignored in this case; to the given URL; most other fields are ignored in this case;
- `codecs`: this is a list of codecs allowed in this group. The default - `codecs`: this is a list of codecs allowed in this group. The default

View file

@ -293,7 +293,7 @@ func Add(name string, desc *description) (*Group, error) {
timestamp: time.Now(), timestamp: time.Now(),
api: APIFromNames(desc.Codecs), api: APIFromNames(desc.Codecs),
} }
autolock(g, g.getClientsUnlocked(nil)) autoLockKick(g, g.getClientsUnlocked(nil))
groups.groups[name] = g groups.groups[name] = g
return g, nil return g, nil
} }
@ -320,7 +320,7 @@ func Add(name string, desc *description) (*Group, error) {
} }
g.description = desc g.description = desc
g.api = APIFromNames(desc.Codecs) g.api = APIFromNames(desc.Codecs)
autolock(g, g.getClientsUnlocked(nil)) autoLockKick(g, g.getClientsUnlocked(nil))
return g, nil return g, nil
} }
@ -461,10 +461,27 @@ func AddClient(group string, c Client) (*Group, error) {
} }
} }
clients := g.getClientsUnlocked(nil)
if g.clients[c.Id()] != nil { if g.clients[c.Id()] != nil {
return nil, ProtocolError("duplicate client id") return nil, ProtocolError("duplicate client id")
} }
if !c.Permissions().Op && g.description.Autokick {
ops := false
for _, c := range clients {
if c.Permissions().Op {
ops = true
break
}
}
if !ops {
return nil, UserError(
"there are no operators in this group",
)
}
}
g.clients[c.Id()] = c g.clients[c.Id()] = c
g.timestamp = time.Now() g.timestamp = time.Now()
@ -476,25 +493,30 @@ func AddClient(group string, c Client) (*Group, error) {
c.PushClient(cc.Id(), uu, true) c.PushClient(cc.Id(), uu, true)
cc.PushClient(c.Id(), u, true) cc.PushClient(c.Id(), u, true)
} }
}(g.getClientsUnlocked(c)) }(clients)
return g, nil return g, nil
} }
// called locked // called locked
func autolock(g *Group, clients []Client) { func autoLockKick(g *Group, clients []Client) {
if g.locked == nil && g.description.Autolock { if !(g.description.Autolock && g.locked == nil) &&
lock := true !g.description.Autokick {
for _, c := range clients { return
if c.Permissions().Op { }
lock = false for _, c := range clients {
} if c.Permissions().Op {
} return
if lock {
m := "this group is locked"
g.locked = &m
} }
} }
if g.description.Autolock && g.locked == nil {
m := "this group is locked"
g.locked = &m
}
if g.description.Autokick {
go kickall(g, "there are no operators in this group")
}
} }
func DelClient(c Client) { func DelClient(c Client) {
@ -520,7 +542,7 @@ func DelClient(c Client) {
} }
}(clients) }(clients)
autolock(g, clients) autoLockKick(g, clients)
} }
func (g *Group) GetClients(except Client) []Client { func (g *Group) GetClients(except Client) []Client {
@ -565,7 +587,7 @@ func (g *Group) Range(f func(c Client) bool) {
} }
} }
func (g *Group) Shutdown(message string) { func kickall(g *Group, message string) {
g.Range(func(c Client) bool { g.Range(func(c Client) bool {
cc, ok := c.(Kickable) cc, ok := c.(Kickable)
if ok { if ok {
@ -575,6 +597,10 @@ func (g *Group) Shutdown(message string) {
}) })
} }
func (g *Group) Shutdown(message string) {
kickall(g, message)
}
type warner interface { type warner interface {
Warn(oponly bool, message string) error Warn(oponly bool, message string) error
} }
@ -687,6 +713,7 @@ type description struct {
AllowRecording bool `json:"allow-recording,omitempty"` AllowRecording bool `json:"allow-recording,omitempty"`
AllowSubgroups bool `json:"allow-subgroups,omitempty"` AllowSubgroups bool `json:"allow-subgroups,omitempty"`
Autolock bool `json:"autolock,omitempty"` Autolock bool `json:"autolock,omitempty"`
Autokick bool `json:"autokick,omitempty"`
Op []ClientCredentials `json:"op,omitempty"` Op []ClientCredentials `json:"op,omitempty"`
Presenter []ClientCredentials `json:"presenter,omitempty"` Presenter []ClientCredentials `json:"presenter,omitempty"`
Other []ClientCredentials `json:"other,omitempty"` Other []ClientCredentials `json:"other,omitempty"`