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.receivers = receivers and make_iter(receivers) or []
|
||||||
self.channels = channels and make_iter(channels) or []
|
self.channels = channels and make_iter(channels) or []
|
||||||
self.type = type
|
self.type = type
|
||||||
self.header, header
|
self.header = header
|
||||||
self.message = message
|
self.message = message
|
||||||
self.lock_storage = lockstring
|
self.lock_storage = lockstring
|
||||||
self.locks = LockHandler(self)
|
self.locks = LockHandler(self)
|
||||||
|
|
@ -550,29 +550,32 @@ class Channel(SharedMemoryModel):
|
||||||
"""
|
"""
|
||||||
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
|
||||||
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
|
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
|
keywords will be ignored. If a string, this will either be sent as-is (if persistent=False) or
|
||||||
a Msg/TempMsg on the fly.
|
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.
|
senders (object, player or a list of objects or players) - ignored if msgobj is a Msg or TempMsg, or if
|
||||||
if msgobj is a string. This will be used for the senders of the newly created Msg or TempMsg.
|
persistent=False.
|
||||||
persistent (bool) - ignored if msgobj is a Msg or TempMsg. If True, a Msg will be created, otherwise a TempMsg. If
|
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):
|
if isinstance(msgobj, basestring):
|
||||||
# given msgobj is a string
|
# given msgobj is a string
|
||||||
if persistent:
|
if persistent:
|
||||||
msg = Msg()
|
msg = msgobj
|
||||||
msg.save()
|
msgobj = Msg()
|
||||||
else:
|
msgobj.save()
|
||||||
msg = TempMsg()
|
|
||||||
if senders:
|
if senders:
|
||||||
msg.senders = make_iter(senders)
|
msgobj.senders = make_iter(senders)
|
||||||
msg.header = header
|
msgobj.header = header
|
||||||
msg.message = msgobj
|
msgobj.message = msg
|
||||||
msg.channels = [self] # add this channel
|
msgobj.channels = [self] # add this channel
|
||||||
|
else:
|
||||||
|
# just use the msg as-is
|
||||||
|
msg = msgobj
|
||||||
else:
|
else:
|
||||||
# already in a Msg/TempMsg
|
# already in a Msg/TempMsg
|
||||||
msg = msgobj.message
|
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.
|
they control by simply linking to a new object's user property.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import datetime
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from src.typeclasses.typeclass import TypeClass
|
from src.typeclasses.typeclass import TypeClass
|
||||||
from src.commands import cmdset, command
|
from src.commands import cmdset, command
|
||||||
|
from src.comms.models import Channel
|
||||||
__all__ = ("Object", "Character", "Room", "Exit")
|
__all__ = ("Object", "Character", "Room", "Exit")
|
||||||
|
|
||||||
_GA = object.__getattribute__
|
_GA = object.__getattribute__
|
||||||
_SA = object.__setattr__
|
_SA = object.__setattr__
|
||||||
_DA = object.__delattr__
|
_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.
|
# 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.location.msg_contents("%s has left the game." % self.name, exclude=[self])
|
||||||
self.db.prelogout_location = self.location
|
self.db.prelogout_location = self.location
|
||||||
self.location = None
|
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):
|
def at_post_login(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -804,7 +818,11 @@ class Character(Object):
|
||||||
self.location.at_object_receive(self, self.location)
|
self.location.at_object_receive(self, self.location)
|
||||||
# call look
|
# call look
|
||||||
self.execute_cmd("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
|
between different typeclassed entities such as scripts and
|
||||||
objects (which may still have the same id).
|
objects (which may still have the same id).
|
||||||
"""
|
"""
|
||||||
|
if not obj:
|
||||||
|
return obj
|
||||||
try:
|
try:
|
||||||
hid = _GA(obj, "_hashid")
|
hid = _GA(obj, "_hashid")
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
|
@ -86,7 +88,7 @@ def del_field_cache(obj, name):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def flush_field_cache(obj):
|
def flush_field_cache(obj=None):
|
||||||
"On-model cache resetter"
|
"On-model cache resetter"
|
||||||
hid = hashid(obj)
|
hid = hashid(obj)
|
||||||
global _FIELD_CACHE
|
global _FIELD_CACHE
|
||||||
|
|
@ -128,7 +130,7 @@ def del_prop_cache(obj, name):
|
||||||
del _PROP_CACHE[hashid(obj)][name]
|
del _PROP_CACHE[hashid(obj)][name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
def flush_field_cache(obj):
|
def flush_field_cache(obj=None):
|
||||||
"On-model cache resetter"
|
"On-model cache resetter"
|
||||||
hid = hashid(obj)
|
hid = hashid(obj)
|
||||||
global _PROP_CACHE
|
global _PROP_CACHE
|
||||||
|
|
@ -151,7 +153,9 @@ def set_attr_cache(obj, attrname, attrobj):
|
||||||
Cache an attribute object
|
Cache an attribute object
|
||||||
"""
|
"""
|
||||||
global _ATTR_CACHE
|
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):
|
def del_attr_cache(obj, attrname):
|
||||||
"""
|
"""
|
||||||
|
|
@ -163,7 +167,7 @@ def del_attr_cache(obj, attrname):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def flush_attr_cache(obj):
|
def flush_attr_cache(obj=None):
|
||||||
"""
|
"""
|
||||||
Flush the attribute cache for this object.
|
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)
|
Takes a datetime object instance (e.g. from django's DateTimeField)
|
||||||
and returns a string describing how long ago that date was.
|
and returns a string describing how long ago that date was.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
year, month, day = dtobj.year, dtobj.month, dtobj.day
|
year, month, day = dtobj.year, dtobj.month, dtobj.day
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue