From 178a07e444c6fedb67be9a9f66a9c2a050fed066 Mon Sep 17 00:00:00 2001 From: Noah Bogart Date: Thu, 18 Jul 2024 16:39:51 -0400 Subject: [PATCH] Fix string->num to only work in clj --- src/clj/game/core/servers.cljc | 2 +- src/clj/game/utils.cljc | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/clj/game/core/servers.cljc b/src/clj/game/core/servers.cljc index bc92280ca5..64bfb80fc4 100644 --- a/src/clj/game/core/servers.cljc +++ b/src/clj/game/core/servers.cljc @@ -62,7 +62,7 @@ :archives -3 :rd -2 :hq -1 - (string->num + (parse-long (last (safe-split (str zone) #":remote"))))) (defn zones->sorted-names diff --git a/src/clj/game/utils.cljc b/src/clj/game/utils.cljc index 38a38fc27c..1680fd72d1 100644 --- a/src/clj/game/utils.cljc +++ b/src/clj/game/utils.cljc @@ -45,10 +45,11 @@ (cons x (step more (conj seen k))))))))] (step coll #{}))) -(defn string->num [s] - (cond - (number? s) s - (string? s) (parse-long s))) +#?(:clj (defn string->num [s] + (try + (let [num (bigdec s)] + (if (and (> num Integer/MIN_VALUE) (< num Integer/MAX_VALUE)) (int num) num)) + (catch Exception _ nil)))) (def safe-split (fnil str/split ""))