Commit 69fcdfba authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement client limit.

parent 2890d21c
...@@ -154,6 +154,11 @@ func addClient(name string, client *client, user, pass string) (*group, []userid ...@@ -154,6 +154,11 @@ func addClient(name string, client *client, user, pass string) (*group, []userid
var users []userid var users []userid
g.mu.Lock() g.mu.Lock()
defer g.mu.Unlock() defer g.mu.Unlock()
if !perms.Admin && g.description.MaxClients > 0 {
if len(g.clients) >= g.description.MaxClients {
return nil, nil, userError("too many users")
}
}
for _, c := range g.clients { for _, c := range g.clients {
users = append(users, userid{c.id, c.username}) users = append(users, userid{c.id, c.username})
} }
...@@ -249,6 +254,7 @@ func matchUser(user, pass string, users []groupUser) (bool, bool) { ...@@ -249,6 +254,7 @@ func matchUser(user, pass string, users []groupUser) (bool, bool) {
type groupDescription struct { type groupDescription struct {
Public bool `json:"public,omitempty"` Public bool `json:"public,omitempty"`
MaxClients int `json:"max-clients,omitempty"`
AllowAnonymous bool `json:"allow-anonymous,omitempty"` AllowAnonymous bool `json:"allow-anonymous,omitempty"`
Admin []groupUser `json:"admin,omitempty"` Admin []groupUser `json:"admin,omitempty"`
Presenter []groupUser `json:"presenter,omitempty"` Presenter []groupUser `json:"presenter,omitempty"`
......
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