Http help

I’m trying to throw together a VAC status checker plugin, and I’ve hit something of a brick wall.

[lua]http.Fetch(“http://steamcommunity.com/profiles/” … ID64 … “?xml=true”, VACOnSuccess, VACOnFail)[/lua]

This part doesn’t always work due to auto-redirects to the player profile via their customUrl. (Returns error code of ‘unsuccessful’ to fail callback.)

So the question is, can you get a player’s customUrl code-side? If not, is there a website out there that performs VAC status checks and has a plaintext/XML/some-other-basic-format mode?

Community ID should be reliable. I use it all the time on my website. One thing I noticed is that if I use http, it will fail quite often. Try changing the address to https://steamcommunity.com/
Then you can parse out the <vacBanned> bit and hey presto.

I’ve noticed recently that the profile xml stuff returns 503 errors very randomly. I’m pretty sure Valve are doing it to make people use their Steam Web API instead of the xml though. If you’re doing the http.Fetch call serverside then you may as well use that anyway. The calls to the API returns json, so you can use util.JSONToTable to get the data you need from it.

That’s what I thought. I always used to get 503 errors 'til I tried using https, works each time now

Went with the Steam Web API approach, works like a charm.

In exchange for your help, have a copy of what you helped me make:

[lua]CachedVAC = {}
local APIKey = “YourSteamWebAPIKeyHere”

function VACStatus(ply)
if !IsValid(ply) then return end
local ID64 = ply:SteamID64()
local ID = ply:SteamID()
local function CheckVACBan(body, _, __, ___)
local data = util.JSONToTable(body)
if data and data[“players”] and data[“players”][1] and tobool(data[“players”][1][“VACBanned”]) then
ply:Kick(“VAC-Banned players aren’t welcome here!”) --Your preferred banning option here.
return
end
if IsValid(ply) then
ply.CleanVAC = true
ply.VACPending = nil
end
CacheVACStatus(ID) --Daily cache. Limits API calls.
end

local function VACFail(code)
	ErrorNoHalt("VAC Status Checker: Failed on HTTP Fetch for " .. ID64 .. " (Error Code: " .. code .. ")

")
end

http.Fetch("http://api.steampowered.com/ISteamUser/GetPlayerBans/v0001/?key=" .. APIKey .. "&format=json&steamids=" .. ID64, CheckVACBan, VACFail)

end

local function ReadyVAC(ply)
if ply.CleanVAC or ply.VACPending then return end
if CachedVAC[ply:SteamID()] then
ply.CleanVAC = true
return
end
ply.VACPending = true
timer.Simple(1, function() VACStatus(ply) end) --Delayed API call to allow for admin plugins that kick/ban on GM:PlayerInitialSpawn().
end
hook.Add(“PlayerInitialSpawn”, “VACTester”, ReadyVAC)

function CacheVACStatus(ID)
if CachedVAC[ID] then return end
CachedVAC[ID] = true
file.Append(“cachedvac.txt”, ID … "
")
end

local function LoadCachedVAC()
if _VACReady then return end
_VACReady = true --Don’t reload unless new map.
local NowDate = os.date("%m") … “-” … os.date("%d") … “-” … os.date("%y")
if file.Exists(“vacday.txt”, “DATA”) then
local VACDate = file.Read(“vacday.txt”, “DATA”) --This file determines whether we load the cache or delete it.
if VACDate != NowDate then
file.Write(“vacday.txt”, NowDate)
file.Write(“cachedvac.txt”, "//VAC Cache for " … NowDate … "
“)
return
end
else
file.Write(“vacday.txt”, NowDate)
end
if file.Exists(“cachedvac.txt”, “DATA”) then
local fileparse = string.Explode(”
", file.Read(“cachedvac.txt”, “DATA”))
for _, line in pairs(fileparse) do
if string.sub(string.Trim(line), 1, 2) != “//” and string.Trim(line) != “” then
CachedVAC[string.upper(string.Trim(line))] = true --Trimming and uppering on the offchance some smartass decides to edit the file by hand.
end
end
else
file.Write(“cachedvac.txt”, "//VAC Cache for " … NowDate … "
")
end
end
hook.Add(“Initialize”, “ReadyVAC”, LoadCachedVAC)[/lua]