Skip to content

Commit

Permalink
Reveal lobby, only op.gg supported for now
Browse files Browse the repository at this point in the history
  • Loading branch information
lipeeeee committed Feb 2, 2024
1 parent 0a4e3a6 commit 010de2a
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 13 deletions.
12 changes: 9 additions & 3 deletions sightstone/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
}

"""Multi-Search available websites"""
REVEAL_LOBBY_WEBSITES = [SC.OP_GG, SC.U_GG, SC.PORO_GG, SC.POROFESSOR_GG]
REVEAL_LOBBY_WEBSITES = [SC.OP_GG]

def info_label(sightstone_hook: Sightstone):
"""Returns info label(top label) with sightstone info"""
Expand Down Expand Up @@ -66,8 +66,10 @@ def init_gui(sightstone_hook: Sightstone):
dpg.add_button(label="Dodge", callback=sightstone_hook.dodge_lobby)
dpg.add_button(
label="Reveal Lobby",
callback=sightstone_hook.reveal_lobby,
indent=INDENT_BUTTONS_GROUP_4)
indent=INDENT_BUTTONS_GROUP_4,
callback=lambda:sightstone_hook.open_website_on_reveal(
website=dpg.get_value("revealWebsite"), query=sightstone_hook.transform_participants_into_query(
sightstone_hook.reveal_lobby())))
dpg.add_combo(tag="revealWebsite", width=139, items=REVEAL_LOBBY_WEBSITES, default_value=REVEAL_LOBBY_WEBSITES[0])
dpg.add_checkbox(label="Auto Accept", callback=sightstone_hook.toggle_accept_listener, indent=INDENT_BUTTONS_GROUP_4 * 3)

Expand Down Expand Up @@ -212,6 +214,10 @@ def init_gui(sightstone_hook: Sightstone):
callback=lambda:sightstone_hook.set_positions(
ROLE_TO_INT_MAPPING[dpg.get_value("pos1")],
ROLE_TO_INT_MAPPING[dpg.get_value("pos2")]))
dpg.add_button(label="Reveal Lobby",
callback=lambda:sightstone_hook.open_website_on_reveal(
website=dpg.get_value("revealWebsite"), query=sightstone_hook.transform_participants_into_query(
set(["lipe#69420", "MISSING KERIA ON#000", "naive#444", "wolfs child#EUW"]))))
dpg.set_primary_window("p1", True)

# safe title for riot detection sake
Expand Down
60 changes: 54 additions & 6 deletions sightstone/lca_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ def auth(self):
"""Auth tuple (username, remoting_auth_token)"""
return (self.username, self.remoting_auth_token)

@property
def lcu_header(self):
"""LCU header"""
return self.make_header(self.port, self.remoting_auth_token)

@property
def install_dir(self):
"""League install directory"""
Expand Down Expand Up @@ -141,6 +146,11 @@ def riot_token(self):
def riot_auth(self):
"""Riot auth tuple"""
return (self.username, self.riot_token)

@property
def riot_header(self):
"""Riot http request header"""
return self.make_header(self.riot_port, self.riot_token)

@property
def league_version(self) -> tuple[int, int, int, int] | None:
Expand All @@ -155,9 +165,32 @@ def league_version(self) -> tuple[int, int, int, int] | None:
except Exception as e:
print(f"ERROR: COULD NOT GET LEAGUE VERSION: {e}")

def build_url(self, path: str) -> str:
def make_header(self, port: str, token: str):
"""Dynamic make header function for riot-level acess or just LCU"""
header = {
"Host": f"{self.base_url}:{port}",
"Connection": "keep-alive",
"Authorization": f"Basic {token}",
"Accept": "application/json",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Origin": self.base_url,
"Content-Type": "application/json",
"Origin": f"{self.protocol}://{self.base_url}:{port}",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-User": "?F",
"User-Agent": f"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) RiotClient/{self.league_version} (CEF 74) Safari/537.36",
"sec-ch-ua": "Chromium",
"Referer": f"{self.protocol}://{self.base_url}:{port}/index.html",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9"
}
return header

def build_url(self, path: str, port: str) -> str:
"""Build request url"""
return f"{self.protocol}://{self.base_url}:{self.port}/{path}"
return f"{self.protocol}://{self.base_url}:{port}/{path}"

def listen(self) -> None:
"""Listens to the status of `LCA`
Expand All @@ -179,6 +212,7 @@ def listen(self) -> None:
print(f"INSTALL-DIR: {self.install_dir}")
print(f"LEAGUE-EXE: {self.app_name}")
print(f"FILEINFO: {self.league_version}")
print(f"REGION: {self.region}")
print("--------")

# Slow down requests if we are connected
Expand Down Expand Up @@ -209,18 +243,32 @@ def get(self, path: str) -> Response | None:
return None

try:
return requests.get(self.build_url(path), auth=self.auth, verify=False)
return requests.get(self.build_url(path, self.port), auth=self.auth, verify=False)
except Exception:
return None

def riot_get(self, path: str) -> Response | None:
"""Riot-Level Get request"""
if not self.connected:
return None

try:
response = requests.get(
self.build_url(path, self.riot_port),
auth=self.riot_auth, verify=False,
headers=self.riot_header)
return response
except Exception as e:
print(f"ERROR IN RIOT_GET: {e}")

def post(self, path: str, data: dict | None = None, json: dict | None = None) -> Response | None:
"""Post into LCA"""
if not self.connected:
return None

try:
return requests.post(
self.build_url(path),
self.build_url(path, self.port),
data=data, json=json,
auth=self.auth, verify=False
)
Expand All @@ -234,7 +282,7 @@ def put(self, path: str, data: dict | None = None, json: dict | None = None) ->

try:
return requests.put(
self.build_url(path),
self.build_url(path, self.port),
data=data, json=json,
auth=self.auth, verify=False
)
Expand All @@ -248,7 +296,7 @@ def delete(self, path: str, data: dict | None = None, json: dict | None = None)

try:
return requests.delete(
self.build_url(path),
self.build_url(path, self.port),
data=data, json=json,
auth=self.auth, verify=False)
except Exception:
Expand Down
38 changes: 34 additions & 4 deletions sightstone/sightstone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Main cheat engine

import requests
import webbrowser
from lca_hook import LeagueConnection
from lib.background_thread import BackgroundThread
import sightstone_constants as SC
Expand Down Expand Up @@ -39,8 +40,6 @@ def get_queues(self) -> bool:
response = self.lca_hook.get(
path="lol-game-queues/v1/queues/"
)
if response:
print(response.json())
return self.is_valid_response(response)

def create_lobby(self, lobby_id: str, custom: dict | None = None) -> bool:
Expand Down Expand Up @@ -100,9 +99,29 @@ def queue_accept(self):

def reveal_lobby(self):
"""Reveal ranked teamates"""
response = self.lca_hook.get(path="chat/v5/participants/")
response = self.lca_hook.riot_get(path="chat/v5/participants")
if response:
print(response.json())
summNames:list[str] = list()
for entry in response.json()["participants"]:
summNames.append(f"{entry['game_name']}#{entry['game_tag']}")
return set(summNames[-5:]) # Get last 5

def open_website_on_reveal(self, website, query):
"""Opens lobby checking website with a given query"""
if not query:
return

# compile url with query
url = None
match website:
case SC.OP_GG:
url = f"https://{self.lca_hook.region}.op.gg/multi/query={query}"
case SC.U_GG:
query = query.replace("%23", "-")
url = f"https://u.gg/multisearch?summoners={query}&region={str(self.lca_hook.region).lower()}"

if url:
webbrowser.open(url)

def get_available_bots(self):
"""Gets available bots"""
Expand Down Expand Up @@ -135,6 +154,16 @@ def get_current_user(self):

return None

def transform_participants_into_query(self, participants: set[str] | None):
"""Transforms the return of reveal lobby(list(name#tag)) into a URL readable format"""
if not participants:
return None

query: str = ""
for participant in participants:
query += participant.replace("#", "%23") + ","
return query[:-1]

def create_lobby_with_positions(self, lobby_id: str, pos1: str, pos2: str) -> bool:
"""Creates league lobby with set positions"""
return self.create_lobby(lobby_id) and self.set_positions(pos1, pos2)
Expand All @@ -158,6 +187,7 @@ def custom_game_json(self, game_mode: str, team_size: int, map_code: int) -> dic
},
"isCustom":True
}

def is_valid_response(self, response: requests.Response | None):
"""Checks if the response is valid"""
return not (response is None or response.status_code in (204, 500))
Expand Down

0 comments on commit 010de2a

Please sign in to comment.