WebHost: give proper incompatible version error message.. in the future when this is deployed for next time.

This commit is contained in:
Fabian Dill 2022-01-18 08:23:38 +01:00
parent b82e0749b7
commit a6cca3094d
6 changed files with 22 additions and 10 deletions

View File

@ -311,7 +311,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
multidata = zlib.compress(pickle.dumps(multidata), 9) multidata = zlib.compress(pickle.dumps(multidata), 9)
with open(os.path.join(temp_dir, f'{outfilebase}.archipelago'), 'wb') as f: with open(os.path.join(temp_dir, f'{outfilebase}.archipelago'), 'wb') as f:
f.write(bytes([1])) # version of format f.write(bytes([2])) # version of format
f.write(multidata) f.write(multidata)
multidata_task = pool.submit(write_multidata) multidata_task = pool.submit(write_multidata)

View File

@ -241,8 +241,8 @@ class Context:
@staticmethod @staticmethod
def decompress(data: bytes) -> dict: def decompress(data: bytes) -> dict:
format_version = data[0] format_version = data[0]
if format_version != 1: if format_version > 2:
raise Exception("Incompatible multidata.") raise Utils.VersionException("Incompatible multidata.")
return restricted_loads(zlib.decompress(data[1:])) return restricted_loads(zlib.decompress(data[1:]))
def _load(self, decoded_obj: dict, use_embedded_server_options: bool): def _load(self, decoded_obj: dict, use_embedded_server_options: bool):

View File

@ -474,3 +474,7 @@ def stream_input(stream, queue):
thread = Thread(target=queuer, name=f"Stream handler for {stream.name}", daemon=True) thread = Thread(target=queuer, name=f"Stream handler for {stream.name}", daemon=True)
thread.start() thread.start()
return thread return thread
class VersionException(Exception):
pass

View File

@ -136,7 +136,7 @@ def view_seed(seed: UUID):
seed = Seed.get(id=seed) seed = Seed.get(id=seed)
if not seed: if not seed:
abort(404) abort(404)
return render_template("viewSeed.html", seed=seed) return render_template("viewSeed.html", seed=seed, slot_count=count(seed.slots))
@app.route('/new_room/<suuid:seed>') @app.route('/new_room/<suuid:seed>')

View File

@ -22,6 +22,10 @@
<td>Created:&nbsp;</td> <td>Created:&nbsp;</td>
<td id="creation-time" data-creation-time="{{ seed.creation_time }}"></td> <td id="creation-time" data-creation-time="{{ seed.creation_time }}"></td>
</tr> </tr>
<tr>
<td>Players:&nbsp;</td>
<td>{{ slot_count }}</td>
</tr>
{% if seed.spoiler %} {% if seed.spoiler %}
<tr> <tr>
<td>Spoiler:&nbsp;</td> <td>Spoiler:&nbsp;</td>

View File

@ -9,7 +9,7 @@ from flask import request, flash, redirect, url_for, session, render_template
from pony.orm import flush, select from pony.orm import flush, select
from WebHostLib import app, Seed, Room, Slot from WebHostLib import app, Seed, Room, Slot
from Utils import parse_yaml from Utils import parse_yaml, VersionException
from Patch import preferred_endings from Patch import preferred_endings
banned_zip_contents = (".sfc",) banned_zip_contents = (".sfc",)
@ -102,11 +102,15 @@ def uploads():
elif file and allowed_file(file.filename): elif file and allowed_file(file.filename):
if zipfile.is_zipfile(file): if zipfile.is_zipfile(file):
with zipfile.ZipFile(file, 'r') as zfile: with zipfile.ZipFile(file, 'r') as zfile:
res = upload_zip_to_db(zfile) try:
if type(res) == str: res = upload_zip_to_db(zfile)
return res except VersionException:
elif res: flash(f"Could not load multidata. Wrong Version detected.")
return redirect(url_for("view_seed", seed=res.id)) else:
if type(res) == str:
return res
elif res:
return redirect(url_for("view_seed", seed=res.id))
else: else:
file.seek(0) # offset from is_zipfile check file.seek(0) # offset from is_zipfile check
# noinspection PyBroadException # noinspection PyBroadException