* Implemented a non-persistent cache in src/cache.py. The cache is lost when restarting the server but it has the advantage of not hitting the database, and so is useful for implementing things that should be remembered over time but does not need to be persistently saved in the database at every point, like fast-updating combat systems, timers etc. Using the cache can substantially cut down on database access at the cost of memory comsumption. It is easiest accessed through the object model using normal dot notation. So to store a variable in volatile memory e.g. from your script parent, you can do things like self.scripted_obj.cache.myvariable = variable and be sure that later (unless there was a reboot) doing self.scripted_obj.cache.myvariable will return the value you stored there.

* OBS - doing e.g. self.scripted_obj.myvariable = variable was always iffy and since a few revisions back this will NOT work - this is because the objects are now consistently synced with the database (in the past this was not done consistently which caused strange behaviour).
* Fixed some bugs in the multi-word command handler. It can handle multi-word exits as well now.
This commit is contained in:
Griatch 2009-11-01 15:12:38 +00:00
parent af19724bb2
commit 642932a403
9 changed files with 177 additions and 58 deletions

View file

@ -136,7 +136,7 @@ def parse_batchbuild_file(filename):
else: #comment
if curr_cmd:
commands.append(curr_cmd.strip())
curr_cmd = ""
curr_cmd = ""
if curr_cmd: commands.append(curr_cmd.strip())
#second round to clean up now merged line edges etc.
@ -145,7 +145,6 @@ def parse_batchbuild_file(filename):
#remove eventual newline at the end of commands
commands = [c.strip('\r\n') for c in commands]
return commands
def batch_process(source_object, commands):
@ -202,7 +201,6 @@ def cmd_batchprocess(command):
if not source_object.set_state(STATENAME):
source_object.emit_to("You cannot use the interactive mode while you have the flag ADMIN_NOSTATE set.")
return
CMDSTACKS[source_object] = commands
STACKPTRS[source_object] = 0
FILENAMES[source_object] = filename
@ -263,10 +261,10 @@ def process_commands(source_object, steps=0):
for cmd in cmds:
#this so it is kept in case of traceback
STACKPTRS[source_object] = ptr + 1
show_curr(source_object)
#show_curr(source_object)
source_object.execute_cmd(cmd)
else:
show_curr(source_object)
#show_curr(source_object)
source_object.execute_cmd(commands[ptr])
def reload_stack(source_object):
@ -298,7 +296,7 @@ def exit_state(source_object):
# (to avoid accidental drop-outs by rooms clearing a player's state),
# we have to clear the state directly here.
source_object.state = None
def cmd_state_ll(command):
"""
ll

View file

@ -44,14 +44,15 @@ def cmd_teleport(command):
# a direct teleport, @tel <destination>.
if len(eq_args) > 1:
# Equal sign teleport.
victim = source_object.search_for_object(eq_args[0])
victim = source_object.search_for_object(eq_args[0].strip())
# Use search_for_object to handle duplicate/nonexistant results.
if not victim:
return
if victim.is_room():
source_object.emit_to("You can't teleport a room.")
return
destination = source_object.search_for_object_global(eq_args[1],exact_match=True,
destination = source_object.search_for_object_global(eq_args[1].strip(),
exact_match=True,
limit_types=[defines_global.OTYPE_THING,
defines_global.OTYPE_ROOM])
if not destination:
@ -63,7 +64,7 @@ def cmd_teleport(command):
victim.move_to(destination, quiet=tel_quietly)
else:
# Direct teleport (no equal sign)
target_obj = source_object.search_for_object_global(eq_args[0],exact_match=True,
target_obj = source_object.search_for_object_global(eq_args[0].strip(),exact_match=True,
limit_types=[defines_global.OTYPE_THING,
defines_global.OTYPE_ROOM])
# Use search_for_object to handle duplicate/nonexistant results.
@ -997,7 +998,10 @@ def cmd_dig(command):
arg_list = args.split("=",1)
if len(arg_list) < 2:
#just create a room, no exits
room_name = arg_list[0].strip()
try:
room_name, room_parent = [s.strip() for s in arg_list[0].split(":",1)]
except ValueError:
room_name = arg_list[0].strip()
else:
#deal with args left of =
larg = arg_list[0]
@ -1596,7 +1600,10 @@ def cmd_examine(command):
locks = target_obj.get_attribute_value("LOCKS")
if locks and "%s" % locks:
string += str("Locks: %s" % locks) + newl
state = target_obj.get_state()
if state:
string += str("State: %s" % state) + newl
# Contents container lists for sorting by type.
con_players = []
con_things = []

View file

@ -14,7 +14,7 @@ from src.helpsys.models import HelpEntry
from src.helpsys import helpsystem
from src.config.models import CommandAlias
from src.config import edit_aliases
from src import cache
def cmd_reload(command):
"""
@reload - reload game subsystems
@ -26,30 +26,41 @@ def cmd_reload(command):
aliases - alias definitions
commands - the command modules
scripts, parents - the script parent modules
all
all - reload all of the above
Reloads all the identified subsystems.
cache - flush the volatile cache (warning, this
might cause unexpected results if your
script parents use the cache a lot)
reset - flush cache then reload all
Reloads all the identified subsystems. Flushing the cache is
generally not needed outside the main game development.
"""
source_object = command.source_object
switches = command.command_switches
if not switches or switches[0] not in ['all','aliases','alias',
'commands','command',
'scripts','parents']:
'scripts','parents',
'cache','reset']:
source_object.emit_to("Usage: @reload/<aliases|scripts|commands|all>")
return
switch = switches[0]
sname = source_object.get_name(show_dbref=False)
if switch in ["all","aliases","alias"]:
#reload Aliases
if switch in ["reset", "cache"]:
# Clear the volatile cache
cache.flush()
comsys.cemit_mudinfo("%s flushed the non-persistent cache." % sname)
if switch in ["reset","all","aliases","alias"]:
# Reload Aliases
command.session.server.reload_aliases(source_object=source_object)
comsys.cemit_mudinfo("%s reloaded Aliases." % sname)
if switch in ["all","scripts","parents"]:
#reload Script parents
if switch in ["reset","all","scripts","parents"]:
# Reload Script parents
rebuild_cache()
comsys.cemit_mudinfo("%s reloaded Script parents." % sname)
if switch in ["all","commands","command"]:
#reload command objects.
if switch in ["reset","all","commands","command"]:
# Reload command objects.
comsys.cemit_mudinfo("%s is reloading Command modules ..." % sname)
command.session.server.reload(source_object=command.source_object)
comsys.cemit_mudinfo("... all Command modules were reloaded.")