Raised This Month: $51 Target: $400
 12% 

[ANY] Threaded Mysql Bans


Post New Thread Reply   
 
Thread Tools Display Modes
senseit
Member
Join Date: Aug 2009
Old 07-30-2012 , 00:34   Re: [ANY] Threaded Mysql Bans
Reply With Quote #21

Quote:
Originally Posted by Jim E. Rustler View Post
so the database I created 'mysqlbans' will not work unless I rename it to 'default' and re-do everything?
in your database.cfg change mysqlbans to default.

Code:
"Databases"
{
    "driver_default"        "mysql"
    
    "default"
    {
        "driver"            "mysql"
        "host"                "localhost"
        "database"            "mysqlbans"
        "user"                "user"
        "pass"            "pass"
        //"timeout"            "0"
        "port"            "3306"
    }
}
senseit is offline
senseit
Member
Join Date: Aug 2009
Old 07-30-2012 , 00:36   Re: [ANY] Threaded Mysql Bans
Reply With Quote #22

Quote:
Originally Posted by thetwistedpanda View Post
senseit, it wouldn't be too difficult to get a cvar for clients that lets them pick their database, with the cvar defaulted to "default"
I'll add it later when i come back to this plugin. I just needed something that worked now, so I made it. I've moved onto coding another custom plugin atm.

Last edited by senseit; 07-30-2012 at 00:36.
senseit is offline
senseit
Member
Join Date: Aug 2009
Old 07-30-2012 , 04:32   Re: [ANY] Threaded Mysql Bans
Reply With Quote #23

Quote:
something I just noticed. I've been banning myself to test this plugin and my php page but I just banned a friend and instead of banning him it banned me lol. I'm positive I banned his name and not my own as my PHP page is showing I banned him and even has his correct steamid but I'M THE ONE BANNED! Funny bug I think.
Oops, lol. It kicks the wrong person. Fixed. Updated to 1.02 . I only tested it on myself.

Last edited by senseit; 07-30-2012 at 04:32.
senseit is offline
Jim E. Rustler
BANNED
Join Date: Jul 2012
Old 07-30-2012 , 10:44   Re: [ANY] Threaded Mysql Bans
Reply With Quote #24

Quote:
Originally Posted by senseit View Post
Oops, lol. It kicks the wrong person. Fixed. Updated to 1.02 . I only tested it on myself.
Thanks for fixing this. This plugin combined with my webpage I made for it has made me decide to use it over sourcebans simply because it runs faster on my host. Sourcebans has a lot of bloat and a lot of aspects of it would break as you used it for no reason at all.

One thing I would love to figure out is how to make this the default ban system for the server instead of sourcemods since this is far superior imo. And maybe a way to capture their ip address in the database so you can ban their ip too.

Great work.

EDIT: If someone knows how to make my webpage output all the rows in the database that would be great because I can only get it to fetch the 1st row and cannot figure it out.
PHP Code:
<html>
<head>
<title>MySQL Bans</title>

    <style type="text/css">
        body {
            font-family: Trebuchet MS, Helvetica, sans-serif;
            margin-left: auto;
            margin-right: auto;
        }
table, th, td
{
border: 1px solid black;
}
</style>

</head>

<body>
<?php
$username
="username";
$password="password";
$database="database";

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM my_bans";
$result=mysql_query($query);

$num=mysql_num_rows($result);

mysql_close();
?>

<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Steam ID:</td>
<td>Player Name:</td>
<td>Ban Reason:</td>
<td>Banned By:</td>
<td>Ban Length:</td>
<td>Time:</td>
</tr>

<?php
$i
=0;
while (
$i $num) {

$f1=mysql_result($result,$i,"steam_id");
$f2=mysql_result($result,$i,"player_name");
$f3=mysql_result($result,$i,"ban_reason");
$f4=mysql_result($result,$i,"banned_by");
$f5=mysql_result($result,$i,"ban_length");
$f6=mysql_result($result,$i,"timestamp");

?>

<tr>
<td><?php echo $f1?></td>
<td><?php echo $f2?></td>
<td><?php echo $f3?></td>
<td><?php echo $f4?></td>
<td><?php echo $f5?></td>
<td><?php echo $f6?></td>
</tr>
<?php
$i
++;
}
?>

</body>
</html>

Last edited by Jim E. Rustler; 07-30-2012 at 14:04.
Jim E. Rustler is offline
senseit
Member
Join Date: Aug 2009
Old 07-30-2012 , 14:25   Re: [ANY] Threaded Mysql Bans
Reply With Quote #25

Quote:
Originally Posted by Jim E. Rustler View Post
EDIT: If someone knows how to make my webpage output all the rows in the database that would be great because I can only get it to fetch the 1st row and cannot figure it out.

In regards to overriding sm_ban, there is a way to do it. But I have not sat down yet to do it. I will update that at some point in the future. For now, I'm just telling my admins to use my_ban. I threatened 100 lashes to anyone who used sm_ban. That appears to have worked for me at least (so far).


PHP Code:
<table>
<tr><td> Steam ID </td><td> Player Name </td><td> Ban Length </td><td> Ban Reason </td><td> Banned By </td><td> Timestamp </td></tr>
<tr><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>

<?PHP
$dbh 
"host"
$dbu "user";    
$dbp "pass";
$db "database";

mysql_connect($dbh$dbu$dbp) or die("Error: " mysql_error());   
mysql_select_db($db);   

$sql="SELECT * FROM my_bans";                                                                                                               
$q=mysql_query($sql) or die("Error: " mysql_error());        
$rows=mysql_num_rows($q);  

$i=0
while (
$i $rows) {  

$steam_id=mysql_result($q$i"steam_id");
$player_name=mysql_result($q$i"player_name");
$ban_length=mysql_result($q$i"ban_length");
$ban_reason=mysql_result($q$i"ban_reason");
$banned_by=mysql_result($q$i"banned_by");
$timestamp=mysql_result($q$i"timestamp");

echo 
'<tr><td> '.$steam_id.' </td><td> '.$player_name.' </td><td> '.$ban_length.' </td><td> '.$ban_reason.' </td><td> '.$banned_by.' </td><td> '.$timestamp.' </td></tr>';

$i++; 
}

?>
</table>

Last edited by senseit; 07-30-2012 at 14:27.
senseit is offline
Jim E. Rustler
BANNED
Join Date: Jul 2012
Old 07-30-2012 , 15:27   Re: [ANY] Threaded Mysql Bans
Reply With Quote #26

PHP Code:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<html>
<head>
<title>MySQL Bans</title>

    <style type="text/css">
        body {
            font-family: Trebuchet MS, Helvetica, sans-serif;
            margin-left: auto;
            margin-right: auto;
        }
table, th, td
{
border: 1px solid black;
}
</style>

</head>

<body>
<?php
$username
="username";
$password="password";
$database="database";

mysql_connect(localhost,$username,$password);
@
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM my_bans ORDER BY timestamp DESC";
$result=mysql_query($query);

$rows mysql_num_rows($query);

mysql_close();
?>

<table border="0" cellspacing="2" cellpadding="2">
<tr>
<td>Steam ID:</td>
<td>Player Name:</td>
<td>Ban Reason:</td>
<td>Banned By:</td>
<td>Ban Length:</td>
<td>Time:</td>
</tr>

<?php
while ($row=mysql_fetch_assoc($result)) {

$f1=$row["steam_id"];
$f2=$row["player_name"];
$f3=$row["ban_reason"];
$f4=$row["banned_by"];
$f5=$row["ban_length"];
$f6=$row["timestamp"];

?>

<tr>
<td><?php echo $f1?></td>
<td><?php echo $f2?></td>
<td><?php echo $f3?></td>
<td><?php echo $f4?></td>
<td><?php echo $f5?></td>
<td><?php echo $f6?></td>
</tr>
</tbody>
<?php
$i
++;
}
?>
</table>
</body>
</html>
With special help from Zephyrus we managed to get it to work properly So here is a simple PHP page that will connect to your MySQL Bans database and print out it's contents in a nice table (WARNING: There is no pagination so it can get pretty big. If someone could help me with that it would be appreciated)

EDIT: How difficult would it be to do ip based banning along with the steam id? I ask this because of TF2 being free 2 play most people have several 'troll accounts' they use to cause trouble on.

Last edited by Jim E. Rustler; 07-30-2012 at 16:13.
Jim E. Rustler is offline
Adjo
Member
Join Date: Dec 2009
Location: UK
Old 07-30-2012 , 19:22   Re: [ANY] Threaded Mysql Bans
Reply With Quote #27

Quote:
Originally Posted by Jim E. Rustler View Post
(WARNING: There is no pagination so it can get pretty big. If someone could help me with that it would be appreciated)

EDIT: How difficult would it be to do ip based banning along with the steam id? I ask this because of TF2 being free 2 play most people have several 'troll accounts' they use to cause trouble on.
Here's a version I quickly made for you with pagination
PHP Code:
<?php
    
    $config    
=    array(
        
'host'        =>    'some-host',        //Database host
        
'username'    =>    'some-user',        //Database username
        
'password'    =>    'some-pass',        //Database password
        
'dbname'    =>    'some-dbname',        //Database name
        
        
'perpage'    =>    32,                    //Amount of bans to show per page
    
);
    
    
//---------
    
    
mysql_connect($config['host'], $config['username'], $config['password']) or die('Couldn\'t connect to the database.');
    
mysql_select_db($config['dbname']) or die('Couldn\'t select the database.');
    
    
$currentPage = empty($_GET['page'])||!is_numeric($_GET['page'])||$_GET['page']<1?1:(int)$_GET['page'];
    
$query mysql_query('SELECT * FROM `my_bans` ORDER BY `id` DESC LIMIT '.(($currentPage-1)*$config['perpage']).','.$config['perpage']);
    
$pageResults mysql_num_rows(mysql_query('SELECT * FROM `my_bans`'));
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>MySQL Bans</title>
        <style type="text/css">
            body{
                font-family:Trebuchet MS, Helvetica, sans-serif;
                margin-left:auto;
                margin-right:auto;
            }
            table, th, td{
                border: 1px solid black;
            }
        </style>
    </head>
    <body>
        <?php
            
if(mysql_num_rows($query) == 0){
                echo 
'No players currently on the banlist...';
            }else{
        
?>
            <table border="0" cellspacing="2" cellpadding="2">
                <tr>
                    <td>Steam ID</td>
                    <td>Player Name</td>
                    <td>Ban Reason</td>
                    <td>Banned By</td>
                    <td>Ban Length</td>
                    <td>Time</td>
                </tr>
        <?php
                
while($row mysql_fetch_assoc($query)){
                    echo 
'<tr><td>',$row['steam_id'],'</td><td>',htmlentities($row['player_name']),'</td><td>',htmlentities($row['ban_reason']),'</td><td>',htmlentities($row['banned_by']),'</td><td>',$row['ban_length'],'</td><td>',$row['timestamp'],'</td></tr>';
                }
                echo 
'</table>';
                if(
$pageResults>$config['perpage']){
                    
$pageUrl '?page=';
                    if(
$currentPage>1){
                        echo 
'<a href="',$pageUrl,($currentPage-1),'">Previous</a>&nbsp;';
                    }
                    
$totalPages ceil($pageResults/$config['perpage']);
                    for(
$i=1;$i<=$totalPages;++$i){
                        echo 
'<a href="',$pageUrl,$i,'">',$i,'</a>&nbsp;';
                    }
                    if(
$currentPage<$totalPages){
                        echo 
'<a href="',$pageUrl,($currentPage+1),'">Next</a>&nbsp;';
                    }
                }
            }
        
?>
    </body>
</html>
Adjo is offline
Jim E. Rustler
BANNED
Join Date: Jul 2012
Old 07-30-2012 , 20:21   Re: [ANY] Threaded Mysql Bans
Reply With Quote #28

Awesome job! though I think there is an issue with character encoding as multibyte/unicode characters are looking like jibberish.
Jim E. Rustler is offline
Jim E. Rustler
BANNED
Join Date: Jul 2012
Old 07-31-2012 , 11:06   Re: [ANY] Threaded Mysql Bans
Reply With Quote #29

I'm not sure if this is how you do it. But to fix the character encoding problem I rebuilt the htmlentities echo thingy by adding ENT_QUOTES, "UTF-8":

PHP Code:
echo '<tr><td>',$row['steam_id'],'</td><td>',htmlentities($row['player_name'], ENT_QUOTES"UTF-8"),'</td><td>',htmlentities($row['ban_reason']),'</td><td>',htmlentities($row['banned_by'], ENT_QUOTES"UTF-8"),'</td><td>',$row['ban_length'],'</td><td>',$row['timestamp'],'</td></tr>'
Now players with multibyte/unicode chars in their names appear correctly on the webpage. If this is not the proper way to fix please let me know. Thanks

Also, is it possible for bans to get randomly deleted from the DB? I know for a fact I had 4 permanent bans yesterday and looked at my DB this morning and only 3 showed up. Also, I'm noticing that if you type a players name that isn't on the server it fills up your error logs with this:

Code:
L 07/31/2012 - 11:39:28: [SM] Plugin encountered error 4: Invalid parameter or parameter type
L 07/31/2012 - 11:39:28: [SM] Native "ReplyToCommand" reported: Language phrase "No matching client" not found
L 07/31/2012 - 11:39:28: [SM] Displaying call stack trace for plugin "mysqlt_bans.smx":
L 07/31/2012 - 11:39:28: [SM]   [0]  Line 103, /groups/sourcemod/compiler-1.4/include/commandfilters.inc::ReplyToTargetError()
L 07/31/2012 - 11:39:28: [SM]   [1]  Line 198, /groups/sourcemod/compiler-1.4/include/helpers.inc::FindTarget()
L 07/31/2012 - 11:39:28: [SM]   [2]  Line 116, /home/groups/alliedmodders/forums/files/5/8/2/6/8/107066.attach::Command_Ban()
I tested it by trying to ban a made up name that wasn't on my server then looked and saw a new error log with that in it.

Last edited by Jim E. Rustler; 07-31-2012 at 11:40.
Jim E. Rustler is offline
Adjo
Member
Join Date: Dec 2009
Location: UK
Old 07-31-2012 , 11:51   Re: [ANY] Threaded Mysql Bans
Reply With Quote #30

Quote:
Originally Posted by Jim E. Rustler View Post
I'm not sure if this is how you do it. But to fix the character encoding problem I rebuilt the htmlentities echo thingy by adding ENT_QUOTES, "UTF-8":

Now players with multibyte/unicode chars in their names appear correctly on the webpage. If this is not the proper way to fix please let me know. Thanks

Also, is it possible for bans to get randomly deleted from the DB? I know for a fact I had 4 permanent bans yesterday and looked at my DB this morning and only 3 showed up. Also, I'm noticing that if you type a players name that isn't on the server it fills up your error logs with this:

Code:
L 07/31/2012 - 11:39:28: [SM] Plugin encountered error 4: Invalid parameter or parameter type
L 07/31/2012 - 11:39:28: [SM] Native "ReplyToCommand" reported: Language phrase "No matching client" not found
L 07/31/2012 - 11:39:28: [SM] Displaying call stack trace for plugin "mysqlt_bans.smx":
L 07/31/2012 - 11:39:28: [SM]   [0]  Line 103, /groups/sourcemod/compiler-1.4/include/commandfilters.inc::ReplyToTargetError()
L 07/31/2012 - 11:39:28: [SM]   [1]  Line 198, /groups/sourcemod/compiler-1.4/include/helpers.inc::FindTarget()
L 07/31/2012 - 11:39:28: [SM]   [2]  Line 116, /home/groups/alliedmodders/forums/files/5/8/2/6/8/107066.attach::Command_Ban()
I tested it by trying to ban a made up name that wasn't on my server then looked and saw a new error log with that in it.
Adding ENT_QUOTES, UTF-8 is the way to fix it (or atleast, one of the few ways which are possible)... as for a ban disappearing, the only time a delete query is ran is when the my_unban command is run from the console - it'll remove the record from the database then.

As for those plugin errors, I believe the author needs to have this in OnPluginStart() - LoadTranslations("common.phrases");
Adjo is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode