diff --git a/worlds/animal_well/__init__.py b/worlds/animal_well/__init__.py index 5c43eea73a37..90e3bc3ba14b 100644 --- a/worlds/animal_well/__init__.py +++ b/worlds/animal_well/__init__.py @@ -33,20 +33,21 @@ class TrackerSetting(IntEnum): in_game_tracker: TrackerSetting = TrackerSetting.full_tracker -def launch_client(): +def launch_client(*args): """ Launch the Animal Well Client """ from .client import launch from CommonClient import gui_enabled if gui_enabled: - launch_subprocess(launch, name="AnimalWellClient") + launch_subprocess(launch, name="AnimalWellClient", args=args) else: - launch() + launch(args) components.append(Component("ANIMAL WELL Client", func=launch_client, - component_type=Type.CLIENT, icon="Potate")) + component_type=Type.CLIENT, icon="Potate", + supports_uri=True, game_name="ANIMAL WELL")) icon_paths["Potate"] = f"ap:{__name__}/Potate.png" diff --git a/worlds/animal_well/client.py b/worlds/animal_well/client.py index b745ae476f9b..3dca2461974c 100644 --- a/worlds/animal_well/client.py +++ b/worlds/animal_well/client.py @@ -1495,22 +1495,32 @@ async def console_task(ctx: AnimalWellContext): await asyncio.sleep(1/120) -def launch(): +def launch(args): """ Launch the client """ - async def main(): + async def main(*args): """ main function """ - import sys - args = sys.argv[1:] - if "ANIMAL WELL Client" in args: - args.remove("ANIMAL WELL Client") + import urllib parser = get_base_parser() + parser.add_argument("url", type=str, nargs="?", help="Archipelago Webhost uri to auto connect to.") args = parser.parse_args(args) + # handle if text client is launched using the "archipelago://name:pass@host:port" url from webhost + if args.url: + url = urllib.parse.urlparse(args.url) + if url.scheme == "archipelago": + args.connect = url.netloc + if url.username: + args.name = urllib.parse.unquote(url.username) + if url.password: + args.password = urllib.parse.unquote(url.password) + else: + parser.error(f"bad url, found {args.url}, expected url in form of archipelago://archipelago.gg:38281") + ctx = AnimalWellContext(args.connect, args.password) ctx.server_task = asyncio.create_task(server_loop(ctx), name="ServerLoop") @@ -1548,5 +1558,5 @@ async def main(): import colorama colorama.init() - asyncio.run(main()) + asyncio.run(main(args)) colorama.deinit()