diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index e5a2667..b4a1ba8 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -2,7 +2,7 @@ local apiVersion = "v3" gmInte.http = gmInte.http || {} local function getAPIURL(endpoint) - local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion + local method = gmInte.isPrivateIP(gmInte.config.apiFQDN) && "http" || "https" endpoint = string.gsub(endpoint, ":serverID", gmInte.config.id) @@ -10,7 +10,7 @@ local function getAPIURL(endpoint) endpoint = string.gsub(endpoint, ":steamID64", LocalPlayer():SteamID64()) end - return url .. endpoint + return method .. "://" .. gmInte.config.apiFQDN .. "/" .. apiVersion .. endpoint end local function showableBody(endpoint) diff --git a/lua/gmod_integration/shared/sh_main.lua b/lua/gmod_integration/shared/sh_main.lua index 280f944..f9c5f83 100644 --- a/lua/gmod_integration/shared/sh_main.lua +++ b/lua/gmod_integration/shared/sh_main.lua @@ -24,4 +24,17 @@ end function gmInte.logHint(msg, debug) if (debug && !gmInte.config.debug) then return end print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [HINT] " .. msg) +end + +// Is Private IP +function gmInte.isPrivateIP(ip) + // detect localhost + if (ip == "localhost") then return true end + // detect private IP addresses (RFC 1918) + local parts = string.Explode(".", ip) + if (parts[1] == "192" && parts[2] == "168") then return true end + if (parts[1] == "10") then return true end + if (parts[1] == "172" && tonumber(parts[2]) >= 16 && tonumber(parts[2]) <= 31) then return true end + if (parts[1] == "127") then return true end + return false end \ No newline at end of file