Fixed the entire first_init script process with the new typeclass system.

This commit is contained in:
Griatch 2014-12-26 13:31:23 +01:00
parent 11449f3d62
commit b839614259
6 changed files with 114 additions and 121 deletions

View file

@ -45,9 +45,74 @@ class Channel(ChannelDB):
if cdict["desc"]:
self.attributes.add("desc", cdict["desc"])
def at_channel_creation(self):
"""
Called once, when the channel is first created.
"""
pass
# helper methods, for easy overloading
def has_connection(self, player):
"""
Checks so this player is actually listening
to this channel.
"""
if hasattr(player, "player"):
player = player.player
player = player.dbobj
return player in self.db_subscriptions.all()
def connect(self, player):
"Connect the user to this channel. This checks access."
if hasattr(player, "player"):
player = player.player
# check access
if not self.access(player, 'listen'):
return False
# pre-join hook
connect = self.pre_join_channel(player)
if not connect:
return False
# subscribe
self.db_subscriptions.add(player)
# post-join hook
self.post_join_channel(player)
return True
def disconnect(self, player):
"Disconnect user from this channel."
if hasattr(player, "player"):
player = player.player
# pre-disconnect hook
disconnect = self.pre_leave_channel(player)
if not disconnect:
return False
# disconnect
self.db_subscriptions.remove(player.dbobj)
# post-disconnect hook
self.post_leave_channel(player.dbobj)
return True
def access(self, accessing_obj, access_type='listen', default=False):
"""
Determines if another object has permission to access.
accessing_obj - object trying to access this one
access_type - type of access sought
default - what to return if no lock of access_type was found
"""
return self.locks.check(accessing_obj, access_type=access_type, default=default)
def delete(self):
"""
Deletes channel while also cleaning up channelhandler
"""
self.attributes.clear()
self.aliases.clear()
super(Channel, self).delete()
from src.comms.channelhandler import CHANNELHANDLER
CHANNELHANDLER.update()
def channel_prefix(self, msg=None, emit=False):
"""
How the channel should prefix itself for users. Return a string.
@ -134,12 +199,6 @@ class Channel(ChannelDB):
msg.message = body
return msg
def at_channel_create(self):
"""
Run at channel creation.
"""
pass
def pre_join_channel(self, joiner):
"""
Run right before a channel is joined. If this returns a false value,