Minor update to web code.
This commit is contained in:
parent
e25d8569bb
commit
be71aee08f
2 changed files with 24 additions and 3 deletions
|
|
@ -365,13 +365,32 @@ 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):
|
def player_count(self, count=True):
|
||||||
"""
|
"""
|
||||||
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:
|
||||||
|
number (int): If count=True
|
||||||
|
players (list): I count=False
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return len(set(session.uid for session in self.sessions.values() if session.logged_in))
|
players = 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):
|
||||||
|
"""
|
||||||
|
Returns all conected players (not sessions, since a player may
|
||||||
|
have more than one session depending on sessions)
|
||||||
|
"""
|
||||||
|
return self.player_count(count=False)
|
||||||
|
|
||||||
def session_from_sessid(self, sessid):
|
def session_from_sessid(self, sessid):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from django.conf import settings
|
||||||
from django.contrib.admin.views.decorators import staff_member_required
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
from evennia import SESSION_HANDLER
|
||||||
from evennia.objects.models import ObjectDB
|
from evennia.objects.models import ObjectDB
|
||||||
from evennia.players.models import PlayerDB
|
from evennia.players.models import PlayerDB
|
||||||
|
|
||||||
|
|
@ -29,7 +30,8 @@ def page_index(request):
|
||||||
nplyrs_conn_recent = len(recent_users) or "none"
|
nplyrs_conn_recent = len(recent_users) or "none"
|
||||||
nplyrs = PlayerDB.objects.num_total_players() or "none"
|
nplyrs = PlayerDB.objects.num_total_players() or "none"
|
||||||
nplyrs_reg_recent = len(PlayerDB.objects.get_recently_created_players()) or "none"
|
nplyrs_reg_recent = len(PlayerDB.objects.get_recently_created_players()) or "none"
|
||||||
nsess = len(PlayerDB.objects.get_connected_players()) or "no one"
|
nsess = SESSION_HANDLER.player_count()
|
||||||
|
# nsess = len(PlayerDB.objects.get_connected_players()) or "no one"
|
||||||
|
|
||||||
nobjs = ObjectDB.objects.all().count()
|
nobjs = ObjectDB.objects.all().count()
|
||||||
nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
|
nrooms = ObjectDB.objects.filter(db_location__isnull=True).exclude(db_typeclass_path=_BASE_CHAR_TYPECLASS).count()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue