Integrating my commands with default commands

54 views
Skip to first unread message

Marcus Bell

unread,
Feb 4, 2015, 8:12:04 AM2/4/15
to eve...@googlegroups.com
I have a small command set that provides character creation & deletion options. It works ok but a problem I see with it is that it does not properly update the internals Evennia framework has. When I log in (connect) to the game, Evennia says I have no characters even though I do.

--------------------------------------------------------------------
Account Goldscuttle (you are Out-of-Character)

Connected session:
1 websocket (127.0.0.1)

help
- more commands
ooc
<Text> - talk on public channel

You don't have any characters yet. See help @charcreate for creating one.
--------------------------------------------------------------------

Then when I type 'chars' here it shows a list of characters for this player. They can be puppeted as normal with @ic or deleted.

I'm assuming this is because I bypassed and disabled @charcreate. How would you recommend I keep my character maintenance commands in sync with where Evennia is looking so it gives accurate info at log in?
The larger question may be is there an easy way to wrap existing default commands so that I can do my stuff in parse(), then pass it back to the default command this command is derived from?

A similar case is that I want to prohibit certain words or phrases from being used in any user input. I already have validation code for character names but want to use the same code for Player accounts too. 
So I assume I want to intercept the default_cmds.CmdUnconnectedCreate, parse the command line, apply my rules, then when the options meet my requirements, give it back to default_cmds.CmdUnconnectedCreate.

Well, it's a mess. I thought I could just fall back to super but it is missing all kinds of attributes... I can define them all but it is getting so long I figure there has to be an easier way...

   
   
def func(self):
       
if IsValidLength(self.username) and IsOnlyAlpha(self.username): # check length & contains only legal characters
           
pass
       
else:
           
self.session.msg("Names must be alphabetic only and from 6 to 16 characters in length.")
           
return
       
if IsNaughtyName(self.username) or IsReserved(self.username): # check if name contains prohibited words
           
self.session.msg("That name is not allowed because it contains a prohibited or reserved word.")
           
return
       
else:
           
self.lhs = ""
           
self.rhs = ""            
           
self.switches = ""
           
self.arglist = ['', '']
           
self.lhslist = ['', '']
           
self.rhslist = ['', '']            
           
self.raw = "create %s %s" % (self.username, self.password)# doesn't work

           
super(default_cmds.CmdUnconnectedCreate, self).func()

 
.

Marcus Bell

unread,
Feb 4, 2015, 9:50:02 AM2/4/15
to eve...@googlegroups.com
I love it when I figure it out myself...

    def func(self):
       
"""
        Creates a Player account upon successful validation
        """

        players  
= search_player(self.username)
        n
= len(players)
       
if n:
            player
= players[0]
           
self.session.msg("Sorry, that name is already in use.")
           
return        
       
if IsValidLength(self.username) and IsOnlyAlpha(self.username): # check length & contains only legal characters

           
pass
       
else:
           
self.session.msg("Names must be alphabetic only and from 6 to 16 characters in length.")
           
return
       
if IsNaughtyName(self.username) or IsReserved(self.username): # check if name contains prohibited words
           
self.session.msg("That name is not allowed because it contains a prohibited or reserved word.")
           
return
       
else:

            player
= create_player(self.username, self.email, self.password, settings.BASE_PLAYER_TYPECLASS)
            player
.sessions.append(self.session)
           
self.session.msg("Created user %s. Log in by typing: connect %s <password>" % (self.username, self.username))

.

Griatch Art

unread,
Feb 5, 2015, 4:56:14 AM2/5/15
to eve...@googlegroups.com
While you figured out a better solution in the end, you should not have had to re-set parsed attributes like this.

Your code example does not show what your command inherits from, but if you inherited your own command from the default CmdUnconnectedCreate and didn't overload its parse() method, then these properties should all be set for you. This ability to easily overload is the very reason we separate parse() from func() in the first place. Doing super() to call the parent's func should then work normally (in fact this is how we overload all muxcommands).
.
Griatch
Reply all
Reply to author
Forward
0 new messages