diff --git a/src/treepuncher/__main__.py b/src/treepuncher/__main__.py index 1b9c6af..8286734 100644 --- a/src/treepuncher/__main__.py +++ b/src/treepuncher/__main__.py @@ -62,6 +62,7 @@ def main(): parser.add_argument('--code', dest='code', default='', help='login code for oauth2 flow') parser.add_argument('--mojang', dest='mojang', action='store_const', const=True, default=False, help="use legacy Mojang authenticator") + parser.add_argument('--print-token', dest='print_token', action='store_const', const=True, default=False, help="show legacy token before stopping") parser.add_argument('--addon-path', dest='path', default='', help='path for loading addons') parser.add_argument('--chat-log', dest='chat_log', action='store_const', const=True, default=False, help="print (colored) chat to terminal") @@ -102,6 +103,9 @@ def main(): client.run() + if args.print_token: + logging.info("Token: %s", client.authenticator.serialize()) + if __name__ == "__main__": main() diff --git a/src/treepuncher/helpers.py b/src/treepuncher/helpers.py index b9809a7..a3c4dc0 100644 --- a/src/treepuncher/helpers.py +++ b/src/treepuncher/helpers.py @@ -27,7 +27,7 @@ def configure_logging(name:str, level=logging.INFO, color:bool = True): logger = logging.getLogger() logger.setLevel(level) # create file handler which logs even debug messages - fh = RotatingFileHandler(f'data/{name}.log', maxBytes=1048576, backupCount=5) # 1MB files + fh = RotatingFileHandler(f'log/{name}.log', maxBytes=1048576, backupCount=5) # 1MB files fh.setLevel(logging.DEBUG) # create console handler with a higher log level ch = logging.StreamHandler() diff --git a/src/treepuncher/treepuncher.py b/src/treepuncher/treepuncher.py index 62d2c6e..cf5a9a2 100644 --- a/src/treepuncher/treepuncher.py +++ b/src/treepuncher/treepuncher.py @@ -151,12 +151,6 @@ class Treepuncher( ) self.storage = Storage(self.name) - prev = self.storage.system() # if this isn't 1st time, this won't be None. Load token from there - if prev: - if self.name != prev.name: - self.logger.warning("Saved session belong to another user") - authenticator.deserialize(json.loads(prev.token)) - self.logger.info("Loaded authenticated session") self.modules = [] @@ -168,6 +162,13 @@ class Treepuncher( super().__init__(opt('server', required=True), online_mode=online_mode, authenticator=authenticator) + prev = self.storage.system() # if this isn't 1st time, this won't be None. Load token from there + if prev: + if self.name != prev.name: + self.logger.warning("Saved session belong to another user") + authenticator.deserialize(json.loads(prev.token)) + self.logger.info("Loaded authenticated session") + @property def playerName(self) -> str: @@ -177,7 +178,7 @@ class Treepuncher( await super().authenticate() state = SystemState( name=self.name, - token=json.dumps(self._authenticator.serialize()), + token=json.dumps(self.authenticator.serialize()), start_time=int(time()) ) self.storage._set_state(state) @@ -232,6 +233,7 @@ class Treepuncher( except Exception: self.logger.exception("Unhandled exception") break - await asyncio.sleep(5) # TODO setting + if self._processing: + await asyncio.sleep(self.config['core'].getfloat('reconnect_delay', fallback=5)) if self._processing: await self.stop(force=True)