From fdaf24fd0aff9e1089157fd65d81a5aa3fe550bd Mon Sep 17 00:00:00 2001 From: citrons Date: Mon, 2 Jun 2025 16:32:49 -0500 Subject: user statuses --- server/channel/command.go | 4 ++++ server/user/command.go | 8 ++++++++ server/user/user.go | 8 ++++++-- server/validate/validate.go | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) (limited to 'server') diff --git a/server/channel/command.go b/server/channel/command.go index af5ff16..e645055 100644 --- a/server/channel/command.go +++ b/server/channel/command.go @@ -25,6 +25,10 @@ func (c *Channel) SendRequest(r session.Request) { return } } + if len(m.Fields[""]) > 50000 { + r.Reply(proto.Fail{"too-long", "", nil}.Cmd()) + return + } default: r.ReplyInvalid() return diff --git a/server/user/command.go b/server/user/command.go index b14845c..0c4f6d0 100644 --- a/server/user/command.go +++ b/server/user/command.go @@ -23,15 +23,23 @@ func (u *User) SendRequest(r session.Request) { return } name := u.name + status := u.status for k, v := range upd.Fields { switch k { case "": name = v + case "status": + status = v default: r.ReplyInvalid() return } } + if len(status) > 512 { + r.Reply(proto.Fail{"too-long", "", nil}.Cmd()) + return + } + u.status = status if name != u.name { err := u.Rename(name) if err != nil { diff --git a/server/user/user.go b/server/user/user.go index 0a9ae4e..fa5f37b 100644 --- a/server/user/user.go +++ b/server/user/user.go @@ -17,6 +17,8 @@ type User struct { store *UserStore name string id string + status string + description string Stream session.Stream Channels map[string]bool Anonymous bool @@ -98,9 +100,11 @@ func (u *User) Delete() { } func (u *User) GetInfo() proto.Object { - return proto.Object { - "u", u.id, map[string]string {"": u.name}, + i := map[string]string {"": u.name} + if u.status != "" { + i["status"] = u.status } + return proto.Object {"u", u.id, i} } func (t Tombstone) GetInfo() proto.Object { diff --git a/server/validate/validate.go b/server/validate/validate.go index 4415557..9b3ff0d 100644 --- a/server/validate/validate.go +++ b/server/validate/validate.go @@ -6,7 +6,7 @@ import ( ) func Name(name string) bool { - if len(Fold(name)) == 0 || len(name) >= 256 { + if len(Fold(name)) == 0 || len(name) > 256 { return false } for _, r := range name { -- cgit v1.2.3