Webhost race support as a non-breaking change

This commit is contained in:
Fabian Dill 2020-10-30 00:09:47 +01:00
parent 5f535012f3
commit aab3a3496a
4 changed files with 55 additions and 24 deletions

View File

@ -37,9 +37,10 @@ def download_raw_patch(seed_id, player_id):
return "Patch not found"
else:
import io
if patch.seed.multidata:
pname = patch.seed.multidata["names"][0][patch.player - 1]
else:
pname = "unknown"
patch_data = update_patch_data(patch.data, server="")
patch_data = io.BytesIO(patch_data)

View File

@ -141,7 +141,7 @@ def gen_game(gen_options, race=False, owner=None, sid=None):
del (erargs.progression_balancing)
ERmain(erargs, seed)
return upload_to_db(target.name, owner, sid)
return upload_to_db(target.name, owner, sid, race)
except BaseException:
if sid:
with db_session:
@ -181,9 +181,10 @@ def wait_seed_api(seed: UUID):
return {"text": "Generation running"}, 202
def upload_to_db(folder, owner, sid):
def upload_to_db(folder, owner, sid, race:bool):
patches = set()
spoiler = ""
multidata = None
for file in os.listdir(folder):
file = os.path.join(folder, file)
@ -193,11 +194,17 @@ def upload_to_db(folder, owner, sid):
elif file.endswith(".txt"):
spoiler = open(file, "rt").read()
elif file.endswith("multidata"):
multidata = file
if not race or len(patches) > 1:
try:
multidata = json.loads(zlib.decompress(open(file, "rb").read()))
multidata = json.loads(zlib.decompress(open(multidata, "rb").read()))
except Exception as e:
flash(e)
if multidata:
raise e
else:
multidata = {}
with db_session:
if sid:
seed = Seed(multidata=multidata, spoiler=spoiler, patches=patches, owner=owner, id=sid)

View File

@ -19,10 +19,10 @@
You can also upload a .zip with multiple YAMLs.
A proper menu is in the works.
{% if race -%}
Race Mode means the spoiler log will be unavailable.
Race Mode means the spoiler log will be unavailable, roms will be encrypted and single-player has no multidata.
{%- else -%}
You can go to <a href="{{ url_for("generate", race=True) }}">Race Mode</a> to create a game without
spoiler log.
spoiler log and with encryption.
{%- endif -%}
</p>
<p>

View File

@ -11,6 +11,11 @@
<div id="view-seed-wrapper">
<div class="main-content">
<h3>Seed Info</h3>
{% if not seed.multidata and not seed.spoiler %}
<h4>
Single Player Race Rom: No spoiler or multidata exists, parts of the rom are encrypted and rooms cannot be created.
</h4>
{% endif %}
<table>
<tbody>
<tr>
@ -27,6 +32,7 @@
<td><a href="{{ url_for("download_spoiler", seed_id=seed.id) }}">Download</a></td>
</tr>
{% endif %}
{% if seed.multidata %}
<tr>
<td>Players:&nbsp;</td>
<td>
@ -55,6 +61,23 @@
{% endcall %}
</td>
</tr>
{% else %}
<tr>
<td>Patches:&nbsp;</td>
<td>
<ul>
{% for patch in seed.patches %}
<li>
<a href="{{ url_for("download_raw_patch", seed_id=seed.id, player_id=patch.player) }}">Player {{ patch.player }}</a>
</li>
{% endfor %}
</ul>
</td>
</tr>
{% endif %}
</tbody>
</table>
</div>