adding hint

This commit is contained in:
Linventif 2023-11-05 04:26:08 +01:00
parent 0f500ae9b4
commit 973ccfa1b0
3 changed files with 42 additions and 11 deletions

View File

@ -98,6 +98,11 @@ function gmInte.serverShutDown()
end end
function gmInte.sendStatus(start) 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", gmInte.post("/server/status",
{ {
["start"] = start || false, ["start"] = start || false,
@ -108,7 +113,12 @@ function gmInte.sendStatus(start)
["players"] = #player.GetAll(), ["players"] = #player.GetAll(),
["maxplayers"] = game.MaxPlayers(), ["maxplayers"] = game.MaxPlayers(),
["gamemode"] = engine.ActiveGamemode() ["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 end

View File

@ -24,9 +24,12 @@ local function sendHTTP(params)
if (params.success) then if (params.success) then
params.success(code, body, headers) params.success(code, body, headers)
end end
else
if (params.failed) then
params.failed(code, body, headers)
else else
gmInte.logError("HTTP Request failed with code " .. code) gmInte.logError("HTTP Request failed with code " .. code)
if (gmInte.debug) then gmInte.logError("HTTP Body: " .. body) end end
end end
end, end,
failed = function(error) failed = function(error)
@ -35,37 +38,41 @@ local function sendHTTP(params)
}) })
end end
function gmInte.get(endpoint, onSuccess) function gmInte.get(endpoint, onSuccess, onFailed)
sendHTTP({ sendHTTP({
endpoint = endpoint, endpoint = endpoint,
method = "GET", method = "GET",
success = onSuccess success = onSuccess,
failed = onFailed
}) })
end end
function gmInte.post(endpoint, data, onSuccess) function gmInte.post(endpoint, data, onSuccess, onFailed)
sendHTTP({ sendHTTP({
endpoint = endpoint, endpoint = endpoint,
method = "POST", method = "POST",
body = util.TableToJSON(data), body = util.TableToJSON(data),
success = onSuccess success = onSuccess,
failed = onFailed
}) })
end end
function gmInte.put(endpoint, data, onSuccess) function gmInte.put(endpoint, data, onSuccess, onFailed)
sendHTTP({ sendHTTP({
endpoint = endpoint, endpoint = endpoint,
method = "PUT", method = "PUT",
body = util.TableToJSON(data), body = util.TableToJSON(data),
success = onSuccess success = onSuccess,
failed = onFailed
}) })
end end
function gmInte.delete(endpoint, onSuccess) function gmInte.delete(endpoint, onSuccess, onFailed)
sendHTTP({ sendHTTP({
endpoint = endpoint, endpoint = endpoint,
method = "DELETE", method = "DELETE",
success = onSuccess success = onSuccess,
failed = onFailed
}) })
end end

View File

@ -14,3 +14,17 @@ function gmInte.logError(msg, debug)
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg) print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg)
if (debug) then print(debug.traceback()) end if (debug) then print(debug.traceback()) end
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