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.