-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlol_queue.py
More file actions
114 lines (100 loc) · 3.63 KB
/
lol_queue.py
File metadata and controls
114 lines (100 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import sys
import time
import psutil
import urllib3
import requests
from pathlib import Path
from typing import Literal
from colorama import init, Fore
init()
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def print_info(msg, color: str, sleep_time: int = 0, message_type: Literal['info', 'warning', 'error'] = 'info'):
if sleep_time > 0:
for i in range(sleep_time, 0, -1):
sys.stdout.write(f"\r{color}[{message_type.upper()}]{Fore.RESET} {msg} [{Fore.CYAN}{i}s{Fore.RESET}]" + " "*20)
sys.stdout.flush()
time.sleep(1)
else:
sys.stdout.write(f"\r{color}[{message_type.upper()}]{Fore.RESET} {msg}" + " "*20)
sys.stdout.flush()
def find_lockfile():
for proc in psutil.process_iter(['name']):
if proc.info['name'] == 'LeagueClient.exe':
lc_path = Path(proc.exe()).parent
lockfile_path = lc_path / 'lockfile'
if lockfile_path.exists():
return lockfile_path
return None
def parse_lockfile(path):
try:
with open(path, 'r') as f:
content = f.read()
parts = content.split(':')
return {
"name": parts[0],
"pid": parts[1],
"port": parts[2],
"password": parts[3],
"protocol": parts[4]
}
except:
return None
def get_session(lock):
url = f"https://127.0.0.1:{lock['port']}"
session = requests.Session()
session.verify = False
session.auth = ('riot', lock['password'])
return session, url
def check_ready_check(session, url):
endpoint = f"{url}/lol-matchmaking/v1/ready-check"
resp = session.get(endpoint)
if resp.status_code == 200:
data = resp.json()
return data
return None
def accept_match(session, url):
endpoint = f"{url}/lol-matchmaking/v1/ready-check/accept"
resp = session.post(endpoint)
return resp.status_code == 204
def is_ingame(session, url):
endpoint = f"{url}/lol-gameflow/v1/session"
try:
resp = session.get(endpoint)
if resp.status_code == 200:
data = resp.json()
phase = data.get("phase", "")
return phase == "InProgress"
except:
pass
return False
def main():
while True:
lockfile = find_lockfile()
if not lockfile:
print_info("Waiting for LeagueClient.exe to start...", Fore.RED, sleep_time=15, message_type='error')
lock = parse_lockfile(lockfile)
if not lock:
continue
session, url = get_session(lock)
print_info("Waiting for queue...", Fore.YELLOW)
try:
data = check_ready_check(session, url)
if is_ingame(session, url):
print_info("Currently in game, waiting the end of the match...", Fore.YELLOW, sleep_time=30)
continue
if data:
state = data.get("state")
if state == "InProgress":
print_info("Match found! Accepting...", Fore.YELLOW)
if accept_match(session, url):
print_info("Match accepted successfully!", Fore.GREEN, sleep_time=3)
else:
print_info("Failed to accept match.", Fore.RED, sleep_time=3)
else:
print_info(f"Currently in queue, waiting for match...", Fore.CYAN, sleep_time=3)
else:
print_info("Waiting for queue to start...", Fore.YELLOW, sleep_time=6)
except KeyboardInterrupt:
print_info("Manual script termination.", Fore.RED, sleep_time=2)
if __name__ == "__main__":
main()