Ulysses
General => Developers Corner => Topic started by: Snowden42 on April 08, 2010, 12:07:45 PM
-
As an addendum to my previous questions. I'm more or less wondering if there's anyway to get Ulx to track the admin output through the Sourcebans MySql databases. It'd be a lot easier if Ulx could set up admins from the admin list stored on Sourcebans.
A little background about this:
My current group recently started up our first Gmod server, a sandbox server. Initially, we had Ulx, but it started to become tedious manually installing admins to the users.txt file. We run several TF2 servers, so we already use Sourcebans to keep track of our admins and bans. Since Ulx doesn't, at least to my knowledge, have this support standard, I decided to try out Sourcemod instead. BIG MISTAKE! Sourcemod is basically bare-bones. I mean, it has a GUI derma menu, but it's pretty much completely terrible beyond that. There's no support for gamemode switching, automatic prop removal, or spawn restrictions, among other features it lacks. So I'd love to be able to use Ulx and it'd be completely awesome if it would support some form of Sourcebans admins. I can give you a sample of these files if absolutely necessary.
I can understand why this might be a challenge--Ulx runs independent of Sourcemod, and Sourcebans only supports Sourcemod. But if there's any way to load Sourceban's admin lists into Ulx, I'd appreciate it like you would not believe. Our admin list is quite large, so to manually install all of them would be a pretty big pain in the ass.
Another thought I just had. I don't know if it's possible, but after perusing the forums, I came across a few different threads talking about this. However, they only asked about ban integration, not admin integration, so I assume this hasn't been asked before. I apologize if it has. Anyways, I noticed that you have something called Uban(s). I haven't looked at it, but would this solve the problems I'm currently having? If this is deserving of its own thread, I'll repost it under suggestions/requests. Any help is greatly appreciated. Thanks,
Snowden
-
It wouldn't be difficult at all. This admin list is in a MySQL database? Just promote users to the appropriate user group when they connect.
-
I'm confused. I understand I can promote in game, but I'd like to set up Ulx to set admins based upon the Sourcebans MySql database. The database is hosted on the same box, so access is pretty simple. I just need some instructions about how to get it to integrate properly. In addition, the Sourcebans admin list is probably not compatible with Ulx without some revision on the part of Ulx. Like I said, I'll pm you a copy of the Sourcebans admin list as output it outputs it as a .txt file.
-
By promote I meant programatically. Surely there's some form of groups or level or permissions in Sourcebans that you can translate to an appropriate group. Just decide what group they need to be in when they connect (via lua).
-
Alright, I'm sure what you've said has been very helpful, but I should have prefaced what I asked by saying, I barely understand lua at all. I mean, if I'm given a script, sure I might understand a little of what it's doing, but not to any necessary extent. I presume you're saying that I should keep Sourcemods, so that I can call the admins from it, but beyond that I have no idea how to do this.
-
Alright, I'm sure what you've said has been very helpful, but I should have prefaced what I asked by saying, I barely understand lua at all. I mean, if I'm given a script, sure I might understand a little of what it's doing, but not to any necessary extent. I presume you're saying that I should keep Sourcemods, so that I can call the admins from it, but beyond that I have no idea how to do this.
You don't have someone in your community that could do this for you?
-
I don't know, maybe. Since this is our first move into Gmod, most of the people are just regular players. I suppose I could try, but I doubt I'll get anywhere. Where/how does Ulx load admins?
Edit: Nevermind, realized it uses data/ulib/users.txt
-
I don't know, maybe. Since this is our first move into Gmod, most of the people are just regular players. I suppose I could try, but I doubt I'll get anywhere. Where/how does Ulx load admins?
Edit: Nevermind, realized it uses data/ulib/users.txt
The easiest thing for you would be to just use player:SetUserGroup(). IE, you get a ply object when someone connects... if they belong to superadmin group, do ply:SetUserGroup( "superadmin" ). ULib/ULX will take care of the rest and any other third party mods will recognize the user as a superadmin as well.
-
Ugh I'm still really confused. I kind of understand what you're saying, but I don't understand how to use it. The php coder in me is telling me I have to require certain files to make this run properly, but I'm not sure. Furthermore, I don't even know how to execute lua code on join, or how to convert a text document to a file readable by ulx. I apologize again for being so unhelpful.
-
Ugh I'm still really confused. I kind of understand what you're saying, but I don't understand how to use it. The php coder in me is telling me I have to require certain files to make this run properly, but I'm not sure. Furthermore, I don't even know how to execute lua code on join, or how to convert a text document to a file readable by ulx. I apologize again for being so unhelpful.
You wouldn't want ULX to read the file dump, you'd want to read directly from the SQL database. You can do this by using the sql lib here (http://www.facepunch.com/showthread.php?t=241247). To get something to run on player connect using this hook here (http://wiki.garrysmod.com/?title=Gamemode.PlayerConnect). Use hook.Add (http://wiki.garrysmod.com/?title=Hook.Add) to add your own PlayerConnect hook.
You can think of lua kind of like a huge conglomerate of scripts that are running and working together (in gmod's case though, only on one thread), so there's no need to include or require something if it's already running (IE, don't include ulx/ulib, but DO include mysql since it might not be running elsewhere).
You could try poking around to see if anyone would be willing to make the script for you (either pro bono or for a fee) if you don't want to do it yourself. If you want to try taking it on yourself, I recommend reading up on the following resources (listed in order of importance):
http://www.lua.org/pil/ -- Lua tutorial (written for Lua 5.0, but still works find for 5.1)
http://www.lua.org/manual/5.1/ -- Lua reference manual for looking up specific functions
http://ulyssesmod.net/docs/ -- The ULib documentation
http://wiki.garrysmod.com/?title=Lua -- The Gmod lua documetation
-
Perhaps you could PM the author of this post.
He's mentioned interest in our UCL and SQL.
http://forums.ulyssesmod.net/index.php/topic,4442.msg17765.html
Somewhere around here is the code Megiddo once used to pull admin steamids from SMF database when we had a gmod server too, but I've long lost where the post was.
EDIT - Ah HA! I knew if I used search from the right forum area I'd find it.
http://forums.ulyssesmod.net/index.php/topic,3241.msg9622.html#msg9622
Now, again, that's only example Lua code, pulling from the SMF database.
However, with the links given above, experience with SQL combined with the example, shouldn't be impossible to find the proper Sourcebans admin tables and pull from those/promote the player using Megiddo's ideas.
-
Whatever help you guys can give me is fine. Right now I'm looking through our community for a lua coder to help, and I don't think it's going to materialize.
-
See my edit. :)
-
I took a look, it's definitely a helpful start. I've also got MySql workbench running properly, so I can take a good look at the sourcebans tables.
-
Well, I've taken this in a new direction. Since I'm much better at PHP, and, at least in my opinion, it's much easier to use, I'm in the process of writing a script that will be run through cron. It's gonna query the Sourcebans database and dump it in the proper format as a .txt file in garrysmod/data/ulib/users.txt
Comments or suggestions? I'm not 100% sure how Ulx works, but I do know this will override any changes made in game, which I'm fine with, as we can just use the database to continue making changes.
This isn't a perfect strategy, but for me it should work. If anyone is interested in the code when I'm finished, I'll gladly share it.
-
Well, that's one way to skin a cat.
I learned PHP about 10-15 years ago...then learned Lua about 5 or so.
The transition for me was pretty easy, but I've been doing various script languages most of my PC life.
-
Your idea will work just fine, and though roundabout and the harder way, might be for the best if you already know PHP.
-
Megiddo, correct me if I'm wrong on this, but...
Editing the users.txt file manually will work, but changes wont take effect until the map/server is restarted. ULib reads this list on start and stores its contents in memory.
-
I opened up users.txt, and I'm wondering what the proper format is for it. Here's our current one:
"STEAM_0:0:25502648"
{
"deny"
{
}
"name" "iSins[Fug]"
"allow"
{
}
"group" "superadmin"
}
"STEAM_0:0:14514835"
{
"deny"
{
}
"group" "superadmin"
"allow"
{
}
"name" "Bloodyred [Fug-II]"
}
These are not consistent, so I'm wondering what the proper format is.
-
I'm not really sure where this goes, presumably it'd be helpful in releases, but it's not really a release (a plugin), so I'll post it here, and you can do with it what you want.
You should be aware that this will give superadmin to everyone who fits the query parameters. I will try and support this for at least a few weeks if anyone needs significant help with getting it to assign a larger variety of flags.
I tried to comment it up as much as possible, so that anyone can get it working. You'll need to know how to run a Cron task, or have enough time to run it manually. Although I shouldn't have to mention it, you should know your server's hostname. On that note, please be aware that, if you're hosting it on the same box, it's 99% of the time "localhost". In addition, if it were localhost, you'd set hostname to "localhost:port". Make sure to include the port, it's important. Here's the code:
<?php
//Coded by Snowden42
//It queries the Sourcebans mysql database and then dumps the sb_admins table in the garrysmod data folder in a format readable for ULX.
//You'll want to run this through Cron, or you'll have to manually connect to it through your browser.
//The MySQL variables are defined below
$hostname = '';
$username = '';
$password = '';
//Location of users.txt
//For path, please be aware that you must escape backslashes on the Windows platform. Thus, it is simpler just to use forward slashes.
//Fill in the "..." with the path to Orangebox. The path may or may not start in "C:\\" depending on what system you're on.
$handle = fopen("C:\\...\orangebox\garrysmod\data\ulib\users.txt", "w");
if(!$handle){
die('Failed to Open Users.txt</br>');
};
echo('Opened Users.txt Successfully</br>');
//Connect to the database
$mysql_connect = mysql_connect($hostname, $username, $password);
if(!$mysql_connect){
die('Unable to Connect: '. mysql_error().'</br>');
};
echo('Connected Successfully</br>');
//Select correct database
$db = mysql_select_db('sb', $mysql_connect);
if(!$db){
die('Can\'t use sb: '. mysql_error().'</br>');
};
echo('Database Selected Properly</br>');
//Query the database
//If you only use sb_admins to store admins (we store people with donor flags in it as well) leave it as is.
//The MySQL query syntax is relatively simple. You should be able to figure out how to query specific users with a simple google search.
$query = mysql_query("SELECT * FROM sb_admins", $mysql_connect);
while($row = mysql_fetch_array($query)){
$write = fwrite($handle, '"'.$row['authid'].'"
{
"deny"
{
}
"name" "'.$row['user'].'"
"allow"
{
}
"group" "superadmin"
}
');
};
//Catch errors during writing
if(!$write){
echo('An Error Occured During Writing</br>');
} else{
echo('Writing Successful</br>');
};
//Close users.txt
$fclose = fclose($handle);
if(!$fclose){
die('Unable to Close Users.txt');
};
echo('Closed Users.txt');
?>
I hope that this code helps someone, I can tell you for certain it definitely helps me. While the lua code was probably more efficient and effective, I guarantee this code works. In addition, it will tell you if there were errors when you run it manually, so I recommend you do so to guarantee that it does indeed work on your system.
If you have any questions or problems, feel free to leave them here.
-
Megiddo, correct me if I'm wrong on this, but...
Editing the users.txt file manually will work, but changes wont take effect until the map/server is restarted. ULib reads this list on start and stores its contents in memory.
That's correct Mr. P.
-
Ah, still, this should work fine for me. The main reason I wrote this was because of the sheer volume of our database.
-
I know I bump this thread but I realy want this. The PHP script up there would be perfect for me. Only problem is that it needs server restart or map change. It's a RP server I got and we never change the map. So is there any command you can add to the PHP script so it reloads admin? Is it even possible?
If not can their be a lua code for it? That does the samething as that PHP code and that will load everytime it has change?
I use sourcebans...
Thank you.
-
For lua to "do the same thing as php" as far as SQL compatibility goes... you need a module. I know lexi makes one that works but there isn't anything other than a framework for making sourcebans plugins in gmod. I really wish people would use it to make stuff for the admin mods, but sadly, it's been a slow process
http://www.facepunch.com/threads/980687
SQL: http://www.facepunch.com/threads/952088
-
Thanks for your reply, Im just starting in lua but what I do I need to do with the link of the SQL?