Skip to content

Instantly share code, notes, and snippets.

@BadgerCode
Last active August 16, 2025 11:53
Show Gist options
  • Save BadgerCode/a16b475a21a2233d699d092fde0497de to your computer and use it in GitHub Desktop.
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 goes in:
-- lua/autorun/account-sharing.lua
-- Original post http://facepunch.com/showthread.php?t=1341204&p=43469693&viewfull=1#post43469693
-- Credit to McSimp
-- Updated to use ply:OwnerSteamID64 by BadgerCode
local function CheckFamilySharing(ply)
-- If the player is being shared the game, this will be the other account's steam ID
-- Otherwise, it will be the player's own steam ID
local lenderSteamID = util.SteamIDFrom64(ply:OwnerSteamID64())
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
hook.Remove("PlayerAuthed", "CheckFamilySharing")
hook.Add("PlayerAuthed", "CheckFamilySharing", CheckFamilySharing)
@BadgerCode
Copy link
Author

Hey @isaac309
On line 10, you need to replace APIKEYGOESHERE with your Steam API key

You can get a Steam API key from here- http://steamcommunity.com/dev/apikey

@isaac309
Copy link

Yes I added the apikey to local and still a [sahaddon] addons/sahaddon/lua/sv_bans.lua:103: FamilySharing: Invalid Steam API response for |

error - [C]:-1
onsuccess - addons/sahaddon/lua/sv_bans.lua:103
3. unknown - lua/includes/modules/http.lua:69
SVBANS: safecrackSVBANS: lockpickSVBANS: caSVBANS: hacking[Player1|2|STEAM_0:1:91111823] Lua Error:

[ERROR] gamemodes/darkrp/gamemode/cl_options.lua:137: bad argument #1 to 'pairs' (table expected, got nil)

pairs - [C]:-1
LoadOptions - gamemodes/darkrp/gamemode/cl_options.lua:137
3. CreateOptionsMenuPanel - gamemodes/darkrp/gamemode/cl_mainmenu.lua:1208
4. ShowMainMenu - gamemodes/darkrp/gamemode/cl_mainmenu.lua:2729
5. unknown - gamemodes/darkrp/gamemode/cl_mainmenu.lua:2822
6. unknown - lua/includes/modules/concommand.lua:54

@BadgerCode
Copy link
Author

I've updated the code to have some better logging and error handling.
Could you update your copy of the code @isaac309 ?

@isaac309
Copy link

I've updated the code to have some better logging and error handling. Could you update your copy of the code @isaac309 ?

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!

@BadgerCode
Copy link
Author

BadgerCode commented Aug 6, 2024

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

@BadgerCode
Copy link
Author

Updated to use Player:OwnerSteamID64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment