Ejemplo n.º 1
0
    def setUp(self):
        self.restInterface = Mock(wraps=RestInterface.create())
        self.redis = MockRedis.create()
        self.logger = MockLogger.create()
        self.roomManager = Mock(
            wraps=RoomManager.create(logger=self.logger, redis=self.redis))
        self.deleteAllUsers(self.restInterface)
        self.users = [
            self.createUser(self.restInterface)
            for _ in range(MAX_MEMBERS_IN_ROOM)
        ]
        # tuple of (userId, sessionId)
        self.roomOwner = self.users[0]
        self.roomId = self.createRoom(self.restInterface, self.roomOwner[1])
        self.timeProvider = MockTimeProvider.create()
        self.snakeGameExecution = SnakeGameExecution.create(
            restInterface=self.restInterface,
            roomManager=self.roomManager,
            timeProvider=self.timeProvider,
            logger=self.logger)

        self.chatMessageHandler = ChatMessageHandler.create(
            restInterface=self.restInterface,
            roomManager=self.roomManager,
            snakeGameExecution=self.snakeGameExecution)
    def setUp(self):
        self.restInterface = Mock(wraps = RestInterface.create())
        self.redis = MockRedis.create()
        self.logger = MockLogger.create()
        self.roomManager = Mock(wraps = RoomManager.create(logger = self.logger, redis = self.redis))
        self.deleteAllUsers(self.restInterface)
        self.users = [self.createUser(self.restInterface) for _ in range(MAX_MEMBERS_IN_ROOM)]
            # tuple of (userId, sessionId)
        self.roomOwner = self.users[0]
        self.roomId = self.createRoom(self.restInterface, self.roomOwner[1])
        self.timeProvider = MockTimeProvider.create()
        self.snakeGameExecution = SnakeGameExecution.create(
            restInterface = self.restInterface,
            roomManager = self.roomManager,
            timeProvider = self.timeProvider,
            logger = self.logger)

        self.chatMessageHandler = ChatMessageHandler.create(
            restInterface = self.restInterface,
            roomManager = self.roomManager,
            snakeGameExecution = self.snakeGameExecution)
timeProvider = TimeProvider.create()

restInterface = RestInterface.create()

roomManager = RoomManager.create(
    logger = app.logger,
    redis = redis)

snakeGameExecution = SnakeGameExecution.create(
    restInterface = restInterface,
    roomManager = roomManager,
    timeProvider = timeProvider,
    logger = app.logger)

chatMessageHandler = ChatMessageHandler.create(
    restInterface = restInterface,
    roomManager = roomManager,
    snakeGameExecution = snakeGameExecution)

### rooms route
@sockets.route('/rooms/(\\w+)')
def rooms_route(ws, roomId):
    try:
        message = retrieveNextMessage(ws)
        userId = chatMessageHandler.handleFirstMessage(message, roomId, ws)
    except InvalidInputError as ex:
        ws.send("error " + ex.json())
        return # end this connection if cannot authenticate

    # infinite loop to handle the rest of the messages
    while True:
        message = retrieveNextMessage(ws)
Ejemplo n.º 4
0
redis = redis_module.from_url(REDIS_URL)

timeProvider = TimeProvider.create()

restInterface = RestInterface.create()

roomManager = RoomManager.create(logger=app.logger, redis=redis)

snakeGameExecution = SnakeGameExecution.create(restInterface=restInterface,
                                               roomManager=roomManager,
                                               timeProvider=timeProvider,
                                               logger=app.logger)

chatMessageHandler = ChatMessageHandler.create(
    restInterface=restInterface,
    roomManager=roomManager,
    snakeGameExecution=snakeGameExecution)


### rooms route
@sockets.route('/rooms/(\\w+)')
def rooms_route(ws, roomId):
    try:
        message = retrieveNextMessage(ws)
        userId = chatMessageHandler.handleFirstMessage(message, roomId, ws)
    except InvalidInputError as ex:
        ws.send("error " + ex.json())
        return  # end this connection if cannot authenticate

    # infinite loop to handle the rest of the messages
    while True: