Archipelago/worlds
Bryce Wilson 0d38b41540
BizHawkClient: Add support for multiple concurrent instances (#2475)
This allows multiple client/connector pairs to run at the same time. It also includes a few other miscellaneous small changes that accumulated as I went. They can be split if desired

- Whatever the `client_socket:send` line (~440) was doing with that missing operator, it's no longer doing. Don't ask me how it was working before. Lua is witchcraft.
- Removed the `settimeout(2)` which causes the infamous emulator freeze (and replaced it with a `settimeout(0)` when the server socket is created). It appears to be unnecessary to set a timeout for discovering a client. Maybe at some point in time it was useful to keep the success rate for connecting high, but it seems to not be a problem if the timeout is 0 instead.
  - Also updated the Emerald setup to remove mention of the freezing.
- Connector script now picks the first port that's not in use in a range of 5 ports.
  - To summarize why I was previously under the impression that multiple running scripts would not detect when a port was in use:
    1. Calling `socket.bind` in the existing script will first create an ipv6 socket.
    2. A second concurrent script trying to bind to the same port would I think fail to create an ipv6 socket but then succeed in creating an ipv4 socket on the same port.
    3. That second socket could never communicate with a client; extra clients would just bounce off the first script.
    4. The third concurrent script will then fail on both and actually give an `address already in use` error.  
  - I'm not _really_ sure what's going on there. But forcing one or the other by calling `socket.tcp4()` or `socket.tcp6()` means that only one script will believe it has the port while any others will give `address already in use` as you'd expect.
  - As a side note, our `socket.lua` is much wonkier than I had previously thought. I understand some parts were added for LADX and when BizHawk 2.9 came out, but as far back as the file's history in this repo, it has provided a strange, modified interface as compared to the file it was originally derived from, to no benefit as far as I can tell.
- The connector script closes `server` once it finds a client and opens a new one if the connection drops. I'm not sure this ultimately has an effect, but it seems more proper.
- If the connector script's main function returns because of some error or refusal to proceed, the script no longer tries to resume the coroutine it was part of, which would flood the log with irrelevant errors.
- Creating `SyncError`s in `guarded_read` and `guarded_write` would raise its own error because the wrong variable was being used in its message.
- A call to `_bizhawk.connect` can take a while as the client tries the possible ports. There's a modification that will wait on either the `connect` or the exit event. And if the exit event fires while still looking for a connector script, this cancels the `connect` so the window can close.
  - Related: It takes 2-3 seconds for a call to `asyncio.open_connection` to come back with any sort of response on my machine, which can be significant now that we're trying multiple ports in sequence. I guess it could fire off 5 tasks at once. Might cause some weirdness if there exist multiple scripts and multiple clients looking for each other at the same time.
  - Also related: The first time a client attempts to connect to a script, they accept each other and start communicating as expected. The second client to try that port seems to believe it connects and will then time out on the first message. And then all subsequent attempts to connect to that port by any client will be refused (as expected) until the script shuts down or restarts. I haven't been able to explain this behavior. It adds more time to a client's search for a script, but doesn't ultimately cause problems.
2023-11-23 15:00:46 +01:00
..
_bizhawk BizHawkClient: Add support for multiple concurrent instances (#2475) 2023-11-23 15:00:46 +01:00
_sc2common
adventure Core: deprecate Utils.get_options and remove Utils.get_default_options (#2352) 2023-10-28 19:32:12 +02:00
alttp LttP: write fairy bottle fill to spoiler and prevent fart in a bottle (#2424) 2023-11-13 06:50:45 +01:00
archipidle Core: make state.prog_items a `Dict[int, Counter[str]]` (#2407) 2023-11-02 06:41:20 +01:00
bk_sudoku
blasphemous
bumpstik
checksfinder ChecksFinder: Tweak link in ChecksFinder (#2353) 2023-11-07 11:31:06 -06:00
clique
dark_souls_3 Allow worlds to provide item and location descriptions (#2409) 2023-11-11 01:06:54 -05:00
dkc3
dlcquest DLC Quest Stardew: bug (#2423) 2023-11-06 06:01:49 +01:00
doom_1993
factorio Factorio: Update icons to match vanilla style (#2449) 2023-11-15 03:15:37 +01:00
ff1 Docs, Various Games: Add Unique Local Commands to Game Page (#2285) 2023-10-31 17:20:24 -04:00
generic
hk Hollow Knight: Don't force mimics local (#2482) 2023-11-22 08:15:09 -06:00
hylics2 Hylics 2: Unique entrance names, fix APWorld on 3.8 (#2460) 2023-11-15 07:03:40 +01:00
kh2
ladx LADX: Text shuffle (#2051) 2023-11-22 08:29:33 -06:00
lingo Lingo: Sync config with game update (#2447) 2023-11-16 04:12:44 -06:00
lufia2ac lufia2ac: improve performance of access rules (#2456) 2023-11-15 03:11:02 +01:00
meritous
messenger The Messenger: fix logic rule for spike darts and power seal hunt (#2414) 2023-11-11 05:49:55 +01:00
minecraft minecraft: avoid duplicate prefix in output file name (#2048) 2023-10-28 21:43:09 +02:00
mmbn3 MMBN3: Adds instructions for using the Legacy Collection ROM for setup (#2120) 2023-11-22 09:45:32 -06:00
musedash Muse Dash: Rename some Trap Items to match the wider community name (#2180) 2023-11-16 04:33:56 -06:00
noita
oot OoT: fix incorrect calls to sweep_for_events (#2417) 2023-11-02 20:02:38 +01:00
overcooked2 OC2: fix mistakes when moving to new options api (#2332) 2023-10-20 01:36:18 +02:00
pokemon_emerald BizHawkClient: Add support for multiple concurrent instances (#2475) 2023-11-23 15:00:46 +01:00
pokemon_rb Docs, Various Games: Add Unique Local Commands to Game Page (#2285) 2023-10-31 17:20:24 -04:00
raft Raft: Use world.random instead of global random (#2439) 2023-11-09 08:47:36 +01:00
rogue_legacy Rogue Legacy: Fix a preset including an option that prevents generation. (#2473) 2023-11-22 10:42:21 -06:00
ror2 RoR2: 1.3.0 content update (#2425) 2023-11-22 09:20:32 -06:00
sa2b SA2B: v2.3 - The Chao Update (#2277) 2023-11-16 08:08:38 +01:00
sc2wol SC2: 0.4.3 bugfixes (#2273) 2023-11-08 12:00:55 -06:00
sm SM: fix missed SMWorld.spheres in #2400 (#2419) 2023-11-02 21:08:36 +01:00
sm64ex
smw
smz3 Core: make state.prog_items a `Dict[int, Counter[str]]` (#2407) 2023-11-02 06:41:20 +01:00
soe Core: change Region caching to on_change from on-miss-strategy (#2366) 2023-10-29 19:47:37 +01:00
spire
stardew_valley Stardew Valley: Generate proper filler for item links (#2069) 2023-11-22 10:04:33 -06:00
subnautica
terraria Docs: Terraria Setup Guide added information about the Upgraded Research Mod (#2338) 2023-11-01 16:08:04 -05:00
timespinner Timespinner: New options from TS Rando v1.25 + Logic fix (#2090) 2023-11-22 08:17:33 -06:00
tloz Docs, Various Games: Add Unique Local Commands to Game Page (#2285) 2023-10-31 17:20:24 -04:00
undertale Undertale: Logic fixes (#2436) 2023-11-08 11:50:29 -06:00
v6
wargroove Wargroove: Fixed WargrooveClient retaining victory and location information and minor doc fix (#2464) 2023-11-16 04:35:20 -06:00
witness The Witness: Fix Town Tower 4th Door Logic (#2421) 2023-11-07 07:39:36 +01:00
zillion Docs, Various Games: Add Unique Local Commands to Game Page (#2285) 2023-10-31 17:20:24 -04:00
AutoSNIClient.py
AutoWorld.py WebHost, Core: Developer-defined game option presets. (#2143) 2023-11-16 04:37:06 -06:00
Files.py Core: limit parallel APContainer writing (#2443) 2023-11-13 06:46:40 +01:00
LauncherComponents.py
__init__.py WebHost: Refactor `tracker.py`, removal of dead code, and tweaks to layouts of some tracker pages. (#2438) 2023-11-18 12:29:35 -06:00