Renaming things and cleaning them up a bit.
This commit is contained in:
parent
a0907ec94d
commit
7685ce9623
1 changed files with 22 additions and 78 deletions
|
|
@ -207,10 +207,6 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# Used for sorting / filtering in inventories / room contents.
|
# Used for sorting / filtering in inventories / room contents.
|
||||||
_content_types = ("object",)
|
_content_types = ("object",)
|
||||||
|
|
||||||
# lockstring of newly created objects, for easy overloading.
|
|
||||||
# Will be formatted with the appropriate attributes.
|
|
||||||
lockstring = "control:id({account_id}) or perm(Admin);delete:id({account_id}) or perm(Admin)"
|
|
||||||
|
|
||||||
objects = ObjectManager()
|
objects = ObjectManager()
|
||||||
|
|
||||||
# populated by `return_appearance`
|
# populated by `return_appearance`
|
||||||
|
|
@ -1011,7 +1007,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
obj.move_to(home, move_type="teleport")
|
obj.move_to(home, move_type="teleport")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate_default_locks(
|
def get_default_lockstring(
|
||||||
cls, account: "DefaultAccount" = None, caller: "DefaultObject" = None, **kwargs
|
cls, account: "DefaultAccount" = None, caller: "DefaultObject" = None, **kwargs
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
@ -1025,10 +1021,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
Returns:
|
Returns:
|
||||||
lockstring (str): A lockstring to use for this object.
|
lockstring (str): A lockstring to use for this object.
|
||||||
"""
|
"""
|
||||||
if cls.lockstring:
|
pid = f"pid({account.id})" if account else None
|
||||||
account_id = account.id if account else -1
|
cid = f"id({caller.id})" if caller else None
|
||||||
return cls.lockstring.format(account_id=account_id)
|
admin = "perm(Admin)"
|
||||||
return ""
|
trio = " or ".join([x for x in [pid, cid, admin] if x])
|
||||||
|
return ";".join([f"{x}:{trio}" for x in ["control", "delete", "edit"]])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
|
|
@ -1079,7 +1076,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# Create a sane lockstring if one wasn't supplied
|
# Create a sane lockstring if one wasn't supplied
|
||||||
lockstring = kwargs.get("locks")
|
lockstring = kwargs.get("locks")
|
||||||
if (account or caller) and not lockstring:
|
if (account or caller) and not lockstring:
|
||||||
lockstring = cls.generate_default_locks(account=account, caller=caller, **kwargs)
|
lockstring = cls.get_default_lockstring(account=account, caller=caller, **kwargs)
|
||||||
kwargs["locks"] = lockstring
|
kwargs["locks"] = lockstring
|
||||||
|
|
||||||
# Create object
|
# Create object
|
||||||
|
|
@ -2524,7 +2521,7 @@ class DefaultCharacter(DefaultObject):
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def generate_default_locks(
|
def get_default_lockstring(
|
||||||
cls, account: "DefaultAccount" = None, caller: "DefaultObject" = None, **kwargs
|
cls, account: "DefaultAccount" = None, caller: "DefaultObject" = None, **kwargs
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
@ -2538,12 +2535,17 @@ class DefaultCharacter(DefaultObject):
|
||||||
Returns:
|
Returns:
|
||||||
lockstring (str): A lockstring to use for this object.
|
lockstring (str): A lockstring to use for this object.
|
||||||
"""
|
"""
|
||||||
if cls.lockstring:
|
pid = f"pid({account.id})" if account else None
|
||||||
account_id = account.id if account else -1
|
|
||||||
character = kwargs.get("character", None)
|
character = kwargs.get("character", None)
|
||||||
character_id = character.id if character else -1
|
cid = f"id({character})" if character else None
|
||||||
return cls.lockstring.format(character_id=character.id, account_id=account_id)
|
|
||||||
return ""
|
puppet = "puppet:" + " or ".join(
|
||||||
|
[x for x in [pid, cid, "perm(Developer)", "pperm(Developer)"] if x]
|
||||||
|
)
|
||||||
|
delete = "delete:" + " or ".join([x for x in [pid, "perm(Admin)"] if x])
|
||||||
|
edit = "edit:" + " or ".join([x for x in [pid, "perm(Admin)"] if x])
|
||||||
|
|
||||||
|
return ";".join([puppet, delete, edit])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, key, account=None, **kwargs):
|
def create(cls, key, account=None, **kwargs):
|
||||||
|
|
@ -2618,7 +2620,7 @@ class DefaultCharacter(DefaultObject):
|
||||||
if not locks:
|
if not locks:
|
||||||
# Allow only the character itself and the creator account to puppet this character
|
# Allow only the character itself and the creator account to puppet this character
|
||||||
# (and Developers).
|
# (and Developers).
|
||||||
locks = cls.generate_default_locks(account=account, character=obj)
|
locks = cls.get_default_lockstring(account=account, character=obj)
|
||||||
|
|
||||||
if locks:
|
if locks:
|
||||||
obj.locks.add(locks)
|
obj.locks.add(locks)
|
||||||
|
|
@ -2826,35 +2828,6 @@ class DefaultRoom(DefaultObject):
|
||||||
# Generally, a room isn't expected to HAVE a location, but maybe in some games?
|
# Generally, a room isn't expected to HAVE a location, but maybe in some games?
|
||||||
_content_types = ("room",)
|
_content_types = ("room",)
|
||||||
|
|
||||||
# lockstring of newly created rooms, for easy overloading.
|
|
||||||
# Will be formatted with the {id} of the creating object.
|
|
||||||
lockstring = (
|
|
||||||
"control:id({id}) or perm(Admin); "
|
|
||||||
"delete:id({id}) or perm(Admin); "
|
|
||||||
"edit:id({id}) or perm(Admin)"
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def generate_default_locks(
|
|
||||||
cls, account: "DefaultAccount" = None, caller: "DefaultObject" = None, **kwargs
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Classmethod called during .create() to determine default locks for the object.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
account (Account): Account to attribute this object to.
|
|
||||||
caller (DefaultObject): The object which is creating this one.
|
|
||||||
**kwargs: Arbitrary input.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
lockstring (str): A lockstring to use for this object.
|
|
||||||
"""
|
|
||||||
if cls.lockstring:
|
|
||||||
room = kwargs.get("room")
|
|
||||||
id = account.id if account else caller.id if caller else room.id
|
|
||||||
return cls.lockstring.format(id=id)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
cls,
|
cls,
|
||||||
|
|
@ -2914,7 +2887,7 @@ class DefaultRoom(DefaultObject):
|
||||||
|
|
||||||
# Add locks
|
# Add locks
|
||||||
if not locks:
|
if not locks:
|
||||||
locks = cls.generate_default_locks(account=account, caller=caller, room=obj)
|
locks = cls.get_default_lockstring(account=account, caller=caller, room=obj)
|
||||||
if locks:
|
if locks:
|
||||||
obj.locks.add(locks)
|
obj.locks.add(locks)
|
||||||
|
|
||||||
|
|
@ -3020,14 +2993,6 @@ class DefaultExit(DefaultObject):
|
||||||
exit_command = ExitCommand
|
exit_command = ExitCommand
|
||||||
priority = 101
|
priority = 101
|
||||||
|
|
||||||
# lockstring of newly created exits, for easy overloading.
|
|
||||||
# Will be formatted with the {id} of the creating object.
|
|
||||||
lockstring = (
|
|
||||||
"control:id({id}) or perm(Admin); "
|
|
||||||
"delete:id({id}) or perm(Admin); "
|
|
||||||
"edit:id({id}) or perm(Admin)"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Helper classes and methods to implement the Exit. These need not
|
# Helper classes and methods to implement the Exit. These need not
|
||||||
# be overloaded unless one want to change the foundation for how
|
# be overloaded unless one want to change the foundation for how
|
||||||
# Exits work. See the end of the class for hook methods to overload.
|
# Exits work. See the end of the class for hook methods to overload.
|
||||||
|
|
@ -3068,27 +3033,6 @@ class DefaultExit(DefaultObject):
|
||||||
|
|
||||||
# Command hooks
|
# Command hooks
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def generate_default_locks(
|
|
||||||
cls, account: "DefaultAccount" = None, caller: "DefaultObject" = None, **kwargs
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Classmethod called during .create() to determine default locks for the object.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
account (Account): Account to attribute this object to.
|
|
||||||
caller (DefaultObject): The object which is creating this one.
|
|
||||||
**kwargs: Arbitrary input.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
lockstring (str): A lockstring to use for this object.
|
|
||||||
"""
|
|
||||||
if cls.lockstring:
|
|
||||||
room = kwargs.get("room", None)
|
|
||||||
id = account.id if account else caller.id if caller else room.id if room else -1
|
|
||||||
return cls.lockstring.format(id=id)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(
|
def create(
|
||||||
cls,
|
cls,
|
||||||
|
|
@ -3152,7 +3096,7 @@ class DefaultExit(DefaultObject):
|
||||||
|
|
||||||
# Set appropriate locks
|
# Set appropriate locks
|
||||||
if not locks:
|
if not locks:
|
||||||
locks = cls.generate_default_locks(account=account, caller=caller, exit=obj)
|
locks = cls.get_default_lockstring(account=account, caller=caller, exit=obj)
|
||||||
if locks:
|
if locks:
|
||||||
obj.locks.add(locks)
|
obj.locks.add(locks)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue