Last active
August 6, 2024 20:35
-
-
Save BadgerCode/a16b475a21a2233d699d092fde0497de to your computer and use it in GitHub Desktop.
Checks if a user is using a family-shared copy of Garry's Mod from an account which is banned and then kicks them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This goes in: | |
-- garrysmod/garrysmod/lua/autorun/account-sharing.lua | |
-- Or, if you want to keep your custom code separate from the default GMod server files: | |
-- garrysmod/garrysmod/addons/accountsharing/lua/autorun/account-sharing.lua | |
-- You will need to make some of these folders | |
-- Original post http://facepunch.com/showthread.php?t=1341204&p=43469693&viewfull=1#post43469693 | |
-- Credit to McSimp | |
local APIKey = "APIKEYGOESHERE" -- See http://steamcommunity.com/dev/apikey | |
local function HandleSharedPlayer(ply, lenderSteamID) | |
local chatMessage = string.format("FamilySharing: %s (%s) has been lent Garry's Mod by %s", ply:Nick(), ply:SteamID(), lenderSteamID) | |
print(chatMessage) | |
if not (ULib and ULib.bans) then return end | |
local playerIsBanned = ULib.bans[lenderSteamID] | |
if playerIsBanned then | |
local banMessage = string.format("%s (%s) has been lent Garry's Mod by a banned account- %s", ply:Nick(), ply:SteamID(), lenderSteamID) | |
for i, ply in ipairs(player.GetHumans()) do | |
ply:ChatPrint(banMessage) | |
end | |
ply:Kick("The account that lent you Garry's Mod is banned on this server") | |
end | |
end | |
local function CheckFamilySharing(ply) | |
http.Fetch( | |
string.format("http://api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?key=%s&format=json&steamid=%s&appid_playing=4000", | |
APIKey, | |
ply:SteamID64() | |
), | |
function(rawJSONBody, len, headers, status) | |
body = util.JSONToTable(rawJSONBody) | |
if status ~= 200 or not body or not body.response then | |
error(string.format("FamilySharing: Invalid Steam API response (%s) for %s | %s: \nJSON: \"%s\"\n", status, ply:Nick(), ply:SteamID(), rawJSONBody)) | |
end | |
local lender = body.response.lender_steamid or nil | |
if lender and lender ~= '' and lender ~= "0" then | |
HandleSharedPlayer(ply, util.SteamIDFrom64(lender)) | |
end | |
end, | |
function(code) | |
error(string.format("FamilySharing: Failed API call for %s | %s (Error: %s)\n", ply:Nick(), ply:SteamID(), code)) | |
end | |
) | |
end | |
hook.Remove("PlayerAuthed", "CheckFamilySharing") | |
hook.Add("PlayerAuthed", "CheckFamilySharing", CheckFamilySharing) |
This no longer works as Valve have removed the API endpoint
https://developer.valvesoftware.com/w/index.php?title=Steam_Web_API&type=revision&diff=238804&oldid=230181
IsPlayingSharedGame
This could be re-written to use the newer, in-game method to retrieve this information
https://wiki.facepunch.com/gmod/Player:OwnerSteamID64
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes! The new code was a success erased the error. Thought it maybe could've been the firewall off the localhost, but it cleared right up! Thank you!