Add sessionhandler.portal_disconnect_all to remove another needless call between server and portal on logout. This means logout from either side will clean up on the respective side and then inform the other side once, rather than triggering a return call.
This commit is contained in:
parent
8eb500f8e0
commit
86c970eb62
7 changed files with 54 additions and 9 deletions
|
|
@ -8,7 +8,8 @@ from time import time
|
|||
from collections import deque
|
||||
from twisted.internet import reactor
|
||||
from django.conf import settings
|
||||
from evennia.server.sessionhandler import SessionHandler, PCONN, PDISCONN, PCONNSYNC
|
||||
from evennia.server.sessionhandler import SessionHandler, PCONN, PDISCONN, \
|
||||
PCONNSYNC, PDISCONNALL
|
||||
from evennia.utils.logger import log_trace
|
||||
|
||||
# module import
|
||||
|
|
@ -23,6 +24,10 @@ _ERROR_COMMAND_OVERFLOW = settings.COMMAND_RATE_WARNING
|
|||
|
||||
_CONNECTION_QUEUE = deque()
|
||||
|
||||
class DummySession(object):
|
||||
sessid = 0
|
||||
DUMMYSESSION = DummySession()
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Portal-SessionHandler class
|
||||
#------------------------------------------------------------
|
||||
|
|
@ -152,6 +157,10 @@ class PortalSessionHandler(SessionHandler):
|
|||
|
||||
Args:
|
||||
session (PortalSession): Session to disconnect.
|
||||
delete (bool, optional): Delete the session from
|
||||
the handler. Only time to not do this is when
|
||||
this is called from a loop, such as from
|
||||
self.disconnect_all().
|
||||
|
||||
"""
|
||||
global _CONNECTION_QUEUE
|
||||
|
|
@ -161,7 +170,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
_CONNECTION_QUEUE.remove(session)
|
||||
return
|
||||
|
||||
if session.sessid in self:
|
||||
if session.sessid in self and not hasattr(self, "_disconnect_all"):
|
||||
# if this was called directly from the protocol, the
|
||||
# connection is already dead and we just need to cleanup
|
||||
del self[session.sessid]
|
||||
|
|
@ -170,6 +179,23 @@ class PortalSessionHandler(SessionHandler):
|
|||
self.portal.amp_protocol.send_AdminPortal2Server(session,
|
||||
operation=PDISCONN)
|
||||
|
||||
def disconnect_all(self):
|
||||
"""
|
||||
Disconnect all sessions, informing the Server.
|
||||
"""
|
||||
def _callback(result, sessionhandler):
|
||||
# we set a watchdog to stop self.disconnect from deleting
|
||||
# sessions while we are looping over them.
|
||||
sessionhandler._disconnect_all = True
|
||||
for session in sessionhandler.values():
|
||||
session.disconnect(session)
|
||||
del sessionhandler._disconnect_all
|
||||
|
||||
# inform Server; wait until finished sending before we continue
|
||||
# removing all the sessions.
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(DUMMYSESSION,
|
||||
operation=PDISCONNALL).addCallback(_callback, self)
|
||||
|
||||
def server_connect(self, protocol_path="", config=dict()):
|
||||
"""
|
||||
Called by server to force the initialization of a new protocol
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue