diff --git a/evennia/server/amp.py b/evennia/server/amp.py index df87df58cb..948ec3fc65 100644 --- a/evennia/server/amp.py +++ b/evennia/server/amp.py @@ -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 diff --git a/evennia/server/portal/portalsessionhandler.py b/evennia/server/portal/portalsessionhandler.py index eabf5f0e48..a5f85d4e4e 100644 --- a/evennia/server/portal/portalsessionhandler.py +++ b/evennia/server/portal/portalsessionhandler.py @@ -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) diff --git a/evennia/server/sessionhandler.py b/evennia/server/sessionhandler.py index bda2ab7d9a..0651d4f9c5 100644 --- a/evennia/server/sessionhandler.py +++ b/evennia/server/sessionhandler.py @@ -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): """