Add method to subscription handler to check online members, and put check in Channel typeclass for using this based on settings option.
This commit is contained in:
parent
112e457cc3
commit
f9c369f869
3 changed files with 27 additions and 2 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
Base typeclass for in-game Channels.
|
Base typeclass for in-game Channels.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
from evennia.typeclasses.models import TypeclassBase
|
from evennia.typeclasses.models import TypeclassBase
|
||||||
from evennia.comms.models import TempMsg, ChannelDB
|
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
|
# 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 the entity is muted, we don't send them a message
|
||||||
if entity in self.mutelist:
|
if entity in self.mutelist:
|
||||||
continue
|
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)
|
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,
|
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
|
Send the given message to all players connected to channel. Note that
|
||||||
no permission-checking is done here; it is assumed to have been
|
no permission-checking is done here; it is assumed to have been
|
||||||
|
|
|
||||||
|
|
@ -538,6 +538,24 @@ class SubscriptionHandler(object):
|
||||||
self._recache()
|
self._recache()
|
||||||
return self._cache
|
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):
|
def clear(self):
|
||||||
"""
|
"""
|
||||||
Remove all subscribers from channel.
|
Remove all subscribers from channel.
|
||||||
|
|
|
||||||
|
|
@ -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
|
# file sizes down. Turn off to get ever growing log files and never
|
||||||
# loose log info.
|
# loose log info.
|
||||||
CYCLE_LOGFILES = True
|
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:
|
# 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
|
# http://www.postgresql.org/docs/8.0/interactive/datetime-keywords.html#DATETIME-TIMEZONE-SET-TABLE
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue