mirror of
https://github.com/evennia/evennia.git
synced 2026-04-07 00:45:22 +02:00
Merged. Still need to update some migrations.
This commit is contained in:
commit
c676c9965f
29 changed files with 821 additions and 401 deletions
|
|
@ -90,7 +90,7 @@ class ChannelCommand(command.Command):
|
|||
msgobj.senders = sender
|
||||
msgobj.channels = channel
|
||||
# send new message object to channel
|
||||
channel.msg(msgobj, senders=sender)
|
||||
channel.msg(msgobj, senders=sender, online=True)
|
||||
|
||||
class ChannelHandler(object):
|
||||
"""
|
||||
|
|
@ -136,14 +136,11 @@ class ChannelHandler(object):
|
|||
and run self.update on the handler.
|
||||
"""
|
||||
# map the channel to a searchable command
|
||||
cmd = ChannelCommand()
|
||||
cmd.key = channel.key.strip().lower()
|
||||
cmd.obj = channel
|
||||
cmd = ChannelCommand(key=channel.key.strip().lower(),
|
||||
aliases=channel.aliases if channel.aliases else [],
|
||||
locks="cmd:all();%s" % channel.locks,
|
||||
obj=channel)
|
||||
cmd.__doc__= self._format_help(channel)
|
||||
if channel.aliases:
|
||||
cmd.aliases = channel.aliases
|
||||
cmd.lock_storage = "cmd:all();%s" % channel.locks
|
||||
cmd.lockhandler.reset()
|
||||
self.cached_channel_cmds.append(cmd)
|
||||
self.cached_cmdsets = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ _GA = object.__getattribute__
|
|||
_PlayerDB = None
|
||||
_ObjectDB = None
|
||||
_Channel = None
|
||||
_SESSIONS = None
|
||||
_ExternalConnection = None
|
||||
_User = None
|
||||
|
||||
|
|
@ -198,7 +199,7 @@ class MsgManager(models.Manager):
|
|||
NOTE: This can potentially be slow, so make sure to supply
|
||||
one of the other arguments to limit the search.
|
||||
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.
|
||||
"""
|
||||
# unique msg id
|
||||
|
|
@ -299,19 +300,33 @@ class ChannelManager(models.Manager):
|
|||
CHANNELHANDLER.update()
|
||||
return None
|
||||
|
||||
def get_all_connections(self, channel):
|
||||
def get_all_connections(self, channel, online=False):
|
||||
"""
|
||||
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
|
||||
global _SESSIONS
|
||||
if not _SESSIONS:
|
||||
from src.server.sessionhandler import SESSIONS as _SESSIONS
|
||||
|
||||
PlayerChannelConnection = ContentType.objects.get(app_label="comms",
|
||||
model="playerchannelconnection").model_class()
|
||||
ExternalChannelConnection = ContentType.objects.get(app_label="comms",
|
||||
model="externalchannelconnection").model_class()
|
||||
return itertools.chain(PlayerChannelConnection.objects.get_all_connections(channel),
|
||||
ExternalChannelConnection.objects.get_all_connections(channel))
|
||||
players = []
|
||||
if online:
|
||||
session_list = _SESSIONS.get_sessions()
|
||||
unique_online_users = set(sess.uid for sess in session_list if sess.logged_in)
|
||||
online_players = (sess.get_player() for sess in session_list if sess.uid in unique_online_users)
|
||||
for player in online_players:
|
||||
players.extend(PlayerChannelConnection.objects.filter(db_player=player, db_channel=channel))
|
||||
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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -553,7 +553,7 @@ class Channel(SharedMemoryModel):
|
|||
# do the check
|
||||
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
|
||||
no permission-checking is done here; it is assumed to have been
|
||||
|
|
@ -566,7 +566,8 @@ class Channel(SharedMemoryModel):
|
|||
persistent=False.
|
||||
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.
|
||||
|
||||
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):
|
||||
|
|
@ -588,7 +589,7 @@ class Channel(SharedMemoryModel):
|
|||
msg = msgobj.message
|
||||
|
||||
# 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:
|
||||
conn.player.msg(msg, senders)
|
||||
except AttributeError:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue