diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index f50d3bf4a8..fd51c03d72 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -2,7 +2,6 @@ Base typeclass for in-game Channels. """ - from evennia.typeclasses.models import TypeclassBase from evennia.comms.models import TempMsg, ChannelDB from evennia.comms.managers import ChannelManager @@ -239,14 +238,17 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)): Args: msgobj (Msg or TempMsg): Message to distribute. online (bool): Only send to receivers who are actually online - (not currently used): Notes: This is also where logging happens, if enabled. """ # get all players or objects connected to this channel and send to them - for entity in self.subscriptions.all(): + if online: + subs = self.subscriptions.online() + else: + subs = self.subscriptions.all() + for entity in subs: # if the entity is muted, we don't send them a message if entity in self.mutelist: continue diff --git a/evennia/comms/models.py b/evennia/comms/models.py index ce5f3d739c..c7b5e8d7b9 100644 --- a/evennia/comms/models.py +++ b/evennia/comms/models.py @@ -538,6 +538,24 @@ class SubscriptionHandler(object): self._recache() return self._cache + def online(self): + """ + Get all online players from our cache + Returns: + subscribers (list): Subscribers who are online or + are puppeted by an online player. + """ + subs = [] + for obj in self.all(): + if hasattr(obj, 'player'): + if not obj.player: + continue + obj = obj.player + if not obj.is_connected: + continue + subs.append(obj) + return subs + def clear(self): """ Remove all subscribers from channel.