Author Topic: ULX & Sourcebans Integration  (Read 20366 times)

0 Members and 5 Guests are viewing this topic.

Offline hymsan

  • Newbie
  • *
  • Posts: 28
  • Karma: 2
ULX & Sourcebans Integration
« on: November 18, 2011, 09:47:27 AM »
I know this has been asked a lot, but I'm working on my own version of this now, with the sourcebans lua module that was recently updated on facepunch.

This is my edited ulx ban module.

Code: [Select]
function ulx.ban( calling_ply, target_ply, time, reason )
if target_ply:IsBot() then
ULib.tsayError( calling_ply, "Cannot ban a bot", true )
return
end
local minutes = ULib.stringTimeToSeconds( time )
if not minutes then
ULib.tsayError( calling_ply, "Invalid time format." )
return
end

ULib.kickban( target_ply, minutes, reason, calling_ply )
sourcebans.BanPlayer( target_ply, minutes*60, reason, calling_ply ) -- THIS IS THE SOURCEBANS INTEGRATION.

local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A banned #T " .. time
if reason and reason ~= "" then str = str .. " (#s)" end
ulx.fancyLogAdmin( calling_ply, str, target_ply, minutes ~= 0 and minutes or reason, reason )
end
local ban = ulx.command( CATEGORY_NAME, "ulx ban", ulx.ban, "!ban" )
ban:addParam{ type=ULib.cmds.PlayerArg }
ban:addParam{ type=ULib.cmds.StringArg, hint="minutes, 0 for perma. 'h' for hours, 'd' for days, 'w' for weeks. EG, '2w5d' for 2 weeks 5 days", ULib.cmds.optional }
ban:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
ban:defaultAccess( ULib.ACCESS_ADMIN )
ban:help( "Bans target." )

Everything works when I ban someone, except it doesn't return anything about the admin.

This is the sourcebans lua module "banplayer" function, in which I have being called from "ulx ban."

Code: [Select]
function BanPlayer(ply, time, reason, admin, callback)
callback = callback or blankCallback;
if (not checkConnection()) then
return callback(false, "No Database Connection");
elseif (not ply:IsValid()) then
error("Expected player, got NULL!", 2);
end
doBan(ply:SteamID(), getIP(ply), ply:Name(), time, reason, admin, callback);
end

This is where it makes the first request for admin details.

Code: [Select]
local function getAdminDetails(admin)
if (admin and admin:IsValid()) then
local data = admins[admin:SteamID()]
if (data) then
return data.aid, getIP(admin);
end
end
return 0, serverip;
end

And above is where it tries to get admin data (SteamID) to return to the sourcebans ban page, however it always returns Nil (which the sourcebans lua module reads as "CONSOLE")

I believe this is because of ulx's calling_ply and the fact that the sourcebans module requests a steamid from calling_ply.

I don't know where to go from here.


More information on the module can be located here: http://lexi.org.uk/modules/sourcebans.html
« Last Edit: November 18, 2011, 10:39:47 AM by hymsan »

Offline strategos

  • Jr. Member
  • **
  • Posts: 66
  • Karma: 2
  • I wanna be the guy
    • Community
Re: ULX & Sourcebans Integration
« Reply #1 on: November 18, 2011, 09:40:26 PM »
YES!

THIS IS BEING MADE!!!! (over-reaction?) I think not

Please release this to the public when finished. I'll love you forever.
« Last Edit: November 18, 2011, 09:49:26 PM by strategos »

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: ULX & Sourcebans Integration
« Reply #2 on: November 18, 2011, 09:49:56 PM »
Hmm, honestly I would try to make it separate, because when updates come, users will need to keep editing the main code for it to keep working.

But I would like in on this, I was actually thinking on using player.ConCommand to call both commands, but after seeing this http://lexi.org.uk/modules/sourcebans.html I see how that can be implemented but, I still suggest that the commands should be separate.
« Last Edit: November 19, 2011, 12:48:43 AM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline hymsan

  • Newbie
  • *
  • Posts: 28
  • Karma: 2
Re: ULX & Sourcebans Integration
« Reply #3 on: November 19, 2011, 04:48:02 AM »
I'm actually looking for help on returning the SteamID of calling_ply in ULX, the sourcebans module was released by Lexic on facepunch, and is decently simple to integrate however with ulx there is no normal "ply" function in the util module.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: ULX & Sourcebans Integration
« Reply #4 on: November 19, 2011, 08:32:02 AM »
I made a quick script to make sure every thing is working.

Code: [Select]
-- ULX steamcheck for ULX SVN/ULib SVN by HeLLFox_15
function ulx.steamcheck( calling_ply, target_plys, command )

local plSteamID = calling_ply:SteamID()
Msg(plSteamID .. "\n")
if(calling_ply and calling_ply:IsValid()) then Msg("Server: Entity Returned True\n") else Msg("Server: Entity Returned False\n") end
if(calling_ply) then Msg("Server: " .. calling_ply:Nick() .. "\n") else Msg("Server: Entity Returned False\n") end

ulx.fancyLogAdmin( calling_ply, "SteamID has been printed to Console", target_plys )

end
local steamcheck = ulx.command( "Utility", "ulx steamcheck", ulx.steamcheck, "!steamcheck" )
steamcheck:addParam{ type=ULib.cmds.PlayersArg }
steamcheck:defaultAccess( ULib.ACCESS_SUPERADMIN )
steamcheck:help( "steamcheck." )

And every thing seems to be working fine, the Steam ID is returning and all.
I cry every time I see that I am not a respected member of this community.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX & Sourcebans Integration
« Reply #5 on: November 19, 2011, 09:37:40 AM »
hymsan,
First, I agree with others assessment.
You should write a totally separate ulx command structure so you (and other ULX users) don't have to edit ULX files every time ULX is updated on the local server.
All ULib (and therefore, ULX) commands have a hook method that will allow for intercepting commands, performing additional action, and then either stopping OR proceeding with the original command called.
In simplest terms, you could monitor, using a ULib command, for "ulx ban" and perform the sourceban function.
See ULibCommandCalled or ULibPostTranslatedCommand
Not only will that allow you to monitor ulx ban, it would allow you to write a totally separate, for instance  "ulx sban", command to use if for some reason you didn't want the normal ban function performed.

Second,
(I'm not the lua/Glua expert, but the below seems to me what is going on)
Where is your script being run from? If you're typing in that command on the server console, indeed, it will never find a steamid.
If from server console, you 'could' write in a config or something for you and the public that if detected from server console, place in the hosts SteamID instead.
Even if you're doing it from the client console, it's running as if on the server. Make sure you have your code files in /sh, and that they are running from the client side so that information should be passed (as Hyman's example worked).

I'd get second point working first, then aim for first point I made.
:)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline strategos

  • Jr. Member
  • **
  • Posts: 66
  • Karma: 2
  • I wanna be the guy
    • Community
Re: ULX & Sourcebans Integration
« Reply #6 on: November 19, 2011, 10:05:20 AM »
It would be nice to incorporate this into xgui when finished. If anyone needs a test server I'd be happy to help.
« Last Edit: November 21, 2011, 01:19:41 PM by strategos »

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: ULX & Sourcebans Integration
« Reply #7 on: November 25, 2011, 11:01:36 AM »
OK I have made a script really fast, I did not test it yet because I do not want to install the source-bans stuff on to my client, plus Strategos or Sonicscream can always test for me. :P

Code: [Select]
-- ULX sban for ULX SVN/ULib SVN by HeLLFox_15
function ulx.sban( calling_ply, target_ply, time, reason )

if target_ply:IsBot() then
ULib.tsayError( calling_ply, "Cannot ban a bot", true )
return
end

local minutes = ULib.stringTimeToSeconds( time )
if not minutes then
ULib.tsayError( calling_ply, "Invalid time format." )
return
end

ULib.kickban( target_ply, minutes, reason, calling_ply )
sourcebans.BanPlayer( target_ply, minutes*60, reason, calling_ply )

local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A source banned #T " .. time
if reason and reason ~= "" then str = str .. " (#s)" end
ulx.fancyLogAdmin( calling_ply, str, target_ply, minutes ~= 0 and minutes or reason, reason )

end
local sban = ulx.command( "Utility", "ulx sban", ulx.sban, "!sban" )
sban:addParam{ type=ULib.cmds.PlayerArg }
sban:addParam{ type=ULib.cmds.StringArg, hint="minutes, 0 for perma. 'h' for hours, 'd' for days, 'w' for weeks. EG, '2w5d' for 2 weeks 5 days", ULib.cmds.optional }
sban:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
sban:defaultAccess( ULib.ACCESS_SUPERADMIN )
sban:help( "Bans a target and adds them to the source bans list." )

To install the script above make a folder with the following file path "garrysmod\addons\FolderName\lua\ulx\modules\sh"
Copy and paste the script into notepad then save as sh_sban.lua and move it into "garrysmod\addons\FolderName\lua\ulx\modules\sh".

Post what happens when you run the above script using "!sban <target> <time> <reason>".

( I do realize that I took the script from the first post and separated it into a separate command, but may be that is all that's needed. )

Side Note: I think some one should move this thread to "Developers Corner".
« Last Edit: December 28, 2011, 03:27:31 AM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline strategos

  • Jr. Member
  • **
  • Posts: 66
  • Karma: 2
  • I wanna be the guy
    • Community
Re: ULX & Sourcebans Integration
« Reply #8 on: November 26, 2011, 01:24:47 PM »
I have tried testing it and I couldn't get it to work. Now I'm not saying it is the scripts fault. I think that the current installment of sourcebans.lua has issues returning who is admin because even though I know I set up everything properly, the sm_ban still said I was unauthorized. http://www.facepunch.com/threads/980687?p=33438677&highlight=#post33438677
Apparently lexi is working on fixing it so I'll be happy give it another shot when it gets done. I haven looked too closely but if this is the only problem, it really doesn't why the script shouldn't work. Ulx registers the command fine but it won't ban or kick the player.

Offline sonicscream

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
  • w00t in a can
Re: ULX & Sourcebans Integration
« Reply #9 on: December 03, 2011, 11:10:46 AM »
Before I can actually do anything useful for you, I'm going to have to find some free time before I can install SourceMod and get it running appropriately.
My apologies :P

Offline blackfire88

  • Jr. Member
  • **
  • Posts: 56
  • Karma: 0
Re: ULX & Sourcebans Integration
« Reply #10 on: December 26, 2011, 11:39:00 PM »
Hey hellfox,
I tried your code and it didn't work. Here is a  fixed version:
Code: [Select]
-- ULX sban for ULX SVN/ULib SVN by HeLLFox_15 (Fixed by blackfire88)
function ulx.sban( calling_ply, target_ply, time, reason )

if target_ply:IsBot() then
ULib.tsayError( calling_ply, "Cannot ban a bot", true )
return
end

local minutes = ULib.stringTimeToSeconds( time )
if not minutes then
ULib.tsayError( calling_ply, "Invalid time format." )
return
end

ULib.kickban( target_ply, minutes, reason, calling_ply )
sourcebans.BanPlayer( target_ply, minutes*60, reason, calling_ply )

local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A source banned #T " .. time
if reason and reason ~= "" then str = str .. " (#s)" end
ulx.fancyLogAdmin( calling_ply, str, target_ply, minutes ~= 0 and minutes or reason, reason )

end
local sban = ulx.command( "Utility", "ulx sban", ulx.sban, "!sban" )
sban:addParam{ type=ULib.cmds.PlayerArg }
sban:addParam{ type=ULib.cmds.StringArg, hint="minutes, 0 for perma. 'h' for hours, 'd' for days, 'w' for weeks. EG, '2w5d' for 2 weeks 5 days", ULib.cmds.optional }
sban:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
sban:defaultAccess( ULib.ACCESS_SUPERADMIN )
sban:help( "Bans a target and adds them to the source bans list." )

Offline blackfire88

  • Jr. Member
  • **
  • Posts: 56
  • Karma: 0
Re: ULX & Sourcebans Integration
« Reply #11 on: December 26, 2011, 11:54:02 PM »
Hmm. That still doesn't work 100%.
I tested it with a sourcebans web install and it seems that either the module doesn't work or calling_ply is a nil value.
I think it is the latter.
It doesn't get my admin id and add it into sourcebans.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: ULX & Sourcebans Integration
« Reply #12 on: December 27, 2011, 07:11:45 PM »
Hey hellfox,
I tried your code and it didn't work.

Ah lol, my mistake, I put an unneeded "s" in there. I used http://diffchecker.com/ to check.
« Last Edit: December 28, 2011, 03:21:47 AM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULX & Sourcebans Integration
« Reply #13 on: December 27, 2011, 08:01:02 PM »
I tested it with a sourcebans web install and it seems that either the module doesn't work or calling_ply is a nil value.

Where is your script being run from? If you're typing in that command on the server console, indeed, it will never find a steamid.
If from server console, you 'could' write in a config or something for you and the public that if detected from server console, place in the hosts SteamID instead.
Even if you're doing it from the client console, it's running as if on the server. Make sure you have your code files in /sh, and that they are running from the client side so that information should be passed (as Hyman's example worked).

Even back in mid-November, console steam id hasn't changed.
Not sure how I can make that more clear.
If the sourceban command is being called from server console, there is no steam id for it. You'd have to code in one in some way.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: ULX & Sourcebans Integration
« Reply #14 on: December 28, 2011, 03:13:52 AM »
Even back in mid-November, console steam id hasn't changed.
Not sure how I can make that more clear.
If the sourceban command is being called from server console, there is no steam id for it. You'd have to code in one in some way.

What do you mean, because I am giving it the entity and thus the ID of the person who made the ban, and the entity of the person that is being banned...

Code: [Select]
sourcebans.BanPlayer( target_ply, minutes*60, reason, calling_ply )
Because on the same site that was provided I have read that the command works like so.

Quote
BanPlayer (ply, time, reason, admin, callback)

Bans a player by object

Parameters

ply: The player to ban
time: How long to ban the player for (in seconds)
reason: Why the player is being banned
admin: (Optional) The admin who did the ban. Leave nil for CONSOLE.
callback: (Optional) A function to call with the results of the ban. Passed true if it worked, false and a message if it didn't.

Plus if it cant find a SteamID, it should return nil, and be displayed as console, as it says above.
« Last Edit: December 28, 2011, 03:23:28 AM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.