From f9c369f86912aebfd835ca83f4344dc265d4ce22 Mon Sep 17 00:00:00 2001 From: Tehom Date: Sat, 20 May 2017 23:18:26 -0400 Subject: [PATCH 1/2] Add method to subscription handler to check online members, and put check in Channel typeclass for using this based on settings option. --- evennia/comms/comms.py | 9 +++++++-- evennia/comms/models.py | 18 ++++++++++++++++++ evennia/settings_default.py | 2 ++ 3 files changed, 27 insertions(+), 2 deletions(-) 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' From 27c72d789978b3c87cfa674a7ea6f97725206691 Mon Sep 17 00:00:00 2001 From: Tehom Date: Sat, 20 May 2017 23:33:39 -0400 Subject: [PATCH 2/2] Decided to remove setting because it seemed unnecessary when this was the purported default behavior anyway. It makes sense that if they want to send to offline, they'd override the option to be True in their channel typeclasses. At least that's my thinking, maybe I'm off base. Remove docstr line that says online arg is not currently used. --- evennia/comms/comms.py | 5 +---- evennia/settings_default.py | 2 -- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/evennia/comms/comms.py b/evennia/comms/comms.py index dd6090b374..fd51c03d72 100644 --- a/evennia/comms/comms.py +++ b/evennia/comms/comms.py @@ -2,8 +2,6 @@ Base typeclass for in-game Channels. """ -from django.conf import settings - from evennia.typeclasses.models import TypeclassBase from evennia.comms.models import TempMsg, ChannelDB from evennia.comms.managers import ChannelManager @@ -240,7 +238,6 @@ 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. @@ -267,7 +264,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=settings.CHANNELS_MSG_OFFLINE, emit=False, external=False): + keep_log=None, online=False, 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/settings_default.py b/evennia/settings_default.py index 24b68aa8a6..c5844205c7 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -125,8 +125,6 @@ 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'