Minor fixes to improve server messages

This commit is contained in:
Aadi Desai 2024-05-31 14:35:50 +01:00
parent 9254a425f1
commit d28d7e32ee
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 5 additions and 5 deletions

View file

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update to [charmbracelet/bubbletea](https://github.com/charmbracelet/bubbletea) v0.26.4 to fix Windows resizing
- Remove unnecessary alt-screen commands
- Server messages from admin commands
### Security

View file

@ -183,7 +183,7 @@ func (s server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if smsg.Id == s.admin {
cmd := strings.Split(cmsg.Msg, " ")
if len(cmd) == 2 {
if cmd[0] == "mk" {
if cmd[0] == "mk" && cmd[1] != "rooms" {
if _, ok := s.rooms[cmd[1]]; ok {
wsjson.Write(ctx, conn, c.SMsg{Tim: time.Now(), Id: "system", Msg: fmt.Sprintf("Room exists: %v", cmd)})
} else {
@ -207,9 +207,9 @@ func (s server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
s.conns.sm.Unlock()
wsjson.Write(ctx, conn, c.SMsg{Tim: time.Now(), Id: "system", Msg: fmt.Sprintf("Deleted room: %v", cmd)})
wsjson.Write(ctx, conn, c.SMsg{Tim: time.Now(), Id: "system", Msg: fmt.Sprintf("Deleted room: %v", cmd[1])})
} else {
wsjson.Write(ctx, conn, c.SMsg{Tim: time.Now(), Id: "system", Msg: fmt.Sprintf("Room does not exist: %v", cmd)})
wsjson.Write(ctx, conn, c.SMsg{Tim: time.Now(), Id: "system", Msg: fmt.Sprintf("Room does not exist: %v", cmd[1])})
}
} else if cmd[0] == "yeet" {
found := false
@ -300,8 +300,7 @@ func (s server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.conns.cm[conn] = u
s.conns.sm.Unlock()
wsjson.Write(ctx, conn, c.SMsg{Tim: time.Now(), Id: "system", Msg: fmt.Sprintf("connected to: %v", u.room)})
rhistSize := max(len(s.rhist[u.room])-10, 0)
recentHistory := s.rhist[u.room][rhistSize:]
recentHistory := s.rhist[u.room]
for i := range recentHistory {
wsjson.Write(ctx, conn, recentHistory[i])
}