ULX

Author Topic: Sourcebans integration  (Read 39032 times)

0 Members and 1 Guest are viewing this topic.

Offline Ninjadude101

  • Newbie
  • *
  • Posts: 38
  • Karma: 4
Sourcebans integration
« on: May 29, 2009, 11:15:20 AM »
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: [Select]
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 )

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

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Sourcebans integration
« Reply #1 on: May 29, 2009, 11:52:47 AM »
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
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Snowden42

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
Re: Sourcebans integration
« Reply #2 on: April 07, 2010, 11:06:10 AM »
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?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Sourcebans integration
« Reply #3 on: April 07, 2010, 04:01:24 PM »
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.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: Sourcebans integration
« Reply #4 on: April 08, 2010, 01:28:21 PM »
Moved a long sub-thread out of this thread to here: http://forums.ulyssesmod.net/index.php/topic,4632.0.html
Experiencing God's grace one day at a time.

Offline Buggzie

  • Newbie
  • *
  • Posts: 48
  • Karma: 2
Re: Sourcebans integration
« Reply #5 on: June 13, 2010, 06:36:22 AM »
Since this is dead and i've got multiple servers and want them all connected through sourcebans, could someone have a go at fixing this, i mean do i have to install sourcemod onto my garrys mod server, I'm pretty sure it will not work because it runs on .dll files not lua.

Thanks for reading

~Eye

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Sourcebans integration
« Reply #6 on: June 13, 2010, 10:44:39 AM »
go at fixing this, i mean do i have to install sourcemod onto my garrys mod server,
Once our SVN is put out as a release, I plan on having a go at converting many of the releases that would be easy to convert.
This is one of them.,
As for SourceMod installation, yes, this and every other sourceban lua release I've seen is intended for SourceBans running on the gmod server.
When this release was made SourceBans could be installed following instructions found through Google or other search engines.
I've no idea about now.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline mishappp

  • Newbie
  • *
  • Posts: 23
  • Karma: 0
Re: Sourcebans integration
« Reply #7 on: July 24, 2010, 07:34:47 PM »
Is there any news on this, does this work, or has it been converted, I really need this.

Offline ZachPL

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Re: Sourcebans integration
« Reply #8 on: November 04, 2012, 03:35:11 PM »
I realize this is dead and super old, but if someone could get ulx working with sourcebans on gmod 13 I would be forever happy.

Also willing to test with a large server.

Offline Tristian Wood

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 0
Re: Sourcebans integration
« Reply #9 on: November 04, 2012, 08:52:21 PM »
I realize this is dead and super old, but if someone could get ulx working with sourcebans on gmod 13 I would be forever happy.

Also willing to test with a large server.
I agree It would be extremely helpful.
Owner of soul gaming




Offline iSnipeu

  • Jr. Member
  • **
  • Posts: 83
  • Karma: 12
Re: Sourcebans integration
« Reply #10 on: November 04, 2012, 09:24:12 PM »
Code: [Select]
local CATEGORY_NAME = "Sourcebans"

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

calling_ply:ConCommand( "sm_ban #" .. target_ply:UserID() .. " " .. minutes .. " " .. (reason or "") )

local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A sourcebanned #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( CATEGORY_NAME, "ulx sban", ulx.sban, "!sban" )
sban:addParam{ type=ULib.cmds.PlayerArg }
sban:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
sban:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
sban:defaultAccess( ULib.ACCESS_ADMIN )
sban:help( "Bans target via sourcebans." )

function ulx.sbanid( calling_ply, steamid, minutes, reason )
steamid = steamid:upper()
if not ULib.isValidSteamID( steamid ) then
ULib.tsayError( calling_ply, "Invalid steamid." )
return
end

local name
local plys = player.GetAll()
for i=1, #plys do
if plys[ i ]:SteamID() == steamid then
name = plys[ i ]:Nick()
break
end
end

calling_ply:ConCommand( "sm_addban " .. minutes .. " " .. steamid .. " " .. (reason or "") )

local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A sourcebanned steamid #s "
if name then
steamid = steamid .. "(" .. name .. ") "
end
str = str .. time
if reason and reason ~= "" then str = str .. " (#4s)" end
ulx.fancyLogAdmin( calling_ply, str, steamid, minutes ~= 0 and minutes or reason, reason )
end
local sbanid = ulx.command( CATEGORY_NAME, "ulx sbanid", ulx.sbanid )
sbanid:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
sbanid:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
sbanid:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
sbanid:defaultAccess( ULib.ACCESS_SUPERADMIN )
sbanid:help( "Bans steamid via sourcebans." )

function ulx.sunban( calling_ply, steamid )
steamid = steamid:upper()
if not ULib.isValidSteamID( steamid ) then
ULib.tsayError( calling_ply, "Invalid steamid." )
return
end

calling_ply:ConCommand( "sm_unban " .. steamid )
ulx.fancyLogAdmin( calling_ply, "#A unbanned steamid #s", steamid )
end
local sunban = ulx.command( CATEGORY_NAME, "ulx sunban", ulx.sunban )
sunban:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
sunban:defaultAccess( ULib.ACCESS_ADMIN )
sunban:help( "Unbans steamid via sourcebans." )

This should work, but I don't have sourcebans so I'm unable to test it.

Offline Tristian Wood

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 0
Re: Sourcebans integration
« Reply #11 on: November 04, 2012, 10:02:50 PM »
Code: [Select]
local CATEGORY_NAME = "Sourcebans"

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

calling_ply:ConCommand( "sm_ban #" .. target_ply:UserID() .. " " .. minutes .. " " .. (reason or "") )

local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A sourcebanned #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( CATEGORY_NAME, "ulx sban", ulx.sban, "!sban" )
sban:addParam{ type=ULib.cmds.PlayerArg }
sban:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
sban:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
sban:defaultAccess( ULib.ACCESS_ADMIN )
sban:help( "Bans target via sourcebans." )

function ulx.sbanid( calling_ply, steamid, minutes, reason )
steamid = steamid:upper()
if not ULib.isValidSteamID( steamid ) then
ULib.tsayError( calling_ply, "Invalid steamid." )
return
end

local name
local plys = player.GetAll()
for i=1, #plys do
if plys[ i ]:SteamID() == steamid then
name = plys[ i ]:Nick()
break
end
end

calling_ply:ConCommand( "sm_addban " .. minutes .. " " .. steamid .. " " .. (reason or "") )

local time = "for #i minute(s)"
if minutes == 0 then time = "permanently" end
local str = "#A sourcebanned steamid #s "
if name then
steamid = steamid .. "(" .. name .. ") "
end
str = str .. time
if reason and reason ~= "" then str = str .. " (#4s)" end
ulx.fancyLogAdmin( calling_ply, str, steamid, minutes ~= 0 and minutes or reason, reason )
end
local sbanid = ulx.command( CATEGORY_NAME, "ulx sbanid", ulx.sbanid )
sbanid:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
sbanid:addParam{ type=ULib.cmds.NumArg, hint="minutes, 0 for perma", ULib.cmds.optional, ULib.cmds.allowTimeString, min=0 }
sbanid:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine, completes=ulx.common_kick_reasons }
sbanid:defaultAccess( ULib.ACCESS_SUPERADMIN )
sbanid:help( "Bans steamid via sourcebans." )

function ulx.sunban( calling_ply, steamid )
steamid = steamid:upper()
if not ULib.isValidSteamID( steamid ) then
ULib.tsayError( calling_ply, "Invalid steamid." )
return
end

calling_ply:ConCommand( "sm_unban " .. steamid )
ulx.fancyLogAdmin( calling_ply, "#A unbanned steamid #s", steamid )
end
local sunban = ulx.command( CATEGORY_NAME, "ulx sunban", ulx.sunban )
sunban:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
sunban:defaultAccess( ULib.ACCESS_ADMIN )
sunban:help( "Unbans steamid via sourcebans." )

This should work, but I don't have sourcebans so I'm unable to test it.
I'll test it, but where do I put it?
Owner of soul gaming




Offline iSnipeu

  • Jr. Member
  • **
  • Posts: 83
  • Karma: 12
Re: Sourcebans integration
« Reply #12 on: November 04, 2012, 10:04:22 PM »
lua\ulx\modules\sh\sourcebans.lua

Offline ZachPL

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Re: Sourcebans integration
« Reply #13 on: November 05, 2012, 05:30:54 AM »
Alright first of all thanks for the help, but I am slightly confused on how this works...

Does this module require sourcemod in order to function correctly and if so I thought sourcemod is not compatible with gmod13. This is what is currently showing trying to use console command sm_ban

http://cloud-2.steampowered.com/ugc/939259113205840370/5E99A66529982528E85EE1A9F5DCCB4DC32E25BC/

Also the xgui part seems to be a little bit funky.


Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: Sourcebans integration
« Reply #14 on: November 05, 2012, 10:35:20 AM »
Also the xgui part seems to be a little bit funky.

Yeah.. one of these days I'll get around to fixing that.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6