text
stringlengths
1
93.6k
lang = forcelang
country = forcelang[-2:]
else:
lang = USER_LANG
country = USER_COUNTRY
graphql_head = {
'Authorization': f'Bearer {BULLETTOKEN}', # update every time it's called with current global var
'Accept-Language': lang,
'User-Agent': APP_USER_AGENT,
'X-Web-View-Ver': iksm.get_web_view_ver(),
'Content-Type': 'application/json',
'Accept': '*/*',
'Origin': iksm.SPLATNET3_URL,
'X-Requested-With': 'com.nintendo.znca',
'Referer': f'{iksm.SPLATNET3_URL}?lang={lang}&na_country={country}&na_lang={lang}',
'Accept-Encoding': 'gzip, deflate'
}
return graphql_head
def prefetch_checks(printout=False):
'''Queries the SplatNet 3 homepage to check if our gtoken & bulletToken are still valid and regenerates them if not.'''
if printout:
print("Validating your tokens...", end='\r')
iksm.get_web_view_ver() # setup
if SESSION_TOKEN == "" or GTOKEN == "" or BULLETTOKEN == "":
gen_new_tokens("blank")
sha = utils.translate_rid["HomeQuery"]
test = requests.post(iksm.GRAPHQL_URL, data=utils.gen_graphql_body(sha, "naCountry", USER_COUNTRY), headers=headbutt(), cookies=dict(_gtoken=GTOKEN))
if test.status_code != 200:
if printout:
print("\n")
gen_new_tokens("expiry")
else:
if printout:
print("Validating your tokens... done.\n")
def gen_new_tokens(reason, force=False):
'''Attempts to generate new tokens when the saved ones have expired.'''
manual_entry = False
if force != True: # unless we force our way through
if reason == "blank":
print("Blank token(s). ")
elif reason == "expiry":
print("The stored tokens have expired.")
else:
print("Cannot access SplatNet 3 without having played online.")
sys.exit(0)
if SESSION_TOKEN == "":
print("Please log in to your Nintendo Account to obtain your session_token.")
new_token = iksm.log_in(A_VERSION, APP_USER_AGENT, F_GEN_URL)
if new_token is None:
print("There was a problem logging you in. Please try again later.")
elif new_token == "skip":
manual_entry = True
else:
print("\nWrote session_token to config.txt.")
CONFIG_DATA["session_token"] = new_token
write_config(CONFIG_DATA)
elif SESSION_TOKEN == "skip":
manual_entry = True
if manual_entry: # no session_token ever gets stored
print("\nYou have opted against automatic token generation and must manually input your tokens.\n")
new_gtoken, new_bullettoken = iksm.enter_tokens()
acc_lang = "en-US" # overwritten by user setting
acc_country = "US"
print("Using `US` for country by default. This can be changed in config.txt.")
else:
print("Attempting to generate new gtoken and bulletToken...")
new_gtoken, acc_name, acc_lang, acc_country = iksm.get_gtoken(F_GEN_URL, SESSION_TOKEN, A_VERSION)
new_bullettoken = iksm.get_bullet(new_gtoken, APP_USER_AGENT, acc_lang, acc_country)
CONFIG_DATA["gtoken"] = new_gtoken # valid for 6 hours
CONFIG_DATA["bullettoken"] = new_bullettoken # valid for 2 hours
global USER_LANG
if acc_lang != USER_LANG:
acc_lang = USER_LANG
CONFIG_DATA["acc_loc"] = f"{acc_lang}|{acc_country}"
write_config(CONFIG_DATA)
if new_bullettoken == "":
print("Wrote gtoken to config.txt, but could not generate bulletToken.")
print("Is SplatNet 3 undergoing maintenance?")
sys.exit(1)
if manual_entry:
print("Wrote tokens to config.txt.\n") # and updates acc_country if necessary...
else:
print(f"Wrote tokens for {acc_name} to config.txt.\n")