fix downloading and displaying patches for seeds/rooms with teams

This commit is contained in:
Fabian Dill
2021-01-03 18:28:07 +01:00
parent 07954fc230
commit eb58ee2422
6 changed files with 44 additions and 34 deletions

View File

@@ -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/<suuid:seed_id>/<int:player_id>")
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/<suuid:seed_id>/<int:player_id>/<int:team_id>")
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)