Skip to content

Commit

Permalink
Merge pull request #287 from anthony5301/Reconnect_test
Browse files Browse the repository at this point in the history
Reconnect when the game failed to connect
  • Loading branch information
anthony5301 authored Jan 16, 2024
2 parents 287f060 + b2f439e commit 6628496
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
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

0 comments on commit 6628496

Please sign in to comment.