From 8c2e4823cdc0c0e6679705056330595252a969c8 Mon Sep 17 00:00:00 2001 From: Ethan Stubbs <37120476+tgpethan@users.noreply.github.com> Date: Fri, 5 Feb 2021 03:15:05 +0000 Subject: [PATCH] Make default location null island --- server/loginHandler.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/server/loginHandler.js b/server/loginHandler.js index c767aa7..0e7189c 100644 --- a/server/loginHandler.js +++ b/server/loginHandler.js @@ -24,17 +24,22 @@ module.exports = function(req, res, loginInfo) { // Get users IP for getting location let requestIP = req.get('X-Real-IP'); - if (requestIP == null) { + if (requestIP == null) requestIP = req.remote_addr; - } + + // Make sure requestIP is never null + if (requestIP == null) + requestIP = ""; + let userLocationData = [], userLocation; - // Check if it is a local IP - if (`${requestIP}`.includes("192.168.")) { - userLocationData.country = "GB"; // My country - userLocation = [53, -2]; // My rough location lol + // Check if it is a local or null IP + if (requestIP.includes("192.168.") || requestIP.includes("127.0.") || requestIP == "") { + // Set location to null island + userLocationData.country = "XX"; + userLocation = [0, 0]; } else { - // Get user's location from zxq + // Get user's location using zxq userLocationData = JSON.parse(request("GET", `http://ip.zxq.co/${requestIP}`).getBody()); userLocation = userLocationData.loc.split(","); }