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

    Valrix

    Wow, nice tweaks you've got there.
     
  3. Offline

    xPaw

    It creates .stats file as a folder.
    java.io.FileNotFoundException: /**/plugins/Netstats/players/xPawww.stats (Is a directory)
     
  4. Offline

    Valrix

    Bah, crap... I'm on it.

    Jar has been updated, have at it. Sorry about that, I missed a functions and that messed everything up.

    I just noticed a problem with the current method of tracking how long a player has been playing. Currently it just keeps a running total of how long they've played in milliseconds which is incredibly accurate, but restricts the max play time to around 24 days or 9223372036854775807 milliseconds to be precise (big number, I know). But I'm going to fix how it's kept track of by still keeping track of milliseconds, but when possible it'll break that into seconds and if the total seconds is greater than 60 it adds to the minutes, if minutes are greater than 60 it adds to hours, and so on and so forth. This way it'll remain accurate, but will just change how the time is managed.

    I've also started working on v5, which I can already tell you is much, MUCH faster at sending data to the stats page than getting it from the database.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 8, 2016
  5. Offline

    xPaw

    Can't you just switch to unix time based on seconds. it's fine enough, and miliseconds counting is absolutely not needed.
     
  6. Offline

    Plague

    plus sign in title CB version is not allowed, removed
     
  7. Offline

    Valrix

    It's easier to do System.currentTimeMillis(); and use my current time-keeping methods then break up the total into correct increments of time as needed.
     
  8. Offline

    xPaw

    System.currentTimeMillis() / 1000L;

    should be safe to use. it won't be that huge number to store, and you divide by 1000 in php script each time anyway.
     
  9. Offline

    loveduckie

    Hey,

    If possible, would it be okay to get a hold of the .sql file that we require to import at some point?

    I had to import one with the old version but this new version grabs new data and I need to update my databases table structure D:
     
  10. Offline

    Pontus Lantz

    Hmm im having some problems and checked the thread. And as far as i understand the plugin should auto generate an config file. But i get this error on my first start of the server with the plugin.
    Code:
    [SEVERE] [Netstats]: Couldn't find file C:\Games\Minecraft\CraftBukkit 689\plugins\Netstats\config.txt
    java.io.FileNotFoundException: C:\Games\Minecraft\CraftBukkit 689\plugins\Netstats\config.txt (Access is denied)
    
    Edit: I got CB 689.
     
  11. Offline

    Valrix

    Make sure you have correct permissions set up to allow file read and write.

    You shouldn't need an .sql file because the plugin makes everything itself.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 8, 2016
  12. Offline

    Pontus Lantz

    All other plugins have no problems at all creating and deleting files.

    Ehm. I just checked and realised that for some reason the plugin created a folder named config.txt instead of making an actual file.
    Although now i'm not sure what should be in the real config file.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 8, 2016
  13. Offline

    Valrix

    I'll try forcing the correct permissions on the created files and folders to see if that'll help.
     
  14. Offline

    marshall007

    @Valrix I just installed the latest version, and this is my update from v3. My server startup is hung at enabling Netstats 4.2, what would you recommend?

    Edit: And just to clarify, I followed recommended procedure for upgrading via command line.
    Edit2: After force restarting, it started up fine, so I checked my db tables and they haven't cleared. I ran through the commands again from console, but it's again hung up on starting Netstats.
     
  15. Offline

    Valrix

    I'm sure I fixed that, let me update the jar again and make sure to get the latest version. The previous build caused the files to be made as folders which I fixed.

    So you were upgrading from 3.9 to 4.2?

    EDIT: I'm really not sure why it would be hanging.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 8, 2016
  16. Offline

    Pontus Lantz

    I downloaded the jar only instead and got it working now.
     
  17. Offline

    marshall007

    Yep, from 3.9. I tried restarting again, and this time it wiped my config file, which is weird too. After re-configuring and attempting to start up again it's still hanging after I attempt a wipe and it auto-restarts.

    This doesn't seem solvable, I'll just drop the table and let it reconfigure automatically. Great plugin, though haven't had any trouble in the past.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 8, 2016
  18. Offline

    Valrix

    Odd, I'll have to try out a few different things and play with the code to see if I can get it working a bit better. I'll post a patch probably in a few hours.

    And I'm glad you like the plugin. It was my first and so far is the most complex of them all due to how configurable it is. The main issue is for some reason, it breaks on certain builds, so I fix the code, then it breaks again for no reason or I try to update the code and some weird bug will pop up in code that used to work perfectly fine. Since I try to keep my code lean and not full of hacky code, it's a bit more of a pain since most developers do optimization after the code is out and working. Instead, I get it to work while trying to use the best methods I can think up so it runs using code that will be fast and small.

    The problem with this is that it makes for slower development. Also, since I'm only one person trying to work on what's currently 6 plugins (thankfully 2 should be fine for a while where I can ignore them for a bit) then things are a bit...hectic.
     
  19. Offline

    marshall007

    Great! Everything's back to working well now that I let it create a new table. To provide some more information, looking back at my server logs, Netstats was reporting that the data had been wiped, but neither the player.stats files nor the data in the db table was being cleared. I had to both drop the table and clear out the players folder manually to get it to stop hanging on startup. Maybe it was something to do with how my server wrapper passes console lines to Bukkit?

    Cheers!
     
  20. Offline

    Valrix

    Haha, well I'm glad you got it all sorted out.
     
  21. I have a problem which I know a monkey could solve that is driving me absolutely insane.

    I want to make a simple "Players Online" display that shows how many people are online. I figured the easiest way to do this would be to count the 1's in the "logged" column and echo out the answer.

    Could anyone please shed some light as to how my PHP code should be looking to achieve this? Or at least tell me if this is the wrong approach to the problem.
     
  22. Offline

    Valrix

    I'll probably be adding that to the default code which I'm hoping to get done today or at least get it nearly done.
     
  23. Offline

    marshall007

    Assuming your included config.php is properly configured, and you placed the following in the same directory, something like this would work:
    Code:
    <?php
        include("stats_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++;
    ?>
    
    <html>
        Players online: <?=$count?>
    </html>
     
  24. @marshall007
    You're the best! This works perfectly. Thank you. :>
     
  25. Offline

    Valrix

    In case anyone's wondering, I've been working on the PHP a bit more as well as the code for v5. Once I get the PHP worked out a bit more and a method of auto-updating it then I'll be releasing it. I will try to make a nice way for it to migrate your settings over when files are updated so you don't lose anything. Also, for those who already tweaked the code to their liking, it will NOT overwrite your code, all new files are put into a /tmp/ directory so you can move things over as you like and rename the files, etc. I want to make sure nothing is broken or lost and that's why it's take a bit longer to get it out, otherwise I would have released it about a week ago or so.
     
  26. Offline

    Pontus Lantz

    @Valrix
    Sounds awsome! Totaly worth the waiting[meat]
     
  27. Offline

    Valrix

    As a small hint/teaser, there will be a few things you can customize by using custom texture packs. That's all I'm gonna say though so it doesn't ruin the surprise.
     
  28. Offline

    xPaw

    is /lib/ folder still required? If so, you can remake your plugin, because CraftBukkit already includes mysql lib in itself

    EDIT: I think you should provide rss or static link for CraftbukkitUpToDate plugin
     
  29. Offline

    Valrix

    In the next patch you won't need the /lib/ folder. I'm going to update it in just a few minutes. Keep an eye on the thread.

    The only real issue of keeping a static link for it is that I often change the location of where I put the files between MC versions so I can keep track of which versions I'm supporting.

    Also, I will be adding my own method of being able to update Netstats since I already have the code to do it and by doing this I'll be able to control how it updates depending on what version it's upgrading to, that way you won't have to do data wipes, etc. on your own, I'll be able to have it fix everything for you :)
     
    AreLam and xPaw like this.
  30. Offline

    Acrag

    Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in get.php on line 46
    Help Please!!!

    Code:
    <?php
    /* ----------------------------------------------
    File Created by Josh Devecka(Jdev19/amd3th)
    You may use the code as you wish,
    but please give me some credit.
    -------------------------------------------------*/
    
    include("config.php");
    
    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 `logged` DESC, `player` ASC");
    
    // Create table
    echo '<table border="1">';
    echo '<tr><th>Name</th>';
    if ($trackBroken) {
        echo '<th>Blocks Broken</th>';
    }
    if ($trackPlaced) {
        echo '<th>Blocks Placed</th>';
    }
    if ($trackDeaths) {
        echo '<th>Deaths</th>';
    }
    if ($trackMobs) {
        echo '<th>Monsters Killed</th>';
    }
    if ($trackPlayer) {
        echo '<th>Players Killed</th>';
    }
    if ($trackDistance) {
        echo '<th>Distance Traveled</th>';
    }
    echo '<th>Last Login</th>';
    echo '<th>Last Seen</th>';
    echo '<th>Play Time</th>';
    if ($trackIP) {
        echo '<th>Player IP</th>';
    }
    echo '</tr>';
    
    while ($row = mysql_fetch_array($res)) {
        $name = $row['player'];
        $login = $row['enter'];
        $seen = $row['seen'];
        $total = $row['total'];
        $logged = ($row['logged'] == 1) ? true : false;
        $ip = $row['ip'];
        $broken = $row['broken'];
        $placed = $row['placed'];
        $deaths = $row['deaths'];
        $joined = $row['joindate'];
        $mobs = $row['mobskilled'];
        $players = $row['playerskilled'];
        $distance = $row['distance'];
    
        // Total playtime
        $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 " : '';
        $time .= $sec." secs";
    
        // Time they've been gone
        $ago = ((time()*1000)-$seen)/1000;
        $asec = $ago%60;
        $ago = $ago/60;
        $amin = $ago%60;
        $ago = $ago/60;
        $ahrs = $ago%24;
        $ago = $ago/24;
        $aday = $ago%24;
        $atime = ($aday) ? $aday." days " : '';
        $atime .= ($ahrs) ? $ahrs." hours " : '';
        $atime .= ($amin) ? $amin." mins " : '';
        $atime .= ($asec) ? $asec." secs " : '';
        $atime .= " ago";
        $atime = ($logged) ? "Currently Online" : $atime;
    
        // Generate the rest of the table
        echo '<tr>';
        if ($logged) {
        echo '<td style="color: green">'.$name.'</td>';
        } else {
        echo '<td style="color: red">'.$name.'</td>';
        }
        if ($trackBroken) {
            echo '<td>'.$broken.'</td>';
        }
        if ($trackPlaced) {
            echo '<td>'.$placed.'</td>';
        }
        if ($trackDeaths) {
            echo '<td>'.$deaths.'</td>';
        }
        if ($trackMobs) {
            echo '<td>'.$mobs.'</td>';
        }
        if ($trackPlayer) {
            echo '<td>'.$players.'</td>';
        }
        if ($trackDistance) {
            echo '<td>'.round($distance).'</td>';
        }
        echo '<td>'.date("D, M d g:i A", $login/1000).'</td>';
        echo '<td>'.$atime.'</td>';
        echo '<td>'.$time.'</td>';
        if ($trackIP) {
            echo '<td>'.$ip.'</td>';
        }
        echo '</tr>';
    }
    echo '</table>';
    ?>
     
  31. Offline

    Valrix

    Please post the code showing line 46 and 10 lines before and after if you could. Or post the whole document if you really want to help. I suggest using something like pastebin or gist though so we don't clutter the thread.

    Update is out, have at it guys and gals. While you do that, I'll briefly explain what is planned for 4.4 or 4.5, depending on if I have to fix anything else before I do that actual update.

    I plan on implementing native updating of Netstats which will be very version specific, meaning depending on what version you upgrade from and which one you upgrade to, it will do all the patching in the right steps so it doesn't miss anything and will automatically repair your database tables and .stats files and/or folder structures as needed. I will also tell it to inform you if an update will causing any permanent changes that even if you roll back, it can't fix so you can decide if you're ready to update before actually doing it. When automatic updates are set up it will first inform you there has been an update and I'll try to make this as dynamic as an experience as I can. When updating between the same version patches, rarely are things horrible different so auto-updates will alert you that it updated itself and will reload. To be safe, it will download the update to a certain folder first, once the download is done it'll quickly replace the old JAR and reload so little to no tracking is lost in the process.

    I will try to make an option to customize how you have your server act when updating as well so if you want it to kick everyone, update, then reload so nothing can be lost then you can do so. The updater will have it's own config file so the main config won't be a cluttered mess. I'm also thinking of changing how .stats files are saved so the code to save the data is smaller and more efficient, but that will probably be in a later version, maybe somewhere in v5 when I've done enough testing to be sure no data will be lost or corrupted.

    TL;DR: Updating will have it's own config options including auto-updating. Possible breaks will be alerted before you update. You'll be able to roll back certain versions. Breaks will be minimized as much as possible. Expect speed improvements as well as making your life (and mine) easier.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 8, 2016

Share This Page