aboutsummaryrefslogtreecommitdiff
path: root/internal/game/cmd_shutdown.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-28 02:40:30 -0400
committerhistoria <[not public]>2026-06-28 02:40:30 -0400
commita1b6613c6c6a2f8d6e1ecd47e766bd40f92ac295 (patch)
tree4ff8fefb029c93f2aa3db7361658b0b4e9805b66 /internal/game/cmd_shutdown.go
parent87dacfbb3dd16e7f55a82361eace98f9a39d75c8 (diff)
downloadthehouseoficarus-a1b6613c6c6a2f8d6e1ecd47e766bd40f92ac295.tar.gz
feat: admin accounts, god mode, OLC commands like dig/room, 'inline' objects changed to 'local' objects
Diffstat (limited to 'internal/game/cmd_shutdown.go')
-rw-r--r--internal/game/cmd_shutdown.go102
1 files changed, 102 insertions, 0 deletions
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 <minutes> 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))
+}