mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 17:17:33 +00:00
add gmInte.http.METHOD insted of gmInte.METHOD
This commit is contained in:
parent
909b429111
commit
28c064241a
|
@ -163,9 +163,6 @@ local possibleConfig = {
|
|||
["label"] = "Force Player Verif",
|
||||
["description"] = "Sync chat between the server and the discord server.",
|
||||
["type"] = "checkbox",
|
||||
["condition"] = function(data)
|
||||
return false // Disabled for now
|
||||
end,
|
||||
["value"] = function(setting, value)
|
||||
return value
|
||||
end,
|
||||
|
|
|
@ -37,7 +37,7 @@ function gmInte.openVerifPopup()
|
|||
local button = vgui.Create("DButton")
|
||||
button:SetText("Refresh Verification")
|
||||
button.DoClick = function()
|
||||
gmInte.get("/players/" .. LocalPlayer():SteamID64(), function(code, body)
|
||||
gmInte.http.get("/players/" .. LocalPlayer():SteamID64(), function(code, body)
|
||||
gmInte.SendNet(6)
|
||||
frame:Close()
|
||||
end,
|
||||
|
|
|
@ -12,6 +12,15 @@ local function formatName(name)
|
|||
return name
|
||||
end
|
||||
|
||||
function gmInte.chatAddText(data)
|
||||
local args = {}
|
||||
for _, v in ipairs(data) do
|
||||
table.insert(args, v.color)
|
||||
table.insert(args, v.text)
|
||||
end
|
||||
chat.AddText(unpack(args))
|
||||
end
|
||||
|
||||
function gmInte.discordSyncChatPly(data)
|
||||
chat.AddText(Color(92, 105, 255), "(DISCORD) ", Color(12, 151, 12), formatName(data.name) .. ": ", Color(255, 255, 255), data.content)
|
||||
end
|
||||
|
|
|
@ -16,6 +16,9 @@ Receive
|
|||
2 - Get Config
|
||||
3 - Test Connection
|
||||
4 - Take ScreenShot
|
||||
5 - Set Public Config
|
||||
6 - Add Chat
|
||||
7 - Open Verif Popup
|
||||
*/
|
||||
|
||||
// Send
|
||||
|
@ -40,6 +43,15 @@ local netFunc = {
|
|||
end,
|
||||
[4] = function(data)
|
||||
gmInte.takeScreenShot(data.serverID, data.authToken)
|
||||
end,
|
||||
[5] = function(data)
|
||||
gmInte.config = data
|
||||
end,
|
||||
[6] = function(data)
|
||||
gmInte.chatAddText(data)
|
||||
end,
|
||||
[7] = function()
|
||||
gmInte.openVerifPopup()
|
||||
end
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ hook.Add("PostRender", "gmInteScreenshot", function()
|
|||
screenCapture = util.Base64Encode(screenCapture)
|
||||
gmInte.log("Screenshot Taken - " .. string.len(#screenCapture / 1024) .. "KB", true)
|
||||
|
||||
gmInte.post("/screenshots",
|
||||
gmInte.http.post("/screenshots",
|
||||
{
|
||||
["steamID64"] = LocalPlayer():SteamID64(),
|
||||
["screenshot"] = screenCapture,
|
||||
|
|
|
@ -56,9 +56,9 @@ local function playerFilter(data)
|
|||
if (data.bot == 1) then return end
|
||||
data.steamID64 = util.SteamIDTo64(data.networkid)
|
||||
|
||||
gmInte.get("/players/" .. data.steamID64,
|
||||
gmInte.http.get("/players/" .. data.steamID64,
|
||||
function(code, body)
|
||||
if (!body.trust) then return end
|
||||
if (!body || !body.trust) then return end
|
||||
|
||||
if (!checkBanStatus(body.ban)) then
|
||||
game.KickID(data.networkid, filterMessage("You are banned from this server"))
|
||||
|
|
|
@ -63,7 +63,7 @@ end
|
|||
function gmInte.postLogPlayerSay(ply, text, teamChat)
|
||||
if (!validLogAndPlayers({ply})) then return end
|
||||
|
||||
gmInte.post("/logs/playerSay",
|
||||
gmInte.http.post("/logs/playerSay",
|
||||
{
|
||||
["ply"] = gmInte.playerFormat(ply),
|
||||
["text"] = text,
|
||||
|
@ -75,7 +75,7 @@ end
|
|||
function gmInte.postLogPlayerDeath(ply, inflictor, attacker)
|
||||
if (!validLogAndPlayers({ply, attacker})) then return end
|
||||
|
||||
gmInte.post("/logs/playerDeath",
|
||||
gmInte.http.post("/logs/playerDeath",
|
||||
{
|
||||
["ply"] = gmInte.playerFormat(ply),
|
||||
["inflictor"] = logFormatEntity(inflictor),
|
||||
|
@ -87,7 +87,7 @@ end
|
|||
function gmInte.postLogPlayerInitialSpawn(ply)
|
||||
if (!validLogAndPlayers({ply})) then return end
|
||||
|
||||
gmInte.post("/logs/playerInitialSpawn",
|
||||
gmInte.http.post("/logs/playerInitialSpawn",
|
||||
{
|
||||
["ply"] = gmInte.playerFormat(ply)
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ function gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken)
|
|||
return
|
||||
end
|
||||
|
||||
gmInte.post("/logs/playerHurt",
|
||||
gmInte.http.post("/logs/playerHurt",
|
||||
{
|
||||
["ply"] = gmInte.playerFormat(ply),
|
||||
["attacker"] = gmInte.playerFormat(attacker),
|
||||
|
@ -123,7 +123,7 @@ end
|
|||
function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model)
|
||||
if (!validLogAndPlayers({ply})) then return end
|
||||
|
||||
gmInte.post("/logs/playerSpawnedSomething",
|
||||
gmInte.http.post("/logs/playerSpawnedSomething",
|
||||
{
|
||||
["object"] = object,
|
||||
["ply"] = gmInte.playerFormat(ply),
|
||||
|
@ -136,7 +136,7 @@ end
|
|||
function gmInte.postLogPlayerSpawn(ply)
|
||||
if (!validLogAndPlayers({ply})) then return end
|
||||
|
||||
gmInte.post("/logs/playerSpawn",
|
||||
gmInte.http.post("/logs/playerSpawn",
|
||||
{
|
||||
["ply"] = gmInte.playerFormat(ply)
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ end
|
|||
function gmInte.postLogPlayerDisconnect(ply)
|
||||
if (!validLogAndPlayers({ply})) then return end
|
||||
|
||||
gmInte.post("/logs/playerDisconnect",
|
||||
gmInte.http.post("/logs/playerDisconnect",
|
||||
{
|
||||
["ply"] = gmInte.playerFormat(ply)
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ end
|
|||
function gmInte.postLogPlayerConnect(data)
|
||||
if (logDisable() || data.bot) then return end
|
||||
|
||||
gmInte.post("/logs/playerConnect",
|
||||
gmInte.http.post("/logs/playerConnect",
|
||||
{
|
||||
["steamID64"] = util.SteamIDTo64(data.networkid),
|
||||
["steamID"] = data.networkid,
|
||||
|
@ -169,7 +169,7 @@ end
|
|||
function gmInte.postLogPlayerGivet(ply, class, swep)
|
||||
if (!validLogAndPlayers({ply})) then return end
|
||||
|
||||
gmInte.post("/logs/playerGive",
|
||||
gmInte.http.post("/logs/playerGive",
|
||||
{
|
||||
["ply"] = gmInte.playerFormat(ply),
|
||||
["class"] = class,
|
||||
|
|
|
@ -8,6 +8,9 @@ Upload
|
|||
2 - Get Config
|
||||
3 - Test Connection
|
||||
4 - Take Screenshot
|
||||
5 - Send Public Config
|
||||
6 - Send Message
|
||||
7 - Open Verif Popup
|
||||
Receive
|
||||
0 - Player is Ready
|
||||
1 - Test Connection
|
||||
|
|
|
@ -77,48 +77,64 @@ end
|
|||
|
||||
function gmInte.verifyPlayer(ply)
|
||||
if (!gmInte.plyValid(ply)) then return end
|
||||
gmInte.get("/players/" .. ply:SteamID64(), function(data)
|
||||
if (data.discordID && ply.gmIntUnVerified) then
|
||||
gmInte.http.get("/players/" .. ply:SteamID64(), function(code, data)
|
||||
if ((data && data.steam_id && ply.gmIntUnVerified) || !gmInte.config.forcePlayerLink) then
|
||||
gmInte.SendNet(6, {
|
||||
[1] = {
|
||||
["text"] = "You have been verified",
|
||||
["color"] = Color(255, 255, 255)
|
||||
}
|
||||
}, ply)
|
||||
ply:Freeze(false)
|
||||
ply.gmIntUnVerified = false
|
||||
else
|
||||
gmInte.SendNet(6, {
|
||||
[1] = {
|
||||
["text"] = "You are not verified",
|
||||
["color"] = Color(255, 0, 0)
|
||||
}
|
||||
}, ply)
|
||||
ply:Freeze(true)
|
||||
ply.gmIntUnVerified = true
|
||||
gmInte.SendNet(7, nil, ply)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
// Generate a unique token that allow player to update data link to this server (ex: screnshot, report bug, etc.)
|
||||
function gmInte.getClientOneTimeToken(ply, callback)
|
||||
gmInte.get("/players/" .. ply:SteamID64() .. "/get-one-time-token", function(data)
|
||||
gmInte.http.get("/players/" .. ply:SteamID64() .. "/get-one-time-token", function(code, data)
|
||||
callback(data.token)
|
||||
end)
|
||||
end
|
||||
|
||||
function gmInte.playerConnect(data)
|
||||
gmInte.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/connect", data)
|
||||
gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/connect", data)
|
||||
end
|
||||
|
||||
function gmInte.userFinishConnect(ply)
|
||||
if (!gmInte.plyValid(ply)) then return end
|
||||
|
||||
// Initialize Time
|
||||
ply.gmIntTimeConnect = math.Round(RealTime())
|
||||
|
||||
gmInte.post("/players/" .. ply:SteamID64() .. "/finish-connect",
|
||||
// Send Public Config
|
||||
gmInte.publicGetConfig(ply)
|
||||
|
||||
gmInte.http.post("/players/" .. ply:SteamID64() .. "/finish-connect",
|
||||
{
|
||||
["player"] = gmInte.playerFormat(ply),
|
||||
}
|
||||
)
|
||||
|
||||
if (!gmInte.config.forcePlayerLink) then return end
|
||||
gmInte.get("/players/" .. ply:SteamID64(), function(data)
|
||||
if (!data.discordID) then
|
||||
ply:Freeze(true)
|
||||
ply.gmIntUnVerified = true
|
||||
end
|
||||
end)
|
||||
gmInte.verifyPlayer(ply)
|
||||
end
|
||||
|
||||
function gmInte.playerDisconnected(ply)
|
||||
if (!gmInte.plyValid(ply)) then return end
|
||||
|
||||
gmInte.post("/players/" .. ply:SteamID64() .. "/disconnect",
|
||||
gmInte.http.post("/players/" .. ply:SteamID64() .. "/disconnect",
|
||||
{
|
||||
["player"] = gmInte.playerFormat(ply),
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ function gmInte.saveSetting(setting, value)
|
|||
end
|
||||
|
||||
function gmInte.tryConfig()
|
||||
gmInte.get("",
|
||||
gmInte.http.get("",
|
||||
function(code, body)
|
||||
print(" ")
|
||||
gmInte.log("Congratulations your server is now connected to Gmod Integration")
|
||||
|
@ -29,7 +29,7 @@ function gmInte.tryConfig()
|
|||
end
|
||||
|
||||
function gmInte.testConnection(ply)
|
||||
gmInte.get("",
|
||||
gmInte.http.get("",
|
||||
function(code, body)
|
||||
if (ply) then gmInte.SendNet(3, body, ply) end
|
||||
end,
|
||||
|
@ -52,6 +52,15 @@ function gmInte.superadminGetConfig(ply)
|
|||
gmInte.SendNet(2, gmInte.config, ply)
|
||||
end
|
||||
|
||||
function gmInte.publicGetConfig(ply)
|
||||
if (!gmInte.plyValid(ply)) then return end
|
||||
|
||||
gmInte.SendNet(5, {
|
||||
["debug"] = gmInte.config.debug,
|
||||
["devInstance"] = gmInte.config.devInstance
|
||||
}, ply)
|
||||
end
|
||||
|
||||
function gmInte.superadminSetConfig(ply, data)
|
||||
if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end
|
||||
|
||||
|
|
|
@ -16,15 +16,15 @@ local function getServerFormat()
|
|||
end
|
||||
|
||||
function gmInte.sendStatus()
|
||||
gmInte.post("/status", getServerFormat())
|
||||
gmInte.http.post("/status", getServerFormat())
|
||||
end
|
||||
|
||||
-- function gmInte.serverStart()
|
||||
-- gmInte.post("/start", getServerFormat())
|
||||
-- gmInte.http.post("/start", getServerFormat())
|
||||
-- end
|
||||
|
||||
function gmInte.serverShutDown()
|
||||
gmInte.post("/shutdown")
|
||||
gmInte.http.post("/shutdown")
|
||||
end
|
||||
|
||||
//
|
||||
|
|
|
@ -15,7 +15,7 @@ end
|
|||
//
|
||||
|
||||
function gmInte.playerBan(data)
|
||||
gmInte.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/bans", data)
|
||||
gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/bans", data)
|
||||
end
|
||||
|
||||
//
|
||||
|
|
|
@ -13,7 +13,7 @@ end
|
|||
function gmInte.playerSay(ply, text, team)
|
||||
if (!gmInte.config.syncChat) then return end
|
||||
|
||||
gmInte.post("/players/" .. ply:SteamID64() .. "/say",
|
||||
gmInte.http.post("/players/" .. ply:SteamID64() .. "/say",
|
||||
{
|
||||
["player"] = gmInte.playerFormat(ply),
|
||||
["text"] = text,
|
||||
|
|
|
@ -15,7 +15,7 @@ end
|
|||
function gmInte.playerChangeName(ply, oldName, newName)
|
||||
if (!gmInte.plyValid(ply)) then return end
|
||||
|
||||
gmInte.post("/players/" .. ply:SteamID64() .. "/name",
|
||||
gmInte.http.post("/players/" .. ply:SteamID64() .. "/name",
|
||||
{
|
||||
["player"] = gmInte.playerFormat(ply),
|
||||
["oldName"] = oldName,
|
||||
|
|
|
@ -2,6 +2,8 @@ local apiVersion = "v3"
|
|||
local apiFQDN = "api.gmod-integration.com"
|
||||
local apiDevFQDN = "dev-api.gmod-integration.com"
|
||||
|
||||
gmInte.http = gmInte.http || {}
|
||||
|
||||
//
|
||||
// HTTP
|
||||
//
|
||||
|
@ -11,14 +13,18 @@ local function getAPIURL(endpoint)
|
|||
|
||||
if (SERVER) then
|
||||
url = url .. "/servers/" .. gmInte.config.id
|
||||
elseif (endpoint == "/players") then
|
||||
else
|
||||
if (string.sub(endpoint, 1, 8) == "/players" || string.sub(endpoint, 1, 7) == "/errors") then
|
||||
return url .. endpoint
|
||||
end
|
||||
|
||||
url = url .. "/clients/" .. LocalPlayer():SteamID64()
|
||||
end
|
||||
|
||||
return url .. endpoint
|
||||
end
|
||||
|
||||
function gmInte.requestAPI(params)
|
||||
function gmInte.http.requestAPI(params)
|
||||
local body = params.body || ""
|
||||
local bodyLength = string.len(body)
|
||||
local token = params.token || gmInte.config.token || ""
|
||||
|
@ -67,7 +73,7 @@ function gmInte.requestAPI(params)
|
|||
body = util.JSONToTable(body || "{}")
|
||||
|
||||
// Return success
|
||||
return success(code, body, headers)
|
||||
return success(body)
|
||||
end,
|
||||
["failed"] = function(error)
|
||||
gmInte.logError(error)
|
||||
|
@ -79,8 +85,8 @@ end
|
|||
// HTTP Methods
|
||||
//
|
||||
|
||||
function gmInte.get(endpoint, onSuccess, onFailed)
|
||||
gmInte.requestAPI({
|
||||
function gmInte.http.get(endpoint, onSuccess, onFailed)
|
||||
gmInte.http.requestAPI({
|
||||
["endpoint"] = endpoint,
|
||||
["method"] = "GET",
|
||||
["success"] = onSuccess,
|
||||
|
@ -88,8 +94,8 @@ function gmInte.get(endpoint, onSuccess, onFailed)
|
|||
})
|
||||
end
|
||||
|
||||
function gmInte.post(endpoint, data, onSuccess, onFailed)
|
||||
gmInte.requestAPI({
|
||||
function gmInte.http.post(endpoint, data, onSuccess, onFailed)
|
||||
gmInte.http.requestAPI({
|
||||
["endpoint"] = endpoint,
|
||||
["method"] = "POST",
|
||||
["body"] = util.TableToJSON(data),
|
||||
|
@ -98,8 +104,8 @@ function gmInte.post(endpoint, data, onSuccess, onFailed)
|
|||
})
|
||||
end
|
||||
|
||||
function gmInte.put(endpoint, data, onSuccess, onFailed)
|
||||
gmInte.requestAPI({
|
||||
function gmInte.http.put(endpoint, data, onSuccess, onFailed)
|
||||
gmInte.http.requestAPI({
|
||||
["endpoint"] = endpoint,
|
||||
["method"] = "PUT",
|
||||
["body"] = util.TableToJSON(data),
|
||||
|
@ -108,8 +114,8 @@ function gmInte.put(endpoint, data, onSuccess, onFailed)
|
|||
})
|
||||
end
|
||||
|
||||
function gmInte.delete(endpoint, onSuccess, onFailed)
|
||||
gmInte.requestAPI({
|
||||
function gmInte.http.delete(endpoint, onSuccess, onFailed)
|
||||
gmInte.http.requestAPI({
|
||||
["endpoint"] = endpoint,
|
||||
["method"] = "DELETE",
|
||||
["success"] = onSuccess,
|
||||
|
|
Loading…
Reference in New Issue
Block a user