Moved login and disconnect from session-level to sessionhandler level to make the process cleaner with hooks rather than direct calls.

This commit is contained in:
Griatch 2013-02-17 18:48:48 +01:00
parent 261363bae7
commit 25505d69a6
7 changed files with 109 additions and 70 deletions

View file

@ -59,23 +59,12 @@ class ServerSession(Session):
else:
self.player.reconnect_session_to_character(self.sessid)
def session_login(self, player):
def at_login(self, player):
"""
Startup mechanisms that need to run at login. This is called
by the login command (which need to have handled authentication
already before calling this method)
Hook called by sessionhandler when the session becomes authenticated.
player - the connected player
player - the player associated with the session
"""
# we have to check this first before uid has been assigned
# this session.
if not self.sessionhandler.sessions_from_player(player):
player.is_connected = True
# actually do the login by assigning session data
self.player = player
self.user = player.user
self.uid = self.user.id
@ -87,31 +76,9 @@ class ServerSession(Session):
self.user.last_login = datetime.now()
self.user.save()
# player init
player.at_init()
# Check if this is the first time the *player* logs in
if player.db.FIRST_LOGIN:
player.at_first_login()
del player.db.FIRST_LOGIN
player.at_pre_login()
self.log(_('Logged in: %(self)s') % {'self': self})
# start (persistent) scripts on this object
#ScriptDB.objects.validate(obj=self.player.character)
#add session to connected list
self.sessionhandler.login(self)
player.at_post_login()
def session_disconnect(self):
def at_disconnect(self):
"""
Clean up the session, removing it from the game and doing some
accounting. This method is used also for non-loggedin
accounts.
Hook called by sessionhandler when disconnecting this session.
"""
if self.logged_in:
sessid = self.sessid
@ -123,8 +90,9 @@ class ServerSession(Session):
uaccount.save()
self.logged_in = False
if not self.sessionhandler.sessions_from_player(player):
# no more sessions connected to this player
player.is_connected = False
self.sessionhandler.disconnect(self)
def get_player(self):
"""
@ -268,12 +236,12 @@ class ServerSession(Session):
# easy-access functions
def login(self, player):
"alias for at_login"
self.session_login(player)
def disconnect(self):
"alias for session_disconnect"
self.session_disconnect()
#def login(self, player):
# "alias for at_login"
# self.session_login(player)
#def disconnect(self):
# "alias for session_disconnect"
# self.session_disconnect()
def msg(self, string='', data=None):
"alias for at_data_out"
self.data_out(string, data=data)

View file

@ -199,6 +199,7 @@ class ServerSessionHandler(SessionHandler):
"""
session = self.sessions.get(session.sessid, None)
if session:
session.at_disconnect()
sessid = session.sessid
del self.sessions[sessid]
# inform portal that session should be closed.
@ -206,7 +207,7 @@ class ServerSessionHandler(SessionHandler):
operation=SDISCONN,
data=reason)
def login(self, session):
def login(self, session, player):
"""
Log in the previously unloggedin session and the player we by
now should know is connected to it. After this point we
@ -214,15 +215,41 @@ class ServerSessionHandler(SessionHandler):
"""
# prep the session with player/user info
# we have to check this first before uid has been assigned
# this session.
if not self.sessions_from_player(player):
player.is_connected = True
# sets up and assigns all properties on the session
session.at_login(player)
# player init
player.at_init()
# Check if this is the first time the *player* logs in
if player.db.FIRST_LOGIN:
player.at_first_login()
del player.db.FIRST_LOGIN
player.at_pre_login()
session.log(_('Logged in: %(self)s') % {'self': self})
# start (persistent) scripts on this object
#ScriptDB.objects.validate(obj=self.player.character)
if MULTISESSION_MODE == 0:
# disconnect all previous sessions.
self.disconnect_duplicate_sessions(session)
session.logged_in = True
# sync the portal to this session
# sync the portal to the session
sessdata = session.get_sync_data()
self.server.amp_protocol.call_remote_PortalAdmin(session.sessid,
operation=SLOGIN,
data=sessdata)
player.at_post_login()
def all_sessions_portal_sync(self):
"""