예제 #1
0
def stat_master(game: str, game_info: dict, master_list: list):
  """Stats the master server"""
  try:
    backend_config_object = helpers.load_table(BACKEND_CONFIG)

    server_json_table = []
    server_table = []

    for master_uri in master_list:
        server_json_table += get_json(master_uri)

    for entry in server_json_table:
        entry_dict = parse_json_entry(entry)

        server_table.append(entry_dict)

    ping.add_rtt_info(server_table)

    for i in range(len(server_table)):
        entry = server_table[i]
        entry["game_id"] = game
        server_table[i] = entry

    return server_table
  except Exception as e:
    raise Exception(helpers.debug_msg_str([BACKENDCAT_MSG + MINETEST_MSG, e.args[0]]))
예제 #2
0
def stat_master(game: str, game_info: dict, master_list: list):
    """Stats the master server"""
    try:
        backend_config_object = helpers.load_table(BACKEND_CONFIG)

        server_json_table = []
        server_table = []

        for master_uri in master_list:
            server_json_table += get_json(master_uri)

        for entry in server_json_table:
            entry_dict = parse_json_entry(entry)

            server_table.append(entry_dict)

        ping.add_rtt_info(server_table)

        for i in range(len(server_table)):
            entry = server_table[i]
            entry["game_id"] = game
            server_table[i] = entry

        return server_table
    except Exception as e:
        raise Exception(
            helpers.debug_msg_str([BACKENDCAT_MSG + MINETEST_MSG, e.args[0]]))
예제 #3
0
def stat_master(game: str, game_info: dict, master_list: list):
    hosts_array = []

    qstat_stdin_object = ""

    master_server_uri = None
    stat_start_time = None
    stat_end_time = None

    game_name = game_info["name"]
    backend_config_object = helpers.load_table(BACKEND_CONFIG)

    qstat_master_type = backend_config_object['game'][game]['master_type']
    qstat_server_type = backend_config_object['game'][game]['server_type']

    if "server_gamename" not in backend_config_object['game'][game].keys():
        backend_config_object['game'][game]['server_gamename'] = None

    server_game_name = backend_config_object['game'][game]['server_gamename']
    if "server_gamename" in backend_config_object['game'][game].keys():
        server_game_name = backend_config_object['game'][game][
            'server_gamename']

    server_game_type = None
    if "server_gametype" in backend_config_object['game'][game].keys():
        server_game_type = backend_config_object['game'][game][
            'server_gametype']

    for entry in master_list:
        entry = entry.strip()
        if '://' in entry:
            entry_protocol, entry_host = entry.split('://')
        else:
            entry_protocol = 'master'
            entry_host = entry
        hosts_array.append(entry_host)

    hosts_array = list(set(hosts_array))

    qstat_cmd = [
        "qstat", "-xml", "-utf8", "-maxsim", "9999", "-sendinterval", "1",
        "-R", "-P", "-f", "-"
    ]

    qstat_stdin_descriptor = backend_config_object['game'][game]['master_type']
    if server_game_type is not None:
        qstat_stdin_descriptor = qstat_stdin_descriptor + ",game=" + server_game_type

    for entry in hosts_array:
        qstat_stdin_object = qstat_stdin_object + qstat_stdin_descriptor + " " + entry + "\n"

    debug_msg(game_name, i18n._("Requesting server info."))
    stat_start_time = time.time()
    try:
        qstat_output_raw, _ = subprocess.Popen(
            qstat_cmd, stdin=subprocess.PIPE,
            stdout=subprocess.PIPE).communicate(
                input=qstat_stdin_object.strip().encode())
        qstat_output = qstat_output_raw.decode()
    except Exception as e:
        raise Exception(
            helpers.debug_msg_str([QSTAT_MSG, game_name, e.args[0]]))
    stat_end_time = time.time()

    stat_total_time = stat_end_time - stat_start_time
    debug_msg(
        game_name,
        i18n._("Received server info. Elapsed time: %(stat_time)s s.") %
        {'stat_time': round(stat_total_time, 2)})

    parse_start_time = time.time()
    server_table = adapt_server_list(qstat_output, game, game_name,
                                     qstat_master_type, qstat_server_type,
                                     server_game_name, server_game_type)
    parse_end_time = time.time()

    debug_msg(
        game_name,
        i18n._("Parsed QStat response. Elapsed time: %(parse_time)s ms") %
        {'parse_time': round((parse_end_time - parse_start_time) * 1000, 2)})

    return server_table
예제 #4
0
파일: qstat.py 프로젝트: skybon/obozrenie
def stat_master(game: str, game_info: dict, master_list: list):
    hosts_array = []

    qstat_stdin_object = ""

    master_server_uri = None
    stat_start_time = None
    stat_end_time = None

    game_name = game_info["name"]
    backend_config_object = helpers.load_table(BACKEND_CONFIG)

    qstat_master_type = backend_config_object['game'][game]['master_type']
    qstat_server_type = backend_config_object['game'][game]['server_type']

    if "server_gamename" not in backend_config_object['game'][game].keys():
        backend_config_object['game'][game]['server_gamename'] = None

    server_game_name = backend_config_object['game'][game]['server_gamename']
    if "server_gamename" in backend_config_object['game'][game].keys():
        server_game_name = backend_config_object['game'][game]['server_gamename']

    server_game_type = None
    if "server_gametype" in backend_config_object['game'][game].keys():
        server_game_type = backend_config_object['game'][game]['server_gametype']

    for entry in master_list:
        entry = entry.strip()
        if '://' in entry:
            entry_protocol, entry_host = entry.split('://')
        else:
            entry_protocol = 'master'
            entry_host = entry
        hosts_array.append(entry_host)

    hosts_array = list(set(hosts_array))

    qstat_cmd = ["qstat", "-xml", "-utf8", "-maxsim", "9999", "-sendinterval", "1", "-R", "-P", "-f", "-"]

    qstat_stdin_descriptor = backend_config_object['game'][game]['master_type']
    if server_game_type is not None:
        qstat_stdin_descriptor = qstat_stdin_descriptor + ",game=" + server_game_type

    for entry in hosts_array:
        qstat_stdin_object = qstat_stdin_object + qstat_stdin_descriptor + " " + entry + "\n"

    debug_msg(game_name, i18n._("Requesting server info."))
    stat_start_time = time.time()
    try:
        qstat_output_raw, _ = subprocess.Popen(qstat_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE).communicate(input=qstat_stdin_object.strip().encode())
        qstat_output = qstat_output_raw.decode()
    except Exception as e:
        raise Exception(helpers.debug_msg_str([QSTAT_MSG, game_name, e.args[0]]))
    stat_end_time = time.time()

    stat_total_time = stat_end_time - stat_start_time
    debug_msg(game_name, i18n._("Received server info. Elapsed time: %(stat_time)s s.") % {'stat_time': round(stat_total_time, 2)})

    parse_start_time = time.time()
    server_table = adapt_server_list(qstat_output, game, game_name, qstat_master_type, qstat_server_type, server_game_name, server_game_type)
    parse_end_time = time.time()

    debug_msg(game_name, i18n._("Parsed QStat response. Elapsed time: %(parse_time)s ms") % {'parse_time': round((parse_end_time - parse_start_time) * 1000, 2)})

    return server_table