def getSecret(self, username, message): """ Start chatting with the bot server. GLADOS replies back to the client socket so we have to keep the connection open and wait to receive replies from bot. """ try: if len(self.__userList) == 0: raise Exception, 'Use the list command to see the online users' if (username in self.__userList): uIp, uP = self.__userList[username] c = ConnectionManager(uIp, uP) c.connect() c.send(p.T_MESSAGE, [self.__username], message) # We wait for four replies from GLADOS to receive the final token # The application is going to block until GLADOS replies. # Quick and dirty solution as GLaDOS speaks "differently" from # the way this client is implemented. So, the message is printed # in raw format just to get the final token. for i in range(0,3): r = c.receive() self.__agent.printMessage(str(r),'Bot user') if(r.type == p.T_PING): c.send(p.T_PONG, [self.__username]) c.disconnect() else: raise Exception, 'User %s can\'t be reached.' % username except Exception,e: self.__handleError('Chat', e)
def __init__(self, ip, port, verbose=False): super().__init__() # Set up mouse input base.cTrav = CollisionTraverser() self.handler = CollisionHandlerQueue() self.mouseHandler = MouseHandler() self.taskMgr.add(self.inputTask, "InputTask") # Set up the UI self.fonts = hud.hud.Fonts() self._scene = None # Set up audio self.audioMaster = audio.AudioMaster() # Set up the NetworkManager self.client = protocol.client.Client(ip, port, verbose) instr = networkInstructions.NetworkInstructions(self) self.client.add_observer(instr) self.clientActions = self.client.clientActions self.gameState = self.client.state # Connect to the server self.scene = hud.connection.ConnectionUI() self.connectionManager = ConnectionManager((ip, port), self, self.scene) self.connectionManager.tryConnect() self.taskMgr.add(self.networkUpdateTask, "NetworkUpdateTask")
def compareRepData(self, selectSql, resultset, timeout=300): """ Define compareRepData inside of test class to generate the new expect result file named DPAdapterAAsimpleDPHANATest The expected result set file has limitation of 10M size. Existing DPAdapterDataCompareExpected.py contains too many resultsets. When the file size exceed 10m, we have to put the file to /area51 and also need many extra steps to let test find the file. See more details on the limitation at: http://trexweb.wdf.sap.corp:1080/wiki/index.php/PyUnit_Test_Framework """ conman = ConnectionManager(verbosity=self._verbosity) self.conn = conman.createConnection(autocommit=True) cursor = self.conn.cursor() msg = "compareRepData:" + selectSql + ":" + str(resultset) loggerTest.info(msg) wait_period = os.getenv('WAIT_PERIOD') if wait_period != None: timeout = int(wait_period) if timeout < 0: loggerTest.info("Illegal timeout value given. Acceptable value should be >= 0, will use default value 300 (seconds).") timeout = 300 # check only once if timeout = 0 intv = 5 if timeout == 0: try: cursor.execute(selectSql) e = ExpectedSimpleResultSet(cursor) self.assertExpected(e, resultset, "Data not replicated correctly to HANA.") except Exception as err: raise else: # check data within timeout seconds wait_time = 0 while (wait_time < timeout): try: cursor.execute(selectSql) e = ExpectedSimpleResultSet(cursor) if self.assertExpected(e, resultset, "Data not replicated correctly to HANA.") is None: break except Exception as err: time.sleep(intv) wait_time = wait_time + intv msg = "wait " + str(wait_time) + " sec" loggerTest.info(msg) if wait_time >= timeout: errmsg = "Data not replicated correctly to HANA after waiting for " + str(timeout) + " seconds." try: cursor.execute(selectSql) e = ExpectedSimpleResultSet(cursor) self.assertExpected(e, resultset, errmsg) except Exception as err: raise
def init(self): self._nodeManager = NodeManager() self._connectionManager = ConnectionManager() self._viewerManager = ViewerManager() # connect undoRedoChanged signal self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged) self._connectionManager.undoRedoChanged.connect( self.emitUndoRedoChanged) self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged) return self
def init(self): self._nodeManager = NodeManager() self._connectionManager = ConnectionManager() self._viewerManager = ViewerManager() # connect undoRedoChanged signal self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged) self._connectionManager.undoRedoChanged.connect(self.emitUndoRedoChanged) self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged) return self
def cleanUp(self): global remoteSubList global virTableList global targetTableList global remoteTableList global src conman = ConnectionManager(verbosity=self._verbosity) self.conn = conman.createConnection(autocommit=True) cursor = self.conn.cursor() consrc = ConnectionManager() self.conn_src = consrc.createConnection(address=src['pds_host_name'], port=int(src['pds_database_port']), user="******", password=src['system_password'],autocommit=True) cursor_src = self.conn_src.cursor() testapi = DPAdapterApi(self.conn, cursor) testSrc = DPAdapterRemoteHDB(self.conn_src, cursor_src) try: if len(remoteSubList) > 0: try: testapi.dropRemoteSubscription(subName, "SYSTEM") except Exception as e: pass if len(targetTableList) > 0: try: testapi.dropTargetTable(tableName, "SYSTEM") except Exception as e: pass if len(virTableList) > 0: try: testapi.dropVirtualTable(tableName, "SYSTEM") except Exception as e: pass print 'drop remote source "HDBAdapterSrc" cascade' try: self.execute('drop remote source "' + src['RemoteSourceName'] + '" cascade') except Exception as e: pass print 'drop adapter "HanaAdapter" cascade' try: self.execute('drop adapter "HanaAdapter" cascade') except Exception as e: pass print 'drop agent "' , self.agent_name , '"' try: self.execute('drop agent "' + self.agent_name + '"') except Exception as e: pass print 'cleanup done' self.dp.appendTrace('cleanup done') except dbapi.Error, err: self.dp.appendTrace('Error in cleanup') self.dp.appendTrace(str(err)) pass
def ping(self, username): """ Ping user """ try: if len(self.__userList) == 0: raise Exception, 'Use the list command to see the online users' if (username in self.__userList): uIp, uP = self.__userList[username] c = ConnectionManager(uIp, uP) c.connect() c.send(p.T_PING, [self.__username]) pong = c.receive() self.__agent.printMessage(pong.type, pong.args.pop()) c.disconnect() else: raise Exception, 'User %s can\'t be pinged.' % username except Exception, e: self.__handleError('Ping', e)
def chat(self, username, message, getSecret=False): """ Start chatting with a specific user """ try: if len(self.__userList) == 0: raise Exception, 'Use the list command to see the online users' if (username in self.__userList): # Setup a new socket connection with the other user and send data. # The user can reply at the binded port from the directory server uIp, uP = self.__userList[username] c = ConnectionManager(uIp, uP) c.connect() c.send(p.T_MESSAGE, [self.__username], message) c.disconnect() else: raise Exception, 'User %s can\'t be reached.' % username except Exception, e: self.__handleError('Chat', e)
def ping(self, username): """ Ping user """ try: if len(self.__userList) == 0: raise Exception, 'Use the list command to see the online users' if (username in self.__userList): uIp, uP = self.__userList[username] c = ConnectionManager(uIp, uP) c.connect() c.send(p.T_PING, [self.__username]) pong = c.receive() self.__agent.printMessage(pong.type, pong.args.pop()) c.disconnect() else: raise Exception, 'User %s can\'t be pinged.' % username except Exception,e: self.__handleError('Ping', e)
def chat(self, username, message, getSecret = False): """ Start chatting with a specific user """ try: if len(self.__userList) == 0: raise Exception, 'Use the list command to see the online users' if (username in self.__userList): # Setup a new socket connection with the other user and send data. # The user can reply at the binded port from the directory server uIp, uP = self.__userList[username] c = ConnectionManager(uIp, uP) c.connect() c.send(p.T_MESSAGE, [self.__username], message) c.disconnect() else: raise Exception, 'User %s can\'t be reached.' % username except Exception,e: self.__handleError('Chat', e)
# Primary control over the application from connectionManager import ConnectionManager from tables import Tables # get connection to DynamoDB instance conn = ConnectionManager() tables = Tables() tables.create_category_tbl(conn.db) # delete table code: #tables.delete_category_tbl(conn.db)
def __init__(self, host, username, agent): threading.Thread.__init__(self) self.daemon = True self.__agent = agent self.__username = username self.__sock = ConnectionManager.createListeningSocket(host)
class ChatClient: """ Chat client handles all outcoming requests like (authentication, user searching and of course chatting. The general idea of the client is to open a connection for sending messages and receive all the incoming messages at the server port that is known through the directory server.""" def __init__(self, host, port, username, password, agent): self.__host = host self.__port = port self.__username = username self.__password = password self.__agent = agent self.__cm = None self.__userList = {} def __connect(self): self.__cm = ConnectionManager(self.__host, self.__port) self.__cm.connect() def __disconnect(self): self.__cm.disconnect() def __trigger(self, toBeExecuted, args = []): """ Trigger function uses the power of functinal programing to execute the functions that are passed as parameters. In details, its a wrapper for every command that requires re-authentication with the directory server. """ self.__connect() [ f(args) for f in toBeExecuted ] self.__disconnect() def authenticate(self): self.__trigger([self.__login, self.__bind]) def search(self, username): self.__trigger([self.__login, self.__searchUser], [username]) def listAll(self): self.__trigger([self.__login, self.__searchUser]) def leave(self): self.__trigger([self.__login, self.__unregister]) def chat(self, username, message, getSecret = False): """ Start chatting with a specific user """ try: if len(self.__userList) == 0: raise Exception, 'Use the list command to see the online users' if (username in self.__userList): # Setup a new socket connection with the other user and send data. # The user can reply at the binded port from the directory server uIp, uP = self.__userList[username] c = ConnectionManager(uIp, uP) c.connect() c.send(p.T_MESSAGE, [self.__username], message) c.disconnect() else: raise Exception, 'User %s can\'t be reached.' % username except Exception,e: self.__handleError('Chat', e)
def testHDBBarrier(self): """ Creates agent and test adapter. Create remote source and CDC """ env_dict = str(os.environ) #print env_dict #self.dp.appendTrace(env_dict) global remoteSubList global virTableList global targetTableList global remoteTableList global src global agent try: if run_test == 1: #self.dp.appendTrace(env_dict) self.agent_name = self.dp.getAgentName() port = str(self.dp.getAgentPort()) host = self.dp.getAgentHost() cursor = self.conn.cursor() testapi = DPAdapterApi(self.conn, cursor) ra_port = self.dp.ra_port remoteTableName='dpagent_testAdapter_emp' remoteTableOwner='SYSTEM' remoteTableSchema="COL1 INT" agent['agent_host'] = host agent['agent_port'] = port agent['agent_dir'] = '/usr/sap/dp/' + self.agent_name agent['agent_name'] = self.agent_name agent['java_path'] = '/usr/sap/dp/java/bin' src['admin_port'] = str(ra_port) consrc = ConnectionManager() self.conn_src = consrc.createConnection(address=src['pds_host_name'], port=string.atoi(src['pds_port_number']), user="******", password='******' , autocommit=True) cursor_src = self.conn_src.cursor() testSrc = DPAdapterRemoteHDB(self.conn_src, cursor_src) # cleanup RA system objects from source HDB in case these objects left in previous test failure testSrc.cleanRAObjects(src['pds_username']) # create pds_username on source HDB userType = "admin_user" testSrc.createUser(userType, src['pds_username'], src['pds_password']) self.dp.appendTrace('create agent') testapi.createAgent(agent) self.dp.appendTrace('create adapter') testapi.createAdapter(src['adapter_name'], self.agent_name) self.dp.appendTrace('create remote source') adapterType = "hana" testapi.createRemoteSource(adapterType, src, agent) dummy['dumTableName'] = "DPDUMMY" dummy['dumTableOwner'] = src['pds_username'].upper() dummy['dumTableSchema'] = "COL1 INT PRIMARY KEY" dummy['dumSubName'] = "SUB_DPDUMMY" dummy['dumVTableName'] = testapi.getVirtualTableName(src['pds_username'], dummy['dumTableName']) dummy['dumTTableName'] = 'T_' + dummy['dumTableName'] targetTableOwner = "SYSTEM" virtualTableOwner = "SYSTEM" testSrc.createTable(dummy['dumTableName'], dummy['dumTableOwner'], dummy['dumTableSchema']) insert_data = 10000 insertDataList = [] i = 1 rowcnt = 3 while (i < rowcnt + 1): ini_data = str(i + insert_data) insertDataList.append(ini_data) i += 1 testSrc.insertManyRows(dummy['dumTableName'], dummy['dumTableOwner'], insertDataList) self.dp.appendTrace('create virtual table') testapi.createVirtualTable(src['RemoteSourceName'], dummy['dumTableOwner'], dummy['dumTableName'], dummy['dumVTableName']) virTableList.append(dummy['dumVTableName']) self.dp.appendTrace('create target table') testapi.createTargetTable(dummy['dumTTableName'], dummy['dumVTableName']) targetTableStr = targetTableOwner + "." + dummy['dumTTableName'] targetTableList.append(targetTableStr) self.dp.appendTrace('create remote subscription') testapi.createRemoteSubscription(dummy['dumSubName'], dummy['dumVTableName'], dummy['dumTTableName']) remoteSubList.append(dummy['dumSubName']) self.dp.appendTrace('QUEUE') status = "QUEUE" testapi.alterRemoteSubscription(dummy['dumSubName'], status) self.dp.appendTrace('initial load') virtualTableWhereClause = "None" exprowcnt = testSrc.getRowCount(dummy['dumTableName'], dummy['dumTableOwner'], virtualTableWhereClause) virtualTableColumns = '*' timeout = 5 testapi.iniLoadTargetTable( dummy['dumVTableName'], virtualTableColumns, exprowcnt, dummy['dumTTableName'], targetTableOwner, timeout, virtualTableOwner, virtualTableWhereClause) self.dp.appendTrace('DISTRIBUTE') status = 'DISTRIBUTE' testapi.alterRemoteSubscription(dummy['dumSubName'], status) self.dp.appendTrace('insert and compare data') #insert to source testSrc.insertManyRows(dummy['dumTableName'], dummy['dumTableOwner'], ["12345"], True, "None") print "Checking if INSERT replicated correctly to HANA ..." selectSql = 'SELECT * FROM ' + targetTableOwner + '.' + dummy['dumTTableName'] + ' ORDER BY COL1 ASC' resultset = "testHDBBarrier1i" self.compareRepData(selectSql, resultset) setClause = "COL1 = 678910" updateWhereClause = "COL1 = 12345" testSrc.updateRow(dummy['dumTableName'], dummy['dumTableOwner'], setClause, updateWhereClause) print "Checking if UPDATE replicated correctly to HANA ..." resultset = "testHDBBarrier1u" self.compareRepData(selectSql, resultset) deleteWhereClause = "COL1 > 10002" testSrc.deleteRow(dummy['dumTableName'], dummy['dumTableOwner'], deleteWhereClause) print "Checking if DELETE replicated correctly to HANA ..." resultset = "testHDBBarrier1d" self.compareRepData(selectSql, resultset) print 'Test complete successful !' else: pass except dbapi.Error, err: self.dp.appendTrace('Error in the test') self.dp.appendTrace(str(err)) self.assertEqual("True", "False","Fail to create agent instance!") pass
def __connect(self): self.__cm = ConnectionManager(self.__host, self.__port) self.__cm.connect()
class ChatClient: """ Chat client handles all outcoming requests like (authentication, user searching and of course chatting. The general idea of the client is to open a connection for sending messages and receive all the incoming messages at the server port that is known through the directory server.""" def __init__(self, host, port, username, password, agent): self.__host = host self.__port = port self.__username = username self.__password = password self.__agent = agent self.__cm = None self.__userList = {} def __connect(self): self.__cm = ConnectionManager(self.__host, self.__port) self.__cm.connect() def __disconnect(self): self.__cm.disconnect() def __trigger(self, toBeExecuted, args=[]): """ Trigger function uses the power of functinal programing to execute the functions that are passed as parameters. In details, its a wrapper for every command that requires re-authentication with the directory server. """ self.__connect() [f(args) for f in toBeExecuted] self.__disconnect() def authenticate(self): self.__trigger([self.__login, self.__bind]) def search(self, username): self.__trigger([self.__login, self.__searchUser], [username]) def listAll(self): self.__trigger([self.__login, self.__searchUser]) def leave(self): self.__trigger([self.__login, self.__unregister]) def chat(self, username, message, getSecret=False): """ Start chatting with a specific user """ try: if len(self.__userList) == 0: raise Exception, 'Use the list command to see the online users' if (username in self.__userList): # Setup a new socket connection with the other user and send data. # The user can reply at the binded port from the directory server uIp, uP = self.__userList[username] c = ConnectionManager(uIp, uP) c.connect() c.send(p.T_MESSAGE, [self.__username], message) c.disconnect() else: raise Exception, 'User %s can\'t be reached.' % username except Exception, e: self.__handleError('Chat', e)
class ButtleManager(QtCore.QObject): """ This class catches events from QML, and manages them by calling the right manager or the right methods in core. It's like the front manager, which delegate to other managers. This class also catches events from QML about undo / redo. """ def init(self): self._nodeManager = NodeManager() self._connectionManager = ConnectionManager() self._viewerManager = ViewerManager() # connect undoRedoChanged signal self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged) self._connectionManager.undoRedoChanged.connect( self.emitUndoRedoChanged) self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged) return self ############### getters ############### def getNodeManager(self): return self._nodeManager def getConnectionManager(self): return self._connectionManager def getViewerManager(self): return self._viewerManager ############### UNDO & REDO ############### @QtCore.Slot() def undo(self): """ Calls the cmdManager to undo the last command. """ cmdManager = CommandManager() cmdManager.undo() # emit undo/redo display self.emitUndoRedoChanged() # if we need to update params or viewer buttleData = ButtleDataSingleton().get() buttleData.currentParamNodeChanged.emit() buttleData.currentViewerNodeChanged.emit() @QtCore.Slot() def redo(self): """ Calls the cmdManager to redo the last command. """ cmdManager = CommandManager() cmdManager.redo() # emit undo/redo display self.emitUndoRedoChanged() # if we need to update params or viewer buttleData = ButtleDataSingleton().get() buttleData.currentParamNodeChanged.emit() buttleData.currentViewerNodeChanged.emit() def signalUndoRedo(self): self.undoRedoChanged.emit() def canUndo(self): """ Calls the cmdManager to return if we can undo or not. """ cmdManager = CommandManager() return cmdManager.canUndo() def canRedo(self): """ Calls the cmdManager to return if we can redo or not. """ cmdManager = CommandManager() return cmdManager.canRedo() ############### DELETION ############### @QtCore.Slot() def deleteSelection(self): buttleData = ButtleDataSingleton().get() if (buttleData.currentConnectionWrapper): self._connectionManager.disconnect( buttleData.currentConnectionWrapper) else: self._nodeManager.destructionNodes() ################################################## DATA EXPOSED TO QML ################################################## @QtCore.Signal def changed(self): pass def emitUndoRedoChanged(self): self.changed.emit() # undo redo canUndo = QtCore.Property(bool, canUndo, notify=changed) canRedo = QtCore.Property(bool, canRedo, notify=changed) # managers nodeManager = QtCore.Property(QtCore.QObject, getNodeManager, constant=True) connectionManager = QtCore.Property(QtCore.QObject, getConnectionManager, constant=True) viewerManager = QtCore.Property(QtCore.QObject, getViewerManager, constant=True)
class ButtleManager(QtCore.QObject): """ This class catches events from QML, and manages them by calling the right manager or the right methods in core. It's like the front manager, which delegate to other managers. This class also catches events from QML about undo / redo. """ def init(self): self._nodeManager = NodeManager() self._connectionManager = ConnectionManager() self._viewerManager = ViewerManager() # connect undoRedoChanged signal self._nodeManager.undoRedoChanged.connect(self.emitUndoRedoChanged) self._connectionManager.undoRedoChanged.connect(self.emitUndoRedoChanged) self._viewerManager.undoRedoChanged.connect(self.emitUndoRedoChanged) return self ############### getters ############### def getNodeManager(self): return self._nodeManager def getConnectionManager(self): return self._connectionManager def getViewerManager(self): return self._viewerManager ############### UNDO & REDO ############### @QtCore.Slot() def undo(self): """ Calls the cmdManager to undo the last command. """ cmdManager = CommandManager() cmdManager.undo() # emit undo/redo display self.emitUndoRedoChanged() # if we need to update params or viewer buttleData = ButtleDataSingleton().get() buttleData.currentParamNodeChanged.emit() buttleData.currentViewerNodeChanged.emit() @QtCore.Slot() def redo(self): """ Calls the cmdManager to redo the last command. """ cmdManager = CommandManager() cmdManager.redo() # emit undo/redo display self.emitUndoRedoChanged() # if we need to update params or viewer buttleData = ButtleDataSingleton().get() buttleData.currentParamNodeChanged.emit() buttleData.currentViewerNodeChanged.emit() def signalUndoRedo(self): self.undoRedoChanged.emit() def canUndo(self): """ Calls the cmdManager to return if we can undo or not. """ cmdManager = CommandManager() return cmdManager.canUndo() def canRedo(self): """ Calls the cmdManager to return if we can redo or not. """ cmdManager = CommandManager() return cmdManager.canRedo() ############### DELETION ############### @QtCore.Slot() def deleteSelection(self): buttleData = ButtleDataSingleton().get() if(buttleData.currentConnectionWrapper): self._connectionManager.disconnect(buttleData.currentConnectionWrapper) else: self._nodeManager.destructionNodes() ################################################## DATA EXPOSED TO QML ################################################## @QtCore.Signal def changed(self): pass def emitUndoRedoChanged(self): self.changed.emit() # undo redo canUndo = QtCore.Property(bool, canUndo, notify=changed) canRedo = QtCore.Property(bool, canRedo, notify=changed) # managers nodeManager = QtCore.Property(QtCore.QObject, getNodeManager, constant=True) connectionManager = QtCore.Property(QtCore.QObject, getConnectionManager, constant=True) viewerManager = QtCore.Property(QtCore.QObject, getViewerManager, constant=True)
class App (ShowBase): def __init__(self, ip, port, verbose=False): super().__init__() # Set up mouse input base.cTrav = CollisionTraverser() self.handler = CollisionHandlerQueue() self.mouseHandler = MouseHandler() self.taskMgr.add(self.inputTask, "InputTask") # Set up the UI self.fonts = hud.hud.Fonts() self._scene = None # Set up audio self.audioMaster = audio.AudioMaster() # Set up the NetworkManager self.client = protocol.client.Client(ip, port, verbose) instr = networkInstructions.NetworkInstructions(self) self.client.add_observer(instr) self.clientActions = self.client.clientActions self.gameState = self.client.state # Connect to the server self.scene = hud.connection.ConnectionUI() self.connectionManager = ConnectionManager((ip, port), self, self.scene) self.connectionManager.tryConnect() self.taskMgr.add(self.networkUpdateTask, "NetworkUpdateTask") def onConnectedToServer(self): self.scene = mainMenu.MainMenu() @property def scene(self): return self._scene @scene.setter def scene(self, value): if self._scene: self._scene.unmake() self._scene = value def readyUp(self): """ We are ready to play a game. """ if not self.gameState.ready: self.clientActions.readyUp() self.scene.showWaitMessage() def onEnteredGame(self): self.scene = factionSelect.FactionSelect( ul_core.factions.availableFactions) def pickFaction(self, index): """ Tell the server we've picked a faction and are ready to start the game. """ self.clientActions.pickFaction(index) # Tell the user we're waiting for opponent self.scene.showWaitMessage() def onGameStarted(self, goingFirst=True): self.toMulligan = [] self.scene = game.Scene(self.gameState.player) self.zoneMaker = self.scene.zoneMaker self.hasFirstPlayerPenalty = goingFirst @property def player(self): return self.gameState.player @property def enemy(self): return self.gameState.enemy @property def phase(self): return self.gameState.game.phase @phase.setter def phase(self, value): self.gameState.game.phase = value @property def bothPlayersMulliganed(self): pls = self.gameState.game.players return pls[0].hasMulliganed and pls[1].hasMulliganed def mulligan(self): if not self.gameState.hasMulliganed: self.clientActions.mulligan(self.toMulligan) self.toMulligan = [] # These get GC'd else: print("Already mulliganed.") def nodeToGameEntity(self, node): if node is None: return None elif node.getPythonTag('zone') is self.player.face: return self.player.face elif node.getPythonTag('zone') is self.enemy.face: return self.enemy.face else: return node.getPythonTag('card') def finishTargeting(self): self.targetCallback = None self.activeDecision = None self.mouseHandler.targeting = False self.guiScene.hideTargeting() def playCard(self, card, target=None): """ If the card is fast, play it face-up, otherwise play it face-down. """ c = card.getPythonTag('card') t = self.nodeToGameEntity(target) if c.fast: if c.requiresTarget: self.clientActions.playFaceup(c, t) else: self.clientActions.playFaceup(c) else: self.clientActions.playFacedown(c) def revealFacedown(self, card, target=None): card = card.getPythonTag('card') target = self.nodeToGameEntity(target) self.clientActions.revealFacedown(card, target) def attack(self, card, target): self.clientActions.attack( card.getPythonTag('card'), self.nodeToGameEntity(target)) def endTurn(self, *args, **kwargs): def entityOrBool(arg): return arg if isinstance(arg, bool) else self.nodeToGameEntity(arg) args = [entityOrBool(arg) for arg in args] kwargs = [entityOrBool(arg) for key, arg in kwargs.items()] self.clientActions.endTurn(args + kwargs) self.hasFirstPlayerPenalty = False def useTemplarAbility(self, target): self.clientActions.useTemplarAbility(self.nodeToGameEntity(target)) def useMarinerAbility(self): self.clientActions.useMarinerAbility() def makeDecision(self, nodes): self.audioMaster.playDecision() cards = [self.nodeToGameEntity(node) for node in nodes] self.clientActions.makeDecision(cards) for node in nodes: # NEVER COMPARE NODE PATHS w/ is. It seems to always return False if (node is not None and node.getParent() == self.zoneMaker.playerHand): node.removeNode() def redraw(self): if self.mouseHandler.targeting: self.mouseHandler.targeting = False self.scene.redraw() def quitToMainMenu(self): self.taskMgr.doMethodLater( 1, self._quitToMainMenuTask, "QuitToMainMenu") def _quitToMainMenuTask(self, task): self.scene = mainMenu.MainMenu() self.clientActions.requestNumPlayers() return Task.done def inputTask(self, task): try: self.mouseHandler.mouseOverTask() except IllegalMoveError as e: print(e) return Task.cont def networkUpdateTask(self, task): try: self.client.networkManager.recv() except ConnectionClosed: return Task.done return Task.cont
def getSecret(self, username, message): """ Start chatting with the bot server. GLADOS replies back to the client socket so we have to keep the connection open and wait to receive replies from bot. """ try: if len(self.__userList) == 0: raise Exception, 'Use the list command to see the online users' if (username in self.__userList): uIp, uP = self.__userList[username] c = ConnectionManager(uIp, uP) c.connect() c.send(p.T_MESSAGE, [self.__username], message) # We wait for four replies from GLADOS to receive the final token # The application is going to block until GLADOS replies. # Quick and dirty solution as GLaDOS speaks "differently" from # the way this client is implemented. So, the message is printed # in raw format just to get the final token. for i in range(0, 3): r = c.receive() self.__agent.printMessage(str(r), 'Bot user') if (r.type == p.T_PING): c.send(p.T_PONG, [self.__username]) c.disconnect() else: raise Exception, 'User %s can\'t be reached.' % username except Exception, e: self.__handleError('Chat', e)