From 17cba1d8534b6572170151cea5b505986bbd8cd4 Mon Sep 17 00:00:00 2001 From: InDieTasten Date: Sat, 12 Mar 2022 18:29:01 +0100 Subject: [PATCH] Fix unique ip generation The previous implementation had a bug in it, where the generated IP wouldn't be unique, if the generated IP wouldn't be unique two times in a row. --- src/Server/AllServers.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Server/AllServers.ts b/src/Server/AllServers.ts index baf2d6ac0..42a8b6150 100644 --- a/src/Server/AllServers.ts +++ b/src/Server/AllServers.ts @@ -78,12 +78,11 @@ export function ipExists(ip: string): boolean { } export function createUniqueRandomIp(): string { - const ip = createRandomIp(); - - // If the Ip already exists, recurse to create a new one - if (ipExists(ip)) { - return createRandomIp(); - } + let ip: string; + // Repeat generating ip, until unique one is found + do { + ip = createRandomIp(); + } while (ipExists(ip)); return ip; }