diff options
Diffstat (limited to 'internal/game/cmd_undig.go')
| -rw-r--r-- | internal/game/cmd_undig.go | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/internal/game/cmd_undig.go b/internal/game/cmd_undig.go index c752c86..88dd661 100644 --- a/internal/game/cmd_undig.go +++ b/internal/game/cmd_undig.go @@ -224,18 +224,23 @@ func (g *Game) performUndig(sess *net.Session, p *player.Player, targetID int) { g.World.RebuildRoomIndex(g.DataDir) - if p.RoomID == targetID { - p.RoomID = 0 - } - - for _, other := range g.Hub.AllSessions() { - if other.Player != nil && other.Player.RoomID == targetID { - other.Player.RoomID = p.RoomID - if g.Hub != nil { - g.Hub.EnterRoom(other, p.RoomID) + // Everyone in the deleted room relocates to the admin's room. If the + // admin is somehow standing in the target room (0 is not a valid room), + // fall back to the starting room rather than teleporting players to a + // nonexistent room and soft-locking them. + destination := p.RoomID + if destination == targetID { + destination = g.StartingRoom + } + + if g.Hub != nil { + for _, other := range g.Hub.AllSessions() { + if other.Player != nil && other.Player.RoomID == targetID { + other.Player.RoomID = destination + g.Hub.EnterRoom(other, destination) + other.WriteLine("The room around you dissolves. You find yourself elsewhere.") + g.doLook(other) } - other.WriteLine("The room around you dissolves. You find yourself elsewhere.") - g.doLook(other) } } |
