From 61820f1670fee294106028840c4fec12185d48e0 Mon Sep 17 00:00:00 2001 From: Salad Dais Date: Tue, 19 Dec 2023 04:24:17 +0000 Subject: [PATCH] Better handling of client start locations --- .github/workflows/pytest.yml | 2 +- client_examples/hello_client.py | 2 +- hippolyzer/lib/client/hippo_client.py | 20 ++++++++++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index d4c01c2..ef47a93 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -26,7 +26,7 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip + python -m pip install --upgrade pip wheel pip install -r requirements.txt pip install -r requirements-test.txt sudo apt-get install libopenjp2-7 diff --git a/client_examples/hello_client.py b/client_examples/hello_client.py index 2b2b63e..01b4401 100644 --- a/client_examples/hello_client.py +++ b/client_examples/hello_client.py @@ -27,7 +27,7 @@ async def amain(): await client.login( username=os.environ["HIPPO_USERNAME"], password=os.environ["HIPPO_PASSWORD"], - start_location=os.environ.get("HIPPO_START_LOCATION", "home"), + start_location=os.environ.get("HIPPO_START_LOCATION", "last"), ) print("I'm here") await client.send_chat("Hello World!", chat_type=ChatType.SHOUT) diff --git a/hippolyzer/lib/client/hippo_client.py b/hippolyzer/lib/client/hippo_client.py index 163e060..43e2c84 100644 --- a/hippolyzer/lib/client/hippo_client.py +++ b/hippolyzer/lib/client/hippo_client.py @@ -12,7 +12,7 @@ from typing import * import aiohttp import multidict -from hippolyzer.lib.base.datatypes import Vector3 +from hippolyzer.lib.base.datatypes import Vector3, StringEnum from hippolyzer.lib.base.helpers import proxify, get_resource_filename from hippolyzer.lib.base.message.circuit import Circuit from hippolyzer.lib.base.message.llsd_msg_serializer import LLSDMessageSerializer @@ -35,6 +35,11 @@ from hippolyzer.lib.client.state import BaseClientSession, BaseClientRegion, Bas LOG = logging.getLogger(__name__) +class StartLocation(StringEnum): + LAST = "last" + HOME = "home" + + class ClientSettings(Settings): # Off by default for now, the cert validation is a big mess due to LL using an internal CA. SSL_VERIFY: bool = SettingDescriptor(False) @@ -568,9 +573,9 @@ class HippoClient(BaseClientSessionManager): self, username: str, password: str, - login_uri: Optional[str] = "", + login_uri: Optional[str] = None, agree_to_tos: bool = False, - start_location: str = "home" + start_location: Union[StartLocation, str, None] = StartLocation.LAST ): if self.session: raise RuntimeError("Already logged in!") @@ -578,6 +583,13 @@ class HippoClient(BaseClientSessionManager): if not login_uri: login_uri = self.DEFAULT_LOGIN_URI + if start_location is None: + start_location = StartLocation.LAST + + # This isn't a symbolic start location and isn't a URI, must be a sim name. + if start_location not in iter(StartLocation) and not start_location.startswith("uri:"): + start_location = f"uri:{start_location}&128&128&128" + split_username = username.split(" ") if len(split_username) < 2: first_name = split_username[0] @@ -603,7 +615,7 @@ class HippoClient(BaseClientSessionManager): # TODO: What is this? "platform_version": "2.38.0", "read_critical": 0, - "start": start_location, + "start": str(start_location), "token": "", "version": version("hippolyzer"), "options": list(self._options),