def handleMsg(self, fullLine): event = proto.parseEvent(fullLine) msgStr = event.msgStr try: (teamID, playerID) = proto.TEAMPLAYER.parse(msgStr) self.main.player = Player(teamID, playerID) return True except proto.MessageParseException: pass try: (duration, ) = proto.STARTGAME.parse(msgStr) self.main.gameState.setGameTime(int(duration)) self.main.gameState.startGame() return True except proto.MessageParseException: pass try: proto.STOPGAME.parse(msgStr) self.main.gameState.stopGame() return True except proto.MessageParseException: pass try: proto.DELETED.parse(msgStr) #just treat this as the game stopping for us. self.main.gameState.stopGame() return True except proto.MessageParseException: pass return False
def handleMsg(self, fullLine): event = proto.parseEvent(fullLine) msgStr = event.msgStr h = proto.MessageHandler() @h.handles(proto.TEAMPLAYER) def teamPlayer(teamID, playerID): self.main.player = Player(teamID, playerID) return True @h.handles(proto.STARTGAME) def startGame(duration): self.main.gameState.setGameTime(int(duration)) self.main.gameState.startGame() return True @h.handles(proto.STOPGAME) def stopGame(): self.main.gameState.stopGame() return True @h.handles(proto.DELETED) def deleted(): #just treat this as the game stopping for us. self.main.gameState.stopGame() return True return h.handle(msgStr)
def handleMsg(self, fullLine): with self.eventLock: if mainWindow: # This should only be None in tests. mainWindow.lineReceived(fullLine) event = proto.parseEvent(fullLine) self.playerLastSeen[event.id] = event.time #Check if we need to update the confidence point. If so, we will do so after we have parsed/handled this message. newConfidencePoint = min(self.playerLastSeen.values()) updateConfidencePoint = newConfidencePoint > self.confidencePoint + self.confidencePointMinimumInterval #insert this event in the correct order (just because it was recieved last, doesn't mean it happened last!) insort(self.eventsSinceConfidencePoint, (event.time, event)) #loop over all events since confidence point, creating a new best-guess gameState. self.gameState = self.confidencePointGameState #TODO clone/copy this #print("Processing", self.eventsSinceConfidencePoint) for currEvent in self.eventsSinceConfidencePoint: self.__handleEvent(currEvent[1], self.gameState) if updateConfidencePoint: self.confidencePointGameState = self.gameState self.eventsSinceConfidencePoint = [] self.confidencePoint = newConfidencePoint return "Ack()\n"
def handleMsg(self, fullLine): with self.eventLock: if mainWindow: # This should only be None in tests. mainWindow.lineReceived(fullLine) event = proto.parseEvent(fullLine) self.playerLastSeen[event.id] = event.time # Check if we need to update the confidence point. If so, we will do so after we have parsed/handled this message. newConfidencePoint = min(self.playerLastSeen.values()) updateConfidencePoint = newConfidencePoint > self.confidencePoint + self.confidencePointMinimumInterval # insert this event in the correct order (just because it was recieved last, doesn't mean it happened last!) insort(self.eventsSinceConfidencePoint, (event.time, event)) # loop over all events since confidence point, creating a new best-guess gameState. self.gameState = self.confidencePointGameState # TODO clone/copy this # print("Processing", self.eventsSinceConfidencePoint) for currEvent in self.eventsSinceConfidencePoint: self.__handleEvent(currEvent[1], self.gameState) if updateConfidencePoint: self.confidencePointGameState = self.gameState self.eventsSinceConfidencePoint = [] self.confidencePoint = newConfidencePoint return "Ack()\n"
def handleMsg(self, fullLine): event = proto.parseEvent(fullLine) msgStr = event.msgStr try: (teamID, playerID) = proto.TEAMPLAYER.parse(msgStr) self.main.player = Player(teamID, playerID) return True except proto.MessageParseException: pass try: (duration,) = proto.STARTGAME.parse(msgStr) self.main.gameState.setGameTime(int(duration)) self.main.gameState.startGame() return True except proto.MessageParseException: pass try: proto.STOPGAME.parse(msgStr) self.main.gameState.stopGame() return True except proto.MessageParseException: pass try: proto.DELETED.parse(msgStr) #just treat this as the game stopping for us. self.main.gameState.stopGame() return True except proto.MessageParseException: pass return False
def handleMsg(self, fullLine, connection): with self.eventLock: event = proto.parseEvent(fullLine) if mainWindow: # This should only be None in tests. mainWindow.lineReceived(event) self.__handleEvent(event, self.gameState, connection) #TODO be more discerning return True
def handleMsg(self, fullLine): event = proto.parseEvent(fullLine) msgStr = event.msgStr h = proto.MessageHandler() @h.handles(proto.TEAMPLAYER) def teamPlayer(teamID, playerID): # pylint: disable=W0612 self.main.setPlayer(Player(teamID, playerID)) @h.handles(proto.STARTGAME) def startGame(duration): # pylint: disable=W0612 self.main.gameState.setGameTime(int(duration)) self.main.gameState.startGame() @h.handles(proto.STOPGAME) def stopGame(): # pylint: disable=W0612 self.main.gameState.stopGame() @h.handles(proto.DELETED) def deleted(): # pylint: disable=W0612 #just treat this as the game stopping for us. self.main.gameState.stopGame() #then shutdown as the server won't want us back. self.main.shutdown() @h.handles(proto.RESETGAME) def resetGame(): # pylint: disable=W0612 self.main.player.reset() @h.handles(proto.PING) def ping(): # pylint: disable=W0612 self.queueMessage(proto.PONG.create(event.time, 0)) @h.handles(proto.PONG) def pong(startTime, reply): # pylint: disable=W0612 if int(reply): self.queueMessage(proto.PONG.create(event.time, 0)) return h.handle(msgStr)