diff --git a/lua/gmod_integration/server/sv_main.lua b/lua/gmod_integration/server/sv_main.lua index c65f545..e3ab213 100644 --- a/lua/gmod_integration/server/sv_main.lua +++ b/lua/gmod_integration/server/sv_main.lua @@ -98,6 +98,11 @@ function gmInte.serverShutDown() end function gmInte.sendStatus(start) + if (gmInte.config.id == "" || gmInte.config.token == "") then + gmInte.logError("ID or Token is empty: (id: " .. gmInte.config.id .. ", token: " .. (gmInte.config.token == "" && "empty" || "not empty") .. ")") + gmInte.logHint("Use 'gmod-integration settings id YOUR_SERVER_ID' and 'gmod-integration settings token YOUR_SERVER_TOKEN' to set your credentials, you can find them on https://gmod-integration.com/guild/servers") + return + end gmInte.post("/server/status", { ["start"] = start || false, @@ -108,7 +113,12 @@ function gmInte.sendStatus(start) ["players"] = #player.GetAll(), ["maxplayers"] = game.MaxPlayers(), ["gamemode"] = engine.ActiveGamemode() - } + }, + function() end, + function(code, body, headers) + gmInte.logError("Your Credentials are Invalid: (id: " .. gmInte.config.id .. ", token: " .. (gmInte.config.token == "" && "empty" || "not empty") .. ")") + gmInte.logHint("Use 'gmod-integration settings id YOUR_SERVER_ID' and 'gmod-integration settings token YOUR_SERVER_TOKEN' to set your credentials, you can find them on https://gmod-integration.com/guild/servers") + end ) end diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index 563f930..16b5f6b 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -25,8 +25,11 @@ local function sendHTTP(params) params.success(code, body, headers) end else - gmInte.logError("HTTP Request failed with code " .. code) - if (gmInte.debug) then gmInte.logError("HTTP Body: " .. body) end + if (params.failed) then + params.failed(code, body, headers) + else + gmInte.logError("HTTP Request failed with code " .. code) + end end end, failed = function(error) @@ -35,37 +38,41 @@ local function sendHTTP(params) }) end -function gmInte.get(endpoint, onSuccess) +function gmInte.get(endpoint, onSuccess, onFailed) sendHTTP({ endpoint = endpoint, method = "GET", - success = onSuccess + success = onSuccess, + failed = onFailed }) end -function gmInte.post(endpoint, data, onSuccess) +function gmInte.post(endpoint, data, onSuccess, onFailed) sendHTTP({ endpoint = endpoint, method = "POST", body = util.TableToJSON(data), - success = onSuccess + success = onSuccess, + failed = onFailed }) end -function gmInte.put(endpoint, data, onSuccess) +function gmInte.put(endpoint, data, onSuccess, onFailed) sendHTTP({ endpoint = endpoint, method = "PUT", body = util.TableToJSON(data), - success = onSuccess + success = onSuccess, + failed = onFailed }) end -function gmInte.delete(endpoint, onSuccess) +function gmInte.delete(endpoint, onSuccess, onFailed) sendHTTP({ endpoint = endpoint, method = "DELETE", - success = onSuccess + success = onSuccess, + failed = onFailed }) end diff --git a/lua/gmod_integration/shared/sh_main.lua b/lua/gmod_integration/shared/sh_main.lua index c41384f..d1459df 100644 --- a/lua/gmod_integration/shared/sh_main.lua +++ b/lua/gmod_integration/shared/sh_main.lua @@ -13,4 +13,18 @@ function gmInte.logError(msg, debug) if (debug && !gmInte.debug) then return end print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg) if (debug) then print(debug.traceback()) end +end + +// Log Warning +function gmInte.logWarning(msg, debug) + if (debug && !gmInte.debug) then return end + print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [WARNING] " .. msg) + if (debug) then print(debug.traceback()) end +end + +// Log Hint +function gmInte.logHint(msg, debug) + if (debug && !gmInte.debug) then return end + print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [HINT] " .. msg) + if (debug) then print(debug.traceback()) end end \ No newline at end of file