From 9666676766bf21364f4fc4d0d1d336e72f2a91b4 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 6 Oct 2026 12:57:23 -0400 Subject: refactor: split casino.go, dedup helpers, remove audit docs --- internal/admin/api_rooms.go | 46 ++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'internal/admin/api_rooms.go') 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, -- cgit v1.2.3