Skip to content

Commit

Permalink
Refactor is_visible_to_player to not call self.players (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
Askaholic authored Nov 27, 2020
1 parent f3edcc7 commit d22aa93
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ def players(self):
else:
return frozenset(
player
for player in self._players
if self.get_player_option(player.id, "Army") is not None
and self.get_player_option(player.id, "Army") >= 0
for player, army in (
(player, self.get_player_option(player.id, "Army"))
for player in self._players
)
if army is not None and army >= 0
)

@property
Expand Down Expand Up @@ -820,7 +822,10 @@ def report_army_stats(self, stats_json):
self._process_pending_army_stats()

def is_visible_to_player(self, player: Player) -> bool:
if player == self.host or player in self.players:
if self.host is None:
return False

if player == self.host or player in self._connections:
return True

mean, dev = player.ratings[self.rating_type]
Expand All @@ -831,9 +836,6 @@ def is_visible_to_player(self, player: Player) -> bool:
):
return False

if self.host is None:
return False

if self.visibility is VisibilityState.FRIENDS:
return player.id in self.host.friends
else:
Expand Down

0 comments on commit d22aa93

Please sign in to comment.