Added a @reload command to reload most of the modules. This currently only seems to work for the stuff outside of the apps directory, and doesn't include the server, session_mgr, or events modules, as they have variables in them that we can't have reset. So basically, changes to the functions_ and commands_ modules can be applied with @reload, but little else. Hopefully this will improve with time. Also fixed a bug with @name'ing players but not updating their account's username to reflect it.

This commit is contained in:
Greg Taylor 2007-04-30 17:51:55 +00:00
parent 81b1797144
commit 4fd5a20e2c
6 changed files with 50 additions and 11 deletions

View file

@ -176,8 +176,8 @@ class Object(models.Model):
# If it's a player, we need to update their user object as well.
if self.is_player():
pobject = User.objects.get(id=self.id)
pobject.name = new_name
pobject = self.get_user_account()
pobject.username = new_name
pobject.save()
def get_user_account(self):
@ -292,7 +292,7 @@ class Object(models.Model):
uobj.is_active = False
uobj.save()
except:
functions_general.print_errmsg('Destroying object %s but no matching player.' % (self,))
functions_general.log_errmsg('Destroying object %s but no matching player.' % (self,))
# Set the object type to GOING
self.type = 5
@ -439,7 +439,7 @@ class Object(models.Model):
try:
return self.location
except:
functions_general.print_errmsg("Object '%s(#%d)' has invalid location: #%s" % (self.name,self.id,self.location_id))
functions_general.log_errmsg("Object '%s(#%d)' has invalid location: #%s" % (self.name,self.id,self.location_id))
return False
def get_attribute_value(self, attrib, default=False):

View file

@ -3,6 +3,7 @@ import commands_privileged
import commands_general
import commands_unloggedin
import functions_db
import functions_general
"""
This is the command processing module. It is instanced once in the main
@ -57,6 +58,9 @@ def handle(cdat):
parsed_input['root_cmd'] = alias_list.get(parsed_input['root_cmd'],parsed_input['root_cmd'])
if session.logged_in:
# Lets the users get around badly configured NAT timeouts.
if parsed_input['root_cmd'] == 'idle':
return
# If it's prefixed by an '@', it's a staff command.
if parsed_input['root_cmd'][0] != '@':
cmd = getattr(commands_general, 'cmd_%s' % (parsed_input['root_cmd'],), None )
@ -72,7 +76,7 @@ def handle(cdat):
cmd(cdat)
except:
session.msg("Untrapped error, please file a bug report:\n%s" % (format_exc(),))
functions_general.print_errmsg("Untrapped error, evoker %s: %s" %
functions_general.log_errmsg("Untrapped error, evoker %s: %s" %
(session, format_exc()))
return
@ -94,5 +98,5 @@ def handle(cdat):
raise UnknownCommand
except UnknownCommand:
session.msg("Unknown command.")
session.msg("Huh? (Type \"help\" for help.)")

View file

@ -292,7 +292,7 @@ def cmd_who(cdat):
session = cdat['session']
pobject = session.get_pobject()
retval = "Player Name On For Idle Room Cmds Host\n\r"
retval = "Player Name On For Idle Room Cmds Host\n\r"
for player in session_list:
if not player.logged_in:
continue

View file

@ -17,6 +17,13 @@ builder, staff or otherwise manipulative command that doesn't fall within
the scope of normal gameplay.
"""
def cmd_reload(cdat):
"""
Reloads all modules.
"""
session = cdat['session']
server = session.server.reload(session)
def cmd_destroy(cdat):
"""
Destroy an object.

View file

@ -16,13 +16,22 @@ def cmd_check_num_args(session, arg_list, min_args, errortext="Missing arguments
return False
return True
def print_errmsg(errormsg):
def log_errmsg(errormsg):
"""
Prints/logs an error message. Pipe any errors to be logged through here.
For now we're just printing to standard out.
Prints/logs an error message to the server log.
errormsg: (string) The message to be logged.
"""
print 'ERROR: %s' % (errormsg,)
def log_infomsg(infomsg):
"""
Prints any generic debugging/informative info that should appear in the log.
debugmsg: (string) The message to be logged.
"""
print '%s' % (infomsg,)
def command_list():
"""
Return a list of all commands.

View file

@ -5,6 +5,7 @@ from django.db import models
from django.db import connection
from apps.config.models import CommandAlias
import sys
import scheduler
import functions_general
import session_mgr
@ -88,7 +89,25 @@ class Server(dispatcher):
def shutdown(self, message='The server has been shutdown. Please check back soon.'):
functions_general.announce_all(message)
self.game_running = False
def reload(self, session):
"""
Reload modules that don't have any variables that can be reset.
For changes to the scheduler, server, or session_mgr modules, a cold
restart is needed.
"""
reload_list = ['ansi', 'cmdhandler', 'commands_general',
'commands_privileged', 'commands_unloggedin', 'defines_global',
'events', 'functions_db', 'functions_general', 'functions_help',
'gameconf', 'session', 'apps.objects.models',
'apps.helpsys.models', 'apps.config.models']
for mod in reload_list:
reload(sys.modules[mod])
session.msg("Modules reloaded.")
functions_general.log_infomsg("Modules reloaded by %s." % (session,))
"""
END Server CLASS
"""