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() ) )
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)
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)
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()))
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)
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 invalidCmd( clientId, remaining ): sendToClient( clientId, "Invalid command. ({!{FCcommands{@ for help)\r\n")
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 )
def exitMode(clientId, remaining): popCmdHandler(clientId) sendToClient(clientId, "{!{FG[{FYExiting %s Mode{FG]\r\n" % self.modeName)