Minecraft: write server and port to apmc on download
This commit is contained in:
parent
f655dc0dbc
commit
f62e8b7be9
|
@ -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"
|
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)
|
return send_file(patch_data, as_attachment=True, attachment_filename=fname)
|
||||||
|
|
||||||
@app.route("/slot_file/<suuid:seed_id>/<int:player_id>")
|
@app.route("/slot_file/<suuid:room_id>/<int:player_id>")
|
||||||
def download_slot_file(seed_id, player_id: int):
|
def download_slot_file(room_id, player_id: int):
|
||||||
seed = Seed.get(id=seed_id)
|
room = Room.get(id=room_id)
|
||||||
slot_data: Slot = select(patch for patch in seed.slots if
|
slot_data: Slot = select(patch for patch in room.seed.slots if
|
||||||
patch.player_id == player_id).first()
|
patch.player_id == player_id).first()
|
||||||
|
|
||||||
if not slot_data:
|
if not slot_data:
|
||||||
|
@ -57,7 +57,10 @@ def download_slot_file(seed_id, player_id: int):
|
||||||
import io
|
import io
|
||||||
|
|
||||||
if slot_data.game == "Minecraft":
|
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":
|
elif slot_data.game == "Factorio":
|
||||||
with zipfile.ZipFile(io.BytesIO(slot_data.data)) as zf:
|
with zipfile.ZipFile(io.BytesIO(slot_data.data)) as zf:
|
||||||
for name in zf.namelist():
|
for name in zf.namelist():
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
<ul>
|
<ul>
|
||||||
{% for patch in room.seed.slots|list|sort(attribute="player_id") %}
|
{% for patch in room.seed.slots|list|sort(attribute="player_id") %}
|
||||||
{% if patch.game == "Minecraft" %}
|
{% if patch.game == "Minecraft" %}
|
||||||
<li><a href="{{ url_for("download_slot_file", seed_id=room.seed.id, player_id=patch.player_id) }}">
|
<li><a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}">
|
||||||
APMC for player {{ patch.player_id }} - {{ patch.player_name }}</a></li>
|
APMC for player {{ patch.player_id }} - {{ patch.player_name }}</a></li>
|
||||||
{% elif patch.game == "Factorio" %}
|
{% elif patch.game == "Factorio" %}
|
||||||
<li><a href="{{ url_for("download_slot_file", seed_id=room.seed.id, player_id=patch.player_id) }}">
|
<li><a href="{{ url_for("download_slot_file", room_id=room.id, player_id=patch.player_id) }}">
|
||||||
Mod for player {{ patch.player_id }} - {{ patch.player_name }}</a></li>
|
Mod for player {{ patch.player_id }} - {{ patch.player_name }}</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}">
|
<li><a href="{{ url_for("download_patch", patch_id=patch.id, room_id=room.id) }}">
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
from base64 import b64encode, b64decode
|
||||||
from math import ceil
|
from math import ceil
|
||||||
|
|
||||||
from .Items import MinecraftItem, item_table, required_items, junk_weights
|
from .Items import MinecraftItem, item_table, required_items, junk_weights
|
||||||
|
@ -88,9 +90,6 @@ class MinecraftWorld(World):
|
||||||
link_minecraft_structures(self.world, self.player)
|
link_minecraft_structures(self.world, self.player)
|
||||||
|
|
||||||
def generate_output(self, output_directory: str):
|
def generate_output(self, output_directory: str):
|
||||||
import json
|
|
||||||
from base64 import b64encode
|
|
||||||
|
|
||||||
data = self._get_mc_data()
|
data = self._get_mc_data()
|
||||||
filename = f"AP_{self.world.seed_name}_P{self.player}_{self.world.get_player_names(self.player)}.apmc"
|
filename = f"AP_{self.world.seed_name}_P{self.player}_{self.world.get_player_names(self.player)}.apmc"
|
||||||
with open(os.path.join(output_directory, filename), 'wb') as f:
|
with open(os.path.join(output_directory, filename), 'wb') as f:
|
||||||
|
@ -110,3 +109,9 @@ class MinecraftWorld(World):
|
||||||
if name in nonexcluded_items: # prevent books from going on excluded locations
|
if name in nonexcluded_items: # prevent books from going on excluded locations
|
||||||
item.never_exclude = True
|
item.never_exclude = True
|
||||||
return item
|
return item
|
||||||
|
|
||||||
|
def mc_update_output(raw_data, server, port):
|
||||||
|
data = json.loads(b64decode(raw_data))
|
||||||
|
data['server'] = server
|
||||||
|
data['port'] = port
|
||||||
|
return b64encode(bytes(json.dumps(data), 'utf-8'))
|
||||||
|
|
Loading…
Reference in New Issue