Is this the right way to use tags to identify perma/ or hard coded objects in the db?

13 views
Skip to first unread message

j3b

unread,
Feb 12, 2021, 2:31:00 PM2/12/21
to Evennia

On feb 11, 2021  13:23 Griatch wrote:
> The only reason we have #2 for Limbo is because it's needed as a minimum starting 
> point when building the database (like #1 will be user #1). I'd suggest using tagging to
> find and identify your 'permanent' room instead.

So I'm trying to learn how to do just that.  I've created a room called Euze in my as_initial_setup.py using the following code and tagged with a tag called "euze".

def at_initial_setup():
""" This is the final touches on Setup"""

    logger.log_info("Eunoia initial setup: Euze and other objects ...")

    room_typeclass = settings.BASE_ROOM_TYPECLASS
    euze_obj = create.create_object(room_typeclass, "Euze", nohome=True)
    # limbo_obj.id = 7
    euze_obj.tags.add("Euze")
    euze_obj.save()
    euze_obj.db.desc = "This is the Euze"
    euze_obj.save()

Euze is important because it is the default start location and home for a type of character object that players will create in game using a command called "ib" (see below).

class CmdIB(BaseCommand):
    # This is here b/c its a character command and can't go
    # in the body_commands file with causing trouble
    """
    Go into your body, in the Euze and play Eunoia.

    Usage:
      ib

    This command is available to your character in Limbo and adjacent rooms.
    If you already have a 'body' in the Euze then your puppet it immediately.
    If you do not presently have a live body then one will be created for you.
    """

    key = "ib"

    def func(self):
        from evennia.objects.models import ObjectDB
        from typeclasses.euzebody import Body
        caller = self.caller
        account = self.account
        session = self.session

        # if you do not have a body, create one
        if not caller.db.body:
            typeclass = Body
            start_location = evennia.search_tag("euze")[0]
            # crazy how does this identify a unique room?
            # start_location = ObjectDB.objects.get_id("#7")  # TODO: make this
            # more dynamic, or make it work at least
            # This is likely causing me testing problems since testing doesn't
            # have the Euze. How do I create that?
            # Okay Griatch says to use tags.
            default_home = start_location
            permissions = "body"
            key = "Nebody"

            # create the body
            new_body = create.create_object(typeclass, key=key,
                                            location=start_location,
                                            home=default_home,
                                            permissions=permissions
                                            )

            # only creator can puppet
            new_body.locks.add(f"puppet:id({new_body.id}) or pid({account.id})"
                               f" or puppet:id({caller.id})")
            new_body.tags.add(caller.account.key)  # this links the body to the
            caller.db.body = new_body
            new_body.db.char = caller
            # return some sort of message
            # caller.msg(f"Created new body: {key} for {caller.id}")
            logger.log_sec(
                f"Body created: {key} (Caller: {account},"
                f"IP:{self.session.address}"
                 )
        # if you have a body, puppet it.
        if caller.db.body:
            body = caller.db.body
            # self.msg(f"You have a body: #{body.id}")
            # try to puppet it
            try:
                account.puppet_object(session, caller.db.body)
                logger.log_sec(
                        f"Puppet success: (Caller: {caller}, Body:{body}, "
                        f"IP: {self.session.address}"
                        )
                body.location.msg(f"Your {body} has arrived in {body.room}")
            except RuntimeError as exc:
                self.msg("|rThat failed|n {msg}")
                self.msg(exc)
                logger.log_sec(
                        f"Puppet failed: (Caller: {caller}, Body:{body}, "
                        f"IP: {self.session.address}"
                        )
            body.msg(f"you have entered your body {caller.key}")
            return


This seems to work:

> ib
You become Nebody.

Euze
This is the Euze


But is this what you intended to advise? Is this the best way to write code around permanent objects in the db? My concern with the tags method is that in a production mud, builders could tag rooms with "euze" and they would be added to the search results of search_tags.   At least with dbrefs I know that no one will ever over-write #3.



...


Griatch Art

unread,
Feb 12, 2021, 3:20:47 PM2/12/21
to Evennia
It's up to you as a developer to decide what a builder can do. If you don't want your builders to tag with a given tag, you could protect against that. In particular,  a tag can have a category, so maybe the Euze room has the tag "euze" with category "system". Only a room with these two is the true euze-room referred to in code. Then you lock down your tagging command to not allow non-admins (or non-devs) to create tags with the "system" category. Now, people can tag things "euze" if they want, but that will still not affect your code since it'd have the wrong category. This also gives you your own 'safe' tag category you can use for system-specific things without risking those pesky builders messing things up.
.
Griatch

j3b

unread,
Feb 12, 2021, 3:42:17 PM2/12/21
to Evennia
Oh nice,  this is more elegant and powerful a solution than I had wished for.  Not that I'm likely to need to worry about implementing it until I actually have "builders" .
Reply all
Reply to author
Forward
0 new messages