WebHost: give proper incompatible version error message.. in the future when this is deployed for next time.
This commit is contained in:
parent
b82e0749b7
commit
a6cca3094d
2
Main.py
2
Main.py
|
@ -311,7 +311,7 @@ def main(args, seed=None, baked_server_options: Optional[Dict[str, object]] = No
|
|||
multidata = zlib.compress(pickle.dumps(multidata), 9)
|
||||
|
||||
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)
|
||||
|
||||
multidata_task = pool.submit(write_multidata)
|
||||
|
|
|
@ -241,8 +241,8 @@ class Context:
|
|||
@staticmethod
|
||||
def decompress(data: bytes) -> dict:
|
||||
format_version = data[0]
|
||||
if format_version != 1:
|
||||
raise Exception("Incompatible multidata.")
|
||||
if format_version > 2:
|
||||
raise Utils.VersionException("Incompatible multidata.")
|
||||
return restricted_loads(zlib.decompress(data[1:]))
|
||||
|
||||
def _load(self, decoded_obj: dict, use_embedded_server_options: bool):
|
||||
|
|
4
Utils.py
4
Utils.py
|
@ -474,3 +474,7 @@ def stream_input(stream, queue):
|
|||
thread = Thread(target=queuer, name=f"Stream handler for {stream.name}", daemon=True)
|
||||
thread.start()
|
||||
return thread
|
||||
|
||||
|
||||
class VersionException(Exception):
|
||||
pass
|
||||
|
|
|
@ -136,7 +136,7 @@ def view_seed(seed: UUID):
|
|||
seed = Seed.get(id=seed)
|
||||
if not seed:
|
||||
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>')
|
||||
|
|
|
@ -22,6 +22,10 @@
|
|||
<td>Created: </td>
|
||||
<td id="creation-time" data-creation-time="{{ seed.creation_time }}"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Players: </td>
|
||||
<td>{{ slot_count }}</td>
|
||||
</tr>
|
||||
{% if seed.spoiler %}
|
||||
<tr>
|
||||
<td>Spoiler: </td>
|
||||
|
|
|
@ -9,7 +9,7 @@ from flask import request, flash, redirect, url_for, session, render_template
|
|||
from pony.orm import flush, select
|
||||
|
||||
from WebHostLib import app, Seed, Room, Slot
|
||||
from Utils import parse_yaml
|
||||
from Utils import parse_yaml, VersionException
|
||||
from Patch import preferred_endings
|
||||
|
||||
banned_zip_contents = (".sfc",)
|
||||
|
@ -102,11 +102,15 @@ def uploads():
|
|||
elif file and allowed_file(file.filename):
|
||||
if zipfile.is_zipfile(file):
|
||||
with zipfile.ZipFile(file, 'r') as zfile:
|
||||
res = upload_zip_to_db(zfile)
|
||||
if type(res) == str:
|
||||
return res
|
||||
elif res:
|
||||
return redirect(url_for("view_seed", seed=res.id))
|
||||
try:
|
||||
res = upload_zip_to_db(zfile)
|
||||
except VersionException:
|
||||
flash(f"Could not load multidata. Wrong Version detected.")
|
||||
else:
|
||||
if type(res) == str:
|
||||
return res
|
||||
elif res:
|
||||
return redirect(url_for("view_seed", seed=res.id))
|
||||
else:
|
||||
file.seek(0) # offset from is_zipfile check
|
||||
# noinspection PyBroadException
|
||||
|
|
Loading…
Reference in New Issue