Refactored signals with better names and more of them. Put them after hook calls.

This commit is contained in:
Andrew Bastien 2019-04-13 18:05:15 -04:00
parent 11dc2ee561
commit 72faf039cf
6 changed files with 79 additions and 30 deletions

View file

@ -29,8 +29,8 @@ from evennia.utils import class_from_module, create, logger
from evennia.utils.utils import (lazy_property, to_str,
make_iter, is_iter,
variable_from_module)
from evennia.utils.signals import (ACCOUNT_CREATE, OBJECT_PUPPET,
OBJECT_UNPUPPET, ACCOUNT_LOGOUT)
from evennia.server.signals import (SIGNAL_ACCOUNT_POST_CREATE, SIGNAL_OBJECT_POST_PUPPET,
SIGNAL_OBJECT_POST_UNPUPPET)
from evennia.typeclasses.attributes import NickHandler
from evennia.scripts.scripthandler import ScriptHandler
from evennia.commands.cmdsethandler import CmdSetHandler
@ -230,8 +230,6 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
if not _SESSIONS:
from evennia.server.sessionhandler import SESSIONS as _SESSIONS
_SESSIONS.disconnect(session, reason)
if not self.sessions.all():
ACCOUNT_LOGOUT.send(sender=self)
# puppeting operations
@ -306,8 +304,8 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
# re-cache locks to make sure superuser bypass is updated
obj.locks.cache_lock_bypass(obj)
# final hook
OBJECT_PUPPET.send(sender=obj, account=self, session=session)
obj.at_post_puppet()
SIGNAL_OBJECT_POST_PUPPET.send(sender=obj, account=self, session=session)
def unpuppet_object(self, session):
"""
@ -329,8 +327,8 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
obj.sessions.remove(session)
if not obj.sessions.count():
del obj.account
OBJECT_UNPUPPET.send(sender=obj, session=session, account=self)
obj.at_post_unpuppet(self, session=session)
SIGNAL_OBJECT_POST_UNPUPPET.send(sender=obj, session=session, account=self)
# Just to be sure we're always clear.
session.puppet = None
session.puid = None
@ -745,7 +743,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
# Update the throttle to indicate a new account was created from this IP
if ip and not guest:
CREATION_THROTTLE.update(ip, 'Too many accounts being created.')
ACCOUNT_CREATE.send(sender=account)
SIGNAL_ACCOUNT_POST_CREATE.send(sender=account, ip=ip)
return account, errors
def delete(self, *args, **kwargs):

View file

@ -25,7 +25,7 @@ from django.utils.encoding import smart_str
from evennia.accounts.manager import AccountDBManager
from evennia.typeclasses.models import TypedObject
from evennia.utils.utils import make_iter
from evennia.utils.signals import ACCOUNT_RENAME
from evennia.server.signals import SIGNAL_ACCOUNT_POST_RENAME
__all__ = ("AccountDB",)
@ -150,7 +150,7 @@ class AccountDB(TypedObject, AbstractUser):
old_name = self.username
self.username = value
self.save(update_fields=["username"])
ACCOUNT_RENAME.send(self, old_name=old_name, new_name=value)
SIGNAL_ACCOUNT_POST_RENAME.send(self, old_name=old_name, new_name=value)
def __username_del(self):
del self.username