Skip to content
Browse files

Allow restarting the proxy server.

  • Loading branch information...
1 parent 973925d commit 06c0d011602f2375862cf3c0e5d6fab12700e6b6 @gtaylor committed Nov 2, 2011
Showing with 50 additions and 4 deletions.
  1. +7 −0 proxy.tac
  2. +21 −4 src/game/commands/staff.py
  3. +22 −0 src/server/protocols/proxyamp.py
View
7 proxy.tac
@@ -14,6 +14,7 @@ The benefits are twofold:
import time
from twisted.application import internet, service
+from twisted.internet import reactor
import settings
from src.proxy.protocols.telnet import MudTelnetServerFactory
@@ -66,6 +67,12 @@ class ProxyService(service.Service):
amp_client.setName('dott_amp')
amp_client.setServiceParent(self.service_collection)
+ def shutdown(self):
+ """
+ Gracefully shuts down the service.
+ """
+ reactor.callLater(0, reactor.stop)
+
def is_connected_to_mud_server(self):
"""
Determines whether the proxy has connected to the MUD server.
View
25 src/game/commands/staff.py
@@ -1,26 +1,43 @@
"""
Staff commands.
"""
-from src.game.parents.base_objects.exit import ExitObject
-from src.game.parents.base_objects.room import RoomObject
+from src.server.protocols.proxyamp import ShutdownProxyCmd
from src.server.commands.command import BaseCommand
from src.server.commands.exceptions import CommandError
from src.server.objects.exceptions import InvalidObjectId
from src.server.parent_loader.exceptions import InvalidParent
+from src.game.parents.base_objects.exit import ExitObject
+from src.game.parents.base_objects.room import RoomObject
class CmdRestart(BaseCommand):
"""
Shuts the MUD server down silently. Supervisor restarts it after noticing
the exit, and most users will never notice since the proxy maintains
their connections.
+
+ To restart the MUD server::
+
+ @restart
+ -or-
+ @restart mud
+
+ To restart the proxy server::
+
+ @restart proxy
"""
name = '@restart'
#noinspection PyUnusedLocal
def func(self, invoker, parsed_cmd):
- invoker.emit_to("Restarting...")
mud_service = invoker._mud_service
- mud_service.shutdown()
+
+ if not parsed_cmd.arguments or 'mud' in parsed_cmd.arguments:
+ invoker.emit_to("Restarting MUD server...")
+ mud_service.shutdown()
+
+ if 'proxy' in parsed_cmd.arguments:
+ invoker.emit_to("Restarting proxy server...")
+ mud_service.proxyamp.callRemote(ShutdownProxyCmd)
class CmdFind(BaseCommand):
View
22 src/server/protocols/proxyamp.py
@@ -104,6 +104,14 @@ def clientConnectionFailed(self, connector, reason):
## MUD Server to Proxy commands.
#
+class ShutdownProxyCmd(amp.Command):
+ """
+ Used for letting the MUD server shutdown the proxy.
+ """
+ arguments = []
+ response = []
+
+
class DisconnectSessionsOnObjectCmd(amp.Command):
"""
AMP command for disconnecting all sessions that control the specified
@@ -243,6 +251,20 @@ def connectionLost(self, reason):
## MUD Server to Proxy commands.
#
+ def shutdown_proxy_command(self):
+ """
+ Allows the MUD server to shutdown the proxy.
+ """
+ # The root ProxyService instance.
+ service = self.factory._proxy_service
+ # Shutdown the proxy.
+ service.shutdown()
+
+ return {}
+ ShutdownProxyCmd.responder(
+ shutdown_proxy_command
+ )
+
def emit_to_object_command(self, object_id, message):
"""
Pipe output to a player connected on the proxy, who controls the

0 comments on commit 06c0d01

Please sign in to comment.
Something went wrong with that request. Please try again.