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

    You're welcome.
     
  3. Offline

    maxsteele

    Thanks for the input Valrix. Does the beta version work with CB #617?
     
  4. Offline

    Valrix

    The beta was pushed up to an official 4.0 release. Yes, 4.0 should work perfectly fine with all versions higher than #602.
     
  5. Offline

    crazyoldman

    Hey there,

    I've been running Netstats for the past 2-3 days, and I've noticed some inaccuracies in the play time numbers. For example... a significant number of players appear to have been playing for 8,9, even 23 days.

    I checked the MySQL database, and these players have play times of something like 1303011993099, or 3908669261442, as opposed to the other lower play times of something like 1665893 or 5404319.

    Any idea what could be causing this?

    Also, I appreciate the work on the plugin. Thanks!
     
  6. Offline

    Valrix

    Did you remember to wipe the database before switching to 4.0? Older versions don't calculate total play time correctly. You'll need to get the 4.0 JAR and follow the directions on the first post.
     
  7. Offline

    crazyoldman

    I switched to 4.0 just yesterday, but didn't wipe the database. I'll do that now though, let you know if all works well after. Thanks!
     
  8. Offline

    Letalis

    I have added the following to my site, http://www.hemligastugan.com/swedroid/:
    But I still get a Question mark for IP. When I take the IP direct to the site and given adress it shows the correct flag. I think I have missed something in the code.. Could anyone please help me out?

    PHP:
    <?php
    /* ----------------------------------------------
    File Created by Josh Devecka(Jdev19/amd3th)
    You may use the code as you wish,
    but please give me some credit.
    -------------------------------------------------*/

    //  refresh / redirect to an internal web page
    //  ------------------------------------------
    header'refresh: 30; url=http://www.hemligastugan.com/swedroid/' );
    echo 
    '<font size="2">Denna sidan uppdateras automatiskt var 30:e sekund</font>';

    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"  cellspacing="0">';
    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="background-color: green">'.$name.'</td>';
        } else {
        echo 
    '<td style="background-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><img src="http://api.hostip.info/flag.php?ip="'.$ip .'" /></td>';
        }
        echo 
    '</tr>';
    }
    echo 
    '</table>';
    ?>
     
  9. Offline

    Valrix

    The next web update will fix all of your problems. That website was giving me some issues so I went with a different method instead.
     
  10. Offline

    Letalis

    Looking forward to it.
     
  11. Offline

    Valrix

    I'm quite positive you'll enjoy the new Web setup. I've done a lot of work on it to add new features and such. Just been really busy lately is all and still behind.
     
  12. Offline

    Mason6364

    I keep having the same problem with Netstats (although it could also be my MySQL)

    17:33:41 [SEVERE] [Netstats]: Severe database error. Saving error log to C:\User
    s\MasonHanna\Desktop\New folder (3)\plugins\Netstats\logs
    17:33:43 [SEVERE] [Netstats]: Severe database error. Saving error log to C:\User
    s\MasonHanna\Desktop\New folder (3)\plugins\Netstats\logs

    And then heres all of the error logs I have.

    # Netstats Error Log
    CraftBukkit Version: git-Bukkit-0.0.0-612-g4c7a9e7-b617jnks (MC: 1.4)
    Netstats Version: 4.0
    MySQL Error: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    Stack Trace: [Ljava.lang.StackTraceElement;@1c8dfe6

    And

    # Netstats Error Log
    CraftBukkit Version: git-Bukkit-0.0.0-612-g4c7a9e7-b617jnks (MC: 1.4)
    Netstats Version: 4.0
    MySQL Error: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

    The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    Offending Statement: UPDATE netstats SET logged=0
    Stack Trace: [Ljava.lang.StackTraceElement;@a574b2


    Any help?
     
  13. Offline

    Valrix

    Just looks like it's not able to connect to your database. How does your config look?
     
  14. Offline

    Mason6364

    Config:

    # Netstats Properties File
    admin=Masonnasty
    wipePass=JRAq0HOnLJ
    host=localhost
    database=minecraft
    username=xxxxxxxxxx
    password=xxxxxxxxxxxxx
    oldTable=
    newTable=
    actions=32
    updateRate=90
    # Optional things to track. True = track, False = don't track
    trackIP=false
    trackBroken=true
    trackPlaced=true
    trackDeaths=true
    trackMonsterKills=true
    trackPlayerKills=true
    trackDistanceWalked=true

    Truth is im nooby about MySQL and what a data base is, could you please sum it up because the only reason its set to minecraft is because I didn't know what to put for it so I put what others had in their config.
     
  15. Offline

    Valrix

    database needs to match the database you're going to store the data in on your MySQL database.
     
  16. Offline

    Mason6364

    Okay, can you give me a briefing on what MySQL is?
    like where to find it, how to make it, things like that please?
    Thank you :)
     
  17. Offline

    Valrix

    MySQL is a storage database used to keep data orders by rows and columns, like a table. It's purpose it to try and make data access easier. You can get it at http://mysql.com

    Trying to explain how to set it up, especially since I don't know your OS and many other things, is too hard of a task.
     
  18. Offline

    SunyYun

    [​IMG]

    language support= Korean or English
    Level ICON Support
    Top record ICON Support
    IP asterisk(*) Support


    v0.3 DEMO
    v0.3 DownLoad
     
  19. Offline

    Valrix

    Interesting.
     
  20. Offline

    Valrix

    While in class I had an idea of how v5 could work to ultimately make Netstats work more efficiently and provide nearly real-time updates of player stats. The idea is similar to how Dynmap works. Netstats will create a very small server of it's own for the web part to connect to directly. When the PHP connects to the plugin it will ask for either all player data, or just for one player. Netstats can then quickly respond with the information it was asked for and show it on the website. This means that database calls can be heavily reduced as well as removing the need to watch how many actions a player has done. This way the website shows their stats as they currently are instead of showing what's been saved in the database (which can up to a minute and a half old, depending on how often you have the server auto-save). It will reduce resource usage and will be multi-threaded to improve efficiency so your server won't slow down to a crawl. Another perk is that all data will be kept as flatfiles and the Netstats server will be idle until the PHP requests data, meaning it will take up very little memory until someone looks at the stats page, and the data passed through will only spike, then go back down to nearly nothing again.

    Please let me know how you feel about this since it will be a rather big change (when it comes to the code). The perks are faster code, and possibly less code in general. An addition idea is that if this turns out to be efficient enough then the MySQL can be removed from the plugin itself and the PHP would be left to handle the database stuff to relieve the server a bit more. I'm not sure if ALL the MySQL stuff can be removed without some possible weird problems going on, but I know a good amount of it could. If anything v5 would be even less harsh on the server performance (even though you can barely tell it's running in the first place).

    TL;DR: I had an idea for Netstats v5. It would use a method similar to Dynmap on how it shows player data and saves it so it will take up less resources and improve the accuracy of the stats when shown on the web.
     
  21. Offline

    jascotty2

    would be neat as an optional feature, for sure..
    but please keep is an an optional feature, for those (like me) who don't want to change their site for an update
    for those who don't want to mess with MySQL too much, that might be a nice addition

    (ps.: thanks for keeping MySQL this far.. i was worried you'd remove it, so i made a clone & was keeping that functioning)
     
  22. Offline

    Valrix

    MySQL will have to stay as far as I've noticed and won't be leaving any time in the near future. Netstats v5 would still have MySQL being used and all website changes don't break or risk anything so updating to v5 would be perfectly safe. I still have a lot of reading up and testing to do before it ever gets added which will all have to wait until the newest CraftBukkit release anyhow, so no need to worry :)
     
    AreLam likes this.
  23. Question, where is the players.sql located? :)
     
  24. Offline

    AreLam

    You don't need one.. Just set up the config correctly ;)
     
  25. Thanks, it was crashing on the latest dev build, ill need to wait for an update!
     
  26. Offline

    Lord Chaos

    When will the new web interface be released?
     
  27. Offline

    Valrix

    Once I've got all the new stuff in. I've been real busy with school lately so I had to keep putting it off. Luckily I don't have class tomorrow so I get a 3 day weekend to get some work done.
     
  28. Offline

    jascotty2

    i found this was interfering with cookiemonster: it seems that the entity.remove you were using sometimes wouldn't trigger onEntityDeath (also, PvP was being incremented in unpredictable bursts (with diamond sword))
    in my pull request, i have that fixed, along with arrow kill detection and an onDisable exception fix
    (jar)

    another note: you should put all of those sql & property update blocks consolidated into one function / class ..
    makes it easier to read & update
     
  29. Offline

    Valrix

    Nice, I'll pull that in and check it out. Thanks for all the fixes!

    Once I'm done making sure I didn't do the pull request wrong or possibly mess anything up then I'll be posting an update (it'll be tomorrow in my time, so 8-10 hours from now or so as an estimate) which will have a better system for managing how things die and won't break other plugins. A big thanks goes to jascotty2 for the code improvements.

    On another note, what are people's thoughts on creating a small PHP script that now and then will check if there are updates to the web code for you and will update it for you so if I do any small patches, etc. then you won't have to keep grabbing it? Web code is a bit more of a pain to manage when you update it so having a script to do it for you would make both our lives easier since it means I can update it more often without worrying about it being a burden on you all as well as you not needing to constantly check the first post to see if I've done an update to it or not.

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

    Ratchet

  31. Offline

    lastmikoi

    I got the same problem, with a very clean install of mysql and all this stuff, in Debian Stable.

    I solved my problem by a really weird way : Check if the files (mysqld.pid & mysqld.sock) in /var/run/mysqld/ are readable for all users (chmod +r).
     

Share This Page