Exemple #1
0
def public_info(request):
    status = ctl.get_status()
    try:
        current_map = MapsHistory()[0]
    except IndexError:
        logger.error(
            "Can't get current map time, map_recorder is probably offline")
        current_map = {"name": status["map"], "start": None, "end": None}
    current_map = dict(
        just_name=map_name(current_map["name"]),
        human_name=LONG_HUMAN_MAP_NAMES.get(current_map["name"],
                                            current_map["name"]),
        **current_map,
    )
    vote_status = get_votes_status(none_on_fail=True)
    next_map = ctl.get_next_map()
    return api_response(
        result=dict(
            current_map=current_map,
            **status,
            vote_status=vote_status,
            next_map=next_map,
        ),
        failed=False,
        command="public_info",
    )
Exemple #2
0
def get_scoreboard_maps(request):
    data = _get_data(request)

    page_size = min(int(data.get("limit", 100)), 1000)
    page = max(1, int(data.get("page", 1)))
    server_number = data.get("server_number", os.getenv("SERVER_NUMBER"))

    with enter_session() as sess:
        query = (sess.query(Maps).filter(
            Maps.server_number == server_number).order_by(Maps.start.desc()))
        total = query.count()
        res = query.limit(page_size).offset((page - 1) * page_size).all()

        return api_response(
            result={
                "page":
                page,
                "page_size":
                page_size,
                "total":
                total,
                "maps": [
                    dict(
                        just_name=map_name(r.map_name),
                        long_name=LONG_HUMAN_MAP_NAMES.get(
                            r.map_name, r.map_name),
                        **r.to_dict(),
                    ) for r in res
                ],
            },
            failed=False,
            command="get_scoreboard_maps",
        )
Exemple #3
0
 def get_next_map():
     m = ctl.get_next_map()
     return LONG_HUMAN_MAP_NAMES.get(m, m)