fix downloading and displaying patches for seeds/rooms with teams
This commit is contained in:
parent
07954fc230
commit
eb58ee2422
|
@ -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 = update_patch_data(patch.data, server="berserkermulti.world:" + str(last_port))
|
||||||
patch_data = io.BytesIO(patch_data)
|
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)
|
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")
|
return Response(Seed.get(id=seed_id).spoiler, mimetype="text/plain")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/dl_raw_patch/<suuid:seed_id>/<int:player_id>")
|
@app.route("/dl_raw_patch/<suuid:seed_id>/<int:player_id>/<int:team_id>")
|
||||||
def download_raw_patch(seed_id, player_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).first()
|
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:
|
if not patch:
|
||||||
return "Patch not found"
|
return "Patch not found"
|
||||||
else:
|
else:
|
||||||
import io
|
import io
|
||||||
if patch.seed.multidata:
|
if patch.seed.multidata:
|
||||||
pname = patch.seed.multidata["names"][0][patch.player - 1]
|
pname = patch.seed.multidata["names"][team_id][patch.player - 1]
|
||||||
else:
|
else:
|
||||||
pname = "unknown"
|
pname = "unknown"
|
||||||
patch_data = update_patch_data(patch.data, server="")
|
patch_data = update_patch_data(patch.data, server="")
|
||||||
patch_data = io.BytesIO(patch_data)
|
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)
|
return send_file(patch_data, as_attachment=True, attachment_filename=fname)
|
||||||
|
|
|
@ -12,6 +12,7 @@ STATE_ERROR = -1
|
||||||
class Patch(db.Entity):
|
class Patch(db.Entity):
|
||||||
id = PrimaryKey(int, auto=True)
|
id = PrimaryKey(int, auto=True)
|
||||||
player = Required(int)
|
player = Required(int)
|
||||||
|
team = Required(int, default=0)
|
||||||
data = Required(buffer, lazy=True)
|
data = Required(buffer, lazy=True)
|
||||||
seed = Optional('Seed')
|
seed = Optional('Seed')
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
{% if room.last_port %}
|
{% if room.last_port %}
|
||||||
You can connect to this room by using '/connect archipelago.gg:{{ room.last_port }}'
|
You can connect to this room by using '/connect archipelago.gg:{{ room.last_port }}'
|
||||||
in the <a href="https://github.com/Berserker66/MultiWorld-Utilities/releases">client</a>.<br>{% endif %}
|
in the <a href="https://github.com/Berserker66/MultiWorld-Utilities/releases">client</a>.<br>{% endif %}
|
||||||
{{ macros.list_patches_room(room.seed.patches, room) }}
|
{{ macros.list_patches_room(room) }}
|
||||||
{% if room.owner == session["_id"] %}
|
{% if room.owner == session["_id"] %}
|
||||||
<form method=post>
|
<form method=post>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
{{ caller() }}
|
{{ caller() }}
|
||||||
</ul>
|
</ul>
|
||||||
{%- endmacro %}
|
{%- endmacro %}
|
||||||
{% macro list_patches_room(patches, room) %}
|
{% macro list_patches_room(room) %}
|
||||||
{% if patches %}
|
{% if room.seed.patches %}
|
||||||
<ul>
|
<ul>
|
||||||
{% for patch in patches|list|sort(attribute="player") %}
|
{% for patch in room.seed.patches|list|sort(attribute="team,player") %}
|
||||||
<li><a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}">
|
<li><a href="{{ url_for("download_patch", team = patch.team, patch_id=patch.id, room_id=room.id) }}">
|
||||||
Patch for player {{ patch.player }} - {{ room.seed.multidata["names"][0][patch.player-1] }}</a></li>
|
Patch for team {{ patch.team+1 }} player {{ patch.player }}
|
||||||
|
- {{ room.seed.multidata["names"][patch.team][patch.player-1] }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -33,26 +33,27 @@
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if seed.multidata %}
|
{% if seed.multidata %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Players: </td>
|
<td>Players: </td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
{% for team in seed.multidata["names"] %}
|
{% for team in seed.multidata["names"] %}
|
||||||
<li>Team #{{ loop.index }} - {{ team | length }}
|
{% set outer_loop = loop %}
|
||||||
<ul>
|
<li>Team #{{ loop.index }} - {{ team | length }}
|
||||||
{% for player in team %}
|
<ul>
|
||||||
<li>
|
{% for player in team %}
|
||||||
<a href="{{ url_for("download_raw_patch", seed_id=seed.id, player_id=loop.index) }}">{{ player }}</a>
|
<li>
|
||||||
</li>
|
<a href="{{ url_for("download_raw_patch", seed_id=seed.id, player_id=loop.index, team_id=outer_loop.index0) }}">{{ player }}</a>
|
||||||
{% endfor %}
|
</li>
|
||||||
</ul>
|
{% endfor %}
|
||||||
</li>
|
</ul>
|
||||||
{% endfor %}
|
</li>
|
||||||
</ul>
|
{% endfor %}
|
||||||
</td>
|
</ul>
|
||||||
</tr>
|
</td>
|
||||||
<tr>
|
</tr>
|
||||||
<td>Rooms: </td>
|
<tr>
|
||||||
|
<td>Rooms: </td>
|
||||||
<td>
|
<td>
|
||||||
{% call macros.list_rooms(rooms) %}
|
{% call macros.list_rooms(rooms) %}
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -39,8 +39,14 @@ def uploads():
|
||||||
if file.filename.endswith(banned_zip_contents):
|
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."
|
return "Uploaded data contained a rom file, which is likely to contain copyrighted material. Your file was deleted."
|
||||||
elif file.filename.endswith(".bmbp"):
|
elif file.filename.endswith(".bmbp"):
|
||||||
player = int(file.filename.split("P")[1].split(".")[0].split("_")[0])
|
# get probable team and player ID from filename. Could use a better method.
|
||||||
patches.add(Patch(data=zfile.open(file, "r").read(), player=player))
|
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"):
|
elif file.filename.endswith(".txt"):
|
||||||
spoiler = zfile.open(file, "r").read().decode("utf-8-sig")
|
spoiler = zfile.open(file, "r").read().decode("utf-8-sig")
|
||||||
elif file.filename.endswith("multidata"):
|
elif file.filename.endswith("multidata"):
|
||||||
|
|
Loading…
Reference in New Issue