Author Topic: TempAdd (v2.4) - Add a user to another group for a set amount of time  (Read 89156 times)

0 Members and 1 Guest are viewing this topic.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Hello Everyone!

This is my first official module release for ULX since Garry's Mod 13.

This is in addon format. Drop the ULX_TempAddUser folder inside of the .zip file into your addons folder.
Temporarily add a user for a certain amount of time

Usage
ulx tempadduser <player> <group> <time(minutes)> <group>

player - Player name on server who you wish to temporarily promote
group - Group you wish to promote the user into
time - Time in minutes you wish the player to be in the group. NOTE: this is real time from when you run the command. NOT TIME PLAYED. (ex: 1440 would promote the player for 24 real-time hours)
group - The group the player should return to after their time is up. Set this to user if you wish the player to be the default user rank after.

ulx tempadduserid <steamid> <group> <time(minutes)> <group>

steamid - SteamID of the player you wish to temporarily promote.
group - Group you wish to promote the user into
time - Time in minutes you wish the player to be in the group. NOTE: this is real time from when you run the command. NOT TIME PLAYED. (ex: 1440 would promote the player for 24 real-time hours)
group - The group the player should return to after their time is up. Set this to user if you wish the player to be the default user rank after.


Please let me know if there are any bugs.


ChangeLog

Version: 2.4
+ Added the ability to add offline players using their steamid.
+ Fix for Linux compatibility. (Thanks fopje)
+ Possible fix for some of the issues some players have been having with groups not being reverted. Please let me know if this continues.

Version: 2.3
+ Fixed an issue where loading a player's existing temp data when joining a server was trying to compare a number with a string data. Opps!

Version: 2.2
+ Added some code (Thanks Stickly) that fixes the groups not showing up properly in the autocomplete.
+ Fixed the parameter hints to help users with XGUI
+ Hopefully fixed the bug that was showing up client-side displaying an error for IsConnected.

Version: 2.1
+ The script now checks all connected players every 30 minutes rather than setting a timer up to 24 hours on a connected player.
+ Cleaned up the code (removed a lot of debugging commented out code)
+ Commented the functions so users can see what is being done

Version: 2.0
+ Release
« Last Edit: September 03, 2013, 08:03:59 AM by MrPresident »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: TempAdd - v2.0
« Reply #1 on: January 12, 2013, 07:10:23 AM »
Yay! Good to see you back here releasing things, Mr. P.

I reviewed your code just to see how you approached the problem, etc, and learned quite a bit about new API I hadn't noticed! Why did you choose to use SteamID64, exactly? I'm not around a computer that I can check what that outputs, unfortunately. And, Garry added libraries to support JSON, that's awesome!

Recommendation: You're currently creating a timer to expire access if they join and expire within 24 hours. Instead, create a timer that checks everyone's expirations every x minutes (say, 30), then create additional timers to expire them at that point. This is especially useful because I believe timers are based off game time, not real world time, so 24 hours will offer a lot of time for the clocks to get out of sync. (But I don't recall if this is definitely true or not.)

Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: TempAdd - v2.0
« Reply #2 on: January 12, 2013, 02:44:09 PM »
SteamID64 which is new with GMod13 I believe uses a unique numeric identifier for the player.

Example:
STEAM_0:1:1234567

is

76561197962734863

This makes it so much easier to use a player's unique identifier in code and in save files without having to parse a normal SteamID to make it safe (IE: remove the colons, etc)


The idea for checking every xx minutes is great. I never thought of that.

You'll notice I decided not to use JSON. Turns out that JSON only supports normal signed integers and an EPOC time is much more than 32,786. Considering the file only stored 2 variables I figured a string delimiter was good enough.

Offline SuperAero_

  • Newbie
  • *
  • Posts: 13
  • Karma: 1
Re: TempAdd - v2.0
« Reply #3 on: January 12, 2013, 03:42:26 PM »
TY :D

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: TempAdd - v2.1
« Reply #4 on: January 12, 2013, 04:18:34 PM »
***UPDATE***

Version: 2.1

ChangeLog:
+ The script now checks all connected players every 30 minutes rather than setting a timer up to 24 hours on a connected player.
+ Cleaned up the code (removed a lot of debugging commented out code)
+ Commented the functions so users can see what is being done


Offline lua_error

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #5 on: January 25, 2013, 03:10:01 PM »
Thanks a lot

Offline delagious

  • Newbie
  • *
  • Posts: 21
  • Karma: 0
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #6 on: January 25, 2013, 07:25:33 PM »
I've been waiting for you to come through and you have.
Thank you sooooo very much.

Offline delagious

  • Newbie
  • *
  • Posts: 21
  • Karma: 0
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #7 on: January 25, 2013, 10:00:59 PM »
I am getting an error when I try to access this command from the XGUI:
Code: [Select]
[ERROR] addons/ulx/lua/ulx/modules/cl/xgui_helpers.lua:328: bad argument #1 to 'ipairs' (table expected, got nil)
  1. ipairs - [C]:-1
   2. x_getcontrol - addons/ulx/lua/ulx/modules/cl/xgui_helpers.lua:328
    3. obj - addons/ulx/lua/ulx/xgui/commands.lua:176
     4. func - addons/ulx/lua/ulx/modules/cl/xlib.lua:1041
      5. animQueue_call - addons/ulx/lua/ulx/modules/cl/xlib.lua:1022
       6. func - addons/ulx/lua/ulx/modules/cl/xlib.lua:1041
        7. animQueue_call - addons/ulx/lua/ulx/modules/cl/xlib.lua:1022
         8. animQueue_start - addons/ulx/lua/ulx/modules/cl/xlib.lua:1009
          9. OnSelect - addons/ulx/lua/ulx/xgui/commands.lua:108
           10. unknown - lua/vgui/dlistview_line.lua:94

Not sure what it means but otherwise this works just fine from console.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #8 on: January 26, 2013, 12:16:16 AM »
I am getting an error when I try to access this command from the XGUI:
Code: [Select]
[ERROR] addons/ulx/lua/ulx/modules/cl/xgui_helpers.lua:328: bad argument #1 to 'ipairs' (table expected, got nil)
  1. ipairs - [C]:-1
   2. x_getcontrol - addons/ulx/lua/ulx/modules/cl/xgui_helpers.lua:328
    3. obj - addons/ulx/lua/ulx/xgui/commands.lua:176
     4. func - addons/ulx/lua/ulx/modules/cl/xlib.lua:1041
      5. animQueue_call - addons/ulx/lua/ulx/modules/cl/xlib.lua:1022
       6. func - addons/ulx/lua/ulx/modules/cl/xlib.lua:1041
        7. animQueue_call - addons/ulx/lua/ulx/modules/cl/xlib.lua:1022
         8. animQueue_start - addons/ulx/lua/ulx/modules/cl/xlib.lua:1009
          9. OnSelect - addons/ulx/lua/ulx/xgui/commands.lua:108
           10. unknown - lua/vgui/dlistview_line.lua:94

Not sure what it means but otherwise this works just fine from console.

Try adding access without using XGUI. I don't use XGUI so I never tested with it. If you don't know how to do that, type ulx help in your console and look up:

ulx groupallow
ulx userallow
etc

Offline delagious

  • Newbie
  • *
  • Posts: 21
  • Karma: 0
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #9 on: January 26, 2013, 12:34:43 AM »
What I mean is when I click on the command from it's list in the menu I get kicked for lua errors and that is printed to my console.
I have problem allowing users and groups to use the command. The problem is using the command from the menu.

Offline lua_error

  • Newbie
  • *
  • Posts: 10
  • Karma: 0
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #10 on: January 27, 2013, 09:06:19 AM »
[ERROR] addons/tempusers/lua/ulx/modules/sh/ulxtempuser.lua:49: attempt to call method 'IsConnected' (a nil value)
  1. unknown - addons/vip/lua/ulx/modules/sh/ulxtempuser.lua:49

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #11 on: January 27, 2013, 09:26:42 AM »
I am getting an error when I try to access this command from the XGUI:


No errors for me. Make sure you're running the most up-to-date versions of ULX/ULib.

Mr. President, I would highly recommend adding a hint parameter to your NumArg, something like "Time (minutes)". This will show up when entering the command in console and in XGUI (pictured) instead of "NumArg". Also, you may want to be a little more descriptive on your second group hint, as it may be initially confusing to some who haven't read your nice release post here :P

Lastly, there appears to be a bug where the autocompletes for the groups aren't being sent to the client (try comparing ulx adduser in the console to ulx tempadduser), and it's causing XGUI to not allow you to not be able to specify a group name. I'm looking into what's causing it, and will reply when I can find a fix.


[ERROR] addons/tempusers/lua/ulx/modules/sh/ulxtempuser.lua:49: attempt to call method 'IsConnected' (a nil value)
  1. unknown - addons/vip/lua/ulx/modules/sh/ulxtempuser.lua:49

It appears that <player>:IsConnected() is only available serverside, so the code will have to be changed to adapt to that. :S
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #12 on: January 27, 2013, 10:09:10 AM »
there appears to be a bug where the autocompletes for the groups aren't being sent to the client

Okay, explanation time! You're using the ulx.group_names_no_user table (same would apply when using ulx.group_names) for your autocompletes. However, these tables don't get created until util.lua loads, which most likely happens AFTER your plugin is loaded (alphabetical order), thus, you're essentially passing nil for your autocompletes.

Two valid solutions are:
1) Create your own table of group names completely separate from ulx.group_names, using similar code found in until.lua:
Code: [Select]
<...somewhere near top of file...>

ulx.tempuser_group_names = {}
local function updateNames()
table.Empty( ulx.tempuser_group_names ) -- Don't reassign so we don't lose our refs

for group_name, _ in pairs( ULib.ucl.groups ) do
table.insert( ulx.tempuser_group_names, group_name )
end
end
hook.Add( ULib.HOOK_UCLCHANGED, "ULXTempAddUesrGroupNamesUpdate", updateNames )
updateNames() -- Init

<...plugin code here...>

tempadduser:addParam{ type=ULib.cmds.StringArg, completes=ulx.tempuser_group_names, hint="group", error="invalid group \"%s\" specified", ULib.cmds.restrictToCompletes }
*Note, this code will list all of the groups, including user. I did this mostly because A) You want to have user as a valid group for arg2 so they can be demoted to user and B) Why not be able to temporarily remove an admins access as well by setting group1 to user?

2) See if you can make a reference to the ulx.group_names table right after it's created, but before you register your command. Or something. I've been trying to play around with this and haven't been successful, but I think it's possible.

Anyways, hope that helps!
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline delagious

  • Newbie
  • *
  • Posts: 21
  • Karma: 0
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #13 on: January 27, 2013, 12:42:36 PM »
Thanks stickly my server is currently running XGUI version v12.12.16
I am not sure why it isn't updating as it should :( but I'm sure this is the cause of the error.

<EDIT> Got my XGUI updated and it works fine now, thanks for the addon and the help.
« Last Edit: January 27, 2013, 01:27:31 PM by delagious »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: TempAdd (v2.1) - Add a user to another group for a set amount of time
« Reply #14 on: January 27, 2013, 03:44:22 PM »
Team collaboration FTW!
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming