コード例 #1
0
    def __init__(self, client):
        """CDNClient allows loading and reading of manifests for Steam apps are used
        to list and download content

        :param client: logged in SteamClient instance
        :type  client: :class:`.SteamClient`
        """
        self.gpool = GPool(8)  #: task pool
        self.steam = client  #: SteamClient instance
        if self.steam:
            self.cell_id = self.steam.cell_id

        self.web = make_requests_session()
        self.depot_keys = {}  #: depot decryption keys
        self.manifests = {}  #: CDNDepotManifest instances
        self.app_depots = {}  #: app depot info
        self.beta_passwords = {}  #: beta branch decryption keys
        self.licensed_app_ids = set(
        )  #: app_ids that the SteamClient instance has access to
        self.licensed_depot_ids = set(
        )  #: depot_ids that the SteamClient instance has access to

        if not self.servers:
            self.fetch_content_servers()

        self.load_licenses()
コード例 #2
0
def steam64_from_url(url, http_timeout=30):
    """
    Takes a Steam Community url and returns steam64 or None

    .. warning::
        Each call makes a http request to ``steamcommunity.com``

    .. note::
        For a reliable resolving of vanity urls use ``ISteamUser.ResolveVanityURL`` web api

    :param url: steam community url
    :type url: :class:`str`
    :param http_timeout: how long to wait on http request before turning ``None``
    :type http_timeout: :class:`int`
    :return: steam64, or ``None`` if ``steamcommunity.com`` is down
    :rtype: :class:`int` or :class:`None`

    Example URLs::

        https://steamcommunity.com/gid/[g:1:4]
        https://steamcommunity.com/gid/103582791429521412
        https://steamcommunity.com/groups/Valve
        https://steamcommunity.com/profiles/[U:1:12]
        https://steamcommunity.com/profiles/76561197960265740
        https://steamcommunity.com/id/johnc
        https://steamcommunity.com/user/cv-dgb/
    """

    match = re.match(
        r'^(?P<clean_url>https?://steamcommunity.com/'
        r'(?P<type>profiles|id|gid|groups|user)/(?P<value>.*?))(?:/(?:.*)?)?$',
        url)

    if not match:
        return None

    web = make_requests_session()

    try:
        # user profiles
        if match.group('type') in ('id', 'profiles', 'user'):
            text = web.get(match.group('clean_url'), timeout=http_timeout).text
            data_match = re.search(
                "g_rgProfileData = (?P<json>{.*?});[ \t\r]*\n", text)

            if data_match:
                data = json.loads(data_match.group('json'))
                return int(data['steamid'])
        # group profiles
        else:
            text = web.get(match.group('clean_url'), timeout=http_timeout).text
            data_match = re.search("OpenGroupChat\( *'(?P<steamid>\d+)'", text)

            if data_match:
                return int(data_match.group('steamid'))
    except requests.exceptions.RequestException:
        return None
コード例 #3
0
def get_content_servers_from_cs(cell_id,
                                host='cs.steamcontent.com',
                                port=80,
                                num_servers=20,
                                session=None):
    """Get a list of CS servers from a single CS server

    :param cell_id: location cell id
    :type  cell_id: bytes
    :param host: CS server host
    :type  host: str
    :param port: server port number
    :type  port: int
    :param num_servers: number of servers to return
    :type  num_servers: int
    :param session: requests Session instance
    :type  session: :class:`requests.Session`
    :return: list of CS servers
    :rtype: :class:`list` [:class:`.ContentServer`]
    """
    proto = 'https' if port == 443 else 'http'

    url = '%s://%s:%s/serverlist/%s/%s/' % (proto, host, port, cell_id,
                                            num_servers)
    session = make_requests_session() if session is None else session
    resp = session.get(url)

    if resp.status_code != 200:
        return []

    kv = vdf.loads(resp.text, mapper=OrderedDict)

    if kv.get('deferred') == '1':
        return []

    servers = []

    for entry in itervalues(kv['serverlist']):
        server = ContentServer()
        server.type = entry['type']
        server.https = True if entry['https_support'] == 'mandatory' else False
        server.host = entry['Host']
        server.vhost = entry['vhost']
        server.port = 443 if server.https else 80
        server.cell_id = entry['cell']
        server.load = entry['load']
        server.weighted_load = entry['weightedload']
        servers.append(server)

    return servers
コード例 #4
0
    def get_web_session(self, language='english'):
        """Get a :class:`requests.Session` that is ready for use

        See :meth:`get_web_session_cookies`

        .. note::
            Auth cookies will only be send to ``(help|store).steampowered.com`` and ``steamcommunity.com`` domains

        .. note::
            The session is valid only while :class:`.SteamClient` instance is logged on.

        :param language: localization language for steam pages
        :type language: :class:`str`
        :return: authenticated Session ready for use
        :rtype: :class:`requests.Session`, :class:`None`
        """
        if self._web_session:
            return self._web_session

        cookies = self.get_web_session_cookies()
        if cookies is None:
            return None

        self._web_session = session = make_requests_session()
        session_id = generate_session_id()

        for domain in [
                'store.steampowered.com', 'help.steampowered.com',
                'steamcommunity.com'
        ]:
            for name, val in cookies.items():
                secure = (name == 'steamLoginSecure')
                session.cookies.set(name, val, domain=domain, secure=secure)

            session.cookies.set('Steam_Language', language, domain=domain)
            session.cookies.set('birthtime', '-3333', domain=domain)
            session.cookies.set('sessionid', session_id, domain=domain)

        return session
コード例 #5
0
ファイル: webauth.py プロジェクト: philippj/steam
 def __init__(self, username, password=''):
     self.__dict__.update(locals())
     self.session = make_requests_session()
     self._session_setup()
コード例 #6
0
 def test_make_requests_session(self):
     self.assertIsInstance(uweb.make_requests_session(), requests.Session)