diff --git a/WebHostLib/__init__.py b/WebHostLib/__init__.py index eaf605063c..11a9619a7e 100644 --- a/WebHostLib/__init__.py +++ b/WebHostLib/__init__.py @@ -43,7 +43,7 @@ app.config["SELFLAUNCHKEY"] = None # can point to a SSL Certificate Key to encr app.config["SELFGEN"] = True # application process is in charge of scheduling Generations. app.config["DEBUG"] = False app.config["PORT"] = 80 -app.config["GAME_PORTS"] = "49152-65535,0" +app.config["GAME_PORTS"] = ["49152-65535", 0] app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['MAX_CONTENT_LENGTH'] = 64 * 1024 * 1024 # 64 megabyte limit # if you want to deploy, make sure you have a non-guessable secret key diff --git a/WebHostLib/customserver.py b/WebHostLib/customserver.py index eebcd446d4..275e281350 100644 --- a/WebHostLib/customserver.py +++ b/WebHostLib/customserver.py @@ -183,15 +183,14 @@ class WebHostContext(Context): return d -def get_random_port(game_ports): - config_range_list = game_ports.split(",") +def get_random_port(game_ports: list): available_ports = [] ephemeral_allowed = False - for item in config_range_list: - if '-' in item: + for item in game_ports: + if type(item) is str and '-' in item: start, end = map(int, item.split('-')) available_ports.append(range(start, end+1)) - elif item == "0": + elif int(item) == "0": ephemeral_allowed = True else: available_ports.append([int(item)]) @@ -277,7 +276,7 @@ def tear_down_logging(room_id): def run_server_process(name: str, ponyconfig: dict, static_server_data: dict, cert_file: typing.Optional[str], cert_key_file: typing.Optional[str], - host: str, game_ports: str, rooms_to_run: multiprocessing.Queue, + host: str, game_ports: list, rooms_to_run: multiprocessing.Queue, rooms_shutting_down: multiprocessing.Queue): from setproctitle import setproctitle diff --git a/docs/webhost configuration sample.yaml b/docs/webhost configuration sample.yaml index 42dcada132..059faeeef9 100644 --- a/docs/webhost configuration sample.yaml +++ b/docs/webhost configuration sample.yaml @@ -17,11 +17,11 @@ # Web hosting port #PORT: 80 -# Ports used for game hosting. Values can be specific ports, port ranges or both. Default is: "49152-65535,0" -# Zero means it will use a random free port if there is none in the range available -# 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,0" range. -#GAME_PORTS: "49152-65535,0" +# Ports used for game hosting. Values can be specific ports, port ranges or both. Default is: [49152-65535, 0] +# Zero means it will use a random free port if there is no port in the next 1024 randomly chosen ports from the range +# 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, 0] range. +#GAME_PORTS: [49152-65535, 0] # Place where uploads go. #UPLOAD_FOLDER: uploads