Clients: retry connection with ssl (#1341)
This commit is contained in:
		
							parent
							
								
									96cc7f79dc
								
							
						
					
					
						commit
						d4e2b75520
					
				| 
						 | 
				
			
			@ -494,7 +494,7 @@ class CommonContext:
 | 
			
		|||
        self._messagebox.open()
 | 
			
		||||
        return self._messagebox
 | 
			
		||||
 | 
			
		||||
    def _handle_connection_loss(self, msg: str) -> None:
 | 
			
		||||
    def handle_connection_loss(self, msg: str) -> None:
 | 
			
		||||
        """Helper for logging and displaying a loss of connection. Must be called from an except block."""
 | 
			
		||||
        exc_info = sys.exc_info()
 | 
			
		||||
        logger.exception(msg, exc_info=exc_info, extra={'compact_gui': True})
 | 
			
		||||
| 
						 | 
				
			
			@ -580,14 +580,22 @@ async def server_loop(ctx: CommonContext, address: typing.Optional[str] = None)
 | 
			
		|||
            for msg in decode(data):
 | 
			
		||||
                await process_server_cmd(ctx, msg)
 | 
			
		||||
        logger.warning(f"Disconnected from multiworld server{reconnect_hint()}")
 | 
			
		||||
    except websockets.InvalidMessage:
 | 
			
		||||
        # probably encrypted
 | 
			
		||||
        if address.startswith("ws://"):
 | 
			
		||||
            await server_loop(ctx, "ws" + address[1:])
 | 
			
		||||
        else:
 | 
			
		||||
            ctx.handle_connection_loss(f"Lost connection to the multiworld server due to InvalidMessage"
 | 
			
		||||
                                       f"{reconnect_hint()}")
 | 
			
		||||
    except ConnectionRefusedError:
 | 
			
		||||
        ctx._handle_connection_loss("Connection refused by the server. May not be running Archipelago on that address or port.")
 | 
			
		||||
        ctx.handle_connection_loss("Connection refused by the server. "
 | 
			
		||||
                                   "May not be running Archipelago on that address or port.")
 | 
			
		||||
    except websockets.InvalidURI:
 | 
			
		||||
        ctx._handle_connection_loss("Failed to connect to the multiworld server (invalid URI)")
 | 
			
		||||
        ctx.handle_connection_loss("Failed to connect to the multiworld server (invalid URI)")
 | 
			
		||||
    except OSError:
 | 
			
		||||
        ctx._handle_connection_loss("Failed to connect to the multiworld server")
 | 
			
		||||
        ctx.handle_connection_loss("Failed to connect to the multiworld server")
 | 
			
		||||
    except Exception:
 | 
			
		||||
        ctx._handle_connection_loss(f"Lost connection to the multiworld server{reconnect_hint()}")
 | 
			
		||||
        ctx.handle_connection_loss(f"Lost connection to the multiworld server{reconnect_hint()}")
 | 
			
		||||
    finally:
 | 
			
		||||
        await ctx.connection_closed()
 | 
			
		||||
        if ctx.server_address and ctx.username and not ctx.disconnected_intentionally:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue