示例#1
0
def id_64(value):
    if is_a_URL(value):
        finale_id = steamid.steam64_from_url(value, http_timeout=30)

    else:
        if isinstance(value, str):
            if "STEAM" in value:
                accountID = steamid.steam2_to_tuple(value)[0]
                Steam_Id = steamid.SteamID(accountID)
                finale_id = Steam_Id.as_64

            elif "[U" in value:
                accountID = steamid.steam3_to_tuple(value)[0]
                Steam_Id = steamid.SteamID(accountID)
                finale_id = Steam_Id.as_64

            else:
                possible_URL = 'https://steamcommunity.com/id/{}/'.format(
                    value)
                finale_id = steamid.steam64_from_url(possible_URL,
                                                     http_timeout=30)

        elif isinstance(value, int):
            finale_id = value

    return finale_id
def steam_oAuthLogin(steamguard, token):
    steamguard = steamguard.split("||")
    steamid = sid.SteamID(steamguard[0])

    response = s.post(
        'https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/',
        data={
            'access_token': token
        }).json()['response']

    # No token in response
    if not 'token' in response or not 'token_secure' in response:
        return False

    # Build cookie list
    cookies = {
        'steamLogin':
        str("{id}||{token}".format(id=steamid, token=response['token'])),
        'steamLoginSecure':
        str("{id}||{token}".format(id=steamid,
                                   token=response['token_secure'])),
        'steamMachineAuth' + str(steamid):
        steamguard[1],
        'sessionid':
        sweb.generate_session_id()
    }

    # Create cookie jar
    jar = requests.cookies.RequestsCookieJar()
    for cookie in cookies:
        jar.set(cookie, cookies[cookie], domain='steamcommunity.com', path='/')

    return jar
示例#3
0
def get_client_users():
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "SOFTWARE\Valve\Steam", 0,
                         winreg.KEY_QUERY_VALUE)
    path, t = winreg.QueryValueEx(key, "SteamPath")
    users = {}

    path += "/config/loginusers.vdf"

    with open(path, "r", encoding="utf-8") as file:
        users = vdf.load(file)

    winreg.CloseKey(key)
    users = users["users"]

    rewrite = False
    for key, val in users.items():
        if (users[key]["RememberPassword"] == 0):
            users.pop(key, None)
            continue
        if ("AccountID" not in val):
            users[key]["AccountID"] = str(Sid.SteamID(key).id)
            rewrite = True

    if (rewrite):
        print("重寫 loginusers.")
        with open(path, "w", encoding="utf-8") as file:
            vdf.dump({"users": users}, file)
    return (users)
示例#4
0
def to_steamid(steamid, to_account_id=False):
    Steam = Sid.SteamID(steamid)
    if (to_account_id):
        #accountID
        return str(Steam.as_32)
    else:
        #steamID
        return str(Steam.as_64)
示例#5
0
    def get_persona_names(self, steam_ids: List[steamid.SteamID]
                          ) -> Dict[steamid.SteamID, str]:
        """Return dictionary of Steam IDs to persona names
        for given Steam IDs. Queries the Steam Web API in
        batches of 100 Steam IDs.
        """
        if self._dummy:
            return {steam_id: "" for steam_id in steam_ids}

        ret = {}

        for steam_id in steam_ids:
            try:
                personaname = _ttl_cache[steam_id]
                ret[steam_id] = personaname
            except KeyError:
                pass

        new_ids = [steam_id for steam_id in steam_ids
                   if steam_id not in ret]

        for chunk in _chunks(new_ids, n=100):
            chunk_ids = [str(cid.as_64)
                         for cid in chunk
                         if cid not in ret]
            chunk_ids_str = ",".join(chunk_ids)

            # noinspection PyUnresolvedReferences
            resp = self.ISteamUser.GetPlayerSummaries(
                steamids=chunk_ids_str)["response"]["players"]
            SteamWebAPI._REQUESTS_MADE += 1

            for r in resp:
                steam_id = steamid.SteamID(r["steamid"])
                personaname = r["personaname"]
                ret[steam_id] = personaname
                _ttl_cache[steam_id] = personaname

            input_len = len(chunk_ids)
            output_len = len(ret)
            num_bad = int(abs(input_len - output_len))
            if input_len != output_len:
                logger.warn(
                    f"Steam API did not return valid value "
                    f"for {num_bad} input Steam IDs "
                    f"(input_len={input_len}, output_len={output_len})")

        return ret
示例#6
0
 def _steamAuth(self,
                account=None,
                password=None,
                steamID=None,
                auth_token=None,
                steamguard_token=None):
     """
 Aliased internal function for steam auth. If used with plain username and password
 returns dict with a status request for 2FA when required. Use <>.postSteam2FA() after
 Possible statuses:
 0 - No 2FA required - Plain login, you can now use session
 1 - Captcha required - Post the captcha code
 2 - Email code required - Post the code received on the email
 3 - Steamguard 2FA required - Post the 2FA code from steamguard
 """
     if account and password:
         if not 'sessionid' in self.session.cookies.get_dict():
             self.steamUser = wa.MobileWebAuth(account, password)
             try:
                 self.steamUser.login()
                 self.session.cookies.update(self.steamUser.session.cookies)
                 self._steamSiteLogin()
                 return {
                     "status": 0,
                     "message": "No 2FA required. Check user session"
                 }
             except wa.CaptchaRequired:
                 self.twofaType = "captcha"
                 return {
                     "status": 1,
                     "message": "Captcha Required",
                     "url": self.steamUser.captcha_url
                 }  # User must .postSteam2FA(code)
             except wa.EmailCodeRequired:
                 self.twofaType = "email"
                 return {
                     "status": 2,
                     "message": "Email code Required"
                 }  # User must .postSteam2FA(code)
             except wa.TwoFactorCodeRequired:
                 self.twofaType = "steamguard"
                 return {
                     "status": 3,
                     "message": "Steamguard 2FA Required"
                 }  # User must .postSteam2FA(code)
     elif steamID and auth_token and steamguard_token:
         steamid = sid.SteamID(steamID)
         try:
             response = self.session.post(
                 'https://api.steampowered.com/IMobileAuthService/GetWGToken/v1/',
                 data={
                     'access_token': auth_token
                 }).json()['response']
         except:
             return self._steamSiteLogin()
         if not 'token' in response or not 'token_secure' in response:
             return False
         cookies = {
             'steamLogin': f"{steamid}||{response['token']}",
             'steamLoginSecure': f"{steamid}||{response['token_secure']}",
             f'steamMachineAuth{steamid}': steamguard_token,
             'sessionid': sweb.generate_session_id()
         }
         jar = requests.cookies.RequestsCookieJar()
         for cookie in cookies:
             jar.set(cookie,
                     cookies[cookie],
                     domain='steamcommunity.com',
                     path='/')
         self.session.cookies.update(jar)
         return self._steamSiteLogin()
     else:
         raise MissingSteamLoginData
示例#7
0
def create_account(lvl, data):  # 引入帳號
    if (lvl == "login"):
        global create_acc, acc_setting

        create_acc = wa.MobileWebAuth(data["username"], data["password"])

        try:
            if ("2FA" in data):
                create_acc.login(twofactor_code=data["2FA"])
            else:
                create_acc.login()
        except wa.LoginIncorrect:
            next = 'accpwd'
        except wa.HTTPError:
            next = 'HTTPError'
        except wa.CaptchaRequired:
            next = 'Captcha'
        except wa.EmailCodeRequired:
            next = 'email'
        except wa.TwoFactorCodeRequired:
            next = '2FA'
        except:
            next = sys.exc_info()[0]
        else:
            next = True

        print("try login")
    elif (lvl == "Captcha"):
        try:
            create_acc.login(email_code=data["Captcha"])
        except wa.CaptchaRequired:  # 代碼錯誤
            next = "Captcha"
        except wa.EmailCodeRequired:
            next = 'email'
        except wa.TwoFactorCodeRequired:
            next = '2FA'
        else:
            next = True
    elif (lvl == "email"):
        try:
            create_acc.login(email_code=data["email"])
        except wa.EmailCodeRequired:  # 代碼錯誤
            next = False
        else:
            next = True
    elif (lvl == "2FA"):
        try:
            create_acc.login(twofactor_code=data["2FA"])
        except wa.TwoFactorCodeRequired:  # 代碼錯誤
            next = False
        else:
            next = True

    if (next == True):  # 保存資料
        try:
            with open(path + "user_config/" + data["username"] + ".json",
                      'r') as fcfg:
                org = json.load(fcfg)
        except:
            org = {}

        with open(path + "user_config/" + data["username"] + ".json",
                  "w+") as fcfg:
            user_data = {
                "name": data["username"],
                "password": data["password"],
                "oauth": create_acc.oauth_token,
                "steam_id": create_acc.steam_id,
                "account_id": Sid.SteamID(create_acc.steam_id).id,
                "session_id": create_acc.session_id
            }
            json.dump({**org, **user_data}, fcfg)
            print("create user config [\"" + data["username"] + "\"]")

    return next