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
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

View File

@ -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

View File

@ -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