Author Topic: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one  (Read 12832 times)

0 Members and 5 Guests are viewing this topic.

Offline strategos

  • Jr. Member
  • **
  • Posts: 66
  • Karma: 2
  • I wanna be the guy
    • Community
I'm trying to, when ulx adduser(id)/removeuser(id) is run, to auto-add them to the co-responding FAdmin group when the command is successfully run.

The format for fadmin setaccess is: Fadmin setaccess "nick/steamid" "group"

The functions adduser, adduserid, removeuser, and removeuserid have been modified

It adds them to the ulx group but it returns this (something similar each time)

[addons\ulx\lua\ulx\modules\sh\user.lua:79] attempt to perform arithmetic on a string value

Code: [Select]
function ulx.adduser( calling_ply, target_ply, group_name )
group_name = group_name:lower()

local userInfo = ULib.ucl.authed[ target_ply:UniqueID() ]

local id = ULib.ucl.getUserRegisteredID( target_ply )
if not id then id = target_ply:SteamID() end

ULib.ucl.addUser( id, userInfo.allow, userInfo.deny, group_name )

calling_ply:ConCommand("fadmin", "setaccess " + id + group_name)

ulx.fancyLogAdmin( calling_ply, "#A added #T to group #s", target_ply, group_name )
end
local adduser = ulx.command( CATEGORY_NAME, "ulx adduser", ulx.adduser )
adduser:addParam{ type=ULib.cmds.PlayerArg }
adduser:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names_no_user, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
adduser:defaultAccess( ULib.ACCESS_SUPERADMIN )
adduser:help( "Add a user to specified group." )

function ulx.adduserid( calling_ply, id, group_name )
id = id:upper() -- Steam id needs to be upper
group_name = group_name:lower()

-- Check for valid and properly formatted ID
if not checkForValidId( calling_ply, id ) then return false end

-- Now add the fool!
ULib.ucl.addUser( id, allows, denies, group_name )

calling_ply:ConCommand("fadmin", "setaccess " + id + " " + group_name)

if ULib.ucl.users[ id ] and ULib.ucl.users[ id ].name then
ulx.fancyLogAdmin( calling_ply, "#A added #s to group #s", ULib.ucl.users[ id ].name, group_name )
else
ulx.fancyLogAdmin( calling_ply, "#A added userid #s to group #s", id, group_name )
end
end
local adduserid = ulx.command( CATEGORY_NAME, "ulx adduserid", ulx.adduserid )
adduserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" }
adduserid:addParam{ type=ULib.cmds.StringArg, completes=ulx.group_names_no_user, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
adduserid:defaultAccess( ULib.ACCESS_SUPERADMIN )
adduserid:help( "Add a user by ID to specified group." )

function ulx.removeuser( calling_ply, target_ply )
ULib.ucl.removeUser( target_ply:UniqueID() )

calling_ply:ConCommand("fadmin", "setaccess " + tostring(target_ply:SteamID()) + " user")

ulx.fancyLogAdmin( calling_ply, "#A removed all access rights from #T", target_ply )
end
local removeuser = ulx.command( CATEGORY_NAME, "ulx removeuser", ulx.removeuser )
removeuser:addParam{ type=ULib.cmds.PlayerArg }
removeuser:defaultAccess( ULib.ACCESS_SUPERADMIN )
removeuser:help( "Permanently removes a user's access." )

function ulx.removeuserid( calling_ply, id )
id = id:upper() -- Steam id needs to be upper

-- Check for valid and properly formatted ID
if not checkForValidId( calling_ply, id ) then return false end

if not ULib.ucl.authed[ id ] and not ULib.ucl.users[ id ] then
ULib.tsayError( calling_ply, "No player with id \"" .. id .. "\" exists in the ULib user list", true )
return false
end

local name = (ULib.ucl.authed[ id ] and ULib.ucl.authed[ id ].name) or (ULib.ucl.users[ id ] and ULib.ucl.users[ id ].name)

ULib.ucl.removeUser( id )

calling_ply:ConCommand("fadmin", "setaccess " + id + " user")

if name then
ulx.fancyLogAdmin( calling_ply, "#A removed all access rights from #s", name )
else
ulx.fancyLogAdmin( calling_ply, "#A removed all access rights from #s", id )
end
end
local removeuserid = ulx.command( CATEGORY_NAME, "ulx removeuserid", ulx.removeuserid )
removeuserid:addParam{ type=ULib.cmds.StringArg, hint="SteamID, IP, or UniqueID" }
removeuserid:defaultAccess( ULib.ACCESS_SUPERADMIN )
removeuserid:help( "Permanently removes a user's access by ID." )

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #1 on: November 20, 2011, 07:41:43 PM »
The functions adduser, adduserid, removeuser, and removeuserid have been modified
Don't modify.
ULib has hooks for during and post command.
Use them instead, and make your own addon folder.

[addons\ulx\lua\ulx\modules\sh\user.lua:79] attempt to perform arithmetic on a string value

Code: [Select]
calling_ply:ConCommand("fadmin", "setaccess " + id + group_name)
calling_ply:ConCommand("fadmin", "setaccess " + id + " " + group_name)
calling_ply:ConCommand("fadmin", "setaccess " + tostring(target_ply:SteamID()) + " user")
calling_ply:ConCommand("fadmin", "setaccess " + id + " user")


"+" is a math statement.
I'm pretty sure I know what you're trying to do with +, but that's not how you do it in Lua. :)
I'm not going to give it away and will let you search a bit on your own.

EDIT = Regarding the hooks.
See ULibCommandCalled or ULibPostTranslatedCommand
That will allow you to monitor for any of the normal ULX commands, and run things in addition to them.
« Last Edit: November 20, 2011, 07:47:17 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #2 on: November 20, 2011, 09:29:14 PM »
Ahh, that's harsh Jam. hah! .. I really hope that he can figure out what he needs to use instead of "+".. you know .. so that he can finish his script and get it up and running.


Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #3 on: November 21, 2011, 05:50:24 AM »
Too much coding in E2 :D

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #4 on: November 21, 2011, 02:50:48 PM »
Ahh, that's harsh Jam. hah!

I know, I'm so mean.
Seriously though, I don't know how many times I learned something new from (Lua/Glua/insert any scripting language I know enough to be dangerous with here) while searching for a solution to something else.

A bit of searching, even through other ulx code examples, shouldn't take toooo long.
:)
"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: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #5 on: December 04, 2011, 01:05:57 PM »
Instead of doing that I'm just going to give overriding Fadmin to ulx usergroups a shot.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #6 on: December 04, 2011, 03:04:48 PM »
Strategos, you're going from a right track to something perhaps even more challenging.
The code examples you're showing should, with a bit of proper syntax, work.
"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: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #7 on: December 25, 2011, 01:17:16 AM »
I said the following to Strategos in steam chat. (Its only slightly edited so excuse me for any grammar and or spelling mistakes.)

Quote from: HeLLFox_15
So what you do is check with ULX what rank they are in ULX (Using Gamemode.PlayerInitialSpawn), check if they are in a certain file (the file will be edited by the lua).
If they are not it will rank them and add thier SteamID to that file and put what ever rank they are beside it so it will look like STEAM_0:0:8767896.Admin
Every time some one joins, it will check their rank and steamID,
if they are already in the list under the same rank it wont do any thing how ever if their rank has changed it will go in the file look for the line that their steam ID is at
and change the rank name beside it, afcorse it will rank them in FAdmin before doing that.
So that is my idea, on how you can intergrade it.

I the following commands will help you.

http://wiki.garrysmod.com/?title=Gamemode.PlayerInitialSpawn
http://wiki.garrysmod.com/?title=File.Write
http://wiki.garrysmod.com/?title=File.Append
http://wiki.garrysmod.com/?title=File.Read

Good Luck. (Don't worry I am thinking of making the script. :P)

Also a question, would Player.IsUserGroup return what group a person is in ULX, if the server is running ULX?

Also how would I turn this...

Code: [Select]
"superadmin"
{
"can_target" "!%officer, !%owner"
"team"
{
"color_green" "0"
"health" "200"
"color_red" "255"
"order" "4"
"index" "23"
"name" "Superadmins"
"color_blue" "0"
}
"allow"
{
"All of thier commands"
}
"inherit_from" "admin"
}
"user"
{
"can_target" "%user"
"team"
{
"color_red" "255"
"color_green" "212"
"order" "9"
"index" "28"
"name" "User"
"color_blue" "0"
}
"allow"
{
"All of thier commands"
}
}
"moderator"
{
"team"
{
"color_green" "129"
"color_red" "255"
"name" "Moderator"
"health" "101"
"order" "6"
"index" "25"
"maxHealth" "101"
"color_blue" "255"
}
"can_target" "!%officer,!%owner,!%admin,!%superadmin"
"allow"
{
"All of thier commands"
}
"inherit_from" "vip"
}
"admin"
{
"can_target" "!%superadmin,!%officer,!%owner"
"team"
{
"color_green" "255"
"health" "150"
"color_red" "0"
"order" "5"
"index" "24"
"name" "Admins"
"color_blue" "0"
}
"allow"
{
"All of thier commands"
"sbox_weapons" "access tag"
"weapons" "access tag"
}
"inherit_from" "moderator"
}

into this...

Code: [Select]
"superadmin"
"user"
"moderator"
"admin"

The above transformation, makes it easier to get a list of all the created ranks built in, and custom.
« Last Edit: December 26, 2011, 01:14:32 AM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #8 on: December 30, 2011, 12:02:04 PM »
IsUserGroup is passed a string and returns true if the user belongs to that group you specify and false if they do not. This function is implemented by Garry.
GetUserGroup is implemented by us and should have been included in default gmod, in my opinion.

To get a list of groups, just take a peek at ULib.ucl.groups. The information stored below ULib.ucl is what ULib uses for all access control. Feel free to read from these tables, but do not change any of them or you may get strange behavior. :)
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #9 on: February 20, 2012, 12:24:40 AM »
I decided to kind of bump this, because it seems that more and more users are switching to RP, and better FAdmin compatibility never hurt any one.

I am going to start working on this gain as soon as I can.
I cry every time I see that I am not a respected member of this community.

Offline Assault_Trooper

  • Newbie
  • *
  • Posts: 20
  • Karma: 1
    • Trooper's Gaming Servers
Re: Trying to merge ulx adduser/removeuser and FAdmin setaccess into one
« Reply #10 on: February 26, 2012, 07:03:50 AM »
I decided to kind of bump this, because it seems that more and more users are switching to RP, and better FAdmin compatibility never hurt any one.

I am going to start working on this gain as soon as I can.

Better off with just removing FAdmin.