From 392a45ec89c8cfef0e4b263203f49f8bb21a318c Mon Sep 17 00:00:00 2001 From: Lexipherous Date: Sat, 9 Sep 2023 14:40:52 +0100 Subject: [PATCH] - Added better fallback to default port range when a custom range fails - Updated config to be clearer --- WebHostLib/customserver.py | 9 +++++++++ docs/webhost configuration sample.yaml | 1 + 2 files changed, 10 insertions(+) diff --git a/WebHostLib/customserver.py b/WebHostLib/customserver.py index cf153069cc..1fe0fc4bf6 100644 --- a/WebHostLib/customserver.py +++ b/WebHostLib/customserver.py @@ -146,6 +146,15 @@ def get_random_port(game_ports): available_ports.append(int(item)) port = get_port_from_list(available_ports) + if port == 0: + logging.info("Unable to find port. Expanding search to the default ports. (49152-65535)") + checked_ports = [] + while len(set(checked_ports)) < (65535-49152)+1: + port = random.randint(49152, 65535) + if not is_port_in_use(port): + break + else: + checked_ports.append(port) return port diff --git a/docs/webhost configuration sample.yaml b/docs/webhost configuration sample.yaml index 70e03ec112..2a78e18997 100644 --- a/docs/webhost configuration sample.yaml +++ b/docs/webhost configuration sample.yaml @@ -19,6 +19,7 @@ # Ports used for game hosting. Values can be specific ports, port ranges or both. Default is: "49152-65535" # Examples of valid values: "40000-41000,49152-65535" +# If ports within the range(s) are already in use, the WebHost will fallback to the default "49152-65535" range. #GAME_PORTS: "49152-65535" # Place where uploads go.