Esempio n. 1
0
 async def listen(self):
     while True:
         try:
             await self.listen_inner()
             break
         except websockets.exceptions.InvalidStatusCode:
             logger.warning(
                 "Invalid Request, Do you have an invalid auth token?")
             await asyncio.sleep(300)
         except websockets.exceptions.ConnectionClosedError:
             backoff = self.get_backoff()
             logger.warning(
                 "Websocket connection went away. Will keep trying...", )
             await asyncio.sleep(backoff)
         except ConnectionError:
             backoff = self.get_backoff()
             logger.debug(
                 "Couldn't get connection to spelunky.fyi. Trying again in %s seconds...",
                 backoff,
             )
             await asyncio.sleep(backoff)
         except Exception:  # pylint: disable=broad-except
             backoff = self.get_backoff()
             logger.critical("Unexpected failure: %s", tb_info())
             await asyncio.sleep(backoff)
Esempio n. 2
0
 def func():
     try:
         task.callback(self.call, **kwargs)
     except Exception:  # pylint: disable=broad-except
         logger.critical("Failed to execute command %s: %s",
                         repr(msg.name), tb_info())
     if task.on_complete:
         self.call(task.on_complete)
Esempio n. 3
0
 def _really_poll(self):
     try:
         self.poll()
     except (FeedcodeNotFound, ScalarCValueConstructionError):
         # These exceptions are likely transient
         return
     except Exception:  # pylint: disable=broad-except
         # If the game is no longer running, we assume that caused the failure
         if self.proc.running():
             logger.critical("Unexpected Exception while polling: %s",
                             tb_info())
             self.shutdown()
Esempio n. 4
0
    def run(self):
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        if self.api_token is None:
            logger.warning(
                "Started websocket thread with no token. Exiting...")
            return

        try:
            asyncio.get_event_loop().run_until_complete(self.run_async())
        except Exception:  # pylint: disable=broad-except
            logger.critical("Failed running websocket loop: %s", tb_info())
Esempio n. 5
0
 def poll_tracker(self):
     try:
         data = self.tracker.poll(self.proc, self.config)
         if data is None:
             self.shutdown()
         else:
             self.send(Command.TRACKER_DATA, data)
     except (FeedcodeNotFound, ScalarCValueConstructionError):
         # These exceptions are likely transient
         return
     except Exception:  # pylint: disable=broad-except
         # If the game is no longer running, we assume that caused the failure
         if self.proc.running():
             logger.critical("Unexpected Exception while polling: %s",
                             tb_info())
             self.shutdown()
Esempio n. 6
0
    def register_tab(self, name, cls, **kwargs):
        logger.debug("Registering Tab %s", repr(name))

        try:
            obj = cls(**kwargs)
        except Exception:  # pylint: disable=broad-except
            obj = ErrorTab(tab_control=self.tab_control)
            logger.critical("Failed to register tab %s: %s", name, tb_info())

        num_tabs = len(self.tabs)
        if num_tabs < len(TAB_KEYS):
            self.root.bind(
                f"<Control-Key-{TAB_KEYS[num_tabs]}>",
                lambda _e: self.tab_control.select(obj),
            )

        self.tabs[name] = obj
        self.tab_control.add(obj, text=name)
Esempio n. 7
0
def download_contents(_call, url):

    contents = BytesIO()

    try:
        response = requests.get(url, stream=True, allow_redirects=True)
        response.raise_for_status()
        amount_downloaded = 0
        block_size = 102400

        for data in response.iter_content(block_size):
            amount_downloaded += len(data)
            logger.info("Downloaded %s bytes", amount_downloaded)
            contents.write(data)

    except Exception:  # pylint: disable=broad-except
        logger.critical("Failed to download %s: %s", url, tb_info())
        return None

    contents.seek(0)
    return contents
Esempio n. 8
0
def download_playlunky_release(call, tag, download_url, launch):
    logger.debug("Downloading %s", download_url)

    dest_path = PLAYLUNKY_DATA_DIR / tag
    if not dest_path.exists():
        dest_path.mkdir(parents=True)

    try:
        version, ext = parse_download_url(download_url)
        if ext != ".zip":
            raise ValueError("Expected .zip but didn't find one")

        download_file = BytesIO()
        response = requests.get(download_url, stream=True)
        amount_downloaded = 0
        block_size = 102400

        for data in response.iter_content(block_size):
            amount_downloaded += len(data)
            call("play:download_progress", amount_downloaded=amount_downloaded)
            download_file.write(data)

        playlunky_zip = zipfile.ZipFile(download_file)
        for member in playlunky_zip.infolist():
            if member.filename in PLAYLUNKY_FILES:
                playlunky_zip.extract(member, dest_path)

        version_path = dest_path / PLAYLUNKY_VERSION_FILENAME
        logger.debug("Writing version to %s", version_path)
        with version_path.open("w") as version_file:
            version_file.write(version)

    except Exception:  # pylint: disable=broad-except
        logger.critical("Failed to download %s: %s", download_url, tb_info())
        call("play:download_failed")
        return

    call("play:download_finished", launch=launch)
Esempio n. 9
0
def main():
    parser = argparse.ArgumentParser(
        description="Tool for modding Spelunky 2.")
    parser.add_argument(
        "--config-file",
        type=Path,
        default=None,
        help="The modlunky2 config file to use",
    )
    parser.add_argument(
        "-l",
        "--log-level",
        choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
        default="INFO",
        help="What level to log at. Default: %(default)s",
    )
    parser.add_argument(
        "--launcher-exe",
        type=Path,
        default=None,
        help=argparse.SUPPRESS,
    )
    args = parser.parse_args()

    log_format = "%(asctime)s.%(msecs)03d: %(message)s"
    log_level = logging.getLevelName(args.log_level)
    logging.basicConfig(format=log_format,
                        level=logging.INFO,
                        datefmt="%H:%M:%S")
    logger.setLevel(log_level)

    try:
        launch(args, log_level)
    except Exception:  # pylint: disable=broad-except
        logger.critical("%s", tb_info())
        input("Failed to launch Modlunky 2. Press Enter to exit...")
Esempio n. 10
0
def download_overlunky_release(call, install_dir, launch):
    logger.debug("Downloading %s", OVERLUNKY_RELEASE_URL)

    try:
        download_file = BytesIO()
        response = requests.get(OVERLUNKY_RELEASE_URL, stream=True)
        amount_downloaded = 0
        block_size = 102400

        for data in response.iter_content(block_size):
            amount_downloaded += len(data)
            call("overlunky:download_progress", amount_downloaded=amount_downloaded)
            download_file.write(data)

        logger.info("Extracting to %s", install_dir)
        overlunky_zip = zipfile.ZipFile(download_file)
        overlunky_zip.extractall(install_dir)

    except Exception:  # pylint: disable=broad-except
        logger.critical("Failed to download %s: %s", OVERLUNKY_RELEASE_URL, tb_info())
        call("overlunky:download_failed")
        return

    call("overlunky:download_finished", launch=launch)
Esempio n. 11
0
 def run(self):
     try:
         self._run()
     except Exception:  # pylint: disable=broad-except
         logger.critical("Failed in client thread: %s", tb_info())