Trying to find the "Magic Words"

Trying to find the "Magic Words"

Postby Helix » Wed Jul 09, 2014 9:01 am

I'm trying to find the command codes or "Magic Words" as its called. Here are some files that I think could help.
And thanks I need all the help I could get. :)

Code: Select all
from direct.directnotify import DirectNotifyGlobal
from direct.distributed.DistributedObjectAI import DistributedObjectAI
from import *
from direct.distributed.PyDatagram import PyDatagram
from direct.distributed.MsgTypes import *

class MagicWordManagerAI(DistributedObjectAI):
    notify = DirectNotifyGlobal.directNotify.newCategory("MagicWordManagerAI")

    def sendMagicWord(self, word, targetId):
        invokerId = self.air.getAvatarIdFromSender()
        invoker = self.air.doId2do.get(invokerId)

        if not 'DistributedToonAI' in str(self.air.doId2do.get(targetId)):
            self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['Target is not a toon object!'])
        if not invoker:
            self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['missing invoker'])

        if invoker.getAdminAccess() < MINIMUM_MAGICWORD_ACCESS:
            self.air.writeServerEvent('suspicious', invokerId, 'Attempted to issue magic word: %s' % word)
            dg = PyDatagram()
            dg.addServerHeader(self.GetPuppetConnectionChannel(invokerId), self.air.ourChannel, CLIENTAGENT_EJECT)
            dg.addString('Magic Words are reserved for administrators only!')

        target = self.air.doId2do.get(targetId)
        if not target:
            self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', ['missing target'])

        response = spellbook.process(invoker, target, word)
        if response:
            self.sendUpdateToAvatarId(invokerId, 'sendMagicWordResponse', [response])

                                  invokerId, invoker.getAdminAccess(),
                                  targetId, target.getAdminAccess(),
                                  word, response)

Code: Select all
from direct.distributed import DistributedObject
from direct.directnotify import DirectNotifyGlobal
from import *
from otp.nametag.NametagConstants import *

lastClickedNametag = None

class MagicWordManager(DistributedObject.DistributedObject):
    notify = DirectNotifyGlobal.directNotify.newCategory('MagicWordManager')
    neverDisable = 1

    def generate(self):
        self.accept('magicWord', self.handleMagicWord)

    def disable(self):

    def handleMagicWord(self, magicWord):
        if not

        if magicWord.startswith('~~'):
            if lastClickedNametag == None:
                target = base.localAvatar
                target = lastClickedNametag
            magicWord = magicWord[2:]
        if magicWord.startswith('~'):
            target = base.localAvatar
            magicWord = magicWord[1:]

        targetId = target.doId
        self.sendUpdate('sendMagicWord', [magicWord, targetId])
        if target == base.localAvatar:
            response = spellbook.process(base.localAvatar, target, magicWord)
            if response:

    def sendMagicWordResponse(self, response):
        base.localAvatar.setSystemMessage(0, 'Spellbook: ' + str(response))

Code: Select all
from direct.showbase import PythonUtil

class MagicError(Exception): pass

def ensureAccess(access, msg='Insufficient access'):
    if spellbook.getInvokerAccess() < access:
        raise MagicError(msg)

class Spellbook:
    The Spellbook manages the list of all Magic Words that have been registered
    anywhere in the system. When the MagicWordManager(AI) wants to process a
    Magic Word, it is passed off to the Spellbook, which performs the operation.

    To add Magic Words to the Spellbook, use the @magicWord() decorator.

    def __init__(self):
        self.words = {}

        self.currentInvoker = None
        self.currentTarget = None

    def addWord(self, word):
        self.words[] = word

    def process(self, invoker, target, incantation):
        self.currentInvoker = invoker
        self.currentTarget = target
        word, args = (incantation.split(' ', 1) + [''])[:2]

            return self.doWord(word, args)
        except MagicError as e:
            return e.message
        except Exception:
            return PythonUtil.describeException(backTrace=1)
            self.currentInvoker = None
            self.currentTarget = None

    def doWord(self, wordName, args):
        word = self.words.get(wordName)
        if not word:

        if self.getTarget() and self.getTarget() != self.getInvoker():
            if self.getInvokerAccess() <= self.getTarget().getAdminAccess():
                raise MagicError('Target must have lower access')

        result =
        if result is not None:
            return str(result)

    def getInvoker(self):
        return self.currentInvoker

    def getTarget(self):
        return self.currentTarget

    def getInvokerAccess(self):
        if not self.currentInvoker:
            return 0
        return self.currentInvoker.getAdminAccess()

spellbook = Spellbook()

class MagicWordCategory:
    def __init__(self, name, defaultAccess=600): = name
        self.defaultAccess = defaultAccess

CATEGORY_UNKNOWN = MagicWordCategory('Unknown')
CATEGORY_USER = MagicWordCategory('Community manager', defaultAccess=100)
CATEGORY_COMMUNITY_MANAGER = MagicWordCategory('Community manager', defaultAccess=200)
CATEGORY_MODERATOR = MagicWordCategory('Moderator', defaultAccess=300)
CATEGORY_CREATIVE = MagicWordCategory('Creative', defaultAccess=400)
CATEGORY_PROGRAMMER = MagicWordCategory('Programmer', defaultAccess=500)
CATEGORY_ADMINISTRATOR = MagicWordCategory('Administrator', defaultAccess=600)
CATEGORY_SYSTEM_ADMINISTRATOR = MagicWordCategory('System administrator', defaultAccess=700)


class MagicWord:
    def __init__(self, name, func, types, access, doc): = name
        self.func = func
        self.types = types
        self.access = access
        self.doc = doc

    def parseArgs(self, string):
        maxArgs = self.func.func_code.co_argcount
        minArgs = maxArgs - (len(self.func.func_defaults) if self.func.func_defaults else 0)

        args = string.split(None, maxArgs-1)[:maxArgs]
        if len(args) < minArgs:
            raise MagicError('Magic word %s requires at least %d arguments' % (, minArgs))

        output = []
        for i, (type, arg) in enumerate(zip(self.types, args)):
                targ = type(arg)
            except (TypeError, ValueError):
                raise MagicError('Argument %d of magic word %s must be %s' % (i,, type.__name__))


        return output

    def run(self, rawArgs):
        args = self.parseArgs(rawArgs)
        return self.func(*args)

class MagicWordDecorator:
    This class manages Magic Word decoration. It is aliased as magicWord, so that
    the @magicWord(...) construct instantiates this class and has the resulting
    object process the Magic Word's construction.

    def __init__(self, name=None, types=[str], access=None, category=CATEGORY_UNKNOWN): = name
        self.types = types
        self.category = category
        if access is not None:
            self.access = access
            self.access = self.category.defaultAccess

    def __call__(self, mw):
        # This is the actual decoration routine. We add the function 'mw' as a
        # Magic Word to the Spellbook, using the attributes specified at construction
        # time.

        name =
        if name is None:
            name = mw.func_name

        word = MagicWord(name, mw, self.types, self.access, mw.__doc__)

        return mw

magicWord = MagicWordDecorator
Last edited by stranac on Wed Jul 09, 2014 9:42 am, edited 1 time in total.
Reason: First post lock.
Posts: 2
Joined: Wed Jul 09, 2014 8:56 am

Re: Trying to find the "Magic Words"

Postby stranac » Wed Jul 09, 2014 9:47 am

I think you should explain in more detail what your problem is.
Where does this code come from and what exactly is it you want?
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1298
Joined: Thu Feb 07, 2013 3:42 pm

Re: Trying to find the "Magic Words"

Postby Helix » Wed Jul 09, 2014 5:52 pm

Well first I'll explain where it comes from, I'm a member of a Team that's bringing a closed MMO back to life while adding new styles. I was asked to see if I could help with the coding, so I agreed to try it out. I've been doing alright so far but I'm trying to find ALL of the admin commands which are called "MagicWords" on this game. Those files on the top are the ones thought could help. If I need to upload more I can.
Posts: 2
Joined: Wed Jul 09, 2014 8:56 am

Re: Trying to find the "Magic Words"

Postby stranac » Thu Jul 10, 2014 11:34 am

Yeah, I don't see any defined in the code you posted.
Do you have the code online somewhere (like a vcs)?
It would be much more convenient to see it in a structured fashion, rather than having you upload the files.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1298
Joined: Thu Feb 07, 2013 3:42 pm

Re: Trying to find the "Magic Words"

Postby NerdyNA » Tue Jan 06, 2015 6:25 am

Sorry to bring this up so late, but most (if not all) the magic words are in: toontown\toon\
Last edited by Yoriz on Tue Jan 06, 2015 8:58 pm, edited 1 time in total.
Reason: First post lock.
Posts: 2
Joined: Tue Jan 06, 2015 6:24 am

Return to Game Development

Who is online

Users browsing this forum: No registered users and 2 guests