Skip to content

Commit

Permalink
Add rmdir command. (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkaeriit authored Jul 26, 2024
1 parent 3d2d744 commit c98c58e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var (
{"uname", unameCMD, "", "Show build info"},
{"uptime", uptimeCMD, "", "Show server uptime"},
{"8ball", eightBallCMD, "`question`", "Always tells the truth."},
{"rmdir", rmdirCMD, "#`room`", "Remove an empty room"},
}
SecretCMDs = []CMD{
{"ls", lsCMD, "???", "???"},
Expand Down Expand Up @@ -938,3 +939,18 @@ func eightBallCMD(_ string, u *User) {
u.room.broadcast("8ball", responses[rand.Intn(len(responses))]+u.Name)
}()
}

func rmdirCMD(rest string, u *User) {
if rest == "#main" {
u.room.broadcast("", "rmdir: failed to remove '"+rest+"': Operation not permitted")
} else if room, ok := Rooms[rest]; ok {
if len(room.users) == 0 {
delete(Rooms, rest)
u.room.broadcast("", "rmdir: removing directory, '"+rest+"'")
} else {
u.room.broadcast("", "rmdir: failed to remove '"+rest+"': Room not empty")
}
} else {
u.room.broadcast("", "rmdir: failed to remove '"+rest+"': No such room")
}
}

0 comments on commit c98c58e

Please sign in to comment.