async def test_game_connection_not_restored_if_game_state_prohibits(
        lobbyconnection: LobbyConnection, game_service: GameService,
        game_stats_service, game_state, mocker, database):
    del lobbyconnection.player.game_connection
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.game_service = game_service
    game = mock.create_autospec(
        Game(42, database, game_service, game_stats_service))
    game.state = game_state
    game.password = None
    game.game_mode = 'faf'
    game.id = 42
    game_service._games[42] = game

    await lobbyconnection.on_message_received({
        'command': 'restore_game_session',
        'game_id': 42
    })

    assert not lobbyconnection.game_connection
    assert lobbyconnection.player.state == PlayerState.IDLE

    lobbyconnection.protocol.send_message.assert_any_call({
        "command":
        "notice",
        "style":
        "info",
        "text":
        "The game you were connected to is no longer available"
    })
Example #2
0
async def test_game_connection_restored_if_game_exists(
    lobbyconnection: LobbyConnection,
    game_service: GameService,
    game_stats_service,
    game_state,
    database
):
    del lobbyconnection.player.game_connection
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.game_service = game_service
    game = mock.create_autospec(Game(42, database, game_service, game_stats_service))
    game.state = game_state
    game.password = None
    game.game_mode = "faf"
    game.id = 42
    game_service._games[42] = game

    await lobbyconnection.on_message_received({
        "command": "restore_game_session",
        "game_id": 42
    })

    assert lobbyconnection.game_connection
    assert lobbyconnection.player.state is PlayerState.PLAYING
    assert lobbyconnection.player.game is game
Example #3
0
async def test_game_connection_not_restored_if_game_state_prohibits(
        lobbyconnection: LobbyConnection, game_service: GameService,
        game_stats_service, game_state, mock_player, mocker):
    protocol = mocker.patch.object(lobbyconnection, 'protocol')
    lobbyconnection.player = mock_player
    lobbyconnection.player.game_connection = None
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.game_service = game_service
    game = mock.create_autospec(Game(42, game_service, game_stats_service))
    game.state = game_state
    game.password = None
    game.game_mode = 'faf'
    game.id = 42
    game_service.games[42] = game

    lobbyconnection.command_restore_game_session({'game_id': 42})

    assert not lobbyconnection.game_connection
    assert lobbyconnection.player.state == PlayerState.IDLE

    protocol.send_message.assert_any_call({
        "command":
        "notice",
        "style":
        "info",
        "text":
        "The game you were connected to is no longer available"
    })
Example #4
0
async def game_service(
    database, player_service, game_stats_service,
    rating_service, message_queue_service
):
    game_service = GameService(
        database,
        player_service,
        game_stats_service,
        rating_service,
        message_queue_service,
    )
    await game_service.initialize()
    return game_service
Example #5
0
async def test_game_connection_restored_if_game_exists(
        lobbyconnection: LobbyConnection, game_service: GameService,
        game_stats_service, game_state, mock_player):
    lobbyconnection.player = mock_player
    lobbyconnection.player.game_connection = None
    lobbyconnection.player.state = PlayerState.IDLE
    lobbyconnection.game_service = game_service
    game = mock.create_autospec(Game(42, game_service, game_stats_service))
    game.state = game_state
    game.password = None
    game.game_mode = 'faf'
    game.id = 42
    game_service.games[42] = game

    lobbyconnection.command_restore_game_session({'game_id': 42})

    assert lobbyconnection.game_connection
    assert lobbyconnection.player.state == PlayerState.PLAYING
Example #6
0
    def makeService(self, options):
        """ called by 'python -m twisted -no game-server',
            via twisted.plugins.game_server_plugin
        """
        # config = ConfigParser()
        # config.read([options['config']])

        application = Application(settings.SERVER_NAME)
        main = service.MultiService()

        game_service = GameService()
        game_service.setName(settings.SERVER_NAME + '-game-service')
        game_service.setServiceParent(main)

        main.setServiceParent(application)
        return main
Example #7
0
                                                     loop=loop))
        db_pool = loop.run_until_complete(pool_fut)

        players_online = PlayerService(db_pool)
        api_accessor = ApiAccessor()
        event_service = EventService(api_accessor)
        achievement_service = AchievementService(api_accessor)
        game_stats_service = GameStatsService(event_service,
                                              achievement_service)

        natpacket_server = NatPacketServer(
            addresses=config.LOBBY_NAT_ADDRESSES, loop=loop)
        loop.run_until_complete(natpacket_server.listen())
        server.NatPacketServer.instance = natpacket_server

        games = GameService(players_online, game_stats_service)
        matchmaker_queue = MatchmakerQueue('ladder1v1', players_online, games)
        players_online.ladder_queue = matchmaker_queue

        ctrl_server = loop.run_until_complete(
            server.run_control_server(loop, players_online, games))

        lobby_server = server.run_lobby_server(('', 8001), players_online,
                                               games, loop)

        for sock in lobby_server.sockets:
            sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

        loop.run_until_complete(done)
        loop.close()
Example #8
0
async def game_service(database, player_service, game_stats_service):
    game_service = GameService(database, player_service, game_stats_service)
    await game_service.initialize()
    return game_service
Example #9
0
def mock_games(mock_players, game_stats_service):
    return mock.create_autospec(GameService(mock_players, game_stats_service))
Example #10
0
def game_service(player_service, game_stats_service):
    return GameService(player_service, game_stats_service)