Ejemplo n.º 1
0
    def __init__( self, modeName, modeCmd, modeDefaultCallback = None, modeAddDefaultCmds = True ):
        assert isString( modeCmd )
        assert isString( modeName )

        if not modeDefaultCallback:
            modeDefaultCallback = lambda clientId, remaining: sendToClient( clientId, "Invalid %s mode command. ({!{FC!{@ to exit, {!{FCcommands{@ for help)\r\n" % self.modeName )

        self.modeCmd = modeCmd
        self.modeName = modeName
        self.modeMap = CmdMap( modeDefaultCallback ) 

        def enterMode( clientId, remaining ):
            pushCmdHandler( clientId, self.modeMap )
            sendToClient( clientId, "\r\n{!{FG[{FYEntering %s mode{FG] {@({!{FC!{@ to exit)\r\n" % self.modeName)
            if modeAddDefaultCmds:
                sendToClient( clientId, self.modeMap.commands() )
            sendToClient( clientId, "\r\n" )

        def exitMode( clientId, remaining ):
            popCmdHandler( clientId )
            sendToClient( clientId, "{!{FG[{FYExiting %s Mode{FG]\r\n" % self.modeName)


        self.enterModeCallback = enterMode

        self.modeMap.addCmd("!", exitMode )
        if modeAddDefaultCmds:
            self.modeMap.addCmd("exit", exitMode )
            self.modeMap.addCmd("commands", lambda clientId, remaining: sendToClient( clientId, self.modeMap.commands() ) )
Ejemplo n.º 2
0
def tick():

    dispatcher.send(signals.BEFORE_TICK, tick)

    for clientId in disconnectedClients:
        client.clientDisconnectedFromServer(clientId)

    for clientId in newClients:
        client.clientConnectedToServer(clientId)

    for clientId in flushedClients:
        cmds.clientFlushedCmdQueue(clientId)

    for cmd in clientCmds:
        cmds.clientSentCmd(cmd.key(), cmd.data())

    cmds.handleNextCmdForAllClients()

    def keys(intStringMap):
        return map(lambda i: i.key(), intStringMap)

    map(
        lambda clientId: send.sendToClient(clientId, prompt.prompt(clientId, clientId)),
        list(set(keys(clientCmds)).union(keys(send.clientMsgs))),
    )

    dispatcher.send(signals.AFTER_TICK, tick)
Ejemplo n.º 3
0
def tick():

    dispatcher.send(signals.BEFORE_TICK, tick)

    for clientId in disconnectedClients:
        client.clientDisconnectedFromServer(clientId)

    for clientId in newClients:
        client.clientConnectedToServer(clientId)

    for clientId in flushedClients:
        cmds.clientFlushedCmdQueue(clientId)

    for cmd in clientCmds:
        cmds.clientSentCmd(cmd.key(), cmd.data())

    cmds.handleNextCmdForAllClients()

    def keys(intStringMap):
        return map(lambda i: i.key(), intStringMap)

    map(
        lambda clientId: send.sendToClient(clientId,
                                           prompt.prompt(clientId, clientId)),
        list(set(keys(clientCmds)).union(keys(send.clientMsgs))))

    dispatcher.send(signals.AFTER_TICK, tick)
Ejemplo n.º 4
0
    def __init__(self,
                 modeName,
                 modeCmd,
                 modeDefaultCallback=None,
                 modeAddDefaultCmds=True):
        assert isString(modeCmd)
        assert isString(modeName)

        if not modeDefaultCallback:
            modeDefaultCallback = lambda clientId, remaining: sendToClient(
                clientId,
                "Invalid %s mode command. ({!{FC!{@ to exit, {!{FCcommands{@ for help)\r\n"
                % self.modeName)

        self.modeCmd = modeCmd
        self.modeName = modeName
        self.modeMap = CmdMap(modeDefaultCallback)

        def enterMode(clientId, remaining):
            pushCmdHandler(clientId, self.modeMap)
            sendToClient(
                clientId,
                "\r\n{!{FG[{FYEntering %s mode{FG] {@({!{FC!{@ to exit)\r\n" %
                self.modeName)
            if modeAddDefaultCmds:
                sendToClient(clientId, self.modeMap.commands())
            sendToClient(clientId, "\r\n")

        def exitMode(clientId, remaining):
            popCmdHandler(clientId)
            sendToClient(clientId,
                         "{!{FG[{FYExiting %s Mode{FG]\r\n" % self.modeName)

        self.enterModeCallback = enterMode

        self.modeMap.addCmd("!", exitMode)
        if modeAddDefaultCmds:
            self.modeMap.addCmd("exit", exitMode)
            self.modeMap.addCmd(
                "commands", lambda clientId, remaining: sendToClient(
                    clientId, self.modeMap.commands()))
Ejemplo n.º 5
0
 def enterMode(clientId, remaining):
     pushCmdHandler(clientId, self.modeMap)
     sendToClient(
         clientId,
         "\r\n{!{FG[{FYEntering %s mode{FG] {@({!{FC!{@ to exit)\r\n" %
         self.modeName)
     if modeAddDefaultCmds:
         sendToClient(clientId, self.modeMap.commands())
     sendToClient(clientId, "\r\n")
Ejemplo n.º 6
0
 def exitMode( clientId, remaining ):
     popCmdHandler( clientId )
     sendToClient( clientId, "{!{FG[{FYExiting %s Mode{FG]\r\n" % self.modeName)
Ejemplo n.º 7
0
 def enterMode( clientId, remaining ):
     pushCmdHandler( clientId, self.modeMap )
     sendToClient( clientId, "\r\n{!{FG[{FYEntering %s mode{FG] {@({!{FC!{@ to exit)\r\n" % self.modeName)
     if modeAddDefaultCmds:
         sendToClient( clientId, self.modeMap.commands() )
     sendToClient( clientId, "\r\n" )
Ejemplo n.º 8
0
def invalidCmd( clientId, remaining ):
    sendToClient( clientId, "Invalid command. ({!{FCcommands{@ for help)\r\n")
Ejemplo n.º 9
0
from pydispatch import dispatcher
from mud.parser.cmdMap import CmdMap
from cmds import pushCmdHandler
from send import sendToClient
import signals

def invalidCmd( clientId, remaining ):
    sendToClient( clientId, "Invalid command. ({!{FCcommands{@ for help)\r\n")

rootCmdMap = CmdMap( invalidCmd )
rootCmdMap.addCmd("commands", lambda clientId, remaining: sendToClient( clientId, rootCmdMap.commands() ) )

def addRootMap( clientId ):
    pushCmdHandler( clientId, rootCmdMap )

signals.connect( addRootMap, signals.CONNECTED )


Ejemplo n.º 10
0
 def exitMode(clientId, remaining):
     popCmdHandler(clientId)
     sendToClient(clientId,
                  "{!{FG[{FYExiting %s Mode{FG]\r\n" % self.modeName)