diff --git a/dzgui/api/steam.py b/dzgui/api/steam.py index 668def6..50786b8 100644 --- a/dzgui/api/steam.py +++ b/dzgui/api/steam.py @@ -151,7 +151,9 @@ def get_remote_signatures(mods: list[str]) -> list[tuple[str, str, int, int]]: return hashes -def connect_debug(client: str, addr: str, appid: int, name: str, mods: list[str]) -> str: +def connect_debug( + client: str, addr: str, appid: int, name: str, mods: list[str] +) -> str: concat = concat_mods(mods) client_args = concat_bash_args(client) params = [ @@ -167,6 +169,7 @@ def connect_debug(client: str, addr: str, appid: int, name: str, mods: list[str] client_args.extend(params) return " ".join(client_args) + # TODO: set config to name=user, use official server and no mods, # ensure that formatted string is identical to fixture with same hash def connect(client: str, addr: str, appid: int, name: str, mods: list[str]) -> int: @@ -235,14 +238,19 @@ def find_user_id(path: Path) -> str | None: try: with open(resolved_path, "r") as f: v = vdf.load(f) - # NOTE: beta client - # /package/beta - if len(v["users"]) == 1: - return str(list(v["users"].keys())[0]) - for user in v["users"]: - if v["users"][user]["MostRecent"] == "1": - return str(user) - return None + users = v["users"] + # NOTE: beta client: /package/beta + last_user = next(iter(users)) + if len(users) == 1: + return last_user + last_stamp = int(users[last_user]["Timestamp"]) + for user in users: + stamp = int(users[user]["Timestamp"]) + if stamp > last_stamp: + last_stamp = stamp + last_user = user + print(last_user) + return last_user except Exception as e: logger.debug(e) return None diff --git a/tests/fixtures/api/loginusers_beta_client_multiple.vdf b/tests/fixtures/api/loginusers_beta_client_multiple.vdf new file mode 100644 index 0000000..bc56e12 --- /dev/null +++ b/tests/fixtures/api/loginusers_beta_client_multiple.vdf @@ -0,0 +1,23 @@ +"users" +{ + "0" + { + "AccountName" "STEAMUSER" + "PersonaName" "STEAMUSER" + "RememberPassword" "0" + "WantsOfflineMode" "0" + "SkipOfflineModeWarning" "0" + "AutoLogin" "1" + "Timestamp" "1787904411" + } + "1" + { + "AccountName" "STEAMUSER2" + "PersonaName" "STEAMUSER2" + "RememberPassword" "0" + "WantsOfflineMode" "0" + "SkipOfflineModeWarning" "0" + "AutoLogin" "1" + "Timestamp" "1787904647" + } +} diff --git a/tests/fixtures/api/loginusers_beta_client_multiple_2.vdf b/tests/fixtures/api/loginusers_beta_client_multiple_2.vdf new file mode 100644 index 0000000..7975bde --- /dev/null +++ b/tests/fixtures/api/loginusers_beta_client_multiple_2.vdf @@ -0,0 +1,23 @@ +"users" +{ + "0" + { + "AccountName" "STEAMUSER" + "PersonaName" "STEAMUSER" + "RememberPassword" "0" + "WantsOfflineMode" "0" + "SkipOfflineModeWarning" "0" + "AutoLogin" "1" + "Timestamp" "1797904411" + } + "1" + { + "AccountName" "STEAMUSER2" + "PersonaName" "STEAMUSER2" + "RememberPassword" "0" + "WantsOfflineMode" "0" + "SkipOfflineModeWarning" "0" + "AutoLogin" "1" + "Timestamp" "1787904647" + } +} diff --git a/tests/fixtures/api/loginusers_legacy_client_multiple.vdf b/tests/fixtures/api/loginusers_legacy_client_multiple.vdf index e353f75..8a4a3b2 100644 --- a/tests/fixtures/api/loginusers_legacy_client_multiple.vdf +++ b/tests/fixtures/api/loginusers_legacy_client_multiple.vdf @@ -20,6 +20,6 @@ "SkipOfflineModeWarning" "0" "AllowAutoLogin" "1" "MostRecent" "1" - "Timestamp" "0" + "Timestamp" "10" } } diff --git a/tests/test_loginusers.py b/tests/test_loginusers.py index 34864dd..6665e79 100644 --- a/tests/test_loginusers.py +++ b/tests/test_loginusers.py @@ -14,6 +14,8 @@ pytestmark = pytest.mark.apitest ("api/loginusers_legacy_client.vdf", 0), ("api/loginusers_legacy_client_multiple.vdf", 1), ("api/loginusers_beta_client.vdf", 0), + ("api/loginusers_beta_client_multiple.vdf", 1), + ("api/loginusers_beta_client_multiple_2.vdf", 0), ], ) def test_loginusers(monkeypatch, fixture: str, expect: int) -> None: