Re-activated connect-channel again, called from hooks. Fixed some bugs and minor things to give more control over how messages sent to channels are handled.
This commit is contained in:
parent
d55bee8905
commit
28c625c12c
4 changed files with 46 additions and 20 deletions
|
|
@ -344,7 +344,7 @@ class TempMsg(object):
|
|||
self.receivers = receivers and make_iter(receivers) or []
|
||||
self.channels = channels and make_iter(channels) or []
|
||||
self.type = type
|
||||
self.header, header
|
||||
self.header = header
|
||||
self.message = message
|
||||
self.lock_storage = lockstring
|
||||
self.locks = LockHandler(self)
|
||||
|
|
@ -550,29 +550,32 @@ class Channel(SharedMemoryModel):
|
|||
"""
|
||||
Send the given message to all players connected to channel. Note that
|
||||
no permission-checking is done here; it is assumed to have been
|
||||
done before calling this method.
|
||||
done before calling this method. The optional keywords are not used if persistent is False.
|
||||
|
||||
msgobj - a Msg/TempMsg instance or a message string. If one of the former, the remaining
|
||||
keywords will be ignored. If a string, the other keywords will be used to construct
|
||||
a Msg/TempMsg on the fly.
|
||||
senders (object, player or a list of objects or players) - ignored if msgobj is a Msg or TempMsg.
|
||||
if msgobj is a string. This will be used for the senders of the newly created Msg or TempMsg.
|
||||
persistent (bool) - ignored if msgobj is a Msg or TempMsg. If True, a Msg will be created, otherwise a TempMsg. If
|
||||
keywords will be ignored. If a string, this will either be sent as-is (if persistent=False) or
|
||||
it will be used together with header and senders keywords to create a Msg instance on the fly.
|
||||
senders (object, player or a list of objects or players) - ignored if msgobj is a Msg or TempMsg, or if
|
||||
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.
|
||||
|
||||
"""
|
||||
|
||||
if isinstance(msgobj, basestring):
|
||||
# given msgobj is a string
|
||||
if persistent:
|
||||
msg = Msg()
|
||||
msg.save()
|
||||
msg = msgobj
|
||||
msgobj = Msg()
|
||||
msgobj.save()
|
||||
if senders:
|
||||
msgobj.senders = make_iter(senders)
|
||||
msgobj.header = header
|
||||
msgobj.message = msg
|
||||
msgobj.channels = [self] # add this channel
|
||||
else:
|
||||
msg = TempMsg()
|
||||
if senders:
|
||||
msg.senders = make_iter(senders)
|
||||
msg.header = header
|
||||
msg.message = msgobj
|
||||
msg.channels = [self] # add this channel
|
||||
# just use the msg as-is
|
||||
msg = msgobj
|
||||
else:
|
||||
# already in a Msg/TempMsg
|
||||
msg = msgobj.message
|
||||
|
|
|
|||
|
|
@ -15,15 +15,25 @@ That an object is controlled by a player/user is just defined by its
|
|||
they control by simply linking to a new object's user property.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
from django.conf import settings
|
||||
from src.typeclasses.typeclass import TypeClass
|
||||
from src.commands import cmdset, command
|
||||
from src.comms.models import Channel
|
||||
__all__ = ("Object", "Character", "Room", "Exit")
|
||||
|
||||
_GA = object.__getattribute__
|
||||
_SA = object.__setattr__
|
||||
_DA = object.__delattr__
|
||||
|
||||
|
||||
_CONNECT_CHANNEL = None
|
||||
try:
|
||||
_CONNECT_CHANNEL = Channel.objects.filter(db_key=settings.CHANNEL_CONNECTINFO[0])[0]
|
||||
except Exception, e:
|
||||
print e
|
||||
pass
|
||||
|
||||
#
|
||||
# Base class to inherit from.
|
||||
#
|
||||
|
|
@ -786,6 +796,10 @@ class Character(Object):
|
|||
self.location.msg_contents("%s has left the game." % self.name, exclude=[self])
|
||||
self.db.prelogout_location = self.location
|
||||
self.location = None
|
||||
if _CONNECT_CHANNEL:
|
||||
now = datetime.datetime.now()
|
||||
now = "%02i-%02i-%02i(%02i:%02i)" % (now.year, now.month, now.day, now.hour, now.minute)
|
||||
_CONNECT_CHANNEL.tempmsg("[%s, %s]: {R%s disconnected{n" % (_CONNECT_CHANNEL.key, now, self.key))
|
||||
|
||||
def at_post_login(self):
|
||||
"""
|
||||
|
|
@ -804,7 +818,11 @@ class Character(Object):
|
|||
self.location.at_object_receive(self, self.location)
|
||||
# call look
|
||||
self.execute_cmd("look")
|
||||
|
||||
# send to connect channel, if available
|
||||
if _CONNECT_CHANNEL:
|
||||
now = datetime.datetime.now()
|
||||
now = "%02i-%02i-%02i(%02i:%02i)" % (now.year, now.month, now.day, now.hour, now.minute)
|
||||
_CONNECT_CHANNEL.tempmsg("[%s, %s]: {G%s connected{n" % (_CONNECT_CHANNEL.key, now, self.key))
|
||||
|
||||
|
||||
#
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ def hashid(obj):
|
|||
between different typeclassed entities such as scripts and
|
||||
objects (which may still have the same id).
|
||||
"""
|
||||
if not obj:
|
||||
return obj
|
||||
try:
|
||||
hid = _GA(obj, "_hashid")
|
||||
except AttributeError:
|
||||
|
|
@ -86,7 +88,7 @@ def del_field_cache(obj, name):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
def flush_field_cache(obj):
|
||||
def flush_field_cache(obj=None):
|
||||
"On-model cache resetter"
|
||||
hid = hashid(obj)
|
||||
global _FIELD_CACHE
|
||||
|
|
@ -128,7 +130,7 @@ def del_prop_cache(obj, name):
|
|||
del _PROP_CACHE[hashid(obj)][name]
|
||||
except KeyError:
|
||||
pass
|
||||
def flush_field_cache(obj):
|
||||
def flush_field_cache(obj=None):
|
||||
"On-model cache resetter"
|
||||
hid = hashid(obj)
|
||||
global _PROP_CACHE
|
||||
|
|
@ -151,7 +153,9 @@ def set_attr_cache(obj, attrname, attrobj):
|
|||
Cache an attribute object
|
||||
"""
|
||||
global _ATTR_CACHE
|
||||
_ATTR_CACHE[hashid(obj)][attrname] = attrobj
|
||||
hid = hashid(obj)
|
||||
if hid:
|
||||
_ATTR_CACHE[hid][attrname] = attrobj
|
||||
|
||||
def del_attr_cache(obj, attrname):
|
||||
"""
|
||||
|
|
@ -163,7 +167,7 @@ def del_attr_cache(obj, attrname):
|
|||
except KeyError:
|
||||
pass
|
||||
|
||||
def flush_attr_cache(obj):
|
||||
def flush_attr_cache(obj=None):
|
||||
"""
|
||||
Flush the attribute cache for this object.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -230,6 +230,7 @@ def datetime_format(dtobj):
|
|||
"""
|
||||
Takes a datetime object instance (e.g. from django's DateTimeField)
|
||||
and returns a string describing how long ago that date was.
|
||||
|
||||
"""
|
||||
|
||||
year, month, day = dtobj.year, dtobj.month, dtobj.day
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue