aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_rooms.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/api_rooms.go')
-rw-r--r--internal/admin/api_rooms.go46
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,