Starting the move of typeclass methods off *DB models and onto the typeclasses.

This commit is contained in:
Griatch 2014-12-22 22:46:58 +01:00
parent 9321573c23
commit 0b5e2b94ff
6 changed files with 21 additions and 21 deletions

View file

@ -169,8 +169,8 @@ class Channel(ChannelDB):
this channel, and sending them a message. this channel, and sending them a message.
""" """
# get all players connected to this channel and send to them # get all players connected to this channel and send to them
for player in self.dbobj.db_subscriptions.all(): for player in self.db_subscriptions.all():
player = player.typeclass player = player
try: try:
# note our addition of the from_channel keyword here. This could be checked # note our addition of the from_channel keyword here. This could be checked
# by a custom player.msg() to treat channel-receives differently. # by a custom player.msg() to treat channel-receives differently.
@ -222,7 +222,7 @@ class Channel(ChannelDB):
msgobj = TempMsg() msgobj = TempMsg()
msgobj.header = header msgobj.header = header
msgobj.message = msg msgobj.message = msg
msgobj.channels = [self.dbobj] # add this channel msgobj.channels = [self] # add this channel
if not msgobj.senders: if not msgobj.senders:
msgobj.senders = senders msgobj.senders = senders

View file

@ -121,9 +121,9 @@ class Msg(SharedMemoryModel):
#@property #@property
def __senders_get(self): def __senders_get(self):
"Getter. Allows for value = self.sender" "Getter. Allows for value = self.sender"
return list(self.db_sender_players.all()) + return list(self.db_sender_players.all()) + \
list(self.db_sender_objects.all()) + list(self.db_sender_objects.all()) + \
self.extra_senders] self.extra_senders
#@sender.setter #@sender.setter
def __senders_set(self, value): def __senders_set(self, value):

View file

@ -547,7 +547,7 @@ class ObjectDB(TypedObject):
except Exception: except Exception:
logger.log_trace() logger.log_trace()
try: try:
if not self.at_msg_receive(text=text, **kwargs) if not self.at_msg_receive(text=text, **kwargs):
# if at_msg_receive returns false, we abort message to this object # if at_msg_receive returns false, we abort message to this object
return return
except Exception: except Exception:

View file

@ -123,8 +123,8 @@ class Player(PlayerDB):
a command on a Character, the character automatically stores and a command on a Character, the character automatically stores and
handles the sessid). handles the sessid).
kwargs - extra data to send through protocol kwargs - extra data to send through protocol
""" """
self.dbobj.msg(text=text, from_obj=from_obj, sessid=sessid, **kwargs) self.msg(text=text, from_obj=from_obj, sessid=sessid, **kwargs)
def swap_character(self, new_character, delete_old_character=False): def swap_character(self, new_character, delete_old_character=False):
""" """
@ -135,7 +135,7 @@ class Player(PlayerDB):
Returns: True/False depending on if swap suceeded or not. Returns: True/False depending on if swap suceeded or not.
""" """
return self.dbobj.swap_character(new_character, delete_old_character=delete_old_character) return self.swap_character(new_character, delete_old_character=delete_old_character)
def execute_cmd(self, raw_string, sessid=None, **kwargs): def execute_cmd(self, raw_string, sessid=None, **kwargs):
""" """
@ -163,7 +163,7 @@ class Player(PlayerDB):
be useful for coders intending to implement some sort of nested be useful for coders intending to implement some sort of nested
command structure. command structure.
""" """
return self.dbobj.execute_cmd(raw_string, sessid=sessid, **kwargs) return self.execute_cmd(raw_string, sessid=sessid, **kwargs)
def search(self, searchdata, return_puppet=False, **kwargs): def search(self, searchdata, return_puppet=False, **kwargs):
""" """
@ -183,7 +183,7 @@ class Player(PlayerDB):
# handle wrapping of common terms # handle wrapping of common terms
if searchdata.lower() in ("me", "*me", "self", "*self",): if searchdata.lower() in ("me", "*me", "self", "*self",):
return self return self
return self.dbobj.search(searchdata, return_puppet=return_puppet, **kwargs) return self.search(searchdata, return_puppet=return_puppet, **kwargs)
def is_typeclass(self, typeclass, exact=False): def is_typeclass(self, typeclass, exact=False):
""" """
@ -200,7 +200,7 @@ class Player(PlayerDB):
Returns: Boolean Returns: Boolean
""" """
return self.dbobj.is_typeclass(typeclass, exact=exact) return self.is_typeclass(typeclass, exact=exact)
def swap_typeclass(self, new_typeclass, clean_attributes=False, no_default=True): def swap_typeclass(self, new_typeclass, clean_attributes=False, no_default=True):
""" """
@ -235,7 +235,7 @@ class Player(PlayerDB):
boolean True/False depending on if the swap worked or not. boolean True/False depending on if the swap worked or not.
""" """
self.dbobj.swap_typeclass(new_typeclass, self.swap_typeclass(new_typeclass,
clean_attributes=clean_attributes, no_default=no_default) clean_attributes=clean_attributes, no_default=no_default)
def access(self, accessing_obj, access_type='read', default=False, **kwargs): def access(self, accessing_obj, access_type='read', default=False, **kwargs):
@ -248,7 +248,7 @@ class Player(PlayerDB):
default (bool) - what to return if no lock of access_type was found default (bool) - what to return if no lock of access_type was found
**kwargs - passed to the at_access hook along with the result. **kwargs - passed to the at_access hook along with the result.
""" """
result = self.dbobj.access(accessing_obj, access_type=access_type, default=default) result = self.access(accessing_obj, access_type=access_type, default=default)
self.at_access(result, accessing_obj, access_type, **kwargs) self.at_access(result, accessing_obj, access_type, **kwargs)
return result return result
@ -261,7 +261,7 @@ class Player(PlayerDB):
on the object. (example: 'Builders') on the object. (example: 'Builders')
Note that this method does -not- call the at_access hook. Note that this method does -not- call the at_access hook.
""" """
return self.dbobj.check_permstring(permstring) return self.check_permstring(permstring)
## player hooks ## player hooks

View file

@ -115,18 +115,18 @@ class ServerSession(Session):
if self.logged_in: if self.logged_in:
sessid = self.sessid sessid = self.sessid
player = self.player player = self.player
_GA(player.dbobj, "unpuppet_object")(sessid) player.unpuppet_object(sessid)
uaccount = player.dbobj uaccount = player
uaccount.last_login = datetime.now() uaccount.last_login = datetime.now()
uaccount.save() uaccount.save()
# calling player hook # calling player hook
_GA(player.typeclass, "at_disconnect")() player.at_disconnect()
self.logged_in = False self.logged_in = False
if not self.sessionhandler.sessions_from_player(player): if not self.sessionhandler.sessions_from_player(player):
# no more sessions connected to this player # no more sessions connected to this player
player.is_connected = False player.is_connected = False
# this may be used to e.g. delete player after disconnection etc # this may be used to e.g. delete player after disconnection etc
_GA(player.typeclass, "at_post_disconnect")() player.at_post_disconnect()
def get_player(self): def get_player(self):
""" """

View file

@ -34,7 +34,7 @@ def returns_typeclass(method):
def func(self, *args, **kwargs): def func(self, *args, **kwargs):
self.__doc__ = method.__doc__ self.__doc__ = method.__doc__
query = method(self, *args, **kwargs) query = method(self, *args, **kwargs)
return list(query)[0] if query else None return query
return update_wrapper(func, method) return update_wrapper(func, method)
# Managers # Managers