Refactoring Server Startup to be more idiomatic for Twisted.
This commit is contained in:
parent
40a4bd0592
commit
15653ef1f1
13 changed files with 1155 additions and 1250 deletions
|
|
@ -11,6 +11,7 @@ from django.conf import settings
|
|||
from django.utils.translation import gettext as _
|
||||
from twisted.internet import reactor
|
||||
|
||||
import evennia
|
||||
from evennia.server.portal.amp import PCONN, PCONNSYNC, PDISCONN, PDISCONNALL
|
||||
from evennia.server.sessionhandler import SessionHandler
|
||||
from evennia.utils.logger import log_trace
|
||||
|
|
@ -62,7 +63,6 @@ class PortalSessionHandler(SessionHandler):
|
|||
|
||||
"""
|
||||
super().__init__(*args, **kwargs)
|
||||
self.portal = None
|
||||
self.latest_sessid = 0
|
||||
self.uptime = time.time()
|
||||
self.connection_time = 0
|
||||
|
|
@ -132,7 +132,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
now = time.time()
|
||||
if (
|
||||
now - self.connection_last < _MIN_TIME_BETWEEN_CONNECTS
|
||||
) or not self.portal.amp_protocol:
|
||||
) or not evennia.EVENNIA_SERVICE.amp_protocol:
|
||||
if not session or not self.connection_task:
|
||||
self.connection_task = reactor.callLater(
|
||||
_MIN_TIME_BETWEEN_CONNECTS, self.connect, None
|
||||
|
|
@ -156,7 +156,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
|
||||
self[session.sessid] = session
|
||||
session.server_connected = True
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(
|
||||
evennia.EVENNIA_SERVICE.amp_protocol.send_AdminPortal2Server(
|
||||
session, operation=PCONN, sessiondata=sessdata
|
||||
)
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
# once to the server - if so we must re-sync woth the server, otherwise
|
||||
# we skip this step.
|
||||
sessdata = session.get_sync_data()
|
||||
if self.portal.amp_protocol:
|
||||
if evennia.EVENNIA_SERVICE.amp_protocol:
|
||||
# we only send sessdata that should not have changed
|
||||
# at the server level at this point
|
||||
sessdata = dict(
|
||||
|
|
@ -192,7 +192,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
"server_data",
|
||||
)
|
||||
)
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(
|
||||
evennia.EVENNIA_SERVICE.amp_protocol.send_AdminPortal2Server(
|
||||
session, operation=PCONNSYNC, sessiondata=sessdata
|
||||
)
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
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)
|
||||
evennia.EVENNIA_SERVICE.amp_protocol.send_AdminPortal2Server(session, operation=PDISCONN)
|
||||
|
||||
def disconnect_all(self):
|
||||
"""
|
||||
|
|
@ -240,7 +240,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
|
||||
# inform Server; wait until finished sending before we continue
|
||||
# removing all the sessions.
|
||||
self.portal.amp_protocol.send_AdminPortal2Server(
|
||||
evennia.EVENNIA_SERVICE.amp_protocol.send_AdminPortal2Server(
|
||||
DUMMYSESSION, operation=PDISCONNALL
|
||||
).addCallback(_callback, self)
|
||||
|
||||
|
|
@ -434,7 +434,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
self.data_out(session, text=[[_ERROR_COMMAND_OVERFLOW], {}])
|
||||
return
|
||||
|
||||
if not self.portal.amp_protocol:
|
||||
if not evennia.EVENNIA_SERVICE.amp_protocol:
|
||||
# this can happen if someone connects before AMP connection
|
||||
# was established (usually on first start)
|
||||
reactor.callLater(1.0, self.data_in, session, **kwargs)
|
||||
|
|
@ -445,7 +445,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
|
||||
# relay data to Server
|
||||
session.cmd_last = now
|
||||
self.portal.amp_protocol.send_MsgPortal2Server(session, **kwargs)
|
||||
evennia.EVENNIA_SERVICE.amp_protocol.send_MsgPortal2Server(session, **kwargs)
|
||||
|
||||
# eventual local echo (text input only)
|
||||
if "text" in kwargs and session.protocol_flags.get("LOCALECHO", False):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue