Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
90 lines (75 sloc) 3.2 KB
This module drives the proxy that sits in front of the MUD server. The proxy
is the only one of the two that handles Telnet connections from players.
It uses an auto-reconnect internet.TCPClient to speak to the MUD server
through the Twisted AMP protocol (a two-way async protocol).
The benefits are twofold:
* Telnet handling is solely the domain of the proxy, and the actual MUD server
itself is free to worry about more important things. Like the game.
* The MUD can restart without interrupting player connections. As a result of
this, we don't need to implement any crazy code reloading junk. We can
just cold restart without many players even noticing.
import time
from twisted.application import internet, service
from twisted.internet import reactor
import settings
from src.proxy.protocols.telnet import MudTelnetServerFactory
from src.proxy.sessions.session_manager import SessionManager
from src.proxy.accounts.in_memory_store import InMemoryAccountStore
from src.server.protocols.proxyamp import AmpClientFactory
class ProxyService(service.Service):
This is the main Service class that ties the proxy together. It listens
for telnet connections and maintains a client connection to the MUD
server over AMP.
def __init__(self):
:attr ProxyAMP proxyamp: The currently active ProxyAMP instance.
This can be used to communicate with the MUD server through.
self.session_manager = SessionManager(self)
self.account_store = InMemoryAccountStore(self)
self.proxyamp = None
self.start_time = time.time()
def start_services(self, app_to_start):
Starts all of the TCP services.
self.service_collection = service.IServiceCollection(app_to_start)
telnet_factory = MudTelnetServerFactory(self)
print('\n' + '-' * 50)
print(' Starting %s proxy server' % settings.GAME_NAME)
print(' Version: %s' % settings.VERSION)
print(' Listening for telnet connections on ports:')
for port in settings.PROXY_LISTEN_PORTS:
telnet_server = internet.TCPServer(port, telnet_factory)
telnet_server.setName('dott_telnet_%s' % port)
print(' * %s' % port)
amp_client = internet.TCPClient(
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.
:rtype: boo
:returns: ``True`` if the proxy has established a connection to the
MUD server over AMP. ``False`` if not.
return self.proxyamp.transport is not None
# Putting it all together.
application = service.Application('dott_proxy')
mud_service = ProxyService()
Something went wrong with that request. Please try again.