Rename all instances of Player->Account.

This commit is contained in:
Griatch 2017-07-07 23:47:21 +02:00
parent a14e11640b
commit 5590ee2258
94 changed files with 1316 additions and 2327 deletions

View file

@ -111,7 +111,7 @@ class ChannelCommand(command.Command):
self.msg(string % channelkey)
return
if msg == "on":
caller = caller if not hasattr(caller, 'player') else caller.player
caller = caller if not hasattr(caller, 'account') else caller.account
unmuted = channel.unmute(caller)
if unmuted:
self.msg("You start listening to %s." % channel)
@ -119,7 +119,7 @@ class ChannelCommand(command.Command):
self.msg("You were already listening to %s." % channel)
return
if msg == "off":
caller = caller if not hasattr(caller, 'player') else caller.player
caller = caller if not hasattr(caller, 'account') else caller.account
muted = channel.mute(caller)
if muted:
self.msg("You stop listening to %s." % channel)
@ -133,7 +133,7 @@ class ChannelCommand(command.Command):
if "[-]" in line else line for line in lines))
tail_log_file(log_file, self.history_start, 20, callback=send_msg)
else:
caller = caller if not hasattr(caller, 'player') else caller.player
caller = caller if not hasattr(caller, 'account') else caller.account
if caller in channel.mutelist:
self.msg("You currently have %s muted." % channel)
return
@ -144,7 +144,7 @@ class ChannelCommand(command.Command):
Let users know that this command is for communicating on a channel.
Args:
caller (TypedObject): A Character or Player who has entered an ambiguous command.
caller (TypedObject): A Character or Account who has entered an ambiguous command.
Returns:
A string with identifying information to disambiguate the object, conventionally with a preceding space.

View file

@ -62,26 +62,26 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
def has_connection(self, subscriber):
"""
Checks so this player is actually listening
Checks so this account is actually listening
to this channel.
Args:
subscriber (Player or Object): Entity to check.
subscriber (Account or Object): Entity to check.
Returns:
has_sub (bool): Whether the subscriber is subscribing to
this channel or not.
Notes:
This will first try Player subscribers and only try Object
if the Player fails.
This will first try Account subscribers and only try Object
if the Account fails.
"""
has_sub = self.subscriptions.has(subscriber)
if not has_sub and hasattr(subscriber, "player"):
if not has_sub and hasattr(subscriber, "account"):
# it's common to send an Object when we
# by default only allow Players to subscribe.
has_sub = self.subscriptions.has(subscriber.player)
# by default only allow Accounts to subscribe.
has_sub = self.subscriptions.has(subscriber.account)
return has_sub
@property
@ -94,7 +94,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
listening = [ob for ob in subs if ob.is_connected and ob not in self.mutelist]
if subs:
# display listening subscribers in bold
string = ", ".join([player.key if player not in listening else "|w%s|n" % player.key for player in subs])
string = ", ".join([account.key if account not in listening else "|w%s|n" % account.key for account in subs])
else:
string = "<None>"
return string
@ -106,7 +106,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
but may use channel commands.
Args:
subscriber (Object or Player): Subscriber to mute.
subscriber (Object or Account): Subscriber to mute.
**kwargs (dict): Arbitrary, optional arguments for users
overriding the call (unused by default).
@ -124,7 +124,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
but may use channel commands.
Args:
subscriber (Object or Player): The subscriber to unmute.
subscriber (Object or Account): The subscriber to unmute.
**kwargs (dict): Arbitrary, optional arguments for users
overriding the call (unused by default).
@ -141,7 +141,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
Connect the user to this channel. This checks access.
Args:
subscriber (Player or Object): the entity to subscribe
subscriber (Account or Object): the entity to subscribe
to this channel.
**kwargs (dict): Arbitrary, optional arguments for users
overriding the call (unused by default).
@ -171,7 +171,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
Disconnect entity from this channel.
Args:
subscriber (Player of Object): the
subscriber (Account of Object): the
entity to disconnect.
**kwargs (dict): Arbitrary, optional arguments for users
overriding the call (unused by default).
@ -265,7 +265,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
This is also where logging happens, if enabled.
"""
# get all players or objects connected to this channel and send to them
# get all accounts or objects connected to this channel and send to them
if online:
subs = self.subscriptions.online()
else:
@ -276,7 +276,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
continue
try:
# note our addition of the from_channel keyword here. This could be checked
# by a custom player.msg() to treat channel-receives differently.
# by a custom account.msg() to treat channel-receives differently.
entity.msg(msgobj.message, from_obj=msgobj.senders, options={"from_channel": self.id})
except AttributeError as e:
logger.log_trace("%s\nCannot send msg to '%s'." % (e, entity))
@ -288,7 +288,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
def msg(self, msgobj, header=None, senders=None, sender_strings=None,
keep_log=None, online=False, emit=False, external=False):
"""
Send the given message to all players connected to channel. Note that
Send the given message to all accounts connected to channel. Note that
no permission-checking is done here; it is assumed to have been
done before calling this method. The optional keywords are not used if
persistent is False.
@ -300,10 +300,10 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
(if persistent=False) or it will be used together with `header`
and `senders` keywords to create a Msg instance on the fly.
header (str, optional): A header for building the message.
senders (Object, Player or list, optional): Optional if persistent=False, used
senders (Object, Account or list, optional): Optional if persistent=False, used
to build senders for the message.
sender_strings (list, optional): Name strings of senders. Used for external
connections where the sender is not a player or object.
connections where the sender is not an account or object.
When this is defined, external will be assumed.
keep_log (bool or None, optional): This allows to temporarily change the logging status of
this channel message. If `None`, the Channel's `keep_log` Attribute will
@ -311,8 +311,8 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
message only (note that for unlogged channels, a `True` value here will
create a new log file only for this message).
online (bool, optional) - If this is set true, only messages people who are
online. Otherwise, messages all players connected. This can
make things faster, but may not trigger listeners on players
online. Otherwise, messages all accounts connected. This can
make things faster, but may not trigger listeners on accounts
that are offline.
emit (bool, optional) - Signals to the message formatter that this message is
not to be directly associated with a name.
@ -389,7 +389,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
Notes:
This function exists separately so that external sources
can use it to format source names in the same manner as
normal object/player names.
normal object/account names.
"""
if not senders:
@ -432,7 +432,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
"""
Hook method. Used for formatting external messages. This is
needed as a separate operation because the senders of external
messages may not be in-game objects/players, and so cannot
messages may not be in-game objects/accounts, and so cannot
have things like custom user preferences.
Args:
@ -495,7 +495,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
def post_join_channel(self, joiner, **kwargs):
"""
Hook method. Runs right after an object or player joins a channel.
Hook method. Runs right after an object or account joins a channel.
Args:
joiner (object): The joining object.
@ -523,7 +523,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)):
def post_leave_channel(self, leaver, **kwargs):
"""
Hook method. Runs right after an object or player leaves a channel.
Hook method. Runs right after an object or account leaves a channel.
Args:
leaver (object): The leaving object.

View file

@ -10,7 +10,7 @@ from evennia.typeclasses.managers import (TypedObjectManager, TypeclassManager)
from evennia.utils import logger
_GA = object.__getattribute__
_PlayerDB = None
_AccountDB = None
_ObjectDB = None
_ChannelDB = None
_SESSIONS = None
@ -57,7 +57,7 @@ def dbref(inp, reqhash=True):
def identify_object(inp):
"""
Helper function. Identifies if an object is a player or an object;
Helper function. Identifies if an object is an account or an object;
return its database model
Args:
@ -65,14 +65,14 @@ def identify_object(inp):
Returns:
identified (tuple): This is a tuple with (`inp`, identifier)
where `identifier` is one of "player", "object", "channel",
where `identifier` is one of "account", "object", "channel",
"string", "dbref" or None.
"""
if hasattr(inp, "__dbclass__"):
clsname = inp.__dbclass__.__name__
if clsname == "PlayerDB":
return inp, "player"
if clsname == "AccountDB":
return inp, "account"
elif clsname == "ObjectDB":
return inp ,"object"
elif clsname == "ChannelDB":
@ -85,14 +85,14 @@ def identify_object(inp):
return inp, None
def to_object(inp, objtype='player'):
def to_object(inp, objtype='account'):
"""
Locates the object related to the given playername or channel key.
Locates the object related to the given accountname or channel key.
If input was already the correct object, return it.
Args:
inp (any): The input object/string
objtype (str): Either 'player' or 'channel'.
objtype (str): Either 'account' or 'channel'.
Returns:
obj (object): The correct object related to `inp`.
@ -101,17 +101,17 @@ def to_object(inp, objtype='player'):
obj, typ = identify_object(inp)
if typ == objtype:
return obj
if objtype == 'player':
if objtype == 'account':
if typ == 'object':
return obj.player
return obj.account
if typ == 'string':
return _PlayerDB.objects.get(user_username__iexact=obj)
return _AccountDB.objects.get(user_username__iexact=obj)
if typ == 'dbref':
return _PlayerDB.objects.get(id=obj)
return _AccountDB.objects.get(id=obj)
logger.log_err("%s %s %s %s %s", objtype, inp, obj, typ, type(inp))
raise CommError()
elif objtype == 'object':
if typ == 'player':
if typ == 'account':
return obj.obj
if typ == 'string':
return _ObjectDB.objects.get(db_key__iexact=obj)
@ -158,7 +158,7 @@ class MsgManager(TypedObjectManager):
Returns:
identified (tuple): This is a tuple with (`inp`, identifier)
where `identifier` is one of "player", "object", "channel",
where `identifier` is one of "account", "object", "channel",
"string", "dbref" or None.
"""
@ -183,10 +183,10 @@ class MsgManager(TypedObjectManager):
def get_messages_by_sender(self, sender, exclude_channel_messages=False):
"""
Get all messages sent by one entity - this could be either a
player or an object
account or an object
Args:
sender (Player or Object): The sender of the message.
sender (Account or Object): The sender of the message.
exclude_channel_messages (bool, optional): Only return messages
not aimed at a channel (that is, private tells for example)
@ -200,9 +200,9 @@ class MsgManager(TypedObjectManager):
obj, typ = identify_object(sender)
if exclude_channel_messages:
# explicitly exclude channel recipients
if typ == 'player':
return list(self.filter(db_sender_players=obj,
db_receivers_channels__isnull=True).exclude(db_hide_from_players=obj))
if typ == 'account':
return list(self.filter(db_sender_accounts=obj,
db_receivers_channels__isnull=True).exclude(db_hide_from_accounts=obj))
elif typ == 'object':
return list(self.filter(db_sender_objects=obj,
db_receivers_channels__isnull=True).exclude(db_hide_from_objects=obj))
@ -210,8 +210,8 @@ class MsgManager(TypedObjectManager):
raise CommError
else:
# get everything, channel or not
if typ == 'player':
return list(self.filter(db_sender_players=obj).exclude(db_hide_from_players=obj))
if typ == 'account':
return list(self.filter(db_sender_accounts=obj).exclude(db_hide_from_accounts=obj))
elif typ == 'object':
return list(self.filter(db_sender_objects=obj).exclude(db_hide_from_objects=obj))
else:
@ -222,7 +222,7 @@ class MsgManager(TypedObjectManager):
Get all messages sent to one given recipient.
Args:
recipient (Object, Player or Channel): The recipient of the messages to search for.
recipient (Object, Account or Channel): The recipient of the messages to search for.
Returns:
messages (list): Matching messages.
@ -232,8 +232,8 @@ class MsgManager(TypedObjectManager):
"""
obj, typ = identify_object(recipient)
if typ == 'player':
return list(self.filter(db_receivers_players=obj).exclude(db_hide_from_players=obj))
if typ == 'account':
return list(self.filter(db_receivers_accounts=obj).exclude(db_hide_from_accounts=obj))
elif typ == 'object':
return list(self.filter(db_receivers_objects=obj).exclude(db_hide_from_objects=obj))
elif typ == 'channel':
@ -260,9 +260,9 @@ class MsgManager(TypedObjectManager):
one of the arguments must be given to do a search.
Args:
sender (Object or Player, optional): Get messages sent by a particular player or object
receiver (Object, Player or Channel, optional): Get messages
received by a certain player,object or channel
sender (Object or Account, optional): Get messages sent by a particular account or object
receiver (Object, Account or Channel, optional): Get messages
received by a certain account,object or channel
freetext (str): Search for a text string in a message. NOTE:
This can potentially be slow, so make sure to supply one of
the other arguments to limit the search.
@ -287,16 +287,16 @@ class MsgManager(TypedObjectManager):
# filter by sender
sender, styp = identify_object(sender)
if styp == 'player':
sender_restrict = Q(db_sender_players=sender) & ~Q(db_hide_from_players=sender)
if styp == 'account':
sender_restrict = Q(db_sender_accounts=sender) & ~Q(db_hide_from_accounts=sender)
elif styp == 'object':
sender_restrict = Q(db_sender_objects=sender) & ~Q(db_hide_from_objects=sender)
else:
sender_restrict = Q()
# filter by receiver
receiver, rtyp = identify_object(receiver)
if rtyp == 'player':
receiver_restrict = Q(db_receivers_players=receiver) & ~Q(db_hide_from_players=receiver)
if rtyp == 'account':
receiver_restrict = Q(db_receivers_accounts=receiver) & ~Q(db_hide_from_accounts=receiver)
elif rtyp == 'object':
receiver_restrict = Q(db_receivers_objects=receiver) & ~Q(db_hide_from_objects=receiver)
elif rtyp == 'channel':
@ -369,14 +369,14 @@ class ChannelDBManager(TypedObjectManager):
Return all channels a given entity is subscribed to.
Args:
subscriber (Object or Player): The one subscribing.
subscriber (Object or Account): The one subscribing.
Returns:
subscriptions (list): Channel subscribed to.
"""
clsname = subscriber.__dbclass__.__name__
if clsname == "PlayerDB":
if clsname == "AccountDB":
return subscriber.subscription_set.all()
if clsname == "ObjectDB":
return subscriber.object_subscription_set.all()

View file

@ -13,7 +13,7 @@ For non-persistent (and slightly faster) use one can also use the
TempMsg, which mimics the Msg API but without actually saving to the
database.
Channels are central objects that act as targets for Msgs. Players can
Channels are central objects that act as targets for Msgs. Accounts can
connect to channels by use of a ChannelConnect object (this object is
necessary to easily be able to delete connections on the fly).
"""
@ -48,16 +48,16 @@ _CHANNELHANDLER = None
class Msg(SharedMemoryModel):
"""
A single message. This model describes all ooc messages
sent in-game, both to channels and between players.
sent in-game, both to channels and between accounts.
The Msg class defines the following database fields (all
accessed via specific handler methods):
- db_sender_players: Player senders
- db_sender_accounts: Account senders
- db_sender_objects: Object senders
- db_sender_scripts: Script senders
- db_sender_external: External senders (defined as string names)
- db_receivers_players: Receiving players
- db_receivers_accounts: Receiving accounts
- db_receivers_objects: Receiving objects
- db_receivers_scripts: Receiveing scripts
- db_receivers_channels: Receiving channels
@ -77,7 +77,7 @@ class Msg(SharedMemoryModel):
# These databse fields are all set using their corresponding properties,
# named same as the field, but withtout the db_* prefix.
# Sender is either a player, an object or an external sender, like
# Sender is either an account, an object or an external sender, like
# an IRC channel; normally there is only one, but if co-modification of
# a message is allowed, there may be more than one "author"
db_sender_accounts = models.ManyToManyField("accounts.AccountDB", related_name='sender_account_set',
@ -114,8 +114,8 @@ class Msg(SharedMemoryModel):
db_lock_storage = models.TextField('locks', blank=True,
help_text='access locks on this message.')
# these can be used to filter/hide a given message from supplied objects/players/channels
db_hide_from_players = models.ManyToManyField("players.PlayerDB", related_name='hide_from_players_set', blank=True)
# these can be used to filter/hide a given message from supplied objects/accounts/channels
db_hide_from_accounts = models.ManyToManyField("accounts.AccountDB", related_name='hide_from_accounts_set', blank=True)
db_hide_from_accounts = models.ManyToManyField("accounts.AccountDB", related_name='hide_from_accounts_set', blank=True)
db_hide_from_objects = models.ManyToManyField("objects.ObjectDB", related_name='hide_from_objects_set', blank=True)
@ -156,7 +156,7 @@ class Msg(SharedMemoryModel):
#@property
def __senders_get(self):
"Getter. Allows for value = self.sender"
return list(self.db_sender_players.all()) + \
return list(self.db_sender_accounts.all()) + \
list(self.db_sender_objects.all()) + \
list(self.db_sender_scripts.all()) + \
self.extra_senders
@ -177,15 +177,15 @@ class Msg(SharedMemoryModel):
clsname = sender.__dbclass__.__name__
if clsname == "ObjectDB":
self.db_sender_objects.add(sender)
elif clsname == "PlayerDB":
self.db_sender_players.add(sender)
elif clsname == "AccountDB":
self.db_sender_accounts.add(sender)
elif clsname == "ScriptDB":
self.db_sender_scripts.add(sender)
#@sender.deleter
def __senders_del(self):
"Deleter. Clears all senders"
self.db_sender_players.clear()
self.db_sender_accounts.clear()
self.db_sender_objects.clear()
self.db_sender_scripts.clear()
self.db_sender_external = ""
@ -198,7 +198,7 @@ class Msg(SharedMemoryModel):
Remove a single sender or a list of senders.
Args:
senders (Player, Object, str or list): Senders to remove.
senders (Account, Object, str or list): Senders to remove.
"""
for sender in make_iter(senders):
@ -212,19 +212,19 @@ class Msg(SharedMemoryModel):
clsname = sender.__dbclass__.__name__
if clsname == "ObjectDB":
self.db_sender_objects.remove(sender)
elif clsname == "PlayerDB":
self.db_sender_players.remove(sender)
elif clsname == "AccountDB":
self.db_sender_accounts.remove(sender)
elif clsname == "ScriptDB":
self.db_sender_players.remove(sender)
self.db_sender_accounts.remove(sender)
# receivers property
#@property
def __receivers_get(self):
"""
Getter. Allows for value = self.receivers.
Returns four lists of receivers: players, objects, scripts and channels.
Returns four lists of receivers: accounts, objects, scripts and channels.
"""
return list(self.db_receivers_players.all()) + \
return list(self.db_receivers_accounts.all()) + \
list(self.db_receivers_objects.all()) + \
list(self.db_receivers_scripts.all()) + \
list(self.db_receivers_channels.all())
@ -243,8 +243,8 @@ class Msg(SharedMemoryModel):
clsname = receiver.__dbclass__.__name__
if clsname == "ObjectDB":
self.db_receivers_objects.add(receiver)
elif clsname == "PlayerDB":
self.db_receivers_players.add(receiver)
elif clsname == "AccountDB":
self.db_receivers_accounts.add(receiver)
elif clsname == "ScriptDB":
self.db_receivers_scripts.add(receiver)
elif clsname == "ChannelDB":
@ -254,7 +254,7 @@ class Msg(SharedMemoryModel):
#@receivers.deleter
def __receivers_del(self):
"Deleter. Clears all receivers"
self.db_receivers_players.clear()
self.db_receivers_accounts.clear()
self.db_receivers_objects.clear()
self.db_receivers_scripts.clear()
self.db_receivers_channels.clear()
@ -266,7 +266,7 @@ class Msg(SharedMemoryModel):
Remove a single receiver or a list of receivers.
Args:
receivers (Player, Object, Script, Channel or list): Receiver to remove.
receivers (Account, Object, Script, Channel or list): Receiver to remove.
"""
for receiver in make_iter(receivers):
@ -277,8 +277,8 @@ class Msg(SharedMemoryModel):
clsname = receiver.__dbclass__.__name__
if clsname == "ObjectDB":
self.db_receivers_objects.remove(receiver)
elif clsname == "PlayerDB":
self.db_receivers_players.remove(receiver)
elif clsname == "AccountDB":
self.db_receivers_accounts.remove(receiver)
elif clsname == "ScriptDB":
self.db_receivers_scripts.remove(receiver)
elif clsname == "ChannelDB":
@ -309,9 +309,9 @@ class Msg(SharedMemoryModel):
def __hide_from_get(self):
"""
Getter. Allows for value = self.hide_from.
Returns 3 lists of players, objects and channels
Returns 3 lists of accounts, objects and channels
"""
return self.db_hide_from_players.all(), self.db_hide_from_objects.all(), self.db_hide_from_channels.all()
return self.db_hide_from_accounts.all(), self.db_hide_from_objects.all(), self.db_hide_from_channels.all()
#@hide_from_sender.setter
def __hide_from_set(self, hiders):
@ -322,8 +322,8 @@ class Msg(SharedMemoryModel):
if not hasattr(hider, "__dbclass__"):
raise ValueError("This is a not a typeclassed object!")
clsname = hider.__dbclass__.__name__
if clsname == "PlayerDB":
self.db_hide_from_players.add(hider.__dbclass__)
if clsname == "AccountDB":
self.db_hide_from_accounts.add(hider.__dbclass__)
elif clsname == "ObjectDB":
self.db_hide_from_objects.add(hider.__dbclass__)
elif clsname == "ChannelDB":
@ -332,7 +332,7 @@ class Msg(SharedMemoryModel):
#@hide_from_sender.deleter
def __hide_from_del(self):
"Deleter. Allows for del self.hide_from_senders"
self.db_hide_from_players.clear()
self.db_hide_from_accounts.clear()
self.db_hide_from_objects.clear()
self.db_hide_from_channels.clear()
self.save()
@ -353,7 +353,7 @@ class Msg(SharedMemoryModel):
Checks lock access.
Args:
accessing_obj (Object or Player): The object trying to gain access.
accessing_obj (Object or Account): The object trying to gain access.
access_type (str, optional): The type of lock access to check.
default (bool): Fallback to use if `access_type` lock is not defined.
@ -383,13 +383,13 @@ class TempMsg(object):
Args:
senders (any or list, optional): Senders of the message.
receivers (Player, Object, Channel or list, optional): Receivers of this message.
receivers (Account, Object, Channel or list, optional): Receivers of this message.
channels (Channel or list, optional): Channels to send to.
message (str, optional): Message to send.
header (str, optional): Header of message.
type (str, optional): Message class, if any.
lockstring (str, optional): Lock for the message.
hide_from (Player, Object, Channel or list, optional): Entities to hide this message from.
hide_from (Account, Object, Channel or list, optional): Entities to hide this message from.
"""
self.senders = senders and make_iter(senders) or []
@ -419,7 +419,7 @@ class TempMsg(object):
Remove a sender or a list of senders.
Args:
sender (Object, Player, str or list): Senders to remove.
sender (Object, Account, str or list): Senders to remove.
"""
for o in make_iter(sender):
@ -433,7 +433,7 @@ class TempMsg(object):
Remove a receiver or a list of receivers
Args:
receiver (Object, Player, Channel, str or list): Receivers to remove.
receiver (Object, Account, Channel, str or list): Receivers to remove.
"""
for o in make_iter(receiver):
@ -447,7 +447,7 @@ class TempMsg(object):
Checks lock access.
Args:
accessing_obj (Object or Player): The object trying to gain access.
accessing_obj (Object or Account): The object trying to gain access.
access_type (str, optional): The type of lock access to check.
default (bool): Fallback to use if `access_type` lock is not defined.
@ -469,7 +469,7 @@ class SubscriptionHandler(object):
"""
This handler manages subscriptions to the
channel and hides away which type of entity is
subscribing (Player or Object)
subscribing (Account or Object)
"""
def __init__(self, obj):
"""
@ -483,7 +483,7 @@ class SubscriptionHandler(object):
self._cache = None
def _recache(self):
self._cache = {player : True for player in self.obj.db_subscriptions.all()}
self._cache = {account : True for account in self.obj.db_subscriptions.all()}
self._cache.update({obj : True for obj in self.obj.db_object_subscriptions.all()})
def has(self, entity):
@ -491,12 +491,12 @@ class SubscriptionHandler(object):
Check if the given entity subscribe to this channel
Args:
entity (str, Player or Object): The entity to return. If
entity (str, Account or Object): The entity to return. If
a string, it assumed to be the key or the #dbref
of the entity.
Returns:
subscriber (Player, Object or None): The given
subscriber (Account, Object or None): The given
subscriber.
"""
@ -509,7 +509,7 @@ class SubscriptionHandler(object):
Subscribe an entity to this channel.
Args:
entity (Player, Object or list): The entity or
entity (Account, Object or list): The entity or
list of entities to subscribe to this channel.
Note:
@ -527,7 +527,7 @@ class SubscriptionHandler(object):
# chooses the right type
if clsname == "ObjectDB":
self.obj.db_object_subscriptions.add(subscriber)
elif clsname == "PlayerDB":
elif clsname == "AccountDB":
self.obj.db_subscriptions.add(subscriber)
_CHANNELHANDLER.cached_cmdsets.pop(subscriber, None)
self._recache()
@ -537,7 +537,7 @@ class SubscriptionHandler(object):
Remove a subscriber from the channel.
Args:
entity (Player, Object or list): The entity or
entity (Account, Object or list): The entity or
entities to un-subscribe from the channel.
"""
@ -548,7 +548,7 @@ class SubscriptionHandler(object):
if subscriber:
clsname = subscriber.__dbclass__.__name__
# chooses the right type
if clsname == "PlayerDB":
if clsname == "AccountDB":
self.obj.db_subscriptions.remove(entity)
elif clsname == "ObjectDB":
self.obj.db_object_subscriptions.remove(entity)
@ -561,7 +561,7 @@ class SubscriptionHandler(object):
Returns:
subscribers (list): The subscribers. This
may be a mix of Players and Objects!
may be a mix of Accounts and Objects!
"""
if self._cache is None:
@ -570,17 +570,17 @@ class SubscriptionHandler(object):
def online(self):
"""
Get all online players from our cache
Get all online accounts from our cache
Returns:
subscribers (list): Subscribers who are online or
are puppeted by an online player.
are puppeted by an online account.
"""
subs = []
for obj in self.all():
if hasattr(obj, 'player'):
if not obj.player:
if hasattr(obj, 'account'):
if not obj.account:
continue
obj = obj.player
obj = obj.account
if not obj.is_connected:
continue
subs.append(obj)
@ -604,7 +604,7 @@ class ChannelDB(TypedObject):
The Channel class defines the following database fields
beyond the ones inherited from TypedObject:
- db_subscriptions: The Player subscriptions (this is the most
- db_subscriptions: The Account subscriptions (this is the most
usual case, named this way for legacy.
- db_object_subscriptions: The Object subscriptions.