Skip to content

Commit

Permalink
Core: have webhost slot name links go through the launcher so that co…
Browse files Browse the repository at this point in the history
…mponents can use them
  • Loading branch information
alwaysintreble committed Jan 29, 2024
1 parent 70fdd6b commit 96f7fb5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CommonClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,8 @@ def get_base_parser(description: typing.Optional[str] = None):
return parser


def run_as_textclient():
def run_as_textclient(*args):
logger.info(args)
class TextContext(CommonContext):
# Text Mode to use !hint and such with games that have no text entry
tags = CommonContext.tags | {"TextOnly"}
Expand Down
34 changes: 30 additions & 4 deletions Launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
import shlex
import subprocess
import sys
import urllib.parse
import webbrowser
from os.path import isfile
from shutil import which
from typing import Sequence, Union, Optional
from typing import Sequence, Tuple, Union, Optional

import Utils
import settings
Expand Down Expand Up @@ -107,9 +108,24 @@ def update_settings():
])


def identify(path: Union[None, str]):
def identify(path: Union[None, str]) -> Tuple[Union[None, str], Union[None, Component]]:
if path is None:
return None, None
if path.startswith("archipelago://"):
logging.info("found uri")
queries = urllib.parse.parse_qs(path)
if "game" in queries:
game = urllib.parse.parse_qs(path)["game"][0]
else: # TODO around 0.5.0 - this is for pre this change webhost uri's
game = "Archipelago"
logging.info(game)
for component in components:
if component.supports_uri and component.game_name == game:
return path, component
elif component.display_name == "Text Client":
# fallback
text_client_component = component
return path, text_client_component
for component in components:
if component.handles_file(path):
return path, component
Expand Down Expand Up @@ -253,6 +269,15 @@ def run_component(component: Component, *args):
logging.warning(f"Component {component} does not appear to be executable.")


def find_component(game: str) -> Component:
for component in components:
if component.game_name and component.game_name == game:
return component
elif component.display_name == "Text Client":
text_client_component = component
return text_client_component


def main(args: Optional[Union[argparse.Namespace, dict]] = None):
if isinstance(args, argparse.Namespace):
args = {k: v for k, v in args._get_kwargs()}
Expand All @@ -268,11 +293,12 @@ def main(args: Optional[Union[argparse.Namespace, dict]] = None):
if not component:
logging.warning(f"Could not identify Component responsible for {args['Patch|Game|Component']}")


if args["update_settings"]:
update_settings()
if 'file' in args:
if "file" in args:
run_component(args["component"], args["file"], *args["args"])
elif 'component' in args:
elif "component" in args:
run_component(args["component"], *args["args"])
elif not args["update_settings"]:
run_gui()
Expand Down
2 changes: 1 addition & 1 deletion WebHostLib/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{% for patch in room.seed.slots|list|sort(attribute="player_id") %}
<tr>
<td>{{ patch.player_id }}</td>
<td data-tooltip="Connect via TextClient"><a href="archipelago://{{ patch.player_name | e}}:@{{ config['HOST_ADDRESS'] }}:{{ room.last_port }}">{{ patch.player_name }}</a></td>
<td data-tooltip="Connect via TextClient"><a href="archipelago://{{ patch.player_name | e}}:@{{ config['HOST_ADDRESS'] }}:{{ room.last_port }}?game={{ patch.game }}&room={{ room.id }}">{{ patch.player_name }}</a></td>
<td>{{ patch.game }}</td>
<td>
{% if patch.data %}
Expand Down
4 changes: 2 additions & 2 deletions inno_setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ Root: HKCR; Subkey: "{#MyAppName}multidata\shell\open\command"; ValueData: """{

Root: HKCR; Subkey: "archipelago"; ValueType: "string"; ValueData: "Archipegalo Protocol"; Flags: uninsdeletekey;
Root: HKCR; Subkey: "archipelago"; ValueType: "string"; ValueName: "URL Protocol"; ValueData: "";
Root: HKCR; Subkey: "archipelago\DefaultIcon"; ValueType: "string"; ValueData: "{app}\ArchipelagoTextClient.exe,0";
Root: HKCR; Subkey: "archipelago\shell\open\command"; ValueType: "string"; ValueData: """{app}\ArchipelagoTextClient.exe"" ""%1""";
Root: HKCR; Subkey: "archipelago\DefaultIcon"; ValueType: "string"; ValueData: "{app}\ArchipelagoLauncher.exe,0";
Root: HKCR; Subkey: "archipelago\shell\open\command"; ValueType: "string"; ValueData: """{app}\ArchipelagoLauncher.exe"" ""%1""";

[Code]
// See: https://stackoverflow.com/a/51614652/2287576
Expand Down
11 changes: 8 additions & 3 deletions worlds/LauncherComponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ class Component:
cli: bool
func: Optional[Callable]
file_identifier: Optional[Callable[[str], bool]]
game_name: Optional[str]
supports_uri: Optional[bool]

def __init__(self, display_name: str, script_name: Optional[str] = None, frozen_name: Optional[str] = None,
cli: bool = False, icon: str = 'icon', component_type: Optional[Type] = None,
func: Optional[Callable] = None, file_identifier: Optional[Callable[[str], bool]] = None):
func: Optional[Callable] = None, file_identifier: Optional[Callable[[str], bool]] = None,
game_name: Optional[str] = None, supports_uri: Optional[bool] = False):
self.display_name = display_name
self.script_name = script_name
self.frozen_name = frozen_name or f'Archipelago{script_name}' if script_name else None
Expand All @@ -42,6 +45,8 @@ def __init__(self, display_name: str, script_name: Optional[str] = None, frozen_
Type.ADJUSTER if "Adjuster" in display_name else Type.MISC)
self.func = func
self.file_identifier = file_identifier
self.game_name = game_name
self.supports_uri = supports_uri

def handles_file(self, path: str):
return self.file_identifier(path) if self.file_identifier else False
Expand Down Expand Up @@ -72,9 +77,9 @@ def __call__(self, path: str):
return False


def launch_textclient():
def launch_textclient(*args):
import CommonClient
launch_subprocess(CommonClient.run_as_textclient, name="TextClient")
launch_subprocess(CommonClient.run_as_textclient(*args), name="TextClient")


components: List[Component] = [
Expand Down

0 comments on commit 96f7fb5

Please sign in to comment.