ULX

Author Topic: Sourcebans admin integration?  (Read 17198 times)

0 Members and 1 Guest are viewing this topic.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Sourcebans admin integration?
« Reply #15 on: April 10, 2010, 07:12:54 PM »
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.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: Sourcebans admin integration?
« Reply #16 on: April 10, 2010, 10:18:29 PM »
Your idea will work just fine, and though roundabout and the harder way, might be for the best if you already know PHP.
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Sourcebans admin integration?
« Reply #17 on: April 11, 2010, 04:12:52 AM »
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.

Offline Snowden42

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
Re: Sourcebans admin integration?
« Reply #18 on: April 11, 2010, 07:57:31 AM »
I opened up users.txt, and I'm wondering what the proper format is for it. Here's our current one:
Code: [Select]
"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.
« Last Edit: April 11, 2010, 07:55:08 PM by Snowden42 »

Offline Snowden42

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
Re: Sourcebans admin integration?
« Reply #19 on: April 11, 2010, 11:47:29 AM »
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:

Code: [Select]
<?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.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6213
  • Karma: 394
  • Project Lead
Re: Sourcebans admin integration?
« Reply #20 on: April 11, 2010, 12:07:46 PM »
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.
Experiencing God's grace one day at a time.

Offline Snowden42

  • Newbie
  • *
  • Posts: 12
  • Karma: 2
Re: Sourcebans admin integration?
« Reply #21 on: April 11, 2010, 12:14:22 PM »
Ah, still, this should work fine for me. The main reason I wrote this was because of the sheer volume of our database.

Offline Cyanide

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Sourcebans admin integration?
« Reply #22 on: December 07, 2011, 05:29:59 AM »
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.
« Last Edit: December 07, 2011, 05:34:14 AM by Cyanide »

Offline strategos

  • Jr. Member
  • **
  • Posts: 66
  • Karma: 2
  • I wanna be the guy
    • Community
Re: Sourcebans admin integration?
« Reply #23 on: December 07, 2011, 05:52:16 PM »
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
« Last Edit: December 07, 2011, 05:54:01 PM by strategos »

Offline Cyanide

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
Re: Sourcebans admin integration?
« Reply #24 on: December 08, 2011, 04:30:58 AM »
Thanks for your reply, Im just starting in lua but what I do I need to do with the link of the SQL?