Changed sessionhandler.all_connected_players() to return a list of Player objects rather than a list if uids (pointed out by Volund). Also changed sessionhandler.player_count() only return the count without any extra kwarg and doing so a little more efficiently.
This commit is contained in:
parent
edf6c535a0
commit
1526924b93
1 changed files with 10 additions and 14 deletions
|
|
@ -365,32 +365,28 @@ class ServerSessionHandler(SessionHandler):
|
||||||
and (tcurr - session.cmd_last) > _IDLE_TIMEOUT):
|
and (tcurr - session.cmd_last) > _IDLE_TIMEOUT):
|
||||||
self.disconnect(session, reason=reason)
|
self.disconnect(session, reason=reason)
|
||||||
|
|
||||||
def player_count(self, count=True):
|
def player_count(self):
|
||||||
"""
|
"""
|
||||||
Get the number of connected players (not sessions since a
|
Get the number of connected players (not sessions since a
|
||||||
player may have more than one session depending on settings).
|
player may have more than one session depending on settings).
|
||||||
Only logged-in players are counted here.
|
Only logged-in players are counted here.
|
||||||
|
|
||||||
Args:
|
|
||||||
count (bool): If true, return a count of players, otherwise
|
|
||||||
return a list.
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
number (int): If count=True
|
nplayer (int): Number of connected players
|
||||||
players (list): I count=False
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
players = set(session.uid for session in self.sessions.values() if session.logged_in)
|
return len(set(session.uid for session in self.sessions.values() if session.logged_in))
|
||||||
if count:
|
|
||||||
return len(players)
|
|
||||||
return players
|
|
||||||
|
|
||||||
def all_connected_players(self):
|
def all_connected_players(self):
|
||||||
"""
|
"""
|
||||||
Returns all conected players (not sessions, since a player may
|
Get a unique list of connected and logged-in Players.
|
||||||
have more than one session depending on sessions)
|
|
||||||
|
Returns:
|
||||||
|
players (list): All conected Players (which may be fewer than the
|
||||||
|
amount of Sessions due to multi-playing).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self.player_count(count=False)
|
return list(set(session.player for session in self.sessions.values() if session.logged_in and session.player))
|
||||||
|
|
||||||
def session_from_sessid(self, sessid):
|
def session_from_sessid(self, sessid):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue