So someone asked me to create a resource that checks for the players steam account age but every time I do a PerformHttpRequest
to get the Steam Account Age it always returns a 400 status code.
The code for the resource will be below if someone could help.
fxmanifest.lua
fx_version 'cerulean'
games {'gta5'}
server_scripts {
'config.lua',
'server.lua',
}
config.lua
Config = {}
Config.Debug = true
Config.SteamAPIKey = ''
Config.AllowedAge = 91 --Days
server.lua
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local src = source
deferrals.defer()
Citizen.Wait(0)
deferrals.update('Checking for Steam...')
local steamHex = string.gsub(GetPlayerIdentifier(src, 0), 'steam:', '')
if not steamHex then
deferrals.done('You MUST have Steam running to connect to this server!')
end
local steamID = tonumber(steamHex, 16)
if not steamID then
deferrals.done('You MUST have Steam running to connect to this server!')
end
Citizen.Wait(1500)
local playerSteamAccountCreated = nil
deferrals.update('Checking Steam Account Age...')
PerformHttpRequest('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' .. steamAPIKey .. '&steamids=' .. steamID, function(err, response, headers)
if response then
local accountInfo = json.decode(response)
playerSteamAccountCreated = accountInfo['response']['players'][1]['timecreated']
end
end, 'GET', json.encode({}), { ['Content-Type'] = 'application/json' })
Citizen.Wait(1500)
deferrals.update('Verifying Steam Checks...')
Citizen.Wait(1500)
if playerSteamAccountCreated ~= nil and os.time() - playerSteamAccountCreated < Config.AllowedAge then
deferrals.done('You have been denied access to this server for the following reason: Your Steam Account isn\'t within the threshold (must be ' .. Config.AllowedAge .. ' days old)')
else
deferrals.done()
end
end)