Skip to content

Commit

Permalink
Merge branch 'main' into fix-remaining
Browse files Browse the repository at this point in the history
  • Loading branch information
remyjette authored Jul 3, 2024
2 parents 8777cf5 + 50f7a79 commit 08c59d6
Show file tree
Hide file tree
Showing 31 changed files with 529 additions and 343 deletions.
5 changes: 3 additions & 2 deletions CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

from MultiServer import CommandProcessor
from NetUtils import (Endpoint, decode, NetworkItem, encode, JSONtoTextParser, ClientStatus, Permission, NetworkSlot,
RawJSONtoTextParser, add_json_text, add_json_location, add_json_item, JSONTypes)
RawJSONtoTextParser, add_json_text, add_json_location, add_json_item, JSONTypes, SlotType)
from Utils import Version, stream_input, async_start
from worlds import network_data_package, AutoWorldRegister
import os
Expand Down Expand Up @@ -862,7 +862,8 @@ async def process_server_cmd(ctx: CommonContext, args: dict):
ctx.team = args["team"]
ctx.slot = args["slot"]
# int keys get lost in JSON transfer
ctx.slot_info = {int(pid): data for pid, data in args["slot_info"].items()}
ctx.slot_info = {0: NetworkSlot("Archipelago", "Archipelago", SlotType.player)}
ctx.slot_info.update({int(pid): data for pid, data in args["slot_info"].items()})
ctx.hint_points = args.get("hint_points", 0)
ctx.consume_players_package(args["players"])
ctx.stored_data_notification_keys.add(f"_read_hints_{ctx.team}_{ctx.slot}")
Expand Down
53 changes: 40 additions & 13 deletions WebHostLib/misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime
import os
from typing import List, Dict, Union
from typing import Any, IO, Dict, Iterator, List, Tuple, Union

import jinja2.exceptions
from flask import request, redirect, url_for, render_template, Response, session, abort, send_from_directory
Expand Down Expand Up @@ -97,25 +97,37 @@ def new_room(seed: UUID):
return redirect(url_for("host_room", room=room.id))


def _read_log(path: str):
if os.path.exists(path):
with open(path, encoding="utf-8-sig") as log:
yield from log
else:
yield f"Logfile {path} does not exist. " \
f"Likely a crash during spinup of multiworld instance or it is still spinning up."
def _read_log(log: IO[Any], offset: int = 0) -> Iterator[bytes]:
marker = log.read(3) # skip optional BOM
if marker != b'\xEF\xBB\xBF':
log.seek(0, os.SEEK_SET)
log.seek(offset, os.SEEK_CUR)
yield from log
log.close() # free file handle as soon as possible


@app.route('/log/<suuid:room>')
def display_log(room: UUID):
def display_log(room: UUID) -> Union[str, Response, Tuple[str, int]]:
room = Room.get(id=room)
if room is None:
return abort(404)
if room.owner == session["_id"]:
file_path = os.path.join("logs", str(room.id) + ".txt")
if os.path.exists(file_path):
return Response(_read_log(file_path), mimetype="text/plain;charset=UTF-8")
return "Log File does not exist."
try:
log = open(file_path, "rb")
range_header = request.headers.get("Range")
if range_header:
range_type, range_values = range_header.split('=')
start, end = map(str.strip, range_values.split('-', 1))
if range_type != "bytes" or end != "":
return "Unsupported range", 500
# NOTE: we skip Content-Range in the response here, which isn't great but works for our JS
return Response(_read_log(log, int(start)), mimetype="text/plain", status=206)
return Response(_read_log(log), mimetype="text/plain")
except FileNotFoundError:
return Response(f"Logfile {file_path} does not exist. "
f"Likely a crash during spinup of multiworld instance or it is still spinning up.",
mimetype="text/plain")

return "Access Denied", 403

Expand All @@ -139,7 +151,22 @@ def host_room(room: UUID):
with db_session:
room.last_activity = now # will trigger a spinup, if it's not already running

return render_template("hostRoom.html", room=room, should_refresh=should_refresh)
def get_log(max_size: int = 1024000) -> str:
try:
with open(os.path.join("logs", str(room.id) + ".txt"), "rb") as log:
raw_size = 0
fragments: List[str] = []
for block in _read_log(log):
if raw_size + len(block) > max_size:
fragments.append("…")
break
raw_size += len(block)
fragments.append(block.decode("utf-8"))
return "".join(fragments)
except FileNotFoundError:
return ""

return render_template("hostRoom.html", room=room, should_refresh=should_refresh, get_log=get_log)


@app.route('/favicon.ico')
Expand Down
93 changes: 79 additions & 14 deletions WebHostLib/templates/hostRoom.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
{{ macros.list_patches_room(room) }}
{% if room.owner == session["_id"] %}
<div style="display: flex; align-items: center;">
<form method=post style="flex-grow: 1; margin-right: 1em;">
<form method="post" id="command-form" style="flex-grow: 1; margin-right: 1em;">
<div class="form-group">
<label for="cmd"></label>
<input class="form-control" type="text" id="cmd" name="cmd"
Expand All @@ -55,24 +55,89 @@
Open Log File...
</a>
</div>
<div id="logger"></div>
<script type="application/ecmascript">
let xmlhttp = new XMLHttpRequest();
let url = '{{ url_for('display_log', room = room.id) }}';
{% set log = get_log() -%}
{%- set log_len = log | length - 1 if log.endswith("…") else log | length -%}
<div id="logger" style="white-space: pre">{{ log }}</div>
<script>
let url = '{{ url_for('display_log', room = room.id) }}';
let bytesReceived = {{ log_len }};
let updateLogTimeout;
let awaitingCommandResponse = false;
let logger = document.getElementById("logger");

xmlhttp.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
document.getElementById("logger").innerText = this.responseText;
function scrollToBottom(el) {
let bot = el.scrollHeight - el.clientHeight;
el.scrollTop += Math.ceil((bot - el.scrollTop)/10);
if (bot - el.scrollTop >= 1) {
window.clearTimeout(el.scrollTimer);
el.scrollTimer = window.setTimeout(() => {
scrollToBottom(el)
}, 16);
}
}

async function updateLog() {
try {
let res = await fetch(url, {
headers: {
'Range': `bytes=${bytesReceived}-`,
}
});
if (res.ok) {
let text = await res.text();
if (text.length > 0) {
awaitingCommandResponse = false;
if (bytesReceived === 0 || res.status !== 206) {
logger.innerHTML = '';
}
if (res.status !== 206) {
bytesReceived = 0;
} else {
bytesReceived += new Blob([text]).size;
}
if (logger.innerHTML.endsWith('…')) {
logger.innerHTML = logger.innerHTML.substring(0, logger.innerHTML.length - 1);
}
logger.appendChild(document.createTextNode(text));
scrollToBottom(logger);
}
};
}
}
finally {
window.clearTimeout(updateLogTimeout);
updateLogTimeout = window.setTimeout(updateLog, awaitingCommandResponse ? 500 : 10000);
}
}

function request_new() {
xmlhttp.open("GET", url, true);
xmlhttp.send();
async function postForm(ev) {
/** @type {HTMLInputElement} */
let cmd = document.getElementById("cmd");
if (cmd.value === "") {
ev.preventDefault();
return;
}
/** @type {HTMLFormElement} */
let form = document.getElementById("command-form");
let req = fetch(form.action || window.location.href, {
method: form.method,
body: new FormData(form),
redirect: "manual",
});
ev.preventDefault(); // has to happen before first await
form.reset();
let res = await req;
if (res.ok || res.type === 'opaqueredirect') {
awaitingCommandResponse = true;
window.clearTimeout(updateLogTimeout);
updateLogTimeout = window.setTimeout(updateLog, 100);
} else {
window.alert(res.statusText);
}
}

window.setTimeout(request_new, 1000);
window.setInterval(request_new, 10000);
document.getElementById("command-form").addEventListener("submit", postForm);
updateLogTimeout = window.setTimeout(updateLog, 1000);
logger.scrollTop = logger.scrollHeight;
</script>
{% endif %}
</div>
Expand Down
5 changes: 3 additions & 2 deletions docs/world api.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,9 @@ In addition, the following methods can be implemented and are called in this ord
called to place player's regions and their locations into the MultiWorld's regions list.
If it's hard to separate, this can be done during `generate_early` or `create_items` as well.
* `create_items(self)`
called to place player's items into the MultiWorld's itempool. After this step all regions
and items have to be in the MultiWorld's regions and itempool, and these lists should not be modified afterward.
called to place player's items into the MultiWorld's itempool. By the end of this step all regions, locations and
items have to be in the MultiWorld's regions and itempool. You cannot add or remove items, locations, or regions
after this step. Locations cannot be moved to different regions after this step.
* `set_rules(self)`
called to set access and item rules on locations and entrances.
* `generate_basic(self)`
Expand Down
6 changes: 3 additions & 3 deletions test/general/test_reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ def test_default_all_state_can_reach_everything(self):
state = multiworld.get_all_state(False)
for location in multiworld.get_locations():
if location.name not in excluded:
with self.subTest("Location should be reached", location=location):
with self.subTest("Location should be reached", location=location.name):
self.assertTrue(location.can_reach(state), f"{location.name} unreachable")

for region in multiworld.get_regions():
if region.name in unreachable_regions:
with self.subTest("Region should be unreachable", region=region):
with self.subTest("Region should be unreachable", region=region.name):
self.assertFalse(region.can_reach(state))
else:
with self.subTest("Region should be reached", region=region):
with self.subTest("Region should be reached", region=region.name):
self.assertTrue(region.can_reach(state))

with self.subTest("Completion Condition"):
Expand Down
10 changes: 9 additions & 1 deletion worlds/ladx/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TextShuffle(DefaultOffToggle):
[On] Shuffles all the text in the game
[Off] (default) doesn't shuffle them.
"""
display_name = "Text Shuffle"


class Rooster(DefaultOnToggle, LADXROption):
Expand All @@ -68,7 +69,8 @@ class Boomerang(Choice):
[Normal] requires Magnifying Lens to get the boomerang.
[Gift] The boomerang salesman will give you a random item, and the boomerang is shuffled.
"""

display_name = "Boomerang"

normal = 0
gift = 1
default = gift
Expand Down Expand Up @@ -113,13 +115,15 @@ class APTitleScreen(DefaultOnToggle):


class BossShuffle(Choice):
display_name = "Boss Shuffle"
none = 0
shuffle = 1
random = 2
default = none


class DungeonItemShuffle(Choice):
display_name = "Dungeon Item Shuffle"
option_original_dungeon = 0
option_own_dungeons = 1
option_own_world = 2
Expand Down Expand Up @@ -291,6 +295,7 @@ class Bowwow(Choice):
[Normal] BowWow is in the item pool, but can be logically expected as a damage source.
[Swordless] The progressive swords are removed from the item pool.
"""
display_name = "BowWow"
normal = 0
swordless = 1
default = normal
Expand Down Expand Up @@ -466,6 +471,7 @@ class Music(Choice, LADXROption):
[Shuffled] Shuffled Music
[Off] No music
"""
display_name = "Music"
ladxr_name = "music"
option_vanilla = 0
option_shuffled = 1
Expand All @@ -485,13 +491,15 @@ class WarpImprovements(DefaultOffToggle):
[On] Adds remake style warp screen to the game. Choose your warp destination on the map after jumping in a portal and press B to select.
[Off] No change
"""
display_name = "Warp Improvements"


class AdditionalWarpPoints(DefaultOffToggle):
"""
[On] (requires warp improvements) Adds a warp point at Crazy Tracy's house (the Mambo teleport spot) and Eagle's Tower
[Off] No change
"""
display_name = "Additional Warp Points"

ladx_option_groups = [
OptionGroup("Goal Options", [
Expand Down
10 changes: 10 additions & 0 deletions worlds/musedash/MuseDashData.txt
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,13 @@ Tsukuyomi Ni Naru|74-2|CHUNITHM COURSE MUSE|False|5|7|9|
The wheel to the right|74-3|CHUNITHM COURSE MUSE|True|5|7|9|11
Climax|74-4|CHUNITHM COURSE MUSE|True|4|8|11|11
Spider's Thread|74-5|CHUNITHM COURSE MUSE|True|5|8|10|12
HIT ME UP|43-54|MD Plus Project|True|4|6|8|
Test Me feat. Uyeon|43-55|MD Plus Project|True|3|5|9|
Assault TAXI|43-56|MD Plus Project|True|4|7|10|
No|43-57|MD Plus Project|False|4|6|9|
Pop it|43-58|MD Plus Project|True|1|3|6|
HEARTBEAT! KyunKyun!|43-59|MD Plus Project|True|4|6|9|
SUPERHERO|75-0|Novice Rider Pack|False|2|4|7|
Highway_Summer|75-1|Novice Rider Pack|True|2|4|6|
Mx. Black Box|75-2|Novice Rider Pack|True|5|7|9|
Sweet Encounter|75-3|Novice Rider Pack|True|2|4|7|
7 changes: 4 additions & 3 deletions worlds/musedash/docs/setup_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
## Installing the Archipelago mod to Muse Dash

1. Download [MelonLoader.Installer.exe](https://github.com/LavaGang/MelonLoader/releases/latest) and run it.
2. Choose the automated tab, click the select button and browse to `MuseDash.exe`. Then click install.
2. Choose the automated tab, click the select button and browse to `MuseDash.exe`.
- You can find the folder in steam by finding the game in your library, right clicking it and choosing *Manage→Browse Local Files*.
- If you click the bar at the top telling you your current folder, this will give you a path you can copy. If you paste that into the window popped up by **MelonLoader**, it will automatically go to the same folder.
3. Run the game once, and wait until you get to the Muse Dash start screen before exiting.
4. Download the latest [Muse Dash Archipelago Mod](https://github.com/DeamonHunter/ArchipelagoMuseDash/releases/latest) and then extract that into the newly created `/Mods/` folder in MuseDash's install location.
3. Uncheck "Latest" and select v0.6.1. Then click install.
4. Run the game once, and wait until you get to the Muse Dash start screen before exiting.
5. Download the latest [Muse Dash Archipelago Mod](https://github.com/DeamonHunter/ArchipelagoMuseDash/releases/latest) and then extract that into the newly created `/Mods/` folder in MuseDash's install location.
- All files must be under the `/Mods/` folder and not within a sub folder inside of `/Mods/`

If you've successfully installed everything, a button will appear in the bottom right which will allow you to log into an Archipelago server.
Expand Down
7 changes: 4 additions & 3 deletions worlds/musedash/docs/setup_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
## Instalar el mod de Archipelago en Muse Dash

1. Descarga [MelonLoader.Installer.exe](https://github.com/LavaGang/MelonLoader/releases/latest) y ejecutalo.
2. Elije la pestaña "automated", haz clic en el botón "select" y busca tu `MuseDash.exe`. Luego haz clic en "install".
2. Elije la pestaña "automated", haz clic en el botón "select" y busca tu `MuseDash.exe`.
- Puedes encontrar la carpeta en Steam buscando el juego en tu biblioteca, haciendo clic derecho sobre el y elegir *Administrar→Ver archivos locales*.
- Si haces clic en la barra superior que te indica la carpeta en la que estas, te dará la dirección de ésta para que puedas copiarla. Al pegar esa dirección en la ventana que **MelonLoader** abre, irá automaticamente a esa carpeta.
3. Ejecuta el juego una vez, y espera hasta que aparezca la pantalla de inicio de Muse Dash antes de cerrarlo.
4. Descarga la última version de [Muse Dash Archipelago Mod](https://github.com/DeamonHunter/ArchipelagoMuseDash/releases/latest) y extraelo en la nueva carpeta creada llamada `/Mods/`, localizada en la carpeta de instalación de Muse Dash.
3. Desmarca "Latest" y selecciona v0.6.1. Luego haz clic en "install".
4. Ejecuta el juego una vez, y espera hasta que aparezca la pantalla de inicio de Muse Dash antes de cerrarlo.
5. Descarga la última version de [Muse Dash Archipelago Mod](https://github.com/DeamonHunter/ArchipelagoMuseDash/releases/latest) y extraelo en la nueva carpeta creada llamada `/Mods/`, localizada en la carpeta de instalación de Muse Dash.
- Todos los archivos deben ir directamente en la carpeta `/Mods/`, y NO en una subcarpeta dentro de la carpeta `/Mods/`

Si todo fue instalado correctamente, un botón aparecerá en la parte inferior derecha del juego una vez abierto, que te permitirá conectarte al servidor de Archipelago.
Expand Down
9 changes: 9 additions & 0 deletions worlds/oot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ class OOTWorld(World):
"Adult Trade Item": {"Pocket Egg", "Pocket Cucco", "Cojiro", "Odd Mushroom",
"Odd Potion", "Poachers Saw", "Broken Sword", "Prescription",
"Eyeball Frog", "Eyedrops", "Claim Check"},
"Keys": {"Small Key (Bottom of the Well)", "Small Key (Fire Temple)", "Small Key (Forest Temple)",
"Small Key (Ganons Castle)", "Small Key (Gerudo Training Ground)", "Small Key (Shadow Temple)",
"Small Key (Spirit Temple)", "Small Key (Thieves Hideout)", "Small Key (Water Temple)",
"Small Key Ring (Bottom of the Well)", "Small Key Ring (Fire Temple)",
"Small Key Ring (Forest Temple)", "Small Key Ring (Ganons Castle)",
"Small Key Ring (Gerudo Training Ground)", "Small Key Ring (Shadow Temple)",
"Small Key Ring (Spirit Temple)", "Small Key Ring (Thieves Hideout)", "Small Key Ring (Water Temple)",
"Boss Key (Fire Temple)", "Boss Key (Forest Temple)", "Boss Key (Ganons Castle)",
"Boss Key (Shadow Temple)", "Boss Key (Spirit Temple)", "Boss Key (Water Temple)"},
}

location_name_groups = build_location_name_groups()
Expand Down
Loading

0 comments on commit 08c59d6

Please sign in to comment.