Mixed batch of minor bug fixes and cleanups.

This commit is contained in:
Griatch 2011-04-30 21:09:19 +00:00
parent 9520e261d8
commit 4bcd5239b5
8 changed files with 40 additions and 39 deletions

View file

@ -104,7 +104,7 @@ class Command(BaseCommand):
used by Evennia to create the automatic help entry for
the command, so make sure to document consistently here.
"""
def access(self, srcobj):
def access(self, srcobj, access_type="cmd", default=False):
"""
This is called by the cmdhandler to determine
if srcobj is allowed to execute this command. This
@ -113,7 +113,7 @@ class Command(BaseCommand):
By default, We use checks of the 'cmd' type of lock to determine
if the command should be run.
"""
return super(Command, self).access(srcobj)
return super(Command, self).access(srcobj, access_type=access_type, default=default)
def at_pre_cmd(self):
"""

View file

@ -120,13 +120,12 @@ def get_and_merge_cmdsets(caller):
local_objects_cmdsets = [obj.cmdset.current
for obj in local_objlist
if obj.locks.check(caller, 'call', no_superuser_bypass=True)]
# Merge all command sets into one
# (the order matters, the higher-prio cmdsets are merged last)
cmdset = caller_cmdset
for obj_cmdset in [obj_cmdset for obj_cmdset in local_objects_cmdsets if obj_cmdset]:
# Here only, object cmdsets are merged with duplicates=True
# (or we would never be able to differentiate between objects)
# (or we would never be able to differentiate between same-prio objects)
try:
old_duplicate_flag = obj_cmdset.duplicates
obj_cmdset.duplicates = True
@ -306,7 +305,7 @@ def cmdhandler(caller, raw_string, unloggedin=False, testing=False):
raise ExecSystemCommand(syscmd, sysarg)
# Parse the input string into command candidates
cmd_candidates = COMMAND_PARSER(raw_string)
cmd_candidates = COMMAND_PARSER(raw_string)
#string ="Command candidates"
#for cand in cmd_candidates:

View file

@ -131,10 +131,9 @@ class CmdSet(object):
priority- All cmdsets are always merged in pairs of two so that
the higher set's mergetype is applied to the
lower-priority cmdset. Evennia uses priorities from 0-10
where 10 are used for high-priority things like comsys
channel names and 9 for exit names in order to give
these priority when the given command matches.
lower-priority cmdset. Default commands have priority 0,
high-priority ones like Exits and Channels have 10 and 9. Priorities
can be negative as well to give default commands preference.
duplicates - determines what happens when two sets of equal
priority merge. Default has the first of them in the

View file

@ -1018,6 +1018,8 @@ class CmdOpen(ObjManipCommand):
else:
# exit does not exist before. Create a new one.
if not typeclass:
typeclass = settings.BASE_EXIT_TYPECLASS
exit_obj = create.create_object(typeclass, key=exit_name,
location=location,
aliases=exit_aliases)

View file

@ -11,6 +11,7 @@ class DefaultCmdSet(CmdSet):
Implements the default command set.
"""
key = "DefaultMUX"
priority = 0
def at_cmdset_creation(self):
"Populates the cmdset"

View file

@ -76,7 +76,7 @@ class ExitHandler(object):
exit_cmdset.priority = 9
exit_cmdset.duplicates = True
try:
location = srcobj.location
location = srcobj.location
except Exception:
location = None
if not location:
@ -84,8 +84,7 @@ class ExitHandler(object):
return exit_cmdset
# use exits to create searchable "commands" for the cmdhandler
for exi in (exi for exi in location.contents
if exi.destination):
for exi in location.exits:
if exi.id in self.cached_exit_cmds:
# retrieve from cache
exit_cmdset.add(self.cached_exit_cmds[exi.id])

View file

@ -16,6 +16,7 @@ they control by simply linking to a new object's user property.
"""
from src.typeclasses.typeclass import TypeClass
from src.commands import cmdset, command
from src.objects.exithandler import EXITHANDLER
@ -347,7 +348,7 @@ class Character(Object):
"""
super(Character, self).basetype_setup()
self.locks.add("get:false()") # noone can pick up the character
self.locks.add("call:false()") # no commands can be called on character
self.locks.add("call:false()") # no commands can be called on character from outside
# add the default cmdset
from settings import CMDSET_DEFAULT
@ -393,6 +394,11 @@ class Room(Object):
super(Room, self).basetype_setup()
self.location = None
#
# Exits
#
class Exit(Object):
"""
This is the base exit object - it connects a location
@ -414,23 +420,14 @@ class Exit(Object):
"""
# the lock is open to all by default
super(Exit, self).basetype_setup()
self.locks.add("puppet:false()") # would be weird to puppet an exit ...
self.locks.add("traverse:all()") # who can pass through exit
self.locks.add("traverse:all()") # who can pass through exit by default
self.locks.add("get:false()") # noone can pick up the exit
def at_object_creation(self):
"""
An example just for show; the destination property
is usually set at creation time, not as part of the class
definition (unless you want an entire class of exits
all leadning to the same hard-coded place ...)
"""
# having destination != None is what makes it an exit
# (what's set here won't last)
if self.location:
self.destination = self.location
else:
self.destination = 2 # use limbo as a failsafe
# an exit should have a destination (this is replaced at creation time)
if self.dbobj.location:
self.destination = self.dbobj.location
def at_object_delete(self):
"""

View file

@ -32,6 +32,7 @@ from django.conf import settings
from django.utils.encoding import smart_str
from django.contrib.contenttypes.models import ContentType
from src.utils.idmapper.models import SharedMemoryModel
from src.server.models import ServerConfig
from src.typeclasses import managers
from src.locks.lockhandler import LockHandler
from src.utils import logger, utils
@ -617,21 +618,24 @@ class TypedObject(SharedMemoryModel):
Helper function to display error.
"""
infochan = None
cmessage = message
try:
from src.comms.models import Channel
infochan = settings.CHANNEL_MUDINFO
infochan = Channel.objects.get_channel(infochan[0])
except Exception, e:
print e
pass
if infochan:
cname = infochan.key
cmessage = "\n".join(["[%s]: %s" % (cname, line) for line in message.split('\n')])
infochan.msg(message)
else:
# no mudinfo channel is found. Log instead.
cmessage = "\n".join(["[NO MUDINFO CHANNEL]: %s" % line for line in message.split('\n')])
logger.log_errmsg(cmessage)
infochan = Channel.objects.get_channel(infochan[0])
if infochan:
cname = infochan.key
cmessage = "\n".join(["[%s]: %s" % (cname, line) for line in message.split('\n')])
infochan.msg(message)
else:
# no mudinfo channel is found. Log instead.
cmessage = "\n".join(["[NO MUDINFO CHANNEL]: %s" % line for line in message.split('\n')])
logger.log_errmsg(cmessage)
except Exception, e:
if ServerConfig.objects.conf("server_starting_mode"):
print cmessage
else:
logger.log_trace(cmessage)
#path = self.db_typeclass_path
path = object.__getattribute__(self, 'db_typeclass_path')