Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect when the game failed to connect #287

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions auto_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def check_game_status(client_info: tuple) -> bool:
timeout=10,
verify=False,
)
return status.json()["phase"] == "InProgress"
return status.json().get("phase", "None")
except ConnectionError:
return False

Expand Down Expand Up @@ -124,9 +124,25 @@ def get_client() -> tuple:
return (remoting_auth_token, server_url)


def reconnect(client_info: tuple) -> None:
"""Reconnect to game when "Failed to Connect" windows are found"""
requests.post(
f"{client_info[1]}/lol-gameflow/v1/reconnect",
auth=HTTPBasicAuth('riot', client_info[0]),
timeout=10,
verify=False,
)


def queue() -> None:
"""Function that handles getting into a game"""
client_info: tuple = get_client()
while check_game_status(client_info) == "InProgress":
sleep(1)
if check_game_status(client_info) == "Reconnect":
print(" Reconnecting")
reconnect(client_info)
return
while not create_lobby(client_info):
sleep(3)

Expand All @@ -148,7 +164,7 @@ def queue() -> None:
sleep(5)
start_queue(client_info)
accept_queue(client_info)
if check_game_status(client_info):
if check_game_status(client_info) == "InProgress":
in_queue = False
sleep(1)
time += 1
19 changes: 19 additions & 0 deletions game.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from time import sleep, perf_counter
import random
import multiprocessing
from win32con import BM_CLICK
import win32gui
import settings
import arena_functions
Expand Down Expand Up @@ -60,10 +61,28 @@ def loading_screen(self) -> None:
"""Loop that runs while the game is in the loading screen"""
game_functions.default_pos()
while game_functions.get_round() != "1-1":
if self.check_failed_to_connect_window():
return
sleep(1)
self.start_time: float = perf_counter()
self.game_loop()

def check_failed_to_connect_window(self) -> bool:
"""Check "Failed to Connect" windows and try to reconnect"""
hwnd = win32gui.FindWindow(None, "Failed to Connect")
if hwnd:
print(" Found \"Failed to Connect\" window, trying to exit and reconnect")
if reconnect_button := win32gui.FindWindowEx(hwnd, 0, "Button", None):
if cancel_button := win32gui.FindWindowEx(hwnd, reconnect_button, "Button", None):
print(" Exiting the game.")
win32gui.SendMessage(cancel_button, BM_CLICK, 0, 0)
return True
print(" Cancel button not found.")
else:
print(" Reconnect button not found.")
return False


def game_loop(self) -> None:
"""Loop that runs while the game is active, handles calling the correct tasks for round and exiting game"""
ran_round: str = None
Expand Down