Start work on improving recordings.

This commit is contained in:
Storm Dragon
2026-05-23 23:33:30 -04:00
parent 08b484f106
commit 3e06de7501
8 changed files with 662 additions and 105 deletions
+36 -10
View File
@@ -174,7 +174,17 @@ func (g *Hall) Description() *Description {
func (g *Hall) ClientCount() int {
g.mu.Lock()
defer g.mu.Unlock()
return len(g.clients)
return g.clientCountUnlocked()
}
func (g *Hall) clientCountUnlocked() int {
count := 0
for _, c := range g.clients {
if !isSystemClient(c) {
count++
}
}
return count
}
func (g *Hall) mayExpire() bool {
@@ -525,6 +535,10 @@ func member(v string, l []string) bool {
return false
}
func isSystemClient(c Client) bool {
return member("system", c.Permissions())
}
func AddClient(hall string, c Client, creds ClientCredentials) (*Hall, error) {
g, err := Add(hall, nil)
if err != nil {
@@ -535,8 +549,9 @@ func AddClient(hall string, c Client, creds ClientCredentials) (*Hall, error) {
defer g.mu.Unlock()
clients := g.getClientsUnlocked(nil)
systemClient := isSystemClient(c)
if !member("system", c.Permissions()) {
if !systemClient {
username, perms, err := g.getPermission(creds)
if err != nil {
return nil, err
@@ -587,7 +602,7 @@ func AddClient(hall string, c Client, creds ClientCredentials) (*Hall, error) {
}
if !member("op", perms) && g.description.MaxClients > 0 {
if len(g.clients) >= g.description.MaxClients {
if g.clientCountUnlocked() >= g.description.MaxClients {
return nil, UserError("too many users")
}
}
@@ -607,12 +622,20 @@ func AddClient(hall string, c Client, creds ClientCredentials) (*Hall, error) {
u := c.Username()
p := c.Permissions()
s := c.Data()
c.PushClient(g.Name(), "add", c.Id(), u, p, s)
if !systemClient {
c.PushClient(g.Name(), "add", c.Id(), u, p, s)
}
for _, cc := range clients {
pp := cc.Permissions()
uu := cc.Username()
c.PushClient(g.Name(), "add", cc.Id(), uu, pp, cc.Data())
cc.PushClient(g.Name(), "add", id, u, p, s)
if !isSystemClient(cc) {
c.PushClient(
g.Name(), "add", cc.Id(), uu, pp, cc.Data(),
)
}
if !systemClient {
cc.PushClient(g.Name(), "add", id, u, p, s)
}
}
return g, nil
@@ -659,6 +682,7 @@ func DelClient(c Client) {
if g == nil {
return
}
systemClient := isSystemClient(c)
g.mu.Lock()
if g.clients[c.Id()] != c {
log.Printf("Deleting unknown client")
@@ -671,10 +695,12 @@ func DelClient(c Client) {
g.mu.Unlock()
c.Joined(g.Name(), "leave")
for _, cc := range clients {
cc.PushClient(
g.Name(), "delete", c.Id(), c.Username(), nil, nil,
)
if !systemClient {
for _, cc := range clients {
cc.PushClient(
g.Name(), "delete", c.Id(), c.Username(), nil, nil,
)
}
}
closeSystemClientsIfNoUsers(g, clients)
autoLockKick(g)
+90 -1
View File
@@ -129,6 +129,14 @@ type testClient struct {
id string
username string
permissions []string
pushed []pushedClient
}
type pushedClient struct {
kind string
id string
username string
permissions []string
}
func (c *testClient) Hall() *Hall { return nil }
@@ -144,11 +152,92 @@ func (c *testClient) PushConn(*Hall, string, conn.Up, []conn.UpTrack, string) er
}
func (c *testClient) RequestConns(Client, *Hall, string) error { return nil }
func (c *testClient) Joined(string, string) error { return nil }
func (c *testClient) PushClient(string, string, string, string, []string, map[string]interface{}) error {
func (c *testClient) PushClient(_ string, kind string, id string, username string, permissions []string, _ map[string]interface{}) error {
c.pushed = append(c.pushed, pushedClient{
kind: kind,
id: id,
username: username,
permissions: permissions,
})
return nil
}
func (c *testClient) Kick(string, *string, string) error { return nil }
func TestSystemClientIsNotAdvertisedToUsers(t *testing.T) {
halls.halls = nil
oldDirectory := Directory
Directory = t.TempDir()
t.Cleanup(func() {
Directory = oldDirectory
halls.halls = nil
})
err := os.WriteFile(
filepath.Join(Directory, "system-hidden-test.json"),
[]byte(`{
"users": {
"user1": {"password": "secret", "permissions": "present"},
"user2": {"password": "secret", "permissions": "present"}
}
}`),
0600,
)
if err != nil {
t.Fatal(err)
}
user1 := &testClient{id: "user1-client"}
g, err := AddClient("system-hidden-test", user1, ClientCredentials{
Username: strPtr("user1"),
Password: "secret",
})
if err != nil {
t.Fatal(err)
}
user1.pushed = nil
recorder := &testClient{
id: "recorder-client",
username: "RECORDING",
permissions: []string{"system"},
}
_, err = AddClient("system-hidden-test", recorder, ClientCredentials{
System: true,
})
if err != nil {
t.Fatal(err)
}
if len(user1.pushed) != 0 {
t.Fatalf("user saw system recorder client: %#v", user1.pushed)
}
if count := g.ClientCount(); count != 1 {
t.Fatalf("client count with recorder = %d, expected 1", count)
}
user2 := &testClient{id: "user2-client"}
_, err = AddClient("system-hidden-test", user2, ClientCredentials{
Username: strPtr("user2"),
Password: "secret",
})
if err != nil {
t.Fatal(err)
}
for _, pushed := range user2.pushed {
if pushed.id == recorder.id {
t.Fatalf("joining user saw system recorder client: %#v", user2.pushed)
}
}
for _, pushed := range user1.pushed {
if pushed.id == recorder.id {
t.Fatalf("existing user saw system recorder client: %#v", user1.pushed)
}
}
}
func strPtr(s string) *string {
return &s
}
func TestLockedHallJoinMessage(t *testing.T) {
halls.halls = nil
oldDirectory := Directory