Ulysses Stuff > Ulysses Release Archives

Sourcebans integration

(1/9) > >>

Ninjadude101:
I've been looking into this quite a lot today, and I think some of you might be interested too.
I found someones attempt at creating a sourcebans compatable module for ULX, although they do not have garrysmod so were unable to test. I downloaded the script and had a look and fixed up a few things.

Long story short, I give you working code to create 3 functions (and ULX commands) to ban/unban using SourceBans.
I admit, my code could be cleaner, If anyone could take the time to cleanse it for me I'd be greatful but since it works as-is I'm going to leave it be.

Chat commands:
!sban <name> <time> <reason> -- Ban a user by their name (Uses sm_ban)
!sbanid <steamid> <time> <reason> -- Ban a user by their SteamID (Uses sm_addban)
!sunban <steamid> -- Unbans a user by their SteamID (Uses sm_unban)

Console commands:
ulx sban <name> <time> <reason> -- Ban a user by their name (Uses sm_ban)
ulx sbanid <steamid> <time> <reason> -- Ban a user by their SteamID (Uses sm_addban)
ulx sunban <steamid> -- Unbans a user by their SteamID (Uses sm_unban)

While I HAVE tested this code and confirm it to be working with ULX SVN revision 27, I make no guarantee that it will work for you, you may have a conflicting addon or garry may have broken something AGAIN.

Original credit goes to Alteran Ancient of www.interwavestudios.com/forums for the original release.

If this does break in future, and I'm still using it, I will most likely post a fix, If I'm not still using sourcebans to track my server bans then I'm sorry but I doubt I will have much interest in fixing this.

And here's the code!

--- Code: ---ulx.setCategory( "Sourcebans" )
function ulx.cc_sban( ply, command, argv, args )
if #argv < 1 then
ULib.tsay( ply, ulx.LOW_ARGS, true )
return
end

local target, err = ULib.getUser( argv[ 1 ], _, ply )
local target1 = ( "#" .. target:UserID() )

if not target then
ULib.tsay( ply, err, true )
return
end

local bantime = tonumber( argv[ 2 ] ) or 0
local dummy, dummy, reason = args:find( "^\"*" .. ULib.makePatternSafe( argv[ 1 ] ) .. "\"*%s+" .. ULib.makePatternSafe( argv[ 2 ] or "" ) .. "%s+(.*)$" )
reason = reason or "" -- Make sure it has a value

if bantime < 0 then
ULib.tsay( ply, "Invalid number!", true )
return
end

local time = "for " .. bantime .. " minute(s)"
//if bantime == 0 then time = "permanently" end
if reason ~= "" then reason = "(" .. reason .. ")" end
ulx.logUserAct( ply, target, "#A banned #T " .. time .. " " .. reason )

ply:ConCommand( "sm_ban " .. target1 .. " " .. bantime .. " " .. reason )
end
ulx.concommand( "sban", ulx.cc_sban, "<user> [<time>] [<reason>] - Bans a user for x minutes with Sourcebans, use 0 for permaban.", ULib.ACCESS_ADMIN, "!sban", _, ulx.ID_PLAYER_HELP )
ulx.addToMenu( ulx.ID_MCLIENT, "Sourcebans Ban (perma)", "ulx sban #T 0" )
ulx.addToMenu( ulx.ID_MCLIENT, "Sourcebans Ban (5 mins)", "ulx sban #T 5" )
ulx.addToMenu( ulx.ID_MCLIENT, "Sourcebans Ban (60 mins)", "ulx sban #T 60" )
ulx.addToMenu( ulx.ID_MCLIENT, "Sourcebans Ban (1 day)", "ulx sban #T 1440" )

function ulx.cc_sbanid( ply, cmd, argv, args )
if #argv < 1 then
ULib.tsay( ply, ulx.LOW_ARGS, true )
return
end

if not string.find( argv[ 1 ], "STEAM_%d:%d:%d+" ) then
ULib.tsay( ply, "Invalid steamid." )
return
end

local bantime = tonumber( argv[ 2 ] ) or 0

if bantime < 0 then
ULib.tsay( ply, "Invalid number!", true )
return
end

local reason = string.gsub( args, "%s*" .. argv[ 1 ] .. "%s*" .. argv[ 2 ] .. "%s*", "" )

local time = "for " .. bantime .. " minute(s)"
//if bantime == 0 then time = "permanently" end
if reason then
ulx.logServAct( ply, string.format( "#A banned id %s %s (%s)", argv[ 1 ], time, reason ) )
else
ulx.logServAct( ply, string.format( "#A banned id %s %s", argv[ 1 ], time ) )
end
//ULib.addBan( argv[ 1 ], bantime, reason, nil, ply )

if file.Exists( "../cfg/banned_user.cfg" ) then
ULib.execFile( "../cfg/banned_user.cfg" )
end
ply:ConCommand("sm_addban " .. bantime .. " " .. argv[ 1 ] .. " " .. reason )
end
ulx.concommand( "sbanid", ulx.cc_sbanid, "<steamid> [<time>] [<reason>] - Add a steamid to Sourcebans database, use 0 for perma.", ULib.ACCESS_ADMIN, "!sbanid", _, ulx.ID_HELP )

function ulx.cc_sunban( ply, cmd, argv, args )
if #argv < 1 then
ULib.tsay( ply, ulx.LOW_ARGS, true )
return
end

if not string.find( argv[ 1 ], "STEAM_%d:%d:%d+" ) then
ULib.tsay( ply, "Invalid steamid.", true )
return
end

ply:ConCommand("sm_unban " .. argv[ 1 ] )

ulx.logServAct( ply, "#A unbanned steamid " .. argv[ 1 ] )
end
ulx.concommand( "sunban", ulx.cc_sunban, "<steamid> - Remove the specified steamid from the banlist.", ULib.ACCESS_ADMIN, "!sunban", _, ulx.ID_HELP )
--- End code ---

Simply create a file called sban.lua in addons\Sourcebans ULX Integration\lua\ulx\modules and paste this code inside.

JamminR:
Been discussed much here. I didn't have sourcebans to test.
Couldn't find many willing testers.
And now currently don't have Gmod installed.
Anyway, here's a post by Megiddo, which I linked to other discussions in my reply.
http://forums.ulyssesmod.net/index.php/topic,3835.0.html

Snowden42:
I hate to bump a super old topic, but I'm wondering two things:

Does this still work?
Is there any way to replace the standard ulx ban buttons on the derma with these commands?

JamminR:
This wouldn't work with ULX svn.. command structure totally re-written.
As for replacement, this already adds to menu, you'd have to remove default ban button codes.
That too wouldn't be difficult.

Megiddo:
Moved a long sub-thread out of this thread to here: http://forums.ulyssesmod.net/index.php/topic,4632.0.html

Navigation

[0] Message Index

[#] Next page

Go to full version