From a1b6613c6c6a2f8d6e1ecd47e766bd40f92ac295 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Sun, 28 Jun 2026 02:40:30 -0400 Subject: feat: admin accounts, god mode, OLC commands like dig/room, 'inline' objects changed to 'local' objects --- internal/game/cmd_shutdown.go | 102 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 internal/game/cmd_shutdown.go (limited to 'internal/game/cmd_shutdown.go') diff --git a/internal/game/cmd_shutdown.go b/internal/game/cmd_shutdown.go new file mode 100644 index 0000000..0bb0f8f --- /dev/null +++ b/internal/game/cmd_shutdown.go @@ -0,0 +1,102 @@ +package game + +import ( + "fmt" + "os" + "strconv" + "time" + + "thehouseoficarus/internal/net" +) + +func (g *Game) executeShutdown(sess *net.Session, args []string, rawInput string) { + if !g.checkAdmin(sess) { + sess.WriteLine("Unknown command.") + return + } + if len(args) == 0 { + sess.WriteLine("Usage: shutdown or shutdown cancel") + return + } + + if args[0] == "cancel" { + g.shutdownMu.Lock() + if !g.shutdownActive { + g.shutdownMu.Unlock() + sess.WriteLine("No shutdown in progress.") + return + } + close(g.shutdownCancel) + g.shutdownActive = false + g.shutdownMu.Unlock() + + for _, other := range g.Hub.AllSessions() { + if other.Player != nil { + other.WriteLine("[Server] Shutdown cancelled.") + } + } + return + } + + minutes, err := strconv.Atoi(args[0]) + if err != nil || minutes <= 0 { + sess.WriteLine("Invalid minutes.") + return + } + + g.shutdownMu.Lock() + if g.shutdownActive { + g.shutdownMu.Unlock() + sess.WriteLine("A shutdown is already in progress.") + return + } + g.shutdownActive = true + g.shutdownCancel = make(chan struct{}) + g.shutdownMu.Unlock() + + go func() { + remaining := minutes * 60 + ticker := time.NewTicker(30 * time.Second) + defer ticker.Stop() + + for _, other := range g.Hub.AllSessions() { + if other.Player != nil { + other.WriteLine(fmt.Sprintf("[Server] Shutting down in %d minute(s).", minutes)) + } + } + + for { + select { + case <-ticker.C: + remaining -= 30 + if remaining <= 0 { + for _, other := range g.Hub.AllSessions() { + if other.Player != nil { + other.WriteLine("[Server] Shutting down NOW.") + } + } + os.Exit(0) + } + mins := remaining / 60 + secs := remaining % 60 + if secs == 0 { + for _, other := range g.Hub.AllSessions() { + if other.Player != nil { + other.WriteLine(fmt.Sprintf("[Server] Shutting down in %d minute(s).", mins)) + } + } + } else { + for _, other := range g.Hub.AllSessions() { + if other.Player != nil { + other.WriteLine(fmt.Sprintf("[Server] Shutting down in %d minute(s) %d seconds.", mins, secs)) + } + } + } + case <-g.shutdownCancel: + return + } + } + }() + + sess.WriteLine(fmt.Sprintf("Shutdown scheduled in %d minute(s).", minutes)) +} -- cgit v1.2.3