Inactive [INFO/WEB] Netstats v5.0.4 - Keeps track of player playtime and online status [RB 1.1-R3]

Discussion in 'Inactive/Unsupported Plugins' started by Valrix, Feb 13, 2011.

  1. Offline

    Valrix

    Netstats v5:
    COMPLETE!
    Keep up with development in BukkitDev!
    Netstats - Player Monitoring Plugin:
    Plugin Version: v5.0
    Web Version: v3.0

    Netstats watches players as they join and leave the server and keeps track of how long they've been logged into the server as well as keeping track of their current online/offline status while using very little system resources. The information is stored in a database which is defined by the user. First time using Netstats it will create the config file then disable itself until you change the config to match your database. Then you can reload or restart the server and it'll start collecting information immediately.
    Source Code: Netstats

    OLD CHANGELOG (open)

    Version 4.7
    • Bug fixes
    • If you don't supply a "database" in the config it will attempt to make it's own database named "NetStats" then create the table "netstats" inside it.
    • Fixed repetitive code and unnecessary MySQL connections when doing multiple queries one-after-another (reduces database calls, speeds up the code, and uses less resources).
    • Reduced code complexity (simplified certain calls and removed hacky functions to improve code performance by around 5-10% in my tests)
    Version 4.6
    • Fixed the bug that happened when trying to change the name of your stats table.
    • Fixed the bug that messed up everyone's total play time (sorry)
    • Code improvements and uses less code for database calls
    Version 4.5
    • Fixed the bug where folders weren't being made.
    Version 4.4
    • Converts the total play time to be saved as seconds instead of milliseconds to increase maximum play time. This will now match the PHP code, so if you changed it, change it back.
    • Now disables and re-enables itself instead of reloading the server when doing a wipe
    • Some code improvements
    Version 4.3
    • No longer requires the /lib/ folder since CB already contains the needed drivers
    • v5 is close to being ready and will bring large speed improvements
    Version 4.2
    • Fixes the bug that creates .stats folders instead of files.
    Version 4.1
    • Many code improvements to improve speed and memory usage.
    • Thanks to @jascotty2 for the code to fix how player and mob kills are handled
    Version 4.0
    • Many bug fixes
    • Changed how total play time was saved to the database
    • Fixed a bug with timed events
    • A new and improved Web update is nearly finished
    Version 3.9
    • Should work with RB 617
    Version 3.8
    • Fixed an issue with how files were handled.
    Version 3.7
    • Fixes issue of logged-in users being shown as offline after a reload
    • Fixed file creation bug where .stat files weren't being made properly
    Version 3.6
    • Fixed a bug where, depending on your region, your IP address was logged twice in the database. This was more of an issue with how the IP address was being grabbed than a problem with how it was stored.
    • Few other small fixes to prevent possible future bugs.
    Version 3.5
    • Changed how paths are managed by the plugin to be more OS-independent, hopefully fixing all "file not found" errors.
    • Removed checking if a database password exists or not.
    Version 3.4
    • Improved error logger that create a special log file with the exact info I'll need to find out what caused the problem.
    • Numerous bug fixes and speed tweaks
    Version 3.3
    • Added tracking of distance traveled
    • Added tracking of number of monsters a player has killed
    • Added tracking of number of other players a player has killed
    • Added the date of when the player first joined the server (after this version of Netstats has been installed, will only be correct after a full wipe of other stats)
    • Database will auto-build if it doesn't exist, otherwise it'll add columns if they're needed (so you don't have to do anything to update your database)
    • Config file now auto-updates and allows for comments (they need their own line however)
    • Many other code improvements and fixes to help it run faster and more efficiently.
    Version 3.2
    • Fixed the problem with saving to the database that everyone's been getting. (Only need the JAR)
    Version 3.1
    • Changed the namespace to com.sparkedia.valrix since I did the Java bit.
    Version 3.0
    • Rebuild of v1 to be more efficient.
    • Customized tracking based on "true" or "false"
    • What you don't want tracked won't be watched which improves performance
    • Timed updates (default is 90 seconds)
    • Fixed updating based on total actions user has done (default is 32)
    • Numerous performance tweaks
    • A "pretty" config file
    • Improved web script performance and added customized tracking (make it match your main config, variables are named the same for simplicity)
    • Web view tells when a player is still online and makes their name green if online, red if offline
    • Uses the "hybrid" method of player data saving like v1 to put less strain on the database
    • When saving to a database it is done dynamically so that only changed things are saved to cut down on the code needed and make smaller, faster calls to the database when saving (this was a big improvement on all previous versions)
    • Table name has been changed to "netstats" to not conflict with any other tables
    • NOTICE: You will need to remove your old data since it is outdated and the table is named differently with a few field name changes so make sure to use the .sql file to add it to your database. Please, before complaining about losing all the old data, realize that there's a 99% chance that it's wrong.
    Version 2.0
    • Complete revamp!
    • Now uses only flatfiles to store data, no more database issues!
    • Lots of code removed and improved for faster speed and less resource use
    • Customizable timed updates (default is every 30 seconds)
    • Customized tracking also reduces resource use by registering (or not registering) events as per your config so it only watches events that you want it to.
    • Web script will search for your CraftBukkit server when you first look at the web page.
    • You can choose where the server will save every player's .stats file by setting the "path" option in the config. The path is relative to your main server folder (where the world folder should be at). So if you set "path=../players/" then the .stats files will be in a folder called "players" in the folder that your server is in.
    • Table of player data is built depending on what your tracking and will change as you change the Netstats config file, nice and easy!
    • There are a few rules to setting paths that are listed above, make sure to read them!
    Version 1.8
    • Various code fixes and changes to improve how it runs.
    • Creates a new blank config file if it can't find one.
    • Only JAR has been changed. Get the newest one above, which I'll just reference from now on since it's faster than posting the same link over and over again.
    Version 1.7
    • Changed how files are accessed which should fix the "Too many files open" bug on Linux machines. Update the [JAR]
    Version 1.6
    • Hopefully fixed bug with connecting multiple times to a property file for each user. Only [JAR] needs updating.
    Version 1.5
    • Fixed a critical bug where user property files (where it saved your data before moving it to the database) wasn't re-defined when the plugin was reloaded. Now it looks for it after everything you do to make sure your data is always being recorded. Only the [JAR] needs to be updated.
    Version 1.4
    • Updated the files to work with the new constructor. You'll need only the [JAR] for this update.
    Version 1.3
    • Fixed a bug with how the plugin saves user data after a server crash
    • Added an Update.sql to add new columns to database table [Web.zip] (only for those upgrading from v1.2)
    Version 1.2
    • Added tracking of blocks broken
    • Added tracking of blocks placed
    • Added tracking of player deaths
    • Added more frequent tracking of total time online
    • Implemented new "safety" storage system
    • New storage system reduces number of database calls
    • Improved the way data is stored to database to take less code
    • The table of data is now ordered by who is online
    Version 1.1
    • Added tracking of player's last used IP address
    Version 1.0
    • Release of Netstats
    WEB CHANGELOG (open)

    Version 2.1
    • Some code cleanup and fixes as well as a better auto-updater that makes sure that the updater is the latest version before doing the actual update process.
    • Localization support for 7 different languages.
    • File name changes to be more netstats-specific which will prevent clashes of CSS and other pages.
    • Better include() and require() calls so a page is only added once which speeds up all the pages and keeps them from destroying each other.
    Version 2.0
    • Improved layout
    • Automatic code updates
    Version 1.0
    • Initial release of web code

    Donations: Don't forget to give amd3th some love too since he helped in making Netstats and came up with the idea (you rock!) as well as @marshall007 since he's been awesome by helping me in his spare time.
     
    Phaedrus, Niemand, D-Lew and 5 others like this.
  2. Offline

    Letalis

    Howto unload and replace netstats??
     
  3. Offline

    Valrix

    What do you mean?
     
  4. Offline

    Letalis

    I meant while the server is running.
     
  5. Offline

    Valrix

    Just drop in the new jar, overwrite the old one, and reload and that should work fine. In the future, when it updates, it'll just disable and enable itself again instead of forcing a reload.
     
  6. Offline

    Acrag

    My Poblems continued

    error in line 46 - while ($row = mysql_fetch_array($res)) {

    my php is 5.3.5
     
  7. Offline

    Valrix

    I see the problem, but there's no reason it should be doing that unless maybe you don't have the config set up right. What does it look like? Make sure to hide the username and password, but leave everything else as-is.
     
  8. Offline

    Acrag

    i creating new table it's error??
     
  9. Offline

    Valrix

    I don't know, that's why I asked to see the config.
     
  10. Offline

    Acrag

    OK, Cofig.PHP

    Code:
    <?php
    /* ----------------------------------------------
    File Created by Josh Devecka(Jdev19)
    You may use the code as you wish,
    but please give me some credit.
    ------------------------------------------------- */
    $mysql_host = 'localhost';
    $mysql_user = 'root';
    $mysql_pass = '******';
    $mysql_db = 'bukkit';
    $mysql_table = 'TABLE';
    
    # What you want to be shown, change to false if you want it hidden
    $trackIP       = true; # IP address
    $trackBroken   = true; # Number of blocks broken by player
    $trackPlaced   = true; # Number of blocks placed by player
    $trackDeaths   = true; # Number of times player died
    $trackMobs     = true; # Number of Monsters killed by player
    $trackPlayer   = true; # Number of Players killed by player
    $trackJoined   = true; # Date of when player first joined the server (with Netstats running)
    $trackDistance = true; # Total distance player has traveled
    
    ?>
     
  11. Offline

    Fireside

    Hi Valrix, great plugin, its been very handy. Working on a new server build today and have some feedback on your latest version.
    *The jar in the bundle creates all the folders correctly. EG players, logs, etc. But still makes config.txt as a folder as well as error log files etc..
    *The standalone jar creates files as they should be, but does not create the folder structure at all.

    Between the two I was able to get things up and running. :)
    Edit: pointless info removed.. was just my Sql noobness showing. :S
     
  12. Offline

    maxsteele

    Craftbukkit #733, Ubuntu Server:

    When I try to run a new copy of Netstats for the first time, I get this:
    Code:
    2011-04-26 23:54:49 [SEVERE] [Netstats]: Couldn't create config file. Make sure your plugins directory has write access.
    This is incorrect, as every other plugin hasn't had any issue creating all the files and directories it needs.
     
  13. Offline

    Fireside

    It's been covered. You could work it out from the post above yours if your in a hurry... Or you could wait. I'm sure Valrix will fix it when he has time.
     
  14. Offline

    cullyn

    if anyone is using a e107 forum ive made a few small menu plugins so you can display;
    online players.
    top 5 iConomy balances
    top five total online time

    online players
    PHP:
    <?
    /* ----------------------------------------------
    Based on code by Josh Devecka(Jdev19/amd3th)
    Modified by cullyn culcraft.com
    You may use the code as you wish,
    but please give me some credit.
    -------------------------------------------------*/

    include config.php

    mysql_connect
    ($mysql_host,$mysql_user,$mysql_pass) or die (mysql_error());
    mysql_select_db($mysql_db) or die (mysql_error());

    $res mysql_query("SELECT * from $mysql_table ORDER BY `logged` DESC, `player` ASC");// Create table
    // Create table
    $text "<table border='1' width='200'>
            <tr><th>Online</th>
            </tr>"
    ;
    while (
    $row mysql_fetch_array($res)) {
        
    $name $row['player'];
        
    $logged = ($row['logged'] == 1) ? true false;
        
    // Generate the rest of the table
        
    if ($logged) {
        
    $online++;
        
    $text .= "<td style='color: green'>".$name."</td>
        <tr>"
    ;
        } else {
        ++
    $offline;
        
    $tplay $offline $online;
        }
    }
    $text .= "
        <td>"
    .$online." players online</td>
        <tr>
        <td>"
    .$tplay." total unique players</td>
        </table>"
    ;
    $ns->tablerender(Online$text);
    ?>
    online time
    PHP:
    <?
    /* ----------------------------------------------
    Based on code by Josh Devecka(Jdev19/amd3th)
    Modified by cullyn culcraft.com
    You may use the code as you wish,
    but please give me some credit.
    -------------------------------------------------*/

    include config.php
    $num 
    0;
    # What you want to be shown, change to false if you want it hidden
    date_default_timezone_set(date_default_timezone_get());

    mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die (mysql_error());
    mysql_select_db($mysql_db) or die (mysql_error());

    $res mysql_query("SELECT * from $mysql_table ORDER BY `total` DESC");
    // Create table
    $text "<table border='1' width='200'>
            <tr><td>Name</td><td>Online time</td>
            </tr>"
    ;
    while (
    $row mysql_fetch_array($res)) {

        if(
    $num == 5)
        break;

        
    $name $row['player'];
        
    $total $row['total'];
            
    //work out $time
        
    $total $total/1000;
        
    $sec $total%60;
        
    $total $total/60;
        
    $min $total%60;
        
    $total $total/60;
        
    $hrs $total%24;
        
    $total $total/24;
        
    $day $total%24;
        
    $time = ($day) ? $day.' days ' '';
        
    $time .= ($hrs) ? $hrs.' hours ' '';
        
    $time .= ($min) ? $min.' mins ' '';

        
    $text .= "<td>".$name."</td><td>".$time."</td>
        <tr>"
    ;
        
    $num $num 1;
        }
    $text .= "</table>";

    $ns->tablerender(Time$text);
    ?>
    iConomy
    PHP:
    <?
    /* ----------------------------------------------
     Based on code by Josh Devecka(Jdev19/amd3th)
    Modified by cullyn culcraft.com
     You may use the code as you wish,
     but please give me some credit.
     -------------------------------------------------*/
    include config.php

    mysql_connect
    ($mysql_host,$mysql_user,$mysql_pass) or die (mysql_error());
    mysql_select_db($mysql_db) or die (mysql_error());

    $res mysql_query("SELECT * from $mysql_table ORDER BY `balance` DESC");

    // Create table
    $text "<table border='1' width='200'>
            <tr><td>Name</td><td>Money</td>
            </tr>"
    ;
    //start the fetch
    while ($row mysql_fetch_array($res)) {

        if(
    $num == 5)
        break;

        
    $name $row['username'];
        
    $balance $row['balance'];

        
    $text .= "<td>".$name."</td><td style='color: green'>".$balance."</td>
        <tr>"
    ;
        
    $num $num 1;
        }
    $text .= "</table>";
    $ns->tablerender($caption$text);
    ?>
    yes i realise i have used 2 methods for $count++ i was testing my php
    you can see a partially working demo on culcraft.com online time is a little bugged atm due to an inaccurate database.
     
  15. Offline

    maxsteele

    Thanks for the info Fireside. With 22 pages of a thread, it's difficult to scan every post hoping to see if your problem is in there. I'll read back and find out what's going on.
    EDIT:
    Mmmm, nope. The post above me had nothing to do with the config file not getting created because of a write permissions issue. I saw another post a few pages back that said it created a config.txt directory for the guy instead of the Netstats directory, but that is not occurring either. I don't know what Netstats.jar is trying to do different than every other plugin, but it's not able to create its own folder and files, but all my other plugins can just fine.
    And of course, that's the reason for me posting this, so Valrix will see it and make a change. Thanks for the plugin Valrix!
     
  16. Offline

    Revenger

    I have a players online in my sidebar here but want to expand it to show who is online also.

    Just the online names as rows no table etc.

    The code is:

    PHP:
    <!-- Player count code -->
        <?php
            
    include("modules/playerstats/config.php");

            
    mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die (mysql_error());
            
    mysql_select_db($mysql_db) or die (mysql_error());

            
    $res mysql_query("SELECT * from $mysql_table ORDER BY `logged` DESC, `player` ASC");
            
    $count 0;

            while (
    $row mysql_fetch_array($res))
                if (
    $row['logged'] == 1)
                    
    $count++;
        
    ?>

    <!-- Start Block Content -->

    <div class="block-h">
    Main Online: <?=$count?>
    </div>
    <hr />
    After the </div> and before the <hr /> is where i want to show the online playerlist.

    It shouldn't be hard as you guys above have done it but I cant work it out.
     
  17. Offline

    Acrag

    Hi Man my problen continued, my congif.php
    Code:
    <?php
    /* ----------------------------------------------
    File Created by Josh Devecka(Jdev19)
    You may use the code as you wish,
    but please give me some credit.
    ------------------------------------------------- */
    $mysql_host = 'localhost';
    $mysql_user = 'root';
    $mysql_pass = '******';
    $mysql_db = 'bukkit';
    $mysql_table = 'TABLE';
    
    # What you want to be shown, change to false if you want it hidden
    $trackIP       = true; # IP address
    $trackBroken   = true; # Number of blocks broken by player
    $trackPlaced   = true; # Number of blocks placed by player
    $trackDeaths   = true; # Number of times player died
    $trackMobs     = true; # Number of Monsters killed by player
    $trackPlayer   = true; # Number of Players killed by player
    $trackJoined   = true; # Date of when player first joined the server (with Netstats running)
    $trackDistance = true; # Total distance player has traveled
    
    ?>
    i speack spanish my inglish is bad sorry,
     
  18. Offline

    Fireside

    Hi Max.. I think the error message is misleading. I got the very same one along the way to making things happy.

    For me, the newest jar only download is capable of writing its own config.yml and error log files... But will not create the folders for them to go in. It tries to write to a non existant folder and upon failure, outputs that error.

    Try this if you haven't already. In your plugins folder create a directory called Netstats with the capital N.
    Within that one, create two folders as follows. logs and players

    Then give the server a restart and I believe the rest will fall into place.

    Hope that helps.
     
  19. Offline

    maxsteele

    Thanks Fireside, that's exactly what the problem was.
    After creating those directories, it looks like Netstats is running fine now. Thanks!
     
  20. Offline

    cullyn

    PHP:
    <?
    $text "</div>"//place the closing </div> so we have something to append to
     
    while ($row mysql_fetch_array($res))
                if (
    $row['logged'] == 1)
                    
    $count++;
                    
    $name $row['name'];
                    
    $text .= "<div>".$name."</div>";
        
    ?>

    <!-- Start Block Content -->

    <div class="block-h">
    Main Online: <?=$count?> //the </div> on the next line is not needed as we put it at the top of the $text variable
    <?=$text ?>
    <hr />
    basically what this will do is append a name to the variable $text every time the php loops. the difference between mine and yours i need to put it through my tablerender function thus all my lines to be printed need to appended into a single variable.

    this will come up looking like
    <div>
    Main Online: 3
    </div><div>name1</div><div>name2</div><div>name3</div>
    <hr />
    you can remove the <div></div> from around the $name just make sure you keep the double ""
    "".$name."";
    if you dont want a linebreak and want to have a list put a space between one set of " "
    "".$name." ";
    you can also use anyother html between the ""
    "<br>";
     
  21. Offline

    Chewy954

    I've downloaded every archive including the source and none of them have the player.sql? :/
     
  22. Offline

    Revenger

    Cant seem to get that code to work it just chows Online: (amount) and thats pretty much it.

    Where exactly do I integrate that code with the one I had with the config file and mysql select etc?
     
  23. Offline

    cullyn

    sorry ive messed something up, ill test then post the fixed code.
     
  24. Offline

    Revenger

    Still now working properly but I got all the names showing with the active at the top by adding {} to the code and changing name for row to player which it is on mine.

    Link my test online list

    I dunno if I can hide all the non online ones.

    (done by moving the open bracket change is in code below)

    PHP:
    <!-- Player count code -->

    <?php

    include("../modules/playerstats/config.php");

    mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die (mysql_error());

    mysql_select_db($mysql_db) or die (mysql_error());

    $res mysql_query("SELECT * from $mysql_table ORDER BY `logged` DESC, `player` ASC");

    $count 0;

    $text "</div>"//place the closing </div> so we have something to append to

    while ($row mysql_fetch_array($res))

    if (
    $row['logged'] == 1)

    {

    $count++;

    $name $row['player'];

    $text .= "<div>".$name."</div>";

    }

    ?>

    <!-- Start Block Content -->

    <div class="block-h">

    Main Online: <?=$count?>

    <?=$text?>

    <hr />
     
  25. Offline

    cullyn

    there we go, yes you missed 2 sets of {} and of course i didn't really pay attention.. here is the code, the if ($row['logged'] == 1) will control if you see the online player or all.

    PHP:
    <?php
    include("modules/playerstats/config.php");

            
    mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die (mysql_error());
            
    mysql_select_db($mysql_db) or die (mysql_error());
            
    $res mysql_query("SELECT * from $mysql_table ORDER BY `logged` DESC, `player` ASC");
            
    $count 0;
            
    $text '</div>';
            while (
    $row mysql_fetch_array($res))
            {

                if (
    $row['logged'] == 1)
                    {
                    
    $count++;

                    
    $name $row['player'];
                    
    $text .= "<div>".$name."</div>";
                    }
            }
            
    ?>

    <!-- Start Block Content -->

    <div class="block-h">
    Main Online: <?=$count?>
    <?=$text ?>
    <hr />
     
  26. Offline

    Revenger

    Missed another bracket lol added it in now.
     
  27. Offline

    MadMan2021

  28. Offline

    imaxorz

    Don't know what happened, but for some reason after about 4 hours of having this plug in, two of my player's online time went to 21+ days.
     
  29. Offline

    verboseone

    New sortable friendlier php/jquery page.
    Figured I'd share what I scrambled together.

    Example: http://dftcreeper.com/netstat/getPT.php

    The code assumes all files are located from the web root in /netstat/
    If that is not where yours is located you will need to change the css file, and the link to the css file.
     

    Attached Files:

    Revenger and Letalis like this.
  30. Offline

    imaxorz

    Awesome! I'm going to use it. :)

    http://www.shadecrest.com/netstat/stats.php Also, the issues I mentioned above still happens. If you look one of my players time is 21+ days.
     
  31. Offline

    Piedo_bear

    How about som logging for gold/diamonds or stuff mined. Would be interesting to compare
     

Share This Page