Add sessionhandler.portal_disconnect which cuts down interaction over AMP by one when a player disconnects.

This commit is contained in:
Griatch 2016-09-13 20:42:38 +02:00
parent 5a5884f6da
commit 8eb500f8e0
3 changed files with 30 additions and 6 deletions

View file

@ -329,6 +329,19 @@ class ServerSessionHandler(SessionHandler):
# announce the reconnection
self.announce_all(_(" ... Server restarted."))
def portal_disconnect(self, session):
"""
Called from Portal when Portal session closed from the portal
side. There is no message to report in this case.
Args:
session (Session): The Session to disconnect
"""
# disconnect us without calling Portal since
# Portal already knows.
self.disconnect(session, reason="", sync_portal=False)
# server-side access methods
def start_bot_session(self, protocol_path, configdict):
@ -420,7 +433,7 @@ class ServerSessionHandler(SessionHandler):
sessiondata={"logged_in": True})
player.at_post_login(session=session)
def disconnect(self, session, reason=""):
def disconnect(self, session, reason="", sync_portal=True):
"""
Called from server side to remove session and inform portal
of this fact.
@ -428,6 +441,9 @@ class ServerSessionHandler(SessionHandler):
Args:
session (Session): The Session to disconnect.
reason (str, optional): A motivation for the disconnect.
sync_portal (bool, optional): Sync the disconnect to
Portal side. This should be done unless this was
called by self.portal_disconnect().
"""
session = self.get(session.sessid)
@ -444,10 +460,11 @@ class ServerSessionHandler(SessionHandler):
session.at_disconnect()
sessid = session.sessid
del self[sessid]
# inform portal that session should be closed.
self.server.amp_protocol.send_AdminServer2Portal(session,
operation=SDISCONN,
reason=reason)
if sync_portal:
# inform portal that session should be closed.
self.server.amp_protocol.send_AdminServer2Portal(session,
operation=SDISCONN,
reason=reason)
def all_sessions_portal_sync(self):
"""