• Print

Author Topic: FamilySharing Check : HELP  (Read 6635 times)

0 Members and 1 Guest are viewing this topic.

Offline SaintSin

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
FamilySharing Check : HELP
« on: January 31, 2014, 06:24:16 am »
Hey this was my first swing at a ulx command I used most of the code from the link at the bottom, but I am trying to create a command that will check users for their 'parent' account. This is not intended to be a final product. I intend to incorporate it into my ban function, but I wanted to get this working first.

My issue is I am not getting any errors, but I am not getting the proper results that I'd like.

Quote
] ulx check "wD. SaintSin"
(SILENT) You: Unmodified

Help?

Code: Lua
  1. local CATEGORY_NAME = "Utility"
  2. local APIKey = "<insert API key>" -- See [url]http://steamcommunity.com/dev/apikey[/url]
  3.  
  4. function ulx.check( calling_ply, target_ply )
  5.         local message = "Unmodified"
  6.        
  7.         http.Fetch(string.format("http://api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?key=%s&steamid=%s&appid_playing=240&format=json",
  8.                 APIKey,
  9.                 target_ply:SteamID64()),
  10.  
  11.                 function(body)
  12.                         if not body or not body.response or not body.response.lender_steamid then
  13.                                 message  = string.format("Invalid Steam API response for #T | %s",
  14.                                         target_ply:SteamID())
  15.                         end
  16.  
  17.                         local lender = body.response.lender_steamid
  18.                         if lender == "0" then
  19.                                 message  = string.format("#T | %s is the owner of this account",
  20.                                         target_ply:SteamID())
  21.                         else
  22.                                 message = string.format("#T | %s has been lent Garry's Mod by %s",
  23.                                         target_ply:SteamID(),
  24.                                         util.SteamIDFrom64(lender))
  25.                         end
  26.                 end,
  27.  
  28.                 function(code)
  29.                         message  = string.format("Failed API call for #T | %s (Error: %s)\n",
  30.                                 target_ply:SteamID(), code)
  31.                 end
  32.         )
  33.         ulx.fancyLogAdmin( calling_ply, true, string.format("#A: %s", message), affected_plys )
  34. end    
  35. local check = ulx.command( CATEGORY_NAME, 'ulx check', ulx.check, '!check')
  36. check:addParam{ type=ULib.cmds.PlayerArg}
  37. check:defaultAccess( ULib.ACCESS_ADMIN )
  38. check:help( "Gets the FamilySharing owner of the target's account." )
(majority of this is not my code)
« Last Edit: February 01, 2014, 09:28:22 am by SaintSin »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: FamilySharing Check : HELP
« Reply #1 on: January 31, 2014, 02:41:01 pm »
First, don't put target_ply in a table bracket.
The player is already a table object.
Second, you do have and are inserting a Steam API key where it says 'insert' one, right?
Third, and quite a large 'this won't work' ... you're using ply:SteamID64.
You'd either want affected_plys (why the S, you're using the single ULib player object command in  your command setup) or target_ply.

Fourth, those are all in my quick review, see where it takes you.
I'd have to write my own code to teach myself http.Fetch from there.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline SaintSin

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: FamilySharing Check : HELP
« Reply #2 on: February 01, 2014, 09:32:34 am »
Yeah sorry those were all typos I must have missed. Yes I do have an API key setup. It appears that the issue was http.Fetch would not change the message variable before ulx.fancyLogAdmin would be called.

So by using fancyLog inside of the onconnect and onfailure functions it seems to work. Just prints with a delay.

NOTE: I was tried using the table because after awhile of this not working I was getting desperate and tried it. Didn't think it would change anything, but this is my first time working with ulx so I gave it a shot.

Code: Lua
  1. local CATEGORY_NAME = "Utility"
  2. local APIKey = "<insert API key>" -- See [url]http://steamcommunity.com/dev/apikey[/url]
  3.  
  4. local function ulxcheckResponse( calling_ply, target_ply, message )
  5.         ulx.fancyLogAdmin( calling_ply, true, string.format("#A: %s", message), target_ply )
  6. end
  7.  
  8. function ulx.check( calling_ply, target_ply )
  9.         local message = "Unmodified"
  10.        
  11.     http.Fetch(
  12.         string.format("http://api.steampowered.com/IPlayerService/IsPlayingSharedGame/v0001/?key=%s&format=json&steamid=%s&appid_playing=4000",
  13.             APIKey,
  14.             target_ply:SteamID64()
  15.         ),
  16.        
  17.  
  18.                 function(body)
  19.                         local body = util.JSONToTable(body)
  20.                        
  21.                         if not body or not body.response or not body.response.lender_steamid then
  22.                                 ulxcheckResponse(calling_ply, target_ply, string.format("Invalid Steam API response for #T | %s", target_ply:SteamID()))
  23.                         end
  24.  
  25.                         local lender = body.response.lender_steamid
  26.                         if lender == "0" then
  27.                                 ulxcheckResponse(calling_ply, target_ply, string.format("#T | %s is the owner of this account.",
  28.                                         target_ply:SteamID()))
  29.                         else
  30.                                 ulxcheckResponse(calling_ply, target_ply, string.format("#T | %s has been lent Garry's Mod by %s",
  31.                                         target_ply:SteamID(),
  32.                                         util.SteamIDFrom64(lender)))
  33.                         end
  34.                        
  35.                 end,
  36.  
  37.                 function(code)
  38.                         ulxcheckResponse(calling_ply, target_ply, string.format("Failed API call for #T | %s (Error: %s)\n",
  39.                                 target_ply:SteamID(), code))
  40.                 end
  41.         )
  42.        
  43. end    
  44. local check = ulx.command( CATEGORY_NAME, 'ulx check', ulx.check, '!check')
  45. check:addParam{ type=ULib.cmds.PlayerArg}
  46. check:defaultAccess( ULib.ACCESS_ADMIN )
  47. check:help( "Gets the FamilySharing owner of the target's account." )
« Last Edit: February 01, 2014, 09:35:52 am by SaintSin »

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: FamilySharing Check : HELP
« Reply #3 on: February 01, 2014, 01:03:20 pm »
I'm actually quite curious, why did you make this into a ulx command instead of having it run automatically?
Out of the Garry's Mod business.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: FamilySharing Check : HELP
« Reply #4 on: February 01, 2014, 02:35:45 pm »
Personally, I wouldn't want something like this running for every user join.
Only the ones I want to keep an eye on or know more about.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline SaintSin

  • Newbie
  • *
  • Posts: 14
  • Karma: 0
Re: FamilySharing Check : HELP
« Reply #5 on: February 02, 2014, 03:43:03 pm »
Well this is my first time messing around with ulx commands so I just wanted to get an idea on how it all works. Eventually I will have this integrated into bans. So it will only ban the primary account. Then McSimps code kicks any secondary accounts that have their primary banned.

But it can also be useful to know who is on your server and what they're doing.

  • Print