Skip to content
Snippets Groups Projects
changeme.py 860 B
Newer Older
Ruben Anthony Gonzalez's avatar
Ruben Anthony Gonzalez committed
"""
These are ctf dependent functions.
They have to be aligned.
"""


MESSAGES = [
        "SUCCESS",
        "INVALID",
        "ALREADY_SUBMITTED",
        "ERROR"
]

RES_FILE_PATH = "results.txt"
RES_FILE = None


# TODO: Make list of team ids
all_teams = [i for i in range(16)]


def team_id_to_ip(team_id):
    """
    Somehow map team id to ip adress
    """
    return "10.13.37.{}".format(team_id)


def submit_flag(team_id, flag):
    """
    Submit individual flag.
    """
    global RES_FILE
    if RES_FILE is None:
        RES_FILE = open(RES_FILE_PATH, "a")

    # TODO: submission logic
    # e.g. requests.put(...)
    # set return val to index of appropriate message code
    return_val = 0


    RES_FILE.write("{} {} {}\n".format(return_val, team_id, flag))
    RES_FILE.flush()  # dirty but works for now

    return MESSAGES[return_val]