Skip to content

Commit

Permalink
handle invalid slot states
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Nov 12, 2023
1 parent d6e3f88 commit f11e0fa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 2 additions & 3 deletions app/objects/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,10 @@ def __init__(

self.tourney_clients: set[int] = set() # player ids

# TODO: handle user not found in session situation.
@property # TODO: test cache speed
def host(self) -> Player:
player = app.state.sessions.players.get(id=self.host_id)
assert player is not None
return player
return app.state.sessions.players.get(id=self.host_id) or app.state.sessions.bot

@property
def url(self) -> str:
Expand Down
10 changes: 6 additions & 4 deletions app/objects/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,12 @@ def leave_match(self) -> None:
# player was host, trasnfer to first occupied slot
for s in self.match.slots:
# add double check to ensure match player
if s.player is not None and s.player.match is not None:
self.match.host_id = s.player.id
self.match.host.enqueue(app.packets.match_transfer_host())
break
if s.player is None or s.player.match is None:
continue

self.match.host_id = s.player.id
self.match.host.enqueue(app.packets.match_transfer_host())
break

if self in self.match._refs:
self.match._refs.remove(self)
Expand Down

0 comments on commit f11e0fa

Please sign in to comment.