diff --git a/rustplus/__init__.py b/rustplus/__init__.py index 80658d5..eb80997 100644 --- a/rustplus/__init__.py +++ b/rustplus/__init__.py @@ -22,5 +22,5 @@ __name__ = "rustplus" __author__ = "olijeffers0n" -__version__ = "5.6.14" +__version__ = "5.6.15" __support__ = "Discord: https://discord.gg/nQqJe8qvP8" diff --git a/rustplus/api/base_rust_api.py b/rustplus/api/base_rust_api.py index b48f90e..d1bd5de 100644 --- a/rustplus/api/base_rust_api.py +++ b/rustplus/api/base_rust_api.py @@ -38,6 +38,7 @@ def __init__( use_test_server: bool = False, event_loop: asyncio.AbstractEventLoop = None, rate_limiter: RateLimiter = None, + debug: bool = False, ) -> None: if ip is None: raise ValueError("Ip cannot be None") @@ -65,6 +66,7 @@ def __init__( api=self, use_test_server=use_test_server, rate_limiter=rate_limiter, + debug=debug, ) if heartbeat is None: diff --git a/rustplus/api/remote/rust_remote_interface.py b/rustplus/api/remote/rust_remote_interface.py index 0df46ba..6b97113 100644 --- a/rustplus/api/remote/rust_remote_interface.py +++ b/rustplus/api/remote/rust_remote_interface.py @@ -32,6 +32,7 @@ def __init__( api=None, use_test_server: bool = False, rate_limiter: RateLimiter = None, + debug: bool = False, ) -> None: self.server_id = server_id self.api = api @@ -65,6 +66,7 @@ def __init__( self.use_test_server = use_test_server self.pending_entity_subscriptions = [] self.camera_manager: Union[CameraManager, None] = None + self.debug = debug async def connect( self, @@ -86,6 +88,7 @@ async def connect( delay=delay, on_success_args_kwargs=on_success_args_kwargs, on_failure_args_kwargs=on_failure_args_kwargs, + debug=self.debug, ) await self.ws.connect(retries=retries) @@ -112,6 +115,9 @@ async def send_message(self, request: AppRequest) -> None: if self.ws is None: raise ClientNotConnectedError("No Current Websocket Connection") + if self.debug: + self.logger.info(f"[RustPlus.py] Sending Message with seq {request.seq}: {request}") + self.pending_response_events[request.seq] = YieldingEvent() await self.ws.send_message(request) diff --git a/rustplus/api/remote/rustws.py b/rustplus/api/remote/rustws.py index 703c967..7c42b72 100644 --- a/rustplus/api/remote/rustws.py +++ b/rustplus/api/remote/rustws.py @@ -36,6 +36,7 @@ def __init__( delay, on_success_args_kwargs, on_failure_args_kwargs, + debug: bool = False, ): self.connection: Union[WebSocketClientProtocol, None] = None self.task: Union[Task, None] = None @@ -53,6 +54,7 @@ def __init__( self.delay = delay self.on_success_args_kwargs = on_success_args_kwargs self.on_failure_args_kwargs = on_failure_args_kwargs + self.debug = debug async def connect( self, retries=float("inf"), ignore_open_value: bool = False @@ -83,6 +85,10 @@ async def connect( ) ) address += f"?v={str(self.magic_value)}" + + if self.debug: + self.logger.info(f"[RustPlus.py] Connecting to {address}") + self.connection = await connect( address, close_timeout=0, @@ -108,8 +114,10 @@ async def connect( break except Exception as exception: - print_error = True + self.logger.info(f"[RustPlus.py] {exception}") + + print_error = True if not isinstance(exception, KeyboardInterrupt): # Run the failure callback if self.on_failure is not None: @@ -154,6 +162,9 @@ async def close(self) -> None: self.task = None self.connection_status = CLOSED + if self.debug: + self.logger.info(f"[RustPlus.py] Connection Closed") + async def send_message(self, message: AppRequest) -> None: """ Send the Protobuf to the server @@ -214,6 +225,10 @@ async def run(self) -> None: ) async def handle_message(self, app_message: AppMessage) -> None: + + if self.debug: + self.logger.info(f"[RustPlus.py] Received Message with seq {app_message.response.seq}: {app_message}") + if app_message.response.seq in self.remote.ignored_responses: self.remote.ignored_responses.remove(app_message.response.seq) return @@ -225,12 +240,18 @@ async def handle_message(self, app_message: AppMessage) -> None: if prefix is not None: # This means it is a command + if self.debug: + self.logger.info(f"[RustPlus.py] Attempting to run Command: {app_message}") + message = RustChatMessage(app_message.broadcast.team_message.message) await self.remote.command_handler.run_command(message, prefix) if self.is_entity_broadcast(app_message): # This means that an entity has changed state + if self.debug: + self.logger.info(f"[RustPlus.py] Running Entity Event: {app_message}") + await EventHandler.run_entity_event( app_message.broadcast.entity_changed.entity_id, app_message, @@ -238,18 +259,29 @@ async def handle_message(self, app_message: AppMessage) -> None: ) elif self.is_camera_broadcast(app_message): + + if self.debug: + self.logger.info(f"[RustPlus.py] Running Camera Event: {app_message}") + if self.remote.camera_manager is not None: await self.remote.camera_manager.add_packet( RayPacket(app_message.broadcast.camera_rays) ) elif self.is_team_broadcast(app_message): + + if self.debug: + self.logger.info(f"[RustPlus.py] Running Team Event: {app_message}") + # This means that the team of the current player has changed await EventHandler.run_team_event(app_message, self.server_id) elif self.is_message(app_message): # This means that a message has been sent to the team chat + if self.debug: + self.logger.info(f"[RustPlus.py] Running Chat Event: {app_message}") + steam_id = int(app_message.broadcast.team_message.message.steam_id) message = str(app_message.broadcast.team_message.message.message) @@ -278,16 +310,21 @@ async def handle_message(self, app_message: AppMessage) -> None: else: self.outgoing_conversation_messages.remove(message) - # Conversation API end + # Conversation API end await EventHandler.run_chat_event(app_message, self.server_id) else: # This means that it wasn't sent by the server and is a message from the server in response to an action - event: YieldingEvent = self.remote.pending_response_events[ - app_message.response.seq - ] - event.set_with_value(app_message) + event: YieldingEvent = self.remote.pending_response_events.get( + app_message.response.seq, None + ) + if event is not None: + + if self.debug: + self.logger.info(f"[RustPlus.py] Running Response Event: {app_message}") + + event.set_with_value(app_message) def get_prefix(self, message: str) -> Optional[str]: if self.remote.use_commands: diff --git a/rustplus/api/rust_api.py b/rustplus/api/rust_api.py index 7b99ac3..7976147 100644 --- a/rustplus/api/rust_api.py +++ b/rustplus/api/rust_api.py @@ -54,6 +54,7 @@ def __init__( use_test_server: bool = False, event_loop: asyncio.AbstractEventLoop = None, rate_limiter: RateLimiter = None, + debug: bool = False, ) -> None: super().__init__( ip=ip, @@ -69,6 +70,7 @@ def __init__( use_test_server=use_test_server, event_loop=event_loop, rate_limiter=rate_limiter, + debug=debug, ) async def get_time(self) -> RustTime: