Author Topic: ULib MySQL Authentication  (Read 24233 times)

0 Members and 2 Guests are viewing this topic.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
ULib MySQL Authentication
« on: April 03, 2015, 08:25:05 PM »
What This Is
This is a replacement for ULib's UCL storage system. The current system saves and reads all stored users and their accesses from a single text file. This works fine, unless you have multiple servers or a LOT of information in that file.

What This Does
This overrides the Save and Load functions in UCL. Instead of loading and saving your users to the users.txt file, it will instead load and save them from a database.


What This Doesn't Do
This only handles users. It doesn't store groups or group permissions. Those are still going to be stored in the groups.txt
This doesn't handle banning. There are plenty of MySQL banning modules out there.

What Is Modified
You will need to *replace* your ucl.lua file in addons\ULib\lua\ulib\server\ucl.lua
We typically NEVER recommend that you replace any of our stock files as this could cause issues or the changes will be reverted the next time you update ULib.. However, due to the nature of this kind of modification simply writing it into an addon wouldn't work because of the way modules are loaded. If you choose to install this, I HIGHLY recommend making a backup of your ULib addon first.
Inside the ucl.lua file I added some MySQL functions. I also modified the SaveFile function as well as completely commented out the LoadFromFile function. I also slightly modified addUser and removeUser functions.

How To Install
1. Install the MySQLoo module. If you don't know where/how to get this I suggest Google.
2. Download the copy of ucl.lua from this post (YOU NEED TO BE LOGGED IN TO SEE IT)
3. Replace Addons\ULib\lua\server\ucl.lua with the one I provided.
4. Create a database in your MySQL called 'ulibsql' and set up a user to have permissions for it. (Don't create any tables inside of it, my code will handle that)
5. Edit the information at the top of the file to suit your MySQL database.
6. To be sure the table generated: run 'lua_run ULib_SQL_CreateTable()' from your server console.
7. From your server console or in game (if you are a superadmin) run ulib_loadlegacy to load your users from your users.txt and load them into your database.

WARNING/CAUTION
This is ONLY for people who know how to use the MySQLOO module. I will not provide support for getting that installed or configured.
This is not for server owners who do not know enough about lua or modifying files to at least edit the SQL configuration at the top of the file.
If you update ULib this modification will be lost and you'll have to reinstall it.
This comes as-is and while I did to testing, there is no way for me to know if it'll work in every situation. Please make a backup of your ULib files before installing this.

Help/Support
I am not going to help you install MySQLOO.
If you have MySQLOO installed and configured properly and are having trouble with this modification, please feel free to post here and I will try and assist you the best I can.



Please let me know how this works for you. :)
« Last Edit: April 27, 2015, 07:02:39 PM by MrPresident »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: ULib MySQL Authentication
« Reply #1 on: April 03, 2015, 08:59:09 PM »
But But but, couldn't you use our current ULib hooks for pre/post translate commands to hook into ucl change, prevent the original function, perform yours, and not have to overwrite our original ucl file?
*sniffle*

(I say 'our' because you are 'us' now that we've assimilated you) :)
"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: ULib MySQL Authentication
« Reply #2 on: April 03, 2015, 09:08:18 PM »
No, because all of this stuff happens so far into the background of UCL that it isn't hooked. I could have done it with the Add and Remove user, but the rest I couldn't. I had to override the function entirely and in my experience, addons have a weird way of loading in different orders each time so there really isn't a good way to write a module to do that.

I've talked to Megiddo about redoing how our modules are loaded to allow for something like this. I believe it's on our list of things for the next big ULX/ULib rewrite.

Offline Zaddion

  • Newbie
  • *
  • Posts: 15
  • Karma: 0
Re: ULib MySQL Authentication
« Reply #3 on: April 03, 2015, 10:43:28 PM »
I was really hoping I could get this to work without having to ask for help. I have MYSQLOO installed (another addon that I use requires it), I made a database for the addon, I filled out the sql information at the top of the ucl file, and I overwrote the file. I restarted my server and I tried running the command, I waited, waited longer, it didn't say if it was successful or anything, so I waited a couple of minutes and checked my database, nothing happened? Is it an overtime thing? It'd be nice if it told me if the command worked if it did work. I double checked my sql information and made sure it was all correct. Not sure what I did wrong.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ULib MySQL Authentication
« Reply #4 on: April 03, 2015, 10:52:58 PM »
If you did it correctly, it should generate a table inside of your database when you first start your server.
Make sure you have permissions assigned for the database correctly.

Do you get any messages in console while ULX is loading?

Offline Zaddion

  • Newbie
  • *
  • Posts: 15
  • Karma: 0
Re: ULib MySQL Authentication
« Reply #5 on: April 03, 2015, 10:56:14 PM »
If you did it correctly, it should generate a table inside of your database when you first start your server.
Make sure you have permissions assigned for the database correctly.

Do you get any messages in console while ULX is loading?

Is there a specific message I am looking for? It'd be easier if you could add me on steam where we can discuss this http://steamcommunity.com/id/zaddion/

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ULib MySQL Authentication
« Reply #6 on: April 03, 2015, 11:07:51 PM »
Working with Zaddion, it would appear that in some cases the Table might not generate itself. If that's the case just run the following at your server's console:

lua_run ULib_SQL_CreateTable()

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given