Started removing the global maintenance scripts, but ran into strange AMP issues.
This commit is contained in:
parent
17400ede6b
commit
71e9038c62
7 changed files with 112 additions and 195 deletions
|
|
@ -8,11 +8,13 @@ by game/evennia.py).
|
|||
|
||||
"""
|
||||
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
|
||||
from twisted.application import internet, service
|
||||
from twisted.internet import protocol, reactor
|
||||
from twisted.internet.task import LoopingCall
|
||||
from twisted.web import server
|
||||
import django
|
||||
django.setup()
|
||||
|
|
@ -67,6 +69,28 @@ AMP_INTERFACE = settings.AMP_INTERFACE
|
|||
AMP_ENABLED = AMP_HOST and AMP_PORT and AMP_INTERFACE
|
||||
|
||||
|
||||
# Maintenance function - this is called repeatedly by the portal.
|
||||
|
||||
_IDLE_TIMEOUT = settings.IDLE_TIMEOUT
|
||||
def _portal_maintenance():
|
||||
"""
|
||||
The maintenance function handles repeated checks and updates
|
||||
that the server needs to do. It is called every minute.
|
||||
"""
|
||||
# check for idle sessions
|
||||
now = time.time()
|
||||
|
||||
reason = "Idle timeout exceeded, disconnecting."
|
||||
for session in [sess for sess in PORTAL_SESSIONS.sessions.values()
|
||||
if (now - sess.cmd_last) > _IDLE_TIMEOUT]:
|
||||
session.data_out(reason)
|
||||
PORTAL_SESSIONS.disconnect(session)
|
||||
if _IDLE_TIMEOUT > 0:
|
||||
# only start the maintenance task if we care about idling.
|
||||
_maintenance_task = LoopingCall(_portal_maintenance)
|
||||
_maintenance_task.start(60) # called every minute
|
||||
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Portal Service object
|
||||
#------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -295,6 +295,7 @@ class PortalSessionHandler(SessionHandler):
|
|||
serialized before passed on.
|
||||
|
||||
"""
|
||||
self.cmd_last = time()
|
||||
self.portal.amp_protocol.call_remote_MsgPortal2Server(session.sessid,
|
||||
msg=text,
|
||||
data=kwargs)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ sessions etc.
|
|||
"""
|
||||
|
||||
import re
|
||||
from twisted.internet.task import LoopingCall
|
||||
from twisted.conch.telnet import Telnet, StatefulTelnetProtocol, IAC, LINEMODE, GA, WILL, WONT, ECHO
|
||||
from evennia.server.session import Session
|
||||
from evennia.server.portal import ttype, mssp, telnet_oob, naws
|
||||
|
|
@ -15,6 +16,8 @@ from evennia.server.portal.mccp import Mccp, mccp_compress, MCCP
|
|||
from evennia.server.portal.mxp import Mxp, mxp_parse
|
||||
from evennia.utils import utils, ansi, logger
|
||||
|
||||
NOP = chr(241)
|
||||
|
||||
_RE_N = re.compile(r"\{n$")
|
||||
_RE_LEND = re.compile(r"\n$|\r$", re.MULTILINE)
|
||||
|
||||
|
|
@ -60,6 +63,11 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
from evennia.utils.utils import delay
|
||||
delay(2, callback=self.handshake_done, retval=True)
|
||||
|
||||
# set up a keep-alive
|
||||
self.keep_alive = LoopingCall(self._write, NOP)
|
||||
self.keep_alive.start(30)
|
||||
|
||||
|
||||
def handshake_done(self, force=False):
|
||||
"""
|
||||
This is called by all telnet extensions once they are finished.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue