Faster Way of Cleaning users.txt?

Does anyone know a faster way to clean out the ulx users.txt file which is within the data file? I’ve got lots of groups, e.g… I want to remove everyone within the “silver1” group but not from the “vip” group, Would there be a faster way of doing it than removing one by one of of the users.txt? Thanks

I’m wondering if there is a script which clears the specific ones from users.txt automatically or something along those lines? It’s just now, it’s pain in the backside to clear the users.txt manually with over 2000 lines… :confused: It would be great if there would be a quicker solution to this. Thank you.

[editline]11th February 2017[/editline]

5650 lines to be exact.

The script below is untested. Run it serverside and it should remove all groups that you don’t one (you can easily edit that in the script). It will make a new file called users_new.txt in your data folder. Make sure it removed the groups you wanted and noting more. Then rename your current (old) users.txt to like users_backup.txt and then rename users_new.txt to users.txt.

I know you said users.txt is inside the data folder but by default it’s in the settings folder. This code was edited from lua/includes/extensions/player_auth.lua:63

[lua]
– Groups to remove
local REMOVE_GROUPS = { “silver1”, “silver2”, “etc” };

– Load the users file
local SteamIDs = {}
local UsersKV = util.KeyValuesToTable( file.Read( “settings/users.txt”, “GAME” ) )

– Extract the data into the SteamIDs table
for key, tab in pairs( UsersKV ) do
– If they are still good…
if( !table.HasValue( REMOVE_GROUPS, key ) )then
– insert
for name, steamid in pairs( tab ) do
SteamIDs[ steamid ] = {}
SteamIDs[ steamid ].name = name
SteamIDs[ steamid ].group = key
end
end
end

– Write the new table
file.Write( “users_new.txt”, util.TableToKeyValues( SteamIDs ) );
[/lua]

Wait so, will the script remove everyone within the groups?

[editline]11th February 2017[/editline]

also, is the “ebd” meant to be “end”?

Yes to both

Thank you so much, I will try it out and will report back the results :wink:

I got the following error:
[lua][ERROR] lua/autorun/server/groupcleaner.lua:13: bad argument #1 to ‘pairs’ (table expected, got string)

  1. pairs - [C]:-1
  2. unknown - lua/autorun/server/groupcleaner.lua:13[/lua]

[editline]11th February 2017[/editline]

This is what the code looks like:
[lua]-- Groups to remove
local REMOVE_GROUPS = { “silver1”, “silver2”, “silver3”, “silver4”, “silver5”, “silver6”, “gn1”, “gn2”, “gn3”, “gn4”, “mg1”, “mg2”, “mg3”, “member” };

– Load the users file
local SteamIDs = {}
local UsersKV = util.KeyValuesToTable( file.Read( “data/ulib/users.txt”, “GAME” ) )

– Extract the data into the SteamIDs table
for key, tab in pairs( UsersKV ) do
– If they are still good…
if( !table.HasValue( REMOVE_GROUPS, key ) )then
– insert
for name, steamid in pairs( tab ) do
SteamIDs[ steamid ] = {}
SteamIDs[ steamid ].name = name
SteamIDs[ steamid ].group = key
end
end
end

– Write the new table
file.Write( “users_new.txt”, util.TableToKeyValues( SteamIDs ) );[/lua]

This should work



local groups = {"group1", "group2"}

local path = ULib.UCL_USERS
local users, err = ULib.parseKeyValues( ULib.removeCommentHeader( ULib.fileRead( path, true ) or "", "/" ) )
PrintTable(users)
for steamid, v in pairs(users) do
	if table.HasValue(groups, v.group) then
		users[steamid] = nil
	end
end
PrintTable(users)
ULib.fileWrite( "data/ulib/users_new.txt", ULib.makeKeyValues( users ) )


I will try it out.

[editline]11th February 2017[/editline]

I’ve done it and it successfully worked but now that I have removed it, I’m constantly getting the following
[lua]
[ERROR] addons/ulx/lua/ulx/modules/sh/user.lua:57: attempt to index local ‘userInfo’ (a nil value)

  1. call - addons/ulx/lua/ulx/modules/sh/user.lua:57
  2. __fn - addons/ulib/lua/ulib/shared/commands.lua:943
    3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
    4. unknown - lua/includes/modules/concommand.lua:54
    [/lua]

[editline]11th February 2017[/editline]

Thank you very much for the code but do you know how to fix this?

Did you backup the old one and rename the new one to users.txt?

Also, every time I start up the server, it comes up with the following, bare in mind, this comes up before all of the addons start up messages.

[lua][ERROR] lua/includes/extensions/player_auth.lua:66: bad argument #1 to ‘KeyValuesToTable’ (string expected, got no value)

  1. KeyValuesToTable - [C]:-1
  2. unknown - lua/includes/extensions/player_auth.lua:66
    3. include - [C]:-1
    4. unknown - lua/includes/init.lua:104[/lua]

[editline]11th February 2017[/editline]

Yes to both.

This must be a different problem, I have no errors.

I’m not sure if it all started from zzaacckk’s script

I was able to reproduce your error by removing “settings/users.txt” which you should have left alone. You were only suppose to replace “data/ulib/users.txt”

Kinda, Once I completed your guide, I found out about the errors spamming the console which then I remembered I left users.txt in settings/. I deleted it after but still getting errors.

You weren’t suppose to delete or replace it, it was meant to be left alone.
Create another users.txt in the settings folder and put this in it



"Users"
{
	//
	// This is your users file
	//
	// You can use this file to add people as admins on your server
	// Add them to the relevant section
	//
	// If you're a Lua coder you can add your own sections and use them
	// in your script by doing pl:IsUserGroup( "admin" ) etc
	//

	"superadmin"
	{
		//"garry"			"STEAM_0:1:7099"
	}
	
	"admin"
	{
		//"garry"			"STEAM_0:1:7099"
	}

}


Oh wow, I must have thought that users.txt was generated by the zzaacckk’s script so I deleted it. I have put it up again from my server backup files which has fixed all the errors. I appologise for the mess I have created and I want to massivly thank you 2 for the support! :slight_smile:

[editline]11th February 2017[/editline]

It’s all good now, with no errors. Thank you so much for help! I really, really appreciate it! :slight_smile: