From 85de9944a5535294d116a89a99521695a24c0276 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Wed, 29 Aug 2018 13:49:34 +0200 Subject: [PATCH] Adding a failsafe for rndName and how seeding works on crash --- server/handlers/functions.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/server/handlers/functions.js b/server/handlers/functions.js index 3c7bda5a..53b08711 100644 --- a/server/handlers/functions.js +++ b/server/handlers/functions.js @@ -165,11 +165,15 @@ function rndName(seed, len) { word = ''; is_vowel = false; var arr; - for (var i = 0; i < len; i++) { - if (is_vowel) arr = vowels; - else arr = consts; - is_vowel = !is_vowel; - word += arr[(seed[i%seed.length].charCodeAt()+i) % (arr.length-1)]; + try { + for (var i = 0; i < len; i++) { + if (is_vowel) arr = vowels; + else arr = consts; + is_vowel = !is_vowel; + word += arr[(seed[i%seed.length].charCodeAt()+i) % (arr.length-1)]; + } + } catch(e) { + return rndName(uniqid.time().toLowerCase(), len); } return word; }