From f62e8b7be9d86c1635d2f60223c8b08752254526 Mon Sep 17 00:00:00 2001 From: espeon65536 Date: Thu, 5 Aug 2021 13:17:01 -0500 Subject: [PATCH] Minecraft: write server and port to apmc on download --- WebHostLib/downloads.py | 13 ++++++++----- WebHostLib/templates/macros.html | 4 ++-- worlds/minecraft/__init__.py | 11 ++++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/WebHostLib/downloads.py b/WebHostLib/downloads.py index 3d901bb2..2d944117 100644 --- a/WebHostLib/downloads.py +++ b/WebHostLib/downloads.py @@ -45,10 +45,10 @@ def download_raw_patch(seed_id, player_id: int): fname = f"P{patch.player_id}_{patch.player_name}_{app.jinja_env.filters['suuid'](seed_id)}.apbp" return send_file(patch_data, as_attachment=True, attachment_filename=fname) -@app.route("/slot_file//") -def download_slot_file(seed_id, player_id: int): - seed = Seed.get(id=seed_id) - slot_data: Slot = select(patch for patch in seed.slots if +@app.route("/slot_file//") +def download_slot_file(room_id, player_id: int): + room = Room.get(id=room_id) + slot_data: Slot = select(patch for patch in room.seed.slots if patch.player_id == player_id).first() if not slot_data: @@ -57,7 +57,10 @@ def download_slot_file(seed_id, player_id: int): import io if slot_data.game == "Minecraft": - fname = f"AP_{app.jinja_env.filters['suuid'](seed_id)}_P{slot_data.player_id}_{slot_data.player_name}.apmc" + from worlds.minecraft import mc_update_output + fname = f"AP_{app.jinja_env.filters['suuid'](room_id)}_P{slot_data.player_id}_{slot_data.player_name}.apmc" + data = mc_update_output(slot_data.data, server=app.config['PATCH_TARGET'], port=room.last_port) + return send_file(io.BytesIO(data), as_attachment=True, attachment_filename=fname) elif slot_data.game == "Factorio": with zipfile.ZipFile(io.BytesIO(slot_data.data)) as zf: for name in zf.namelist(): diff --git a/WebHostLib/templates/macros.html b/WebHostLib/templates/macros.html index 1b5146d3..3e32b796 100644 --- a/WebHostLib/templates/macros.html +++ b/WebHostLib/templates/macros.html @@ -11,10 +11,10 @@