mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
add: gmInte.http.postLog for Batching logs event
This commit is contained in:
parent
43a567750e
commit
70ef993039
|
@ -4,7 +4,7 @@ function gmInte.playerReady(ply)
|
||||||
ply.gmIntTimeConnect = math.Round(RealTime())
|
ply.gmIntTimeConnect = math.Round(RealTime())
|
||||||
// Send Public Config
|
// Send Public Config
|
||||||
gmInte.publicGetConfig(ply)
|
gmInte.publicGetConfig(ply)
|
||||||
gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/ready", {
|
gmInte.http.postLog("/servers/:serverID/players/" .. ply:SteamID64() .. "/ready", {
|
||||||
["player"] = gmInte.getPlayerFormat(ply)
|
["player"] = gmInte.getPlayerFormat(ply)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@ end
|
||||||
|
|
||||||
function gmInte.playerSpawn(ply)
|
function gmInte.playerSpawn(ply)
|
||||||
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
||||||
gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/spawn", {
|
gmInte.http.postLog("/servers/:serverID/players/" .. ply:SteamID64() .. "/spawn", {
|
||||||
["player"] = gmInte.getPlayerFormat(ply)
|
["player"] = gmInte.getPlayerFormat(ply)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,7 @@ function gmInte.playerDeath(ply, inflictor, attacker)
|
||||||
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
||||||
if !attacker:IsValid() || !attacker:IsPlayer(attacker) then return end
|
if !attacker:IsValid() || !attacker:IsPlayer(attacker) then return end
|
||||||
if !inflictor:IsValid() then return end
|
if !inflictor:IsValid() then return end
|
||||||
gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/death", {
|
gmInte.http.postLog("/servers/:serverID/players/" .. ply:SteamID64() .. "/death", {
|
||||||
["player"] = gmInte.getPlayerFormat(ply),
|
["player"] = gmInte.getPlayerFormat(ply),
|
||||||
["inflictor"] = gmInte.getEntityFormat(inflictor),
|
["inflictor"] = gmInte.getEntityFormat(inflictor),
|
||||||
["attacker"] = gmInte.getPlayerFormat(attacker)
|
["attacker"] = gmInte.getPlayerFormat(attacker)
|
||||||
|
@ -41,7 +41,7 @@ end
|
||||||
|
|
||||||
function gmInte.playerInitialSpawn(ply)
|
function gmInte.playerInitialSpawn(ply)
|
||||||
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
||||||
gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/initial-spawn", {
|
gmInte.http.postLog("/servers/:serverID/players/" .. ply:SteamID64() .. "/initial-spawn", {
|
||||||
["player"] = gmInte.getPlayerFormat(ply)
|
["player"] = gmInte.getPlayerFormat(ply)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
@ -60,7 +60,7 @@ function gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/hurt", {
|
gmInte.http.postLog("/servers/:serverID/players/" .. ply:SteamID64() .. "/hurt", {
|
||||||
["victim"] = gmInte.getPlayerFormat(ply),
|
["victim"] = gmInte.getPlayerFormat(ply),
|
||||||
["attacker"] = gmInte.getPlayerFormat(attacker),
|
["attacker"] = gmInte.getPlayerFormat(attacker),
|
||||||
["healthRemaining"] = math.Round(healthRemaining),
|
["healthRemaining"] = math.Round(healthRemaining),
|
||||||
|
@ -72,7 +72,7 @@ end
|
||||||
function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model)
|
function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model)
|
||||||
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
||||||
if !ent:IsValid() then return end
|
if !ent:IsValid() then return end
|
||||||
gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/spawn/" .. object, {
|
gmInte.http.postLog("/servers/:serverID/players/" .. ply:SteamID64() .. "/spawn/" .. object, {
|
||||||
["player"] = gmInte.getPlayerFormat(ply),
|
["player"] = gmInte.getPlayerFormat(ply),
|
||||||
["entity"] = gmInte.getEntityFormat(ent),
|
["entity"] = gmInte.getEntityFormat(ent),
|
||||||
["model"] = model || ""
|
["model"] = model || ""
|
||||||
|
@ -81,7 +81,7 @@ end
|
||||||
|
|
||||||
function gmInte.postLogPlayerGive(ply, class, swep)
|
function gmInte.postLogPlayerGive(ply, class, swep)
|
||||||
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
if !ply:IsValid() || !ply:IsPlayer(ply) then return end
|
||||||
gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/give", {
|
gmInte.http.postLog("/servers/:serverID/players/" .. ply:SteamID64() .. "/give", {
|
||||||
["player"] = gmInte.getPlayerFormat(ply),
|
["player"] = gmInte.getPlayerFormat(ply),
|
||||||
["class"] = class,
|
["class"] = class,
|
||||||
["swep"] = swep
|
["swep"] = swep
|
||||||
|
|
|
@ -12,6 +12,7 @@ local function showableBody(endpoint)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local requestIndicator = {}
|
||||||
function gmInte.http.requestAPI(params)
|
function gmInte.http.requestAPI(params)
|
||||||
local body = params.body && util.TableToJSON(params.body || {}) || ""
|
local body = params.body && util.TableToJSON(params.body || {}) || ""
|
||||||
local bodyLength = string.len(body)
|
local bodyLength = string.len(body)
|
||||||
|
@ -23,6 +24,8 @@ function gmInte.http.requestAPI(params)
|
||||||
local version = gmInte.version || "Unknown"
|
local version = gmInte.version || "Unknown"
|
||||||
local showableBody = showableBody(params.endpoint)
|
local showableBody = showableBody(params.endpoint)
|
||||||
local localRequestID = util.CRC(tostring(SysTime()))
|
local localRequestID = util.CRC(tostring(SysTime()))
|
||||||
|
requestIndicator[CurTime()] = requestIndicator[CurTime()] + 1 || 1
|
||||||
|
timer.Simple(10, function() requestIndicator[CurTime()] = requestIndicator[CurTime()] - 1 end)
|
||||||
if token == "" then
|
if token == "" then
|
||||||
return failed(401, {
|
return failed(401, {
|
||||||
["error"] = "No token provided"
|
["error"] = "No token provided"
|
||||||
|
@ -91,6 +94,35 @@ function gmInte.http.post(endpoint, data, onSuccess, onFailed)
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local nextLogPacket = {}
|
||||||
|
function gmInte.http.postLog(endpoint, data)
|
||||||
|
if requestIndicator[CurTime()] > 20 then
|
||||||
|
local logPacketIndex = #nextLogPacket + 1
|
||||||
|
table.insert(nextLogPacket, {
|
||||||
|
["endpoint"] = endpoint,
|
||||||
|
["data"] = data
|
||||||
|
})
|
||||||
|
|
||||||
|
timer.Simple(3, function()
|
||||||
|
if #nextLogPacket == logPacketIndex then
|
||||||
|
gmInte.http.requestAPI({
|
||||||
|
["endpoint"] = "/servers/:serverID/logs",
|
||||||
|
["method"] = "POST",
|
||||||
|
["body"] = nextLogPacket
|
||||||
|
})
|
||||||
|
|
||||||
|
nextLogPacket = {}
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
gmInte.http.requestAPI({
|
||||||
|
["endpoint"] = endpoint,
|
||||||
|
["method"] = "POST",
|
||||||
|
["body"] = data
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function gmInte.http.put(endpoint, data, onSuccess, onFailed)
|
function gmInte.http.put(endpoint, data, onSuccess, onFailed)
|
||||||
gmInte.http.requestAPI({
|
gmInte.http.requestAPI({
|
||||||
["endpoint"] = endpoint,
|
["endpoint"] = endpoint,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user