Skip to content

Commit

Permalink
Valorant acc manager shenaginans (Bug fixes)
Browse files Browse the repository at this point in the history
  • Loading branch information
OwOHamper committed Sep 25, 2023
1 parent fb323e7 commit 93bd736
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/account_manager/account_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def menu(self, account_data):
if account_data != None:
#Logged in as....
if option == 0:
pass
self.start_valorant()
#Change accounts
elif option == 1:
self.menu_change_accounts()
Expand Down
6 changes: 3 additions & 3 deletions src/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def PortError(self, port):
self.log("Port is being blocked by the firewall or in use by another application")
sock.close()

def LockfileError(self, path):

if os.path.exists(path):
def LockfileError(self, path, ignoreLockfile=False):
#ignoring lockfile is for when lockfile exists but it's not really valid, (local endpoints are not initialized yet)
if os.path.exists(path) and ignoreLockfile == False:
return True
else:
self.log("Lockfile does not exist, VALORANT is not open")
Expand Down
47 changes: 37 additions & 10 deletions src/requestsV.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ def __init__(self, version, log, Error):

self.puuid = ''
#fetch puuid so its avaible outside
self.get_headers()
if not self.get_headers(init=True):
self.log("Invalid URI format, invalid lockfile, going back to menu")
self.get_lockfile(ignoreLockfile=True)


@staticmethod
def check_version(version, copy_run_update_script):
Expand Down Expand Up @@ -141,7 +144,7 @@ def fetch(self, url_type: str, endpoint: str, method: str, rate_limit_seconds=5)
else:
break
except ConnectionError:
print("Connection error, retrying in 5 seconds")
self.log("Connection error, retrying in 5 seconds")
time.sleep(5)
if endpoint != "/chat/v4/presences":
self.log(
Expand Down Expand Up @@ -189,24 +192,48 @@ def get_current_version(self):
self.log(f"got version from logs '{version}'")
return version

def get_lockfile(self):
def get_lockfile(self, ignoreLockfile=False):
#ignoring lockfile is for when lockfile exists but it's not really valid, (local endpoints are not initialized yet)
path = os.path.join(os.getenv('LOCALAPPDATA'), R'Riot Games\Riot Client\Config\lockfile')

if self.Error.LockfileError(path):
if self.Error.LockfileError(path, ignoreLockfile=ignoreLockfile):
with open(path) as lockfile:
self.log("opened lockfile")
data = lockfile.read().split(':')
keys = ['name', 'PID', 'port', 'password', 'protocol']
return dict(zip(keys, data))


def get_headers(self, refresh=False):
def get_headers(self, refresh=False, init=False):
if self.headers == {} or refresh:
local_headers = {'Authorization': 'Basic ' + base64.b64encode(
('riot:' + self.lockfile['password']).encode()).decode()}
response = requests.get(f"https://127.0.0.1:{self.lockfile['port']}/entitlements/v1/token",
headers=local_headers, verify=False)
entitlements = response.json()
try_again = True
while try_again:
local_headers = {'Authorization': 'Basic ' + base64.b64encode(
('riot:' + self.lockfile['password']).encode()).decode()}
try:
response = requests.get(f"https://127.0.0.1:{self.lockfile['port']}/entitlements/v1/token",
headers=local_headers, verify=False)
self.log(f"https://127.0.0.1:{self.lockfile['port']}/entitlements/v1/token\n{local_headers}")
except ConnectionError:
self.log(f"https://127.0.0.1:{self.lockfile['port']}/entitlements/v1/token\n{local_headers}")
self.log("Connection error, retrying in 1 seconds, getting new lockfile")
time.sleep(1)
self.lockfile = self.get_lockfile()
continue
entitlements = response.json()
if entitlements.get("message") == "Entitlements token is not ready yet":
try_again = True
time.sleep(1)
elif entitlements.get("message") == "Invalid URI format":
self.log(f"Invalid uri format: {entitlements}")
if init:
return False
else:
try_again = True
time.sleep(5)
else:
try_again = False

self.puuid = entitlements['subject']
headers = {
'Authorization': f"Bearer {entitlements['accessToken']}",
Expand Down

0 comments on commit 93bd736

Please sign in to comment.