예제 #1
0
    def __init__(self, *args, **kwargs):
        CachingSteamClient.__init__(self, *args, **kwargs)

        self.wakeup = gevent.event.Event()
        self.newcards = gevent.event.Event()
        self.playing_blocked = gevent.event.Event()

        self.on(self.EVENT_DISCONNECTED, self.__handle_disconnected)
        self.on(self.EVENT_RECONNECT, self.__handle_reconnect)
        self.on(EMsg.ClientItemAnnouncements, self.__handle_item_notification)
        self.on(EMsg.ClientPlayingSessionState, self.__handle_playing_session)
예제 #2
0
파일: gcmds.py 프로젝트: DMzda/steamctl
def download_via_steampipe(args, pubfile):
    from steamctl.clients import CachingSteamClient

    s = CachingSteamClient()
    if args.cell_id is not None:
        s.cell_id = args.cell_id
    cdn = s.get_cdnclient()

    key = pubfile['consumer_appid'], pubfile['consumer_appid'], pubfile[
        'hcontent_file']

    # only login if we dont have depot decryption key
    if int(pubfile['consumer_appid']) not in cdn.depot_keys:
        result = s.login_from_args(args)

        if result == EResult.OK:
            LOG.info("Login to Steam successful")
        else:
            LOG.error("Failed to login: %r" % result)
            return 1  # error

    try:
        manifest = cdn.get_manifest(*key)
    except SteamError as exp:
        if exp.eresult == EResult.AccessDenied:
            LOG.error("This account doesn't have access to the app depot")
        else:
            LOG.error(str(exp))
        return 1  # error
    else:
        manifest.name = pubfile['title']

    LOG.debug("Got manifest: %r", manifest)
    LOG.info("File manifest acquired")

    if not args.no_progress and sys.stderr.isatty():
        pbar = tqdm(total=manifest.size_original, unit='B', unit_scale=True)
        gevent.spawn(pbar.gevent_refresh_loop)
    else:
        pbar = fake_tqdm()

    tasks = GPool(4)

    for mfile in manifest:
        if not mfile.is_file:
            continue
        tasks.spawn(mfile.download_to,
                    args.output,
                    no_make_dirs=args.no_directories,
                    pbar=pbar)

    # wait on all downloads to finish
    tasks.join()

    # clean and exit
    pbar.close()
    cdn.save_cache()
    s.disconnect()

    LOG.info("Download complete.")
예제 #3
0
 def connect(self, *args, **kwargs):
     self._LOG.info("Connecting to Steam...")
     return CachingSteamClient.connect(self, *args, **kwargs)
예제 #4
0
    def __init__(self, *args, **kwargs):
        CachingSteamClient.__init__(self, *args, **kwargs)

        self.on(self.EVENT_DISCONNECTED, self.__handle_disconnected)
        self.on(self.EVENT_RECONNECT, self.__handle_reconnect)
        self.on(EMsg.ClientItemAnnouncements, self.__handle_item_notification)
예제 #5
0
def init_client(args):
    s = CachingSteamClient()
    s.login_from_args(args)
    yield s
    s.disconnect()
예제 #6
0
def init_clients(args):
    s = CachingSteamClient()

    if args.cell_id is not None:
        s.cell_id = args.cell_id

    cdn = s.get_cdnclient()

    # short-curcuit everything, if we pass manifest file(s)
    if getattr(args, 'file', None):
        manifests = []
        for fp in args.file:
            manifests.append(CTLDepotManifest(cdn, args.app or -1, fp.read()))
        yield None, None, manifests
        return

    # for everything else we need SteamClient and CDNClient

    if not args.app:
        raise SteamError("No app id specified")

    # only login when we may need it
    if (not args.skip_login  # user requested no login
            and (not args.app or not args.depot or not args.manifest
                 or args.depot not in cdn.depot_keys)):
        result = s.login_from_args(args)

        if result == EResult.OK:
            LOG.info("Login to Steam successful")
        else:
            raise SteamError("Failed to login: %r" % result)
    else:
        LOG.info("Skipping login")

    # when app, depot, and manifest are specified, we can just go to CDN
    if args.app and args.depot and args.manifest:
        # we can only decrypt if SteamClient is logged in, or we have depot key cached
        if args.skip_login and args.depot not in cdn.depot_keys:
            decrypt = False
        else:
            decrypt = True

        # load the manifest
        try:
            manifests = [
                cdn.get_manifest(args.app,
                                 args.depot,
                                 args.manifest,
                                 decrypt=decrypt)
            ]
        except SteamError as exp:
            if exp.eresult == EResult.AccessDenied:
                raise SteamError(
                    "This account doesn't have access to the app depot",
                    exp.eresult)
            elif 'HTTP Error 404' in str(exp):
                raise SteamError("Manifest not found on CDN")
            else:
                raise

    # if only app is specified, or app and depot, we need product info to figure out manifests
    else:
        # no license, means no depot keys, and possibly not product info
        if not args.skip_licenses:
            LOG.info("Checking licenses")

            if s.logged_on and not s.licenses and s.steam_id.type != s.steam_id.EType.AnonUser:
                s.wait_event(EMsg.ClientLicenseList, raises=False, timeout=10)

            cdn.load_licenses()

            if args.app not in cdn.licensed_app_ids:
                raise SteamError(
                    "No license available for App ID: %s" % args.app,
                    EResult.AccessDenied)

        # check if we need to invalidate the cache data
        if not args.skip_login:
            LOG.info("Checking change list")
            cdn.check_for_changes()

        # handle any filtering on depot list
        def depot_filter(depot_id, info):
            if args.depot is not None:
                if args.depot != depot_id:
                    return False

            if args.os != 'any':
                if args.os[-2:] == '64':
                    os, arch = args.os[:-2], args.os[-2:]
                else:
                    os, arch = args.os, None

                config = info.get('config', {})

                if 'oslist' in config and (os
                                           not in config['oslist'].split(',')):
                    return False
                if 'osarch' in config and config['osarch'] != arch:
                    return False

            return True

        if args.skip_login:
            if cdn.has_cached_app_depot_info(args.app):
                LOG.info("Using cached app info")
            else:
                raise SteamError("No cached app info. Login to Steam")

        branch = args.branch
        password = args.password

        LOG.info("Getting manifests for %s branch", repr(branch))

        # enumerate manifests
        manifests = []
        for manifest in cdn.get_manifests(args.app,
                                          branch=branch,
                                          password=password,
                                          filter_func=depot_filter,
                                          decrypt=False):
            if not args.skip_licenses and manifest.depot_id not in cdn.licensed_depot_ids:
                LOG.error("No license for depot: %r" % manifest)
                continue

            if manifest.filenames_encrypted:
                if not args.skip_login:
                    try:
                        manifest.decrypt_filenames(
                            cdn.get_depot_key(manifest.app_id,
                                              manifest.depot_id))
                    except Exception as exp:
                        LOG.error(
                            "Failed to decrypt manifest %s (depot %s): %s",
                            manifest.gid, manifest.depot_id, str(exp))

                        if not args.skip_licenses:
                            continue

            manifests.append(manifest)

    LOG.debug("Got manifests: %r", manifests)

    yield s, cdn, manifests

    # clean and exit
    cdn.save_cache()
    s.disconnect()
예제 #7
0
def init_clients(args):
    if getattr(args, 'file', None):
        manifest = CTLDepotManifest(None, -1, args.file.read())
        yield None, None, [manifest]
    else:
        s = CachingSteamClient()
        if args.cell_id is not None:
            s.cell_id = args.cell_id
        cdn = s.get_cdnclient()

        # only login if we dont have depot decryption key
        if (not args.app or not args.depot or not args.manifest or
            args.depot not in cdn.depot_keys):
            result = s.login_from_args(args)

            if result == EResult.OK:
                LOG.info("Login to Steam successful")
            else:
                LOG.error("Failed to login: %r" % result)
                return 1  # error

        if args.app and args.depot and args.manifest:
            try:
                manifests = [cdn.get_manifest(args.app, args.depot, args.manifest)]
            except SteamError as exp:
                if exp.eresult == EResult.AccessDenied:
                    raise SteamError("This account doesn't have access to the app depot", exp.eresult)
                else:
                    raise
        else:
            LOG.info("Checking licenses")
            cdn.load_licenses()

            if args.app not in cdn.licensed_app_ids:
                raise SteamError("No license available for App ID: %s" % args.app, EResult.AccessDenied)

            LOG.info("Checking change list")
            cdn.check_for_changes()

            def branch_filter(depot_id, info):
                if args.depot is not None:
                    if args.depot != depot_id:
                        return False

                if args.os != 'any':
                    if args.os[-2:] == '64':
                        os, arch = args.os[:-2], args.os[-2:]
                    else:
                        os, arch = args.os, None

                    config = info.get('config', {})

                    if 'oslist' in config and (os not in config['oslist'].split(',')):
                        return False
                    if 'osarch' in config and config['osarch'] != arch:
                        return False

                return True

            LOG.info("Getting manifests for 'public' branch")

            manifests = []
            for manifest in cdn.get_manifests(args.app, filter_func=branch_filter, decrypt=False):
                if manifest.depot_id not in cdn.licensed_depot_ids:
                    LOG.error("No license for depot: %r" % manifest)
                    continue
                if manifest.filenames_encrypted:
                    try:
                        manifest.decrypt_filenames(cdn.get_depot_key(manifest.app_id, manifest.depot_id))
                    except Exception as exp:
                        LOG.error("Failed to decrypt manifest: %s" % str(exp))
                        continue
                manifests.append(manifest)

        LOG.debug("Got manifests: %r", manifests)

        yield s, cdn, manifests

        # clean and exit
        cdn.save_cache()
        s.disconnect()