Add anonymous mode, use argparser

This commit is contained in:
Timic 2023-05-23 18:45:55 +02:00
parent 475342f0d8
commit 70c2a92a9e
1 changed files with 43 additions and 35 deletions

View File

@ -13,6 +13,7 @@ from steam.enums import common
from steam.enums.common import EResult from steam.enums.common import EResult
from steam.enums.emsg import EMsg from steam.enums.emsg import EMsg
from steam.core.msg import MsgProto from steam.core.msg import MsgProto
import argparse
import os import os
import sys import sys
import json import json
@ -23,56 +24,63 @@ import queue
prompt_for_unavailable = True prompt_for_unavailable = True
if len(sys.argv) < 2: parser = argparse.ArgumentParser(
print("\nUsage: {} appid appid appid etc..\n\nExample: {} 480\n".format(sys.argv[0], sys.argv[0])) prog="GenerateEmuConfig",
exit(1) description="Emulator Config Generator"
)
appids = [] parser.add_argument("app_id", nargs="+", help="Steam application IDs")
for id in sys.argv[1:]: parser.add_argument("-a", "--anonymous", action="store_true", help="Enable anonymous login mode")
appids += [int(id)]
args = parser.parse_args()
appids = [int(id) for id in args.app_id]
client = SteamClient() client = SteamClient()
if not os.path.exists("login_temp"): if not os.path.exists("login_temp"):
os.makedirs("login_temp") os.makedirs("login_temp")
client.set_credential_location("login_temp") client.set_credential_location("login_temp")
if (len(USERNAME) == 0 or len(PASSWORD) == 0): if args.anonymous:
client.cli_login() client.anonymous_login()
else: else:
result = client.login(USERNAME, password=PASSWORD) if (len(USERNAME) == 0 or len(PASSWORD) == 0):
auth_code, two_factor_code = None, None client.cli_login()
while result in (EResult.AccountLogonDenied, EResult.InvalidLoginAuthCode, else:
EResult.AccountLoginDeniedNeedTwoFactor, EResult.TwoFactorCodeMismatch, result = client.login(USERNAME, password=PASSWORD)
EResult.TryAnotherCM, EResult.ServiceUnavailable, auth_code, two_factor_code = None, None
EResult.InvalidPassword, while result in (EResult.AccountLogonDenied, EResult.InvalidLoginAuthCode,
): EResult.AccountLoginDeniedNeedTwoFactor, EResult.TwoFactorCodeMismatch,
EResult.TryAnotherCM, EResult.ServiceUnavailable,
EResult.InvalidPassword,
):
if result == EResult.InvalidPassword: if result == EResult.InvalidPassword:
print("invalid password, the password you set is wrong.") print("invalid password, the password you set is wrong.")
exit(1) exit(1)
elif result in (EResult.AccountLogonDenied, EResult.InvalidLoginAuthCode): elif result in (EResult.AccountLogonDenied, EResult.InvalidLoginAuthCode):
prompt = ("Enter email code: " if result == EResult.AccountLogonDenied else prompt = ("Enter email code: " if result == EResult.AccountLogonDenied else
"Incorrect code. Enter email code: ") "Incorrect code. Enter email code: ")
auth_code, two_factor_code = input(prompt), None auth_code, two_factor_code = input(prompt), None
elif result in (EResult.AccountLoginDeniedNeedTwoFactor, EResult.TwoFactorCodeMismatch): elif result in (EResult.AccountLoginDeniedNeedTwoFactor, EResult.TwoFactorCodeMismatch):
prompt = ("Enter 2FA code: " if result == EResult.AccountLoginDeniedNeedTwoFactor else prompt = ("Enter 2FA code: " if result == EResult.AccountLoginDeniedNeedTwoFactor else
"Incorrect code. Enter 2FA code: ") "Incorrect code. Enter 2FA code: ")
auth_code, two_factor_code = None, input(prompt) auth_code, two_factor_code = None, input(prompt)
elif result in (EResult.TryAnotherCM, EResult.ServiceUnavailable): elif result in (EResult.TryAnotherCM, EResult.ServiceUnavailable):
if prompt_for_unavailable and result == EResult.ServiceUnavailable: if prompt_for_unavailable and result == EResult.ServiceUnavailable:
while True: while True:
answer = input("Steam is down. Keep retrying? [y/n]: ").lower() answer = input("Steam is down. Keep retrying? [y/n]: ").lower()
if answer in 'yn': break if answer in 'yn': break
prompt_for_unavailable = False prompt_for_unavailable = False
if answer == 'n': break if answer == 'n': break
client.reconnect(maxdelay=15) client.reconnect(maxdelay=15)
result = client.login(USERNAME, PASSWORD, None, auth_code, two_factor_code) result = client.login(USERNAME, PASSWORD, None, auth_code, two_factor_code)
def get_stats_schema(client, game_id, owner_id): def get_stats_schema(client, game_id, owner_id):