Author Topic: Windows Hard-Link Ulib users file. Repair database?  (Read 2476 times)

0 Members and 1 Guest are viewing this topic.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Windows Hard-Link Ulib users file. Repair database?
« on: January 31, 2016, 05:25:59 PM »
I run 4 servers currently and I've been using a Windows Hard-Link to sync all the ranks for all players ever to all the servers so they're all the same. This has been working great for about 6 months, but now I'm experiencing an issue where if a rank is changed using the name of the player instead of their steam2 id, it doesn't stick after the player rejoins/joins one of the other servers. I'm wondering if there's a command that "repairs" the database file or something to that extent. Or perhaps one of the recent updates changed the way rank updates are applied to the file and it's running into issues making that update while the file is open on 4 different servers. Either way, it's getting a little annoying and some users/admins are worried that promotions they have been given are temporary because they roll back after a relog. Please, enlighten me.

My ULib/ULX versions (run "ulx version" in console):
ULib v2.52d (01/09/16)
ULX v3.62d (01/01/16)

Game mode(s) I am having this problem on:
Sandbox
TTT
Cinema
Trash Compactor

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Windows Hard-Link Ulib users file. Repair database?
« Reply #1 on: February 01, 2016, 08:25:03 AM »
using one file among more than one server is dangerous. with four, I'm surprised you haven't had issues before.

With four servers reading/writing to one file, there are bound to be times when two or more of the servers try to read or write at the same time. Not sure what happens when this occurs, but I assume it would be bad.

I'm not sure what you mean by "if their rank is changed using the name of the player". Are you using the XGUI groups menu, or ulx adduser?

In all honestly, this method of using hard links is not sustainable. Look for a MySQL ULX addon, I'm pretty sure a few exist.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Windows Hard-Link Ulib users file. Repair database?
« Reply #2 on: February 01, 2016, 03:31:24 PM »
I wasn't able to find any. If there are I'm not sure that they can convert the already existing ranks to the database.

The reason why I believe this is working is because the users file is built to be accessed and written to while the server is running. I don't think 2 players with the same steamid or 1 player on 2 servers is ever going to happen, so it shouldn't cause any incompatibilities.

And by "change rank by user name" I mean using the command either in the menu or with the command 'ulx adduser' rather than using 'ulx adduserid'. Changing the rank by steamid seems to avoid this issue, although it's not as convenient.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Windows Hard-Link Ulib users file. Repair database?
« Reply #3 on: February 02, 2016, 05:23:13 AM »
It's not two players with the same SteamID.

Any time someone joins the server, someone's permissions are changed, or a user is added/removed from a group, the users.txt file is read from and/or written to.

If any of those things happen at the same time on two servers, you're going to have issues. Unless the file handling in Garry's Mod has a way to check if anything else is accessing the file (no idea how that would work, not sure if it's possible) then you'll have problems.

I may be wrong, but I'm pretty sure writing to a file involves reading it first. If two servers both want to write to users.txt, then they both have to read it. They'll be reading the same file, so all is good. But then they have to write it. One server is bound to write to the file a millisecond before the other. Which ever one writes first, will have its changes overwritten by the second server.

As to why ulx adduserid works, but ulx adduser doesn't... I'm not sure. The only thing I can think of (a stupid question, I know) is if you're trying to add an offline user with ulx adduser. I'm pretty sure ulx adduser will throw an error if you try that.

Again, I could be completely wrong about how GMod/ULib handles I/O. But really, running four servers with one users.txt is a bad idea. One alternative to using a ULX MySQL addon would be to set up a webpage from which you could run commands on all four servers. That way you could modify the users.txt simultaneously for all four servers. A bit more of a hassle, but I still think it's better than your current solution.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Windows Hard-Link Ulib users file. Repair database?
« Reply #4 on: February 02, 2016, 10:13:45 AM »
Sorry, but we don't (and physically can't) support what you're doing here. You WILL have issues with this, I'm amazed you found it a solution that worked at all, to be honest. There is no way to "repair" the database -- what you are doing is just abuse of the data.
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Windows Hard-Link Ulib users file. Repair database?
« Reply #5 on: February 02, 2016, 11:14:12 AM »
Here's the reason it doesn't work

When ULib loads its data, it loads the text file into memory.
In your case each server would load the same file into memory.

When a CHANGE is made on one server, it rebuilds the text file from what the server has in memory.
The other 3 servers still have the old version in their memory. The new version isn't loaded into the other 3 server's memories.

If a change is made on server 2, it will replace the new file that server one made with the old version (plus the new change) that server 2 had in its memory.


There really is no good way to achieve what you're asking with multiple servers reading from the same file at the same time.
Using symbolic links really would only work for a data directory if the servers wanted to share data files but not at the same time as the other server.

For instance, advance dupe files or another example is my gamemode I save player data in flat text files per player. Since the same player can't be on multiple servers at the same time it would work to allow the player to play on either server with their stats.



What you will need to do what you are trying to do is an implementation of MySQL for ULX. There are a few out there that work with varying degrees of success. Just take a look around.

Offline Chiller252

  • Jr. Member
  • **
  • Posts: 59
  • Karma: 3
  • On a Journey to Combine Technology and Design
    • Personal Website
Re: Windows Hard-Link Ulib users file. Repair database?
« Reply #6 on: February 02, 2016, 01:21:34 PM »
Here's the reason it doesn't work

When ULib loads its data, it loads the text file into memory.
In your case each server would load the same file into memory.

When a CHANGE is made on one server, it rebuilds the text file from what the server has in memory.
The other 3 servers still have the old version in their memory. The new version isn't loaded into the other 3 server's memories.

If a change is made on server 2, it will replace the new file that server one made with the old version (plus the new change) that server 2 had in its memory.


There really is no good way to achieve what you're asking with multiple servers reading from the same file at the same time.
Using symbolic links really would only work for a data directory if the servers wanted to share data files but not at the same time as the other server.

For instance, advance dupe files or another example is my gamemode I save player data in flat text files per player. Since the same player can't be on multiple servers at the same time it would work to allow the player to play on either server with their stats.



What you will need to do what you are trying to do is an implementation of MySQL for ULX. There are a few out there that work with varying degrees of success. Just take a look around.

Yeah, I've been looking for a MySQL solution for Ulib ranks, but have been unable to get any implementation to work properly. The apparently, quite-interesting solution I've come up with has it's quirks, but it has by-far worked the best.