예제 #1
0
def test_mis_003():
    """ Tests the MIS response """
    daide_str = 'MIS ( #0 )'
    game = Game(map_name='standard')
    phase_name = 'W1901A'
    power = game.get_power('FRANCE')
    response = responses.MIS(phase_name=phase_name, power=power)
    assert isinstance(response, responses.MIS), 'Expected a MIS response'
    assert bytes(response) == str_to_bytes(daide_str)
예제 #2
0
def test_mis_010():
    """ Tests the MIS response """
    daide_str = 'MIS ( FRA FLT BRE ) ( FRA AMY MAR )'
    game = Game(map_name='standard')
    phase_name = 'S1901M'
    power = game.get_power('FRANCE')
    power.orders['INVALID'] = 'A PAR - BUR'
    response = responses.MIS(phase_name=phase_name, power=power)
    assert isinstance(response, responses.MIS), 'Expected a MIS response'
    assert bytes(response) == str_to_bytes(daide_str)
예제 #3
0
def test_mis_012():
    """ Tests the MIS response """
    daide_str = 'MIS ( #-1 )'
    game = Game(map_name='standard')
    phase_name = 'W1901A'
    power = game.get_power('FRANCE')
    power.centers += ['LON']
    power.units = power.units[:2]
    response = responses.MIS(phase_name=phase_name, power=power)
    assert isinstance(response, responses.MIS), 'Expected a MIS response'
    assert bytes(response) == str_to_bytes(daide_str)
예제 #4
0
def test_mis_008():
    """ Tests the MIS response """
    daide_str = 'MIS ( FRA FLT BRE ) ( FRA AMY MAR )'
    game = Game(map_name='standard')
    game.add_rule('NO_CHECK')
    game.set_orders('FRANCE', ['A PAR - BUR'])
    phase_name = 'S1901M'
    power = game.get_power('FRANCE')
    response = responses.MIS(phase_name=phase_name, power=power)
    assert isinstance(response, responses.MIS), 'Expected a MIS response'
    assert bytes(response) == str_to_bytes(daide_str)
예제 #5
0
def on_missing_orders_request(server, request, connection_handler, game):
    """ Manage MIS request
        :param server: server which receives the request
        :param request: request to manage
        :param connection_handler: connection handler from which the request was sent
        :param game: the game
        :return: the list of responses
    """
    _, _, _, power_name = utils.get_user_connection(server.users, game,
                                                    connection_handler)
    if not power_name:
        return [responses.REJ(bytes(request))]
    return [
        responses.MIS(game.get_current_phase(), game.get_power(power_name))
    ]
예제 #6
0
def test_mis_002():
    """ Tests the MIS response """
    daide_str = 'MIS ( TUR FLT ANK MRT ( ARM ) ) ' \
                '( TUR FLT CON MRT ( BLA SMY ( BUL ECS ) ( BUL SCS ) ) ) ' \
                '( TUR AMY SMY MRT ( SYR ) )'
    game = Game(map_name='standard')
    phase_name = 'S1901R'
    power = game.get_power('TURKEY')
    power.units = ['F ANK', 'F CON', 'A SMY']
    power.retreats['F ANK'] = ['ARM']
    power.retreats['F CON'] = ['BLA', 'SMY', 'BUL/EC', 'BUL/SC']
    power.retreats['A SMY'] = ['SYR']
    response = responses.MIS(phase_name=phase_name, power=power)
    assert isinstance(response, responses.MIS), 'Expected a MIS response'
    assert bytes(response) == str_to_bytes(daide_str)
예제 #7
0
def on_submit_orders_request(server, request, connection_handler, game):
    """ Manage SUB request
        :param server: server which receives the request
        :param request: request to manage
        :param connection_handler: connection handler from which the request was sent
        :param game: the game
        :return: the list of responses
    """
    _, _, token, power_name = utils.get_user_connection(
        server.users, game, connection_handler)

    if request.phase and not request.phase == game.get_current_phase():
        return [responses.REJ(bytes(request))]

    request.token = token
    request.phase = game.get_current_phase()

    power = game.get_power(power_name)
    initial_power_adjusts = power.adjust[:]
    initial_power_orders = []
    initial_game_errors = game.error[:]

    order_responses = []

    # Parsing lead token and turn
    _, request_bytes = parse_bytes(clauses.SingleToken, bytes(request))
    _, request_bytes = parse_bytes(clauses.Turn,
                                   request_bytes,
                                   on_error='ignore')

    # Validate each order individually
    while request_bytes:
        daide_order, request_bytes = parse_bytes(clauses.Order, request_bytes)
        order = str(daide_order)

        set_orders_request = internal_requests.SetOrders(
            power_name=request.power_name,
            orders=[order],
            game_id=request.game_id,
            game_role=request.power_name,
            phase=request.phase,
            token=request.token)
        yield internal_request_managers.handle_request(server,
                                                       set_orders_request,
                                                       connection_handler)

        new_power_adjusts = [
            adjust for adjust in power.adjust
            if adjust not in initial_power_adjusts
        ]
        new_power_orders = {
            id: val
            for id, val in power.orders.items()
            if id not in initial_power_orders
        }
        new_game_errors = [
            error.code for error in game.error
            if error not in initial_game_errors
        ]

        if not new_power_adjusts and not new_power_orders and not new_game_errors:
            new_game_errors.append((err.GAME_ORDER_NOT_ALLOWED % order).code)

        order_responses.append(
            responses.THX(bytes(daide_order), new_game_errors))

    # Setting orders
    set_orders_request = internal_requests.SetOrders(
        power_name=request.power_name,
        orders=request.orders,
        game_id=request.game_id,
        game_role=request.power_name,
        phase=request.phase,
        token=request.token)
    yield internal_request_managers.handle_request(server, set_orders_request,
                                                   connection_handler)

    # Returning results and missing orders
    order_responses.append(responses.MIS(game.get_current_phase(), power))
    return order_responses