def monitor(session, *args, **kwargs): """ Adds monitoring to a given property or Attribute. Kwargs: name (str): The name of the property or Attribute to report. No db_* prefix is needed. Only names in the _monitorable dict earlier in this module are accepted. stop (bool): Stop monitoring the above name. """ from evennia.scripts.monitorhandler import MONITOR_HANDLER name = kwargs.get("name", None) if name and name in _monitorable and session.puppet: field_name = _monitorable[name] obj = session.puppet if kwargs.get("stop", False): MONITOR_HANDLER.remove(obj, field_name, idstring=session.sessid) else: # the handler will add fieldname and obj to the kwargs automatically MONITOR_HANDLER.add( obj, field_name, _on_monitor_change, idstring=session.sessid, persistent=False, name=name, session=session, )
def monitor(session, *args, **kwargs): """ Adds monitoring to a given property or Attribute. Kwargs: name (str): The name of the property or Attribute to report. No db_* prefix is needed. Only names in the _monitorable dict earlier in this module are accepted. stop (bool): Stop monitoring the above name. """ from evennia.scripts.monitorhandler import MONITOR_HANDLER name = kwargs.get("name", None) if name and name in _monitorable and session.puppet: field_name = _monitorable[name] obj = session.puppet if kwargs.get("stop", False): MONITOR_HANDLER.remove(obj, field_name, idstring=session.sessid) else: # the handler will add fieldname and obj to the kwargs automatically MONITOR_HANDLER.add(obj, field_name, _on_monitor_change, idstring=session.sessid, persistent=False, name=name, session=session)
def at_disconnect(self, reason=None): """ Hook called by sessionhandler when disconnecting this session. """ if self.logged_in: account = self.account if self.puppet: account.unpuppet_object(self) uaccount = account uaccount.last_login = timezone.now() uaccount.save() # calling account hook account.at_disconnect(reason) self.logged_in = False if not self.sessionhandler.sessions_from_account(account): # no more sessions connected to this account account.is_connected = False # this may be used to e.g. delete account after disconnection etc account.at_post_disconnect() # remove any webclient settings monitors associated with this # session MONITOR_HANDLER.remove(account, "_saved_webclient_options", self.sessid)
def monitor(session, *args, **kwargs): """ Adds monitoring to a given property or Attribute. Keyword Args: name (str): The name of the property or Attribute to report. No db_* prefix is needed. Only names in the _monitorable dict earlier in this module are accepted. stop (bool): Stop monitoring the above name. outputfunc_name (str, optional): Change the name of the outputfunc name. This is used e.g. by MSDP which has its own specific output format. """ from evennia.scripts.monitorhandler import MONITOR_HANDLER name = kwargs.get("name", None) outputfunc_name = kwargs("outputfunc_name", "monitor") if name and name in _monitorable and session.puppet: field_name = _monitorable[name] obj = session.puppet if kwargs.get("stop", False): MONITOR_HANDLER.remove(obj, field_name, idstring=session.sessid) else: # the handler will add fieldname and obj to the kwargs automatically MONITOR_HANDLER.add( obj, field_name, _on_monitor_change, idstring=session.sessid, persistent=False, name=name, session=session, outputfunc_name=outputfunc_name, )
def at_disconnect(self): """ Hook called by sessionhandler when disconnecting this session. """ if self.logged_in: player = self.player if self.puppet: player.unpuppet_object(self) uaccount = player uaccount.last_login = timezone.now() uaccount.save() # calling player hook player.at_disconnect() self.logged_in = False if not self.sessionhandler.sessions_from_player(player): # no more sessions connected to this player player.is_connected = False # this may be used to e.g. delete player after disconnection etc player.at_post_disconnect() # remove any webclient settings monitors associated with this # session MONITOR_HANDLER.remove(player, "_saved_webclient_options", self.sessid)