Remove player from zone contents on disconnect
Player objects were removed from the players dict on quit/disconnect but never removed from zone._contents, leaving ghost * markers on other players' maps.
This commit is contained in:
parent
b63b054997
commit
a4a95694f8
1 changed files with 38 additions and 0 deletions
|
|
@ -536,3 +536,41 @@ async def test_look_no_here_line_when_alone(player, test_zone):
|
||||||
|
|
||||||
output = "".join(c[0][0] for c in player.writer.write.call_args_list)
|
output = "".join(c[0][0] for c in player.writer.write.call_args_list)
|
||||||
assert "Here:" not in output
|
assert "Here:" not in output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_quit_removes_player_from_zone(monkeypatch):
|
||||||
|
"""Quitting removes player from zone contents."""
|
||||||
|
from mudlib.commands import quit as quit_mod
|
||||||
|
from mudlib.player import players
|
||||||
|
|
||||||
|
monkeypatch.setattr(quit_mod, "save_player", lambda p: None)
|
||||||
|
|
||||||
|
terrain = [["." for _ in range(10)] for _ in range(10)]
|
||||||
|
zone = Zone(
|
||||||
|
name="qz",
|
||||||
|
width=10,
|
||||||
|
height=10,
|
||||||
|
toroidal=True,
|
||||||
|
terrain=terrain,
|
||||||
|
impassable=set(),
|
||||||
|
)
|
||||||
|
writer = MagicMock()
|
||||||
|
writer.write = MagicMock()
|
||||||
|
writer.drain = AsyncMock()
|
||||||
|
writer.close = MagicMock()
|
||||||
|
p = Player(
|
||||||
|
name="quitter",
|
||||||
|
location=zone,
|
||||||
|
x=5,
|
||||||
|
y=5,
|
||||||
|
reader=MagicMock(),
|
||||||
|
writer=writer,
|
||||||
|
)
|
||||||
|
players.clear()
|
||||||
|
players["quitter"] = p
|
||||||
|
|
||||||
|
assert p in zone._contents
|
||||||
|
await quit_mod.cmd_quit(p, "")
|
||||||
|
assert p not in zone._contents
|
||||||
|
assert "quitter" not in players
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue