diff options
| author | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
| commit | 9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch) | |
| tree | 0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/admin/api_rooms.go | |
| parent | 4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff) | |
| download | thehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz | |
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/admin/api_rooms.go')
| -rw-r--r-- | internal/admin/api_rooms.go | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/internal/admin/api_rooms.go b/internal/admin/api_rooms.go index 06e736c..72f4a2c 100644 --- a/internal/admin/api_rooms.go +++ b/internal/admin/api_rooms.go @@ -349,26 +349,9 @@ func (s *AdminServer) handleRoomByID(w http.ResponseWriter, r *http.Request) { return } - courseID, _ := s.detachRoomFromCourse(id) - - if err := os.Remove(path); err != nil { - failJSON(w, fmt.Sprintf("delete room: %v", err)) - return - } - - s.world.RebuildRoomIndex(s.dataDir) - s.world.ClearRoomState(id) - // Drop the room's live mob instances too, or they keep wandering and - // are returned by MobsInRoom for a room that no longer exists. - if s.mobStore != nil { - s.mobStore.RemoveMobsInRoom(id) - } - // Drop any cached in-room games (tables/machines) and refund their - // outstanding wagers — same eviction semantics as bulk delete. - if s.evictRoom != nil { - s.evictRoom(id) - } - + // Clean up references and exits in every OTHER room BEFORE deleting this + // one: a failed write then aborts with the world untouched, instead of + // leaving dangling exits while reporting success. allIDs, _ := listRoomIDs(s.dataDir) var extraFiles []ExtraFile var exitCleaned int @@ -395,7 +378,8 @@ func (s *AdminServer) handleRoomByID(w http.ResponseWriter, r *http.Request) { oldExtra, _ := snapshotFile(otherPath) newContent, writeErr := writeYAMLFile(otherPath, otherRoom) if writeErr != nil { - continue + failJSON(w, fmt.Sprintf("clean exits in room %d: %v", otherID, writeErr)) + return } extraFiles = append(extraFiles, ExtraFile{ FilePath: otherPath, @@ -407,6 +391,26 @@ func (s *AdminServer) handleRoomByID(w http.ResponseWriter, r *http.Request) { } } + courseID, _ := s.detachRoomFromCourse(id) + + if err := os.Remove(path); err != nil { + failJSON(w, fmt.Sprintf("delete room: %v", err)) + return + } + + s.world.RebuildRoomIndex(s.dataDir) + s.world.ClearRoomState(id) + // Drop the room's live mob instances too, or they keep wandering and + // are returned by MobsInRoom for a room that no longer exists. + if s.mobStore != nil { + s.mobStore.RemoveMobsInRoom(id) + } + // Drop any cached in-room games (tables/machines) and refund their + // outstanding wagers — same eviction semantics as bulk delete. + if s.evictRoom != nil { + s.evictRoom(id) + } + s.undoStack.Push(ChangeDesc{ Description: fmt.Sprintf("delete room %d (cleaned %d exits)", id, exitCleaned), FilePath: path, |
