diff options
| author | historia <[not public]> | 2026-06-28 02:40:30 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-06-28 02:40:30 -0400 |
| commit | a1b6613c6c6a2f8d6e1ecd47e766bd40f92ac295 (patch) | |
| tree | 4ff8fefb029c93f2aa3db7361658b0b4e9805b66 /internal/game/cmd_close.go | |
| parent | 87dacfbb3dd16e7f55a82361eace98f9a39d75c8 (diff) | |
| download | thehouseoficarus-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_close.go')
| -rw-r--r-- | internal/game/cmd_close.go | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/internal/game/cmd_close.go b/internal/game/cmd_close.go new file mode 100644 index 0000000..8dab0d9 --- /dev/null +++ b/internal/game/cmd_close.go @@ -0,0 +1,90 @@ +package game + +import ( + "fmt" + "os" + + "gopkg.in/yaml.v3" + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/world" +) + +func (g *Game) executeClose(sess *net.Session, args []string, rawInput string) { + if !g.checkAdmin(sess) { + sess.WriteLine("Unknown command.") + return + } + p := sess.Player + if p == nil { + return + } + if len(args) == 0 { + sess.WriteLine("Close which direction?") + return + } + + dir := g.World.ResolveExit(args[0]) + if dir == "" { + sess.WriteLine("Invalid direction. Use north/south/east/west/up/down.") + return + } + + curRoom, err := g.World.LoadRoom(p.RoomID) + if err != nil { + sess.WriteLine("Error loading current room.") + return + } + + curPath, ok := g.World.GetRoomPath(p.RoomID) + if !ok { + sess.WriteLine("Error: can't find current room file.") + return + } + + exitDef, ok := curRoom.Exits[dir] + if !ok { + sess.WriteLine(fmt.Sprintf("There is no exit to the %s from here.", dir)) + return + } + + targetID := exitDef.Room + targetRoom, err := g.World.LoadRoom(targetID) + targetName := fmt.Sprintf("#%d", targetID) + if err == nil { + targetName = fmt.Sprintf("#%d (%s)", targetID, targetRoom.Name) + } + + delete(curRoom.Exits, dir) + curData, err := yaml.Marshal(curRoom) + if err != nil { + sess.WriteLine("Error updating current room YAML.") + return + } + if err := os.WriteFile(curPath, curData, 0644); err != nil { + sess.WriteLine("Error writing current room file.") + return + } + + reciprocalRemoved := false + if targetRoom != nil { + oppositeDir := world.OppositeExit[dir] + if targetExit, tok := targetRoom.Exits[oppositeDir]; tok && targetExit.Room == p.RoomID { + delete(targetRoom.Exits, oppositeDir) + targetPath, tok2 := g.World.GetRoomPath(targetID) + if tok2 { + targetData, terr := yaml.Marshal(targetRoom) + if terr == nil { + if werr := os.WriteFile(targetPath, targetData, 0644); werr == nil { + reciprocalRemoved = true + } + } + } + } + } + + msg := fmt.Sprintf("Closed exit %s to %s.", dir, targetName) + if reciprocalRemoved { + msg += fmt.Sprintf(" Removed reciprocal exit from %s as well.", targetName) + } + sess.WriteLine(msg) +} |
