Add sessionhandler.portal_disconnect which cuts down interaction over AMP by one when a player disconnects.
This commit is contained in:
parent
5a5884f6da
commit
8eb500f8e0
3 changed files with 30 additions and 6 deletions
|
|
@ -493,7 +493,7 @@ class AMPProtocol(amp.AMP):
|
||||||
elif operation == PDISCONN: # portal_session_disconnect
|
elif operation == PDISCONN: # portal_session_disconnect
|
||||||
# session closed from portal side
|
# session closed from portal side
|
||||||
session = server_sessionhandler[sessid]
|
session = server_sessionhandler[sessid]
|
||||||
self.factory.server.sessions.disconnect(session)
|
server_sessionhandler.portal_disconnect(session)
|
||||||
|
|
||||||
elif operation == PSYNC: # portal_session_sync
|
elif operation == PSYNC: # portal_session_sync
|
||||||
# force a resync of sessions when portal reconnects to
|
# force a resync of sessions when portal reconnects to
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,13 @@ class PortalSessionHandler(SessionHandler):
|
||||||
# to forward this to the Server, so now we just remove it.
|
# to forward this to the Server, so now we just remove it.
|
||||||
_CONNECTION_QUEUE.remove(session)
|
_CONNECTION_QUEUE.remove(session)
|
||||||
return
|
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,
|
self.portal.amp_protocol.send_AdminPortal2Server(session,
|
||||||
operation=PDISCONN)
|
operation=PDISCONN)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -329,6 +329,19 @@ class ServerSessionHandler(SessionHandler):
|
||||||
# announce the reconnection
|
# announce the reconnection
|
||||||
self.announce_all(_(" ... Server restarted."))
|
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
|
# server-side access methods
|
||||||
|
|
||||||
def start_bot_session(self, protocol_path, configdict):
|
def start_bot_session(self, protocol_path, configdict):
|
||||||
|
|
@ -420,7 +433,7 @@ class ServerSessionHandler(SessionHandler):
|
||||||
sessiondata={"logged_in": True})
|
sessiondata={"logged_in": True})
|
||||||
player.at_post_login(session=session)
|
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
|
Called from server side to remove session and inform portal
|
||||||
of this fact.
|
of this fact.
|
||||||
|
|
@ -428,6 +441,9 @@ class ServerSessionHandler(SessionHandler):
|
||||||
Args:
|
Args:
|
||||||
session (Session): The Session to disconnect.
|
session (Session): The Session to disconnect.
|
||||||
reason (str, optional): A motivation for the 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)
|
session = self.get(session.sessid)
|
||||||
|
|
@ -444,6 +460,7 @@ class ServerSessionHandler(SessionHandler):
|
||||||
session.at_disconnect()
|
session.at_disconnect()
|
||||||
sessid = session.sessid
|
sessid = session.sessid
|
||||||
del self[sessid]
|
del self[sessid]
|
||||||
|
if sync_portal:
|
||||||
# inform portal that session should be closed.
|
# inform portal that session should be closed.
|
||||||
self.server.amp_protocol.send_AdminServer2Portal(session,
|
self.server.amp_protocol.send_AdminServer2Portal(session,
|
||||||
operation=SDISCONN,
|
operation=SDISCONN,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue