Make default location null island

This commit is contained in:
Ethan Stubbs 2021-02-05 03:15:05 +00:00
parent 1697c55d0d
commit 8c2e4823cd

View file

@ -24,17 +24,22 @@ module.exports = function(req, res, loginInfo) {
// Get users IP for getting location // Get users IP for getting location
let requestIP = req.get('X-Real-IP'); let requestIP = req.get('X-Real-IP');
if (requestIP == null) { if (requestIP == null)
requestIP = req.remote_addr; requestIP = req.remote_addr;
}
// Make sure requestIP is never null
if (requestIP == null)
requestIP = "";
let userLocationData = [], userLocation; let userLocationData = [], userLocation;
// Check if it is a local IP // Check if it is a local or null IP
if (`${requestIP}`.includes("192.168.")) { if (requestIP.includes("192.168.") || requestIP.includes("127.0.") || requestIP == "") {
userLocationData.country = "GB"; // My country // Set location to null island
userLocation = [53, -2]; // My rough location lol userLocationData.country = "XX";
userLocation = [0, 0];
} else { } else {
// Get user's location from zxq // Get user's location using zxq
userLocationData = JSON.parse(request("GET", `http://ip.zxq.co/${requestIP}`).getBody()); userLocationData = JSON.parse(request("GET", `http://ip.zxq.co/${requestIP}`).getBody());
userLocation = userLocationData.loc.split(","); userLocation = userLocationData.loc.split(",");
} }