Beispiel #1
0
def get_match_result(match_id):
    """
    Checks the status of a match, returning a tuple winner, replay
    winner is either 1, 2 or None
    replay is set to the replay string, only if winner is defined
    """
    try:
        auth_token = util.get_api_auth_token()
        response = requests.get(url=api_match_status(match_id), headers={
            'Authorization': 'Bearer {}'.format(auth_token)
        })
        response.raise_for_status()
        result = response.json()
        status, replay = result['status'], result['replay']
        if status == 'redwon':
            return 1, replay
        elif status == 'bluewon':
            return 2, replay
        elif status == 'queued':
            return None, None
        else:
            raise RuntimeError('Unexpected match status: {}'.format(response.text))
    except Exception as e:
        logging.error('Could not get match winner (game id={})'.format(match_id), exc_info=e)
        return None, None
def run(num_players, maps, replays, first_scrim, last_scrim):

    scrims = []
    for i in range(first_scrim, last_scrim+1):
        try:
            auth_token = util.get_api_auth_token()
            response = requests.get(url=api_match_status(i), headers={
                'Authorization': 'Bearer {}'.format(auth_token)
            })
            response.raise_for_status()
            scrims.append(response.json())
            print (response.json())
            logging.info('{} done'.format(i))
        except Exception as e:
            logging.error('sad', exc_info=e)

    bracket = bracketlib.DoubleEliminationTournament(num_players)
    bracket.generate_bracket()

    for i, match in enumerate(bracket.matches):
        for j in range(3):
            replay = replays[i][j]
            for scrim in scrims:
                if scrim['replay'] == replay:
                    print ('{} -vs- {} | {} {} replay {}'.format(
                        scrim['red_team'].rjust(40),
                        scrim['blue_team'].ljust(40),
                        maps[match.round_str][j].ljust(30),
                        scrim['status'].ljust(8),
                        scrim['replay']))
def request_scrimmages():
    """Generates scrimmages and publishes them to the queue"""
    try:
        auth_token = util.get_api_auth_token()
        response = requests.post(url=API_SCRIMMAGE_MATCHMAKE, headers={
            'Authorization': 'Bearer {}'.format(auth_token)
        })
        response.raise_for_status()
    except:
        logging.critical('Error while generating scrimmages')
def compile_report_result(submissionid, result):
    """Sends the result of the run to the API endpoint"""
    try:
        auth_token = util.get_api_auth_token()
        response = requests.patch(
            url=api_compile_update(submissionid),
            data={'compilation_status': result},
            headers={'Authorization': 'Bearer {}'.format(auth_token)})
        response.raise_for_status()
    except Exception as e:
        logging.critical('Could not report result to API endpoint', exc_info=e)
        sys.exit(1)
Beispiel #5
0
def publish_match(player1, player2):
    try:
        auth_token = util.get_api_auth_token()
        response = requests.post(url=API_SCRIMMAGE_ENQUEUE, data={
            'player1': player1,
            'player2': player2
        }, headers={
            'Authorization': 'Bearer {}'.format(auth_token)
        })
        response.raise_for_status()
    except:
        logging.error('Could not send game to API endpoint')
Beispiel #6
0
def game_report_result(gametype, gameid, result):
    """Sends the result of the run to the API endpoint"""
    try:
        auth_token = util.get_api_auth_token()
        response = requests.post(url=api_game_update(gametype, gameid), data={
            'status': result
        }, headers={
            'Authorization': 'Bearer {}'.format(auth_token)
        })
        response.raise_for_status()
    except:
        logging.critical('Could not report result to API endpoint')
        sys.exit(1)
def matchmake():
    try:
        logging.info('Obtaining scrimmage list')
        auth_token = util.get_api_auth_token()
        response = requests.get(
            url=API_SCRIM_LIST,
            headers={'Authorization': 'Bearer {}'.format(auth_token)})
        response.raise_for_status()
        scrim_list = response.json()["matches"]
        for scrim in scrim_list:
            scrim_queue.put(scrim)
    except Exception as e:
        logging.critical('Could not get scrimmage list', exc_info=e)
Beispiel #8
0
def game_report_result(gametype, gameid, result, reason=None, ack=False):
    """Sends the result of the run to the API endpoint"""
    try:
        auth_token = util.get_api_auth_token()
        response = requests.patch(
            url=api_game_update(gametype, gameid),
            data={'status': result},
            headers={  # TODO: remove auth tokens, or make optional
                'Authorization': 'Bearer {}'.format(auth_token)
            })
        response.raise_for_status()
    except Exception as e:
        logging.critical('Could not report result to API endpoint', exc_info=e)
        if ack: sys.exit(0)
        else: sys.exit(1)
Beispiel #9
0
def game_report_result(gametype, gameid, result, winscore=None, losescore=None, new_replay=None, reason=''):

    """Sends the result of the run to the API endpoint"""
    try:
        auth_token = util.get_api_auth_token()
        response = requests.patch(url=api_game_update(gametype, gameid), data={
            'status': result,
            'winscore': winscore,
            'losescore': losescore,
            'new_replay': new_replay,
            'error_msg': reason
        }, headers={
            'Authorization': 'Bearer {}'.format(auth_token)
        })
        response.raise_for_status()
    except Exception as e:
        logging.critical('Could not report result to API endpoint', exc_info=e)
        sys.exit(1)