mirror of
https://github.com/evennia/evennia.git
synced 2026-04-18 06:09:06 +02:00
We now have the ability via @service to list, start, and stop Twisted services. In this case, this just lets us start/stop IMC2 right now. As people write more services to plug in in the future, this may expand.
@service/list will show you the service names. If you see that your IMC has died due to an error, @service/start IMC2 will get it up and running again. I've also added an 'imcstatus' command to show more detailed information about your IMC2 connection.
This commit is contained in:
parent
b63bcc6132
commit
566a02b848
3 changed files with 112 additions and 28 deletions
|
|
@ -79,15 +79,31 @@ def cmd_imclist(command):
|
|||
source_object.emit_to(retval)
|
||||
GLOBAL_CMD_TABLE.add_command("imclist", cmd_imclist)
|
||||
|
||||
def cmd_imclistupdated(command):
|
||||
def cmd_imcstatus(command):
|
||||
"""
|
||||
Shows the list of cached games from the IMC2 Mud list.
|
||||
Shows some status information for your IMC2 connection.
|
||||
"""
|
||||
source_object = command.source_object
|
||||
# This manages our game's plugged in services.
|
||||
collection = command.session.server.service_collection
|
||||
# Retrieve the IMC2 service.
|
||||
service = collection.getServiceNamed('IMC2')
|
||||
|
||||
if service.running == 1:
|
||||
status_string = 'Running'
|
||||
else:
|
||||
status_string = 'Inactive'
|
||||
|
||||
# Build the output to emit to the player.
|
||||
retval = '-' * 50
|
||||
retval += '\n\r'
|
||||
retval += 'IMC Status\n\r'
|
||||
retval += ' * MUD Name: %s\n\r' % (settings.IMC2_MUDNAME)
|
||||
retval += ' * Status: %s\n\r' % (status_string)
|
||||
retval += ' * Debugging Mode: %s\n\r' % (settings.IMC2_DEBUG)
|
||||
retval += ' * IMC Network Address: %s\n\r' % (settings.IMC2_SERVER_ADDRESS)
|
||||
retval += ' * IMC Network Port: %s\n\r' % (settings.IMC2_SERVER_PORT)
|
||||
retval += '-' * 50
|
||||
|
||||
retval = 'Active MUDs on %s\n\r' % imc2_conn.IMC2_PROTOCOL_INSTANCE.network_name
|
||||
for name, mudinfo in IMC2_MUDLIST.mud_list.items():
|
||||
tdelta = time() - mudinfo.last_updated
|
||||
retval += ' %-20s %s\n\r' % (name, tdelta)
|
||||
source_object.emit_to(retval)
|
||||
GLOBAL_CMD_TABLE.add_command("imclistupdated", cmd_imclistupdated)
|
||||
GLOBAL_CMD_TABLE.add_command("imcstatus", cmd_imcstatus)
|
||||
|
|
@ -171,6 +171,71 @@ def cmd_home(command):
|
|||
GLOBAL_CMD_TABLE.add_command("home", cmd_home,
|
||||
priv_tuple=("genperms.tel_anywhere"))
|
||||
|
||||
def cmd_service(command):
|
||||
"""
|
||||
Service management system. Allows for the listing, starting, and stopping
|
||||
of services.
|
||||
"""
|
||||
pobject = command.source_object
|
||||
if "list" in command.command_switches:
|
||||
"""
|
||||
Just display the list of installed services and their status and die.
|
||||
"""
|
||||
pobject.emit_to('-' * 40)
|
||||
pobject.emit_to('Service Listing')
|
||||
for service in command.session.server.service_collection.services:
|
||||
# running is either 1 or 0, 1 meaning the service is running.
|
||||
if service.running == 1:
|
||||
status = 'Running'
|
||||
else:
|
||||
status = 'Inactive'
|
||||
pobject.emit_to(' * %s (%s)' % (service.name, status))
|
||||
pobject.emit_to('-' * 40)
|
||||
return
|
||||
|
||||
# This stuff is common to both start and stop switches.
|
||||
if "stop" in command.command_switches or "start" in command.command_switches:
|
||||
collection = command.session.server.service_collection
|
||||
try:
|
||||
service = collection.getServiceNamed(command.command_argument)
|
||||
except:
|
||||
pobject.emit_to('Invalid service name. This command is case-sensitive. See @service/list.')
|
||||
return
|
||||
|
||||
if "stop" in command.command_switches:
|
||||
"""
|
||||
Stopping a service gracefully closes it and disconnects any connections
|
||||
(if applicable).
|
||||
"""
|
||||
if service.running == 0:
|
||||
pobject.emit_to('That service is not currently running.')
|
||||
return
|
||||
# We don't want them killing main Evennia TCPServer services here. If
|
||||
# they'd like to nix a listening port, they need to do it through
|
||||
# settings.py and a restart.
|
||||
if service.name[:7] == 'Evennia':
|
||||
pobject.emit_to('You can not Evennia TCPServer services this way.')
|
||||
return
|
||||
pobject.emit_to('Stopping the %s service.' % service.name)
|
||||
service.stopService()
|
||||
return
|
||||
|
||||
if "start" in command.command_switches:
|
||||
"""
|
||||
Starts a service.
|
||||
"""
|
||||
if service.running == 1:
|
||||
pobject.emit_to('That service is already running.')
|
||||
return
|
||||
pobject.emit_to('Starting the %s service.' % service.name)
|
||||
service.startService()
|
||||
return
|
||||
|
||||
# If they don't provide any switches, let them know to do so.
|
||||
pobject.emit_to("You must specify a switch with @service. May be one of: list, start, stop")
|
||||
GLOBAL_CMD_TABLE.add_command("@service", cmd_service,
|
||||
priv_tuple=("genperms.process_control"))
|
||||
|
||||
def cmd_shutdown(command):
|
||||
"""
|
||||
Shut the server down gracefully.
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ from src.util import functions_general
|
|||
|
||||
class EvenniaService(service.Service):
|
||||
def __init__(self):
|
||||
# Holds the TCP services.
|
||||
self.service_collection = None
|
||||
self.game_running = True
|
||||
sys.path.append('.')
|
||||
|
||||
|
|
@ -130,27 +132,28 @@ class EvenniaService(service.Service):
|
|||
f.server = self
|
||||
return f
|
||||
|
||||
"""
|
||||
END Server CLASS
|
||||
"""
|
||||
|
||||
def start_services(self, application):
|
||||
"""
|
||||
Starts all of the TCP services.
|
||||
"""
|
||||
self.service_collection = service.IServiceCollection(application)
|
||||
for port in settings.GAMEPORTS:
|
||||
evennia_server = internet.TCPServer(port, self.getEvenniaServiceFactory())
|
||||
evennia_server.setName('Evennia%s' %port)
|
||||
evennia_server.setServiceParent(self.service_collection)
|
||||
|
||||
if settings.IMC2_ENABLED:
|
||||
from src.imc2.connection import IMC2ClientFactory
|
||||
from src.imc2 import events as imc2_events
|
||||
imc2_factory = IMC2ClientFactory()
|
||||
svc = internet.TCPClient(settings.IMC2_SERVER_ADDRESS,
|
||||
settings.IMC2_SERVER_PORT,
|
||||
imc2_factory)
|
||||
svc.setName('IMC2')
|
||||
svc.setServiceParent(self.service_collection)
|
||||
imc2_events.add_events()
|
||||
|
||||
application = service.Application('Evennia')
|
||||
mud_service = EvenniaService()
|
||||
|
||||
# Sheet sheet, fire ze missiles!
|
||||
serviceCollection = service.IServiceCollection(application)
|
||||
for port in settings.GAMEPORTS:
|
||||
internet.TCPServer(port,
|
||||
mud_service.getEvenniaServiceFactory()).setServiceParent(serviceCollection)
|
||||
|
||||
|
||||
if settings.IMC2_ENABLED:
|
||||
from src.imc2.connection import IMC2ClientFactory
|
||||
from src.imc2 import events as imc2_events
|
||||
imc2_factory = IMC2ClientFactory()
|
||||
svc = internet.TCPClient(settings.IMC2_SERVER_ADDRESS,
|
||||
settings.IMC2_SERVER_PORT,
|
||||
imc2_factory)
|
||||
svc.setName('IMC2')
|
||||
svc.setServiceParent(serviceCollection)
|
||||
imc2_events.add_events()
|
||||
mud_service.start_services(application)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue