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

@ -493,7 +493,7 @@ class AMPProtocol(amp.AMP):
elif operation == PDISCONN: # portal_session_disconnect
# session closed from portal side
session = server_sessionhandler[sessid]
self.factory.server.sessions.disconnect(session)
server_sessionhandler.portal_disconnect(session)
elif operation == PSYNC: # portal_session_sync
# force a resync of sessions when portal reconnects to

View file

@ -160,6 +160,13 @@ class PortalSessionHandler(SessionHandler):
# to forward this to the Server, so now we just remove it.
_CONNECTION_QUEUE.remove(session)
return
if session.sessid in self:
# if this was called directly from the protocol, the
# connection is already dead and we just need to cleanup
del self[session.sessid]
# Tell the Server to disconnect its version of the Session as well.
self.portal.amp_protocol.send_AdminPortal2Server(session,
operation=PDISCONN)

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):
"""