diff --git a/src/objects/objects.py b/src/objects/objects.py index 93c56f8487..ababa69496 100644 --- a/src/objects/objects.py +++ b/src/objects/objects.py @@ -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. """ -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 -from src.utils import logger __all__ = ("Object", "Character", "Room", "Exit") @@ -28,9 +25,6 @@ _GA = object.__getattribute__ _SA = object.__setattr__ _DA = object.__delattr__ - -_CONNECT_CHANNEL = None - # # 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 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 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): """ 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: # try to recover self.location = self.db.prelogout_location @@ -828,13 +805,6 @@ 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)) - - # # Base Room object # diff --git a/src/players/player.py b/src/players/player.py index 62caacd6eb..b73b1e536e 100644 --- a/src/players/player.py +++ b/src/players/player.py @@ -10,10 +10,17 @@ character object, so you should customize that instead for most things). """ + +import datetime from django.conf import settings from src.typeclasses.typeclass import TypeClass +from src.comms.models import Channel +from src.utils import logger __all__ = ("Player",) -CMDSET_OOC = settings.CMDSET_OOC + +_CMDSET_OOC = settings.CMDSET_OOC +_CONNECT_CHANNEL = None + class Player(TypeClass): """ @@ -238,7 +245,7 @@ class Player(TypeClass): self.locks.add("msg:all()") # 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): """ @@ -293,12 +300,28 @@ class Player(TypeClass): """ 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): """ Called at the end of the login process, just before letting them loose. This is called before an eventual Character's at_post_login hook. """ + self._send_to_connect_channel("{G%s connected{n" % self.key) # Character.at_post_login also looks around. Only use # this as a backup when logging in without a character self.execute_cmd("look") @@ -308,7 +331,7 @@ class Player(TypeClass): Called just before user is disconnected. """ - pass + self._send_to_connect_channel("{R%s disconnected{n" % self.key) def at_message_receive(self, message, from_obj=None): """