Support in-game server-control commands

This commit is contained in:
Griatch 2018-01-14 23:11:59 +01:00
parent 5656b841d6
commit aa7b57e92f
5 changed files with 20 additions and 18 deletions

View file

@ -119,7 +119,6 @@ class CmdShutdown(COMMAND_DEFAULT_CLASS):
announcement += "%s\n" % self.args
logger.log_info('Server shutdown by %s.' % self.caller.name)
SESSIONS.announce_all(announcement)
SESSIONS.server.shutdown(mode='shutdown')
SESSIONS.portal_shutdown()

View file

@ -71,7 +71,7 @@ class AMPClientFactory(protocol.ReconnectingClientFactory):
reason (str): Eventual text describing why connection was lost.
"""
logger.log_info("Server lost connection to the Portal. Reconnecting ...")
logger.log_info("Server disconnected from the portal.")
protocol.ReconnectingClientFactory.clientConnectionLost(self, connector, reason)
def clientConnectionFailed(self, connector, reason):

View file

@ -72,6 +72,19 @@ class AMPServerProtocol(amp.AMPMultiConnectionProtocol):
Protocol subclass for the AMP-server run by the Portal.
"""
def connectionLost(self, reason):
"""
Set up a simple callback mechanism to let the amp-server wait for a connection to close.
"""
callback, args, kwargs = self.factory.disconnect_callbacks.pop(self, (None, None, None))
if callback:
try:
callback(*args, **kwargs)
except Exception:
logger.log_trace()
def start_server(self, server_twistd_cmd):
"""
(Re-)Launch the Evennia server.
@ -98,18 +111,6 @@ class AMPServerProtocol(amp.AMPMultiConnectionProtocol):
self.factory.portal.server_twistd_cmd = server_twistd_cmd
return process.pid
def connectionLost(self, reason):
"""
Set up a simple callback mechanism to let the amp-server wait for a connection to close.
"""
callback, args, kwargs = self.factory.disconnect_callbacks.pop(self, (None, None, None))
if callback:
try:
callback(*args, **kwargs)
except Exception:
logger.log_trace()
def wait_for_disconnect(self, callback, *args, **kwargs):
"""
Add a callback for when this connection is lost.
@ -319,20 +320,21 @@ class AMPServerProtocol(amp.AMPMultiConnectionProtocol):
elif operation == amp.SRELOAD: # server reload
self.factory.server_connection.wait_for_disconnect(
self.start_server, self.factory.portal.server_twisted_cmd)
self.start_server, self.factory.portal.server_twistd_cmd)
self.stop_server(mode='reload')
elif operation == amp.SRESET: # server reset
self.factory.server_connection.wait_for_disconnect(
self.start_server, self.factory.portal.server_twisted_cmd)
self.start_server, self.factory.portal.server_twistd_cmd)
self.stop_server(mode='reset')
elif operation == amp.SSHUTD: # server-only shutdown
self.stop_server(mode='shutdown')
elif operation == amp.PSHUTD: # full server+server shutdown
self.factory.server_connection.wait_for_disconnect(
self.factory.portal.shutdown, restart=False)
self.stop_server(mode='shutdown')
self.factory.portal.shutdown()
elif operation == amp.PSYNC: # portal sync
# Server has (re-)connected and wants the session data from portal

View file

@ -148,6 +148,7 @@ class Portal(object):
case it always needs to be restarted manually.
"""
print("portal.shutdown: restart=", restart)
if _reactor_stopping and hasattr(self, "shutdown_complete"):
# we get here due to us calling reactor.stop below. No need
# to do the shutdown procedure again.

View file

@ -459,7 +459,7 @@ class ServerSessionHandler(SessionHandler):
"""
self.server.amp_protocol.send_AdminServer2Portal(DUMMYSESSION,
operation=SSHUTD)
operation=PSHUTD)
def login(self, session, account, force=False, testmode=False):
"""