diff options
| author | historia <[not public]> | 2026-09-18 01:50:17 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-18 01:50:17 -0400 |
| commit | 87d08f0151e643951769e323995f1c5ed89ee200 (patch) | |
| tree | dc42a0b30ebb5a00dd7ba505cc4eaa44f4f308bc /internal/admin/api_rooms.go | |
| parent | 32a3c59cebf2a16277e54d715a67adfdbe00b456 (diff) | |
| download | thehouseoficarus-87d08f0151e643951769e323995f1c5ed89ee200.tar.gz | |
fix: harden economy recovery, shutdown concurrency, world validation, and inventory-loss paths
Diffstat (limited to 'internal/admin/api_rooms.go')
| -rw-r--r-- | internal/admin/api_rooms.go | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/internal/admin/api_rooms.go b/internal/admin/api_rooms.go index f9508f6..d84449b 100644 --- a/internal/admin/api_rooms.go +++ b/internal/admin/api_rooms.go @@ -298,9 +298,17 @@ func (s *AdminServer) handleRoomByID(w http.ResponseWriter, r *http.Request) { return } - newContent, writeErr := writeMapAsYAML(path, m) - if writeErr != nil { - failJSON(w, fmt.Sprintf("write room: %v", writeErr)) + newContent, marshalErr := marshalMapYAML(m) + if marshalErr != nil { + failJSON(w, fmt.Sprintf("marshal room: %v", marshalErr)) + return + } + if err := validateRoomSchema(newContent); err != nil { + writeJSONError(w, "room failed schema validation: "+err.Error(), http.StatusBadRequest) + return + } + if err := writeFilePreservingMode(path, newContent); err != nil { + failJSON(w, fmt.Sprintf("write room: %v", err)) return } @@ -455,14 +463,19 @@ func (s *AdminServer) handleRenameRoomDir(w http.ResponseWriter, r *http.Request failJSON(w, "cannot rename root") return } + dir, err := s.resolveRoomSubdir(body.Dir) + if err != nil || dir == "" { + failJSON(w, "invalid directory") + return + } newName := strings.TrimSpace(body.NewName) if newName == "" || strings.ContainsAny(newName, "/\\") || newName == "." || newName == ".." { failJSON(w, "invalid directory name") return } base := filepath.Join(s.dataDir, "rooms") - parent := filepath.Dir(body.Dir) - oldPath := filepath.Join(base, body.Dir) + parent := filepath.Dir(dir) + oldPath := filepath.Join(base, dir) newRel := filepath.Join(parent, newName) newPath := filepath.Join(base, newRel) if _, err := os.Stat(oldPath); os.IsNotExist(err) { @@ -825,7 +838,11 @@ func (s *AdminServer) handleRoomMove(w http.ResponseWriter, r *http.Request) { failJSON(w, "room not found") return } - dir := strings.TrimSpace(body.Dir) + dir, err := s.resolveRoomSubdir(body.Dir) + if err != nil { + failJSON(w, err.Error()) + return + } destDir := filepath.Join(s.dataDir, "rooms", dir) if _, err := os.Stat(destDir); os.IsNotExist(err) { failJSON(w, "directory does not exist: "+dir) @@ -1279,8 +1296,11 @@ func (s *AdminServer) handleCreateEmptyRoom(w http.ResponseWriter, r *http.Reque } base := filepath.Join(s.dataDir, "rooms") targetDir := base - if body.Dir != "" { - targetDir = filepath.Join(base, body.Dir) + if dir, err := s.resolveRoomSubdir(body.Dir); err != nil { + failJSON(w, err.Error()) + return + } else if dir != "" { + targetDir = filepath.Join(base, dir) if _, err := os.Stat(targetDir); os.IsNotExist(err) { failJSON(w, "directory not found") return |
