Moved connect/disconnect messages to be triggered by Player, not by Character.
This commit is contained in:
parent
707a21c7d7
commit
261363bae7
2 changed files with 26 additions and 33 deletions
|
|
@ -15,12 +15,9 @@ 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
|
|
||||||
from src.utils import logger
|
|
||||||
|
|
||||||
__all__ = ("Object", "Character", "Room", "Exit")
|
__all__ = ("Object", "Character", "Room", "Exit")
|
||||||
|
|
||||||
|
|
@ -28,9 +25,6 @@ _GA = object.__getattribute__
|
||||||
_SA = object.__setattr__
|
_SA = object.__setattr__
|
||||||
_DA = object.__delattr__
|
_DA = object.__delattr__
|
||||||
|
|
||||||
|
|
||||||
_CONNECT_CHANNEL = None
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Base class to inherit from.
|
# Base class to inherit from.
|
||||||
#
|
#
|
||||||
|
|
@ -789,32 +783,15 @@ class Character(Object):
|
||||||
We stove away the character when logging off, otherwise the character object will
|
We stove away the character when logging off, otherwise the character object will
|
||||||
remain in the room also after the player logged off ("headless", so to say).
|
remain in the room also after the player logged off ("headless", so to say).
|
||||||
"""
|
"""
|
||||||
global _CONNECT_CHANNEL
|
|
||||||
if not _CONNECT_CHANNEL:
|
|
||||||
try:
|
|
||||||
_CONNECT_CHANNEL = Channel.objects.filter(db_key=settings.CHANNEL_CONNECTINFO[0])[0]
|
|
||||||
except Exception, e:
|
|
||||||
logger.log_trace()
|
|
||||||
|
|
||||||
if self.location: # have to check, in case of multiple connections closing
|
if self.location: # have to check, in case of multiple connections closing
|
||||||
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):
|
||||||
"""
|
"""
|
||||||
This recovers the character again after having been "stoved away" at disconnect.
|
This recovers the character again after having been "stoved away" at disconnect.
|
||||||
"""
|
"""
|
||||||
global _CONNECT_CHANNEL
|
|
||||||
if not _CONNECT_CHANNEL:
|
|
||||||
try:
|
|
||||||
_CONNECT_CHANNEL = Channel.objects.filter(db_key=settings.CHANNEL_CONNECTINFO[0])[0]
|
|
||||||
except Exception, e:
|
|
||||||
logger.log_trace()
|
|
||||||
if self.db.prelogout_location:
|
if self.db.prelogout_location:
|
||||||
# try to recover
|
# try to recover
|
||||||
self.location = self.db.prelogout_location
|
self.location = self.db.prelogout_location
|
||||||
|
|
@ -828,13 +805,6 @@ 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))
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Base Room object
|
# Base Room object
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,17 @@ character object, so you should customize that
|
||||||
instead for most things).
|
instead for most things).
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
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.comms.models import Channel
|
||||||
|
from src.utils import logger
|
||||||
__all__ = ("Player",)
|
__all__ = ("Player",)
|
||||||
CMDSET_OOC = settings.CMDSET_OOC
|
|
||||||
|
_CMDSET_OOC = settings.CMDSET_OOC
|
||||||
|
_CONNECT_CHANNEL = None
|
||||||
|
|
||||||
|
|
||||||
class Player(TypeClass):
|
class Player(TypeClass):
|
||||||
"""
|
"""
|
||||||
|
|
@ -238,7 +245,7 @@ class Player(TypeClass):
|
||||||
self.locks.add("msg:all()")
|
self.locks.add("msg:all()")
|
||||||
|
|
||||||
# The ooc player cmdset
|
# The ooc player cmdset
|
||||||
self.cmdset.add_default(CMDSET_OOC, permanent=True)
|
self.cmdset.add_default(_CMDSET_OOC, permanent=True)
|
||||||
|
|
||||||
def at_player_creation(self):
|
def at_player_creation(self):
|
||||||
"""
|
"""
|
||||||
|
|
@ -293,12 +300,28 @@ class Player(TypeClass):
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _send_to_connect_channel(self, message):
|
||||||
|
"Helper method for loading the default comm channel"
|
||||||
|
global _CONNECT_CHANNEL
|
||||||
|
if not _CONNECT_CHANNEL:
|
||||||
|
try:
|
||||||
|
_CONNECT_CHANNEL = Channel.objects.filter(db_key=settings.CHANNEL_CONNECTINFO[0])[0]
|
||||||
|
except Exception:
|
||||||
|
logger.log_trace()
|
||||||
|
now = datetime.datetime.now()
|
||||||
|
now = "%02i-%02i-%02i(%02i:%02i)" % (now.year, now.month, now.day, now.hour, now.minute)
|
||||||
|
if _CONNECT_CHANNEL:
|
||||||
|
_CONNECT_CHANNEL.tempmsg("[%s, %s]: %s" % (_CONNECT_CHANNEL.key, now, message))
|
||||||
|
else:
|
||||||
|
logger.log_infomsg("[%s]: %s" % (now, message))
|
||||||
|
|
||||||
def at_post_login(self):
|
def at_post_login(self):
|
||||||
"""
|
"""
|
||||||
Called at the end of the login process, just before letting
|
Called at the end of the login process, just before letting
|
||||||
them loose. This is called before an eventual Character's
|
them loose. This is called before an eventual Character's
|
||||||
at_post_login hook.
|
at_post_login hook.
|
||||||
"""
|
"""
|
||||||
|
self._send_to_connect_channel("{G%s connected{n" % self.key)
|
||||||
# Character.at_post_login also looks around. Only use
|
# Character.at_post_login also looks around. Only use
|
||||||
# this as a backup when logging in without a character
|
# this as a backup when logging in without a character
|
||||||
self.execute_cmd("look")
|
self.execute_cmd("look")
|
||||||
|
|
@ -308,7 +331,7 @@ class Player(TypeClass):
|
||||||
Called just before user
|
Called just before user
|
||||||
is disconnected.
|
is disconnected.
|
||||||
"""
|
"""
|
||||||
pass
|
self._send_to_connect_channel("{R%s disconnected{n" % self.key)
|
||||||
|
|
||||||
def at_message_receive(self, message, from_obj=None):
|
def at_message_receive(self, message, from_obj=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue