Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
Restart League Client If Disconnected And/or Sending Confusing Messag…
Browse files Browse the repository at this point in the history
…es (#224)

* Restart League Client If Disconnected And/or Sending Confusing Messages

* Bump that actually works

* Additional debugging for rare edge case
Kyrluckechuck authored Nov 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 4fd2c19 commit 37be469
Showing 2 changed files with 44 additions and 11 deletions.
7 changes: 7 additions & 0 deletions tft.py
Original file line number Diff line number Diff line change
@@ -219,6 +219,12 @@ def queue() -> None: # pylint: disable=too-many-branches
if not PLAY_NEXT_GAME:
evaluate_next_game_logic()

if not LCU_INTEGRATION.client_connected():
logger.warning("Client is not connected or sending confusing messages, restarting the client")
restart_league_client()
time.sleep(5)
continue

if LCU_INTEGRATION.session_expired():
logger.warning("Our login session expired, restarting the client")
restart_league_client()
@@ -716,6 +722,7 @@ def update_riot_client_constants(riot_client_install_location: str) -> None:
riot_client_install_location (str): The determined location for the executables
"""
logger.debug(rf"Updating riot client install location to {riot_client_install_location}")
logger.debug(rf"{riot_client_install_location}{CONSTANTS['executables']['riot_client']['client_services']}")
CONSTANTS["executables"]["riot_client"][
"client_services"
] = rf"{riot_client_install_location}{CONSTANTS['executables']['riot_client']['client_services']}"
48 changes: 37 additions & 11 deletions tft_bot/league_api/league_api_integration.py
Original file line number Diff line number Diff line change
@@ -145,22 +145,25 @@ def connect_to_lcu(self, wait_for_availability: bool = False) -> bool:
response.raise_for_status()
logger.debug("Connected to LCUx server.")
break
except requests.exceptions.RequestException:
logger.debug("Can't connect to LCUx server. Retrying...")
except (requests.exceptions.RequestException, requests.exceptions.ConnectionError):
logger.warning("Can't connect to LCUx server. Retrying...")
time.sleep(1)
timeout += 1

logger.info("Successfully connected to the League client")

if wait_for_availability:
availability_timeout = config.get_timeout(config.Timeout.CLIENT_AVAILABILITY, 120)
logger.info(f"Waiting for client availability (~{availability_timeout}s timeout)")
for _ in range(availability_timeout):
availability_response = self._session.get(url=f"{self._url}/lol-gameflow/v1/availability")
if availability_response.status_code == 200 and availability_response.json()["isAvailable"]:
logger.info("Client available, queue logic should start")
return True
time.sleep(1)
try:
availability_timeout = config.get_timeout(config.Timeout.CLIENT_AVAILABILITY, 120)
logger.info(f"Waiting for client availability (~{availability_timeout}s timeout)")
for _ in range(availability_timeout):
availability_response = self._session.get(url=f"{self._url}/lol-gameflow/v1/availability")
if availability_response.status_code == 200 and availability_response.json()["isAvailable"]:
logger.info("Client available, queue logic should start")
return True
time.sleep(1)
except (requests.exceptions.RequestException, requests.exceptions.ConnectionError) as e:
logger.critical(e)
logger.error("Client did not become available. Exiting.")
return False

@@ -335,7 +338,30 @@ def session_expired(self) -> bool:
logger.debug("Checking if our login session is expired")
session_response = _http_error_wrapper(self._session.get, url=f"{self._url}/lol-login/v1/session")

return session_response is not None and session_response.json()["error"] is not None
return session_response.json()["error"] if session_response is not None else None

def client_connected(self) -> bool:
"""
Checks if the client is currently connected / sending understandable responses
Returns:
bool: True if connected, False otherwise
"""
logger.debug("Checking if the client is connected")
try:
availability_response = _http_error_wrapper(
self._session.get, url=f"{self._url}/lol-gameflow/v1/availability"
)
if (
availability_response is not None
and availability_response.status_code == 200
and availability_response.json()["isAvailable"]
):
return True
except (requests.exceptions.RequestException, requests.exceptions.ConnectionError):
logger.warning("Can't determine client was available")

return False

def _get_player_uid(self) -> str | None:
"""

0 comments on commit 37be469

Please sign in to comment.