diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index f50d3bf4a8..dd6090b374 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -2,6 +2,7 @@ Base typeclass for in-game Channels. """ +from django.conf import settings from evennia.typeclasses.models import TypeclassBase from evennia.comms.models import TempMsg, ChannelDB @@ -246,7 +247,11 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)): """ # 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 @@ -262,7 +267,7 @@ class DefaultChannel(with_metaclass(TypeclassBase, ChannelDB)): logger.log_file(msgobj.message, self.attributes.get("log_file") or "channel_%s.log" % self.key) def msg(self, msgobj, header=None, senders=None, sender_strings=None, - keep_log=None, online=False, emit=False, external=False): + keep_log=None, online=settings.CHANNELS_MSG_OFFLINE, emit=False, external=False): """ Send the given message to all players connected to channel. Note that no permission-checking is done here; it is assumed to have been 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. diff --git a/evennia/settings_default.py b/evennia/settings_default.py index c5844205c7..24b68aa8a6 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -125,6 +125,8 @@ LOCKWARNING_LOG_FILE = os.path.join(LOG_DIR, 'lockwarnings.log') # file sizes down. Turn off to get ever growing log files and never # loose log info. CYCLE_LOGFILES = True +# whether channels attempt to message offline players by default +CHANNELS_MSG_OFFLINE = False # Local time zone for this installation. All choices can be found here: # http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE TIME_ZONE = 'UTC'