diff --git a/WebHostLib/downloads.py b/WebHostLib/downloads.py index e8c32b83..cbd156af 100644 --- a/WebHostLib/downloads.py +++ b/WebHostLib/downloads.py @@ -20,7 +20,7 @@ def download_patch(room_id, patch_id): patch_data = update_patch_data(patch.data, server="berserkermulti.world:" + str(last_port)) patch_data = io.BytesIO(patch_data) - fname = f"P{patch.player}_{pname}_{app.jinja_env.filters['suuid'](room_id)}.bmbp" + fname = f"T{patch.team + 1}_P{patch.player}_{pname}_{app.jinja_env.filters['suuid'](room_id)}.bmbp" return send_file(patch_data, as_attachment=True, attachment_filename=fname) @@ -29,20 +29,21 @@ def download_spoiler(seed_id): return Response(Seed.get(id=seed_id).spoiler, mimetype="text/plain") -@app.route("/dl_raw_patch//") -def download_raw_patch(seed_id, player_id): - patch = select(patch for patch in Patch if patch.player == player_id and patch.seed.id == seed_id).first() +@app.route("/dl_raw_patch///") +def download_raw_patch(seed_id, player_id: int, team_id: int): + patch = select(patch for patch in Patch if + patch.player == player_id and patch.seed.id == seed_id and patch.team == team_id).first() if not patch: return "Patch not found" else: import io if patch.seed.multidata: - pname = patch.seed.multidata["names"][0][patch.player - 1] + pname = patch.seed.multidata["names"][team_id][patch.player - 1] else: pname = "unknown" patch_data = update_patch_data(patch.data, server="") patch_data = io.BytesIO(patch_data) - fname = f"P{patch.player}_{pname}_{app.jinja_env.filters['suuid'](seed_id)}.bmbp" + fname = f"T{team_id + 1}_P{patch.player}_{pname}_{app.jinja_env.filters['suuid'](seed_id)}.bmbp" return send_file(patch_data, as_attachment=True, attachment_filename=fname) diff --git a/WebHostLib/models.py b/WebHostLib/models.py index 77bd6f2f..287489f6 100644 --- a/WebHostLib/models.py +++ b/WebHostLib/models.py @@ -12,6 +12,7 @@ STATE_ERROR = -1 class Patch(db.Entity): id = PrimaryKey(int, auto=True) player = Required(int) + team = Required(int, default=0) data = Required(buffer, lazy=True) seed = Optional('Seed') diff --git a/WebHostLib/templates/hostRoom.html b/WebHostLib/templates/hostRoom.html index 69bf8675..ed741c54 100644 --- a/WebHostLib/templates/hostRoom.html +++ b/WebHostLib/templates/hostRoom.html @@ -22,7 +22,7 @@ {% if room.last_port %} You can connect to this room by using '/connect archipelago.gg:{{ room.last_port }}' in the client.
{% endif %} - {{ macros.list_patches_room(room.seed.patches, room) }} + {{ macros.list_patches_room(room) }} {% if room.owner == session["_id"] %}
diff --git a/WebHostLib/templates/macros.html b/WebHostLib/templates/macros.html index bf5dbcca..8934d5e2 100644 --- a/WebHostLib/templates/macros.html +++ b/WebHostLib/templates/macros.html @@ -6,12 +6,13 @@ {{ caller() }} {%- endmacro %} -{% macro list_patches_room(patches, room) %} - {% if patches %} +{% macro list_patches_room(room) %} + {% if room.seed.patches %} {% endif %} diff --git a/WebHostLib/templates/viewSeed.html b/WebHostLib/templates/viewSeed.html index a6916bec..64ebac20 100644 --- a/WebHostLib/templates/viewSeed.html +++ b/WebHostLib/templates/viewSeed.html @@ -33,26 +33,27 @@ {% endif %} {% if seed.multidata %} - - Players:  - -
    - {% for team in seed.multidata["names"] %} -
  • Team #{{ loop.index }} - {{ team | length }} -
      - {% for player in team %} -
    • - {{ player }} -
    • - {% endfor %} -
    -
  • - {% endfor %} -
- - - - Rooms:  + + Players:  + +
    + {% for team in seed.multidata["names"] %} + {% set outer_loop = loop %} +
  • Team #{{ loop.index }} - {{ team | length }} +
      + {% for player in team %} +
    • + {{ player }} +
    • + {% endfor %} +
    +
  • + {% endfor %} +
+ + + + Rooms:  {% call macros.list_rooms(rooms) %}
  • diff --git a/WebHostLib/upload.py b/WebHostLib/upload.py index 3e329e4e..d0e24b67 100644 --- a/WebHostLib/upload.py +++ b/WebHostLib/upload.py @@ -39,8 +39,14 @@ def uploads(): if file.filename.endswith(banned_zip_contents): return "Uploaded data contained a rom file, which is likely to contain copyrighted material. Your file was deleted." elif file.filename.endswith(".bmbp"): - player = int(file.filename.split("P")[1].split(".")[0].split("_")[0]) - patches.add(Patch(data=zfile.open(file, "r").read(), player=player)) + # get probable team and player ID from filename. Could use a better method. + splitted = file.filename.split("/")[-1][3:].split("P", 1) + player = int(splitted[1].split(".")[0].split("_")[0]) + if "T" in splitted[0]: + team = int(splitted[0].split("T")[1].split(".")[0].split("_")[0]) - 1 + else: + team = 0 + patches.add(Patch(data=zfile.open(file, "r").read(), player=player, team=team)) elif file.filename.endswith(".txt"): spoiler = zfile.open(file, "r").read().decode("utf-8-sig") elif file.filename.endswith("multidata"):