Swap so Server is the AMP-client and Portal the AMP-server
This commit is contained in:
parent
3971a08412
commit
82fd9ff698
3 changed files with 26 additions and 37 deletions
|
|
@ -93,22 +93,22 @@ def get_restart_mode(restart_file):
|
||||||
|
|
||||||
class AmpServerFactory(protocol.ServerFactory):
|
class AmpServerFactory(protocol.ServerFactory):
|
||||||
"""
|
"""
|
||||||
This factory creates the Server as a new AMPProtocol instance for accepting
|
This factory creates AMP Server instance. This
|
||||||
connections from the Portal.
|
is meant to sit on the Evennia Portal service.
|
||||||
"""
|
"""
|
||||||
noisy = False
|
noisy = False
|
||||||
|
|
||||||
def __init__(self, server):
|
def __init__(self, portal):
|
||||||
"""
|
"""
|
||||||
Initialize the factory.
|
Initialize the factory.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
server (Server): The Evennia server service instance.
|
portal (Portal): The Evennia Portal service instance.
|
||||||
protocol (Protocol): The protocol the factory creates
|
protocol (Protocol): The protocol the factory creates
|
||||||
instances of.
|
instances of.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.server = server
|
self.portal = portal
|
||||||
self.protocol = AMPProtocol
|
self.protocol = AMPProtocol
|
||||||
self.broadcasts = []
|
self.broadcasts = []
|
||||||
|
|
||||||
|
|
@ -123,9 +123,9 @@ class AmpServerFactory(protocol.ServerFactory):
|
||||||
protocol (Protocol): The created protocol.
|
protocol (Protocol): The created protocol.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.server.amp_protocol = AMPProtocol()
|
self.portal.amp_protocol = AMPProtocol()
|
||||||
self.server.amp_protocol.factory = self
|
self.portal.amp_protocol.factory = self
|
||||||
return self.server.amp_protocol
|
return self.portal.amp_protocol
|
||||||
|
|
||||||
|
|
||||||
_AMP_TRANSPORTS = []
|
_AMP_TRANSPORTS = []
|
||||||
|
|
@ -133,8 +133,8 @@ _AMP_TRANSPORTS = []
|
||||||
|
|
||||||
class AmpClientFactory(protocol.ReconnectingClientFactory):
|
class AmpClientFactory(protocol.ReconnectingClientFactory):
|
||||||
"""
|
"""
|
||||||
This factory creates an instance of the Portal, an AMPProtocol
|
This factory creates an instance of an AMP client. This
|
||||||
instances to use to connect
|
is intended to be the Evennia 'Server' service.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Initial reconnect delay in seconds.
|
# Initial reconnect delay in seconds.
|
||||||
|
|
@ -143,16 +143,17 @@ class AmpClientFactory(protocol.ReconnectingClientFactory):
|
||||||
maxDelay = 1
|
maxDelay = 1
|
||||||
noisy = False
|
noisy = False
|
||||||
|
|
||||||
def __init__(self, portal):
|
def __init__(self, server):
|
||||||
"""
|
"""
|
||||||
Initializes the client factory.
|
Initializes the client factory.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
portal (Portal): Portal instance.
|
server (server): server instance.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.portal = portal
|
self.server = server
|
||||||
self.protocol = AMPProtocol
|
self.protocol = AMPProtocol
|
||||||
|
self.maxDelay = 10
|
||||||
# not really used unless connecting to multiple servers, but
|
# not really used unless connecting to multiple servers, but
|
||||||
# avoids having to check for its existence on the protocol
|
# avoids having to check for its existence on the protocol
|
||||||
self.broadcasts = []
|
self.broadcasts = []
|
||||||
|
|
@ -177,9 +178,9 @@ class AmpClientFactory(protocol.ReconnectingClientFactory):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.resetDelay()
|
self.resetDelay()
|
||||||
self.portal.amp_protocol = AMPProtocol()
|
self.server.amp_protocol = AMPProtocol()
|
||||||
self.portal.amp_protocol.factory = self
|
self.server.amp_protocol.factory = self
|
||||||
return self.portal.amp_protocol
|
return self.server.amp_protocol
|
||||||
|
|
||||||
def clientConnectionLost(self, connector, reason):
|
def clientConnectionLost(self, connector, reason):
|
||||||
"""
|
"""
|
||||||
|
|
@ -191,13 +192,7 @@ class AmpClientFactory(protocol.ReconnectingClientFactory):
|
||||||
reason (str): Eventual text describing why connection was lost.
|
reason (str): Eventual text describing why connection was lost.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if hasattr(self, "server_restart_mode"):
|
logger.log_info("Server lost connection to the Portal. Reconnecting ...")
|
||||||
self.portal.sessions.announce_all(" Server restarting ...")
|
|
||||||
self.maxDelay = 2
|
|
||||||
else:
|
|
||||||
# Don't translate this; avoid loading django on portal side.
|
|
||||||
self.maxDelay = 10
|
|
||||||
self.portal.sessions.announce_all(" ... Portal lost connection to Server.")
|
|
||||||
protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
|
||||||
|
|
||||||
def clientConnectionFailed(self, connector, reason):
|
def clientConnectionFailed(self, connector, reason):
|
||||||
|
|
@ -210,11 +205,7 @@ class AmpClientFactory(protocol.ReconnectingClientFactory):
|
||||||
reason (str): Eventual text describing why connection failed.
|
reason (str): Eventual text describing why connection failed.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if hasattr(self, "server_restart_mode"):
|
logger.log_info("Attempting to reconnect to Portal ...")
|
||||||
self.maxDelay = 2
|
|
||||||
else:
|
|
||||||
self.maxDelay = 10
|
|
||||||
self.portal.sessions.announce_all(" ...")
|
|
||||||
protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
protocol.ReconnectingClientFactory.clientConnectionFailed(self, connector, reason)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -411,8 +402,6 @@ class AMPProtocol(amp.AMP):
|
||||||
PSYNC,
|
PSYNC,
|
||||||
sessiondata=sessdata)
|
sessiondata=sessdata)
|
||||||
self.factory.portal.sessions.at_server_connection()
|
self.factory.portal.sessions.at_server_connection()
|
||||||
if hasattr(self.factory, "server_restart_mode"):
|
|
||||||
del self.factory.server_restart_mode
|
|
||||||
|
|
||||||
def connectionLost(self, reason):
|
def connectionLost(self, reason):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -191,10 +191,10 @@ if AMP_ENABLED:
|
||||||
|
|
||||||
print(' amp (to Server): %s (internal)' % AMP_PORT)
|
print(' amp (to Server): %s (internal)' % AMP_PORT)
|
||||||
|
|
||||||
factory = amp.AmpClientFactory(PORTAL)
|
factory = amp.AmpServerFactory(PORTAL)
|
||||||
amp_client = internet.TCPClient(AMP_HOST, AMP_PORT, factory)
|
amp_service = internet.TCPServer(AMP_PORT, factory, interface=AMP_INTERFACE)
|
||||||
amp_client.setName('evennia_amp')
|
amp_service.setName("PortalAMPService")
|
||||||
PORTAL.services.addService(amp_client)
|
PORTAL.services.addService(amp_service)
|
||||||
|
|
||||||
|
|
||||||
# We group all the various services under the same twisted app.
|
# We group all the various services under the same twisted app.
|
||||||
|
|
|
||||||
|
|
@ -550,9 +550,9 @@ if AMP_ENABLED:
|
||||||
|
|
||||||
from evennia.server import amp
|
from evennia.server import amp
|
||||||
|
|
||||||
factory = amp.AmpServerFactory(EVENNIA)
|
factory = amp.AmpClientFactory(EVENNIA)
|
||||||
amp_service = internet.TCPServer(AMP_PORT, factory, interface=AMP_INTERFACE)
|
amp_service = internet.TCPClient(AMP_HOST, AMP_PORT, factory)
|
||||||
amp_service.setName("EvenniaPortal")
|
amp_service.setName('ServerAMPClient')
|
||||||
EVENNIA.services.addService(amp_service)
|
EVENNIA.services.addService(amp_service)
|
||||||
|
|
||||||
if WEBSERVER_ENABLED:
|
if WEBSERVER_ENABLED:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue