Made normal channels not message offline users by default.

This commit is contained in:
Kelketek 2013-06-29 18:52:15 -05:00
parent 240dee1d5b
commit c4db3e5370
3 changed files with 29 additions and 11 deletions

View file

@ -90,7 +90,7 @@ class ChannelCommand(command.Command):
msgobj.senders = sender msgobj.senders = sender
msgobj.channels = channel msgobj.channels = channel
# send new message object to channel # send new message object to channel
channel.msg(msgobj, senders=sender) channel.msg(msgobj, senders=sender, online=True)
class ChannelHandler(object): class ChannelHandler(object):
""" """

View file

@ -198,7 +198,7 @@ class MsgManager(models.Manager):
NOTE: This can potentially be slow, so make sure to supply NOTE: This can potentially be slow, so make sure to supply
one of the other arguments to limit the search. one of the other arguments to limit the search.
dbref - (int) the exact database id of the message. This will override dbref - (int) the exact database id of the message. This will override
all other search crieteria since it's unique and all other search criteria since it's unique and
always gives a list with only one match. always gives a list with only one match.
""" """
# unique msg id # unique msg id
@ -299,19 +299,36 @@ class ChannelManager(models.Manager):
CHANNELHANDLER.update() CHANNELHANDLER.update()
return None return None
def get_all_connections(self, channel): def get_all_connections(self, channel, online=False):
""" """
Return the connections of all players listening Return the connections of all players listening
to this channel to this channel. If Online is true, it only returns
connected players.
""" """
# import here to avoid circular imports
#from src.comms.models import PlayerChannelConnection
PlayerChannelConnection = ContentType.objects.get(app_label="comms", PlayerChannelConnection = ContentType.objects.get(app_label="comms",
model="playerchannelconnection").model_class() model="playerchannelconnection").model_class()
ExternalChannelConnection = ContentType.objects.get(app_label="comms", ExternalChannelConnection = ContentType.objects.get(app_label="comms",
model="externalchannelconnection").model_class() model="externalchannelconnection").model_class()
return itertools.chain(PlayerChannelConnection.objects.get_all_connections(channel), # Importing here to avoid circular imports.
ExternalChannelConnection.objects.get_all_connections(channel)) from src.server.sessionhandler import SESSIONS
players = []
if online:
session_list = SESSIONS.get_sessions()
for session in session_list:
if not session.logged_in:
continue
try:
players.append(PlayerChannelConnection.objects.get(db_player=session.get_player(),
db_channel=channel))
except PlayerChannelConnection.DoesNotExist:
pass
else:
players.extend(PlayerChannelConnection.objects.get_all_connections(channel))
external_connections = ExternalChannelConnection.objects.get_all_connections(channel)
return itertools.chain(players, external_connections)
def channel_search(self, ostring): def channel_search(self, ostring):
""" """

View file

@ -555,7 +555,7 @@ class Channel(SharedMemoryModel):
# do the check # do the check
return PlayerChannelConnection.objects.has_player_connection(player, self) return PlayerChannelConnection.objects.has_player_connection(player, self)
def msg(self, msgobj, header=None, senders=None, persistent=True): def msg(self, msgobj, header=None, senders=None, persistent=True, online=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
@ -568,7 +568,8 @@ class Channel(SharedMemoryModel):
persistent=False. persistent=False.
persistent (bool) - ignored if msgobj is a Msg or TempMsg. If True, a Msg will be created, using persistent (bool) - ignored if msgobj is a Msg or TempMsg. If True, a Msg will be created, using
header and senders keywords. If False, other keywords will be ignored. header and senders keywords. If False, other keywords will be ignored.
online (bool) - 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 that are offline.
""" """
if isinstance(msgobj, basestring): if isinstance(msgobj, basestring):
@ -590,7 +591,7 @@ class Channel(SharedMemoryModel):
msg = msgobj.message msg = msgobj.message
# get all players connected to this channel and send to them # get all players connected to this channel and send to them
for conn in Channel.objects.get_all_connections(self): for conn in Channel.objects.get_all_connections(self, online=online):
try: try:
conn.player.msg(msg, senders) conn.player.msg(msg, senders)
except AttributeError: except AttributeError: