Mutiegenesis Posted March 17, 2017 Share Posted March 17, 2017 A cool widget thingy for your community website. Displays online users in a dial gauge (via google charts api). no mysql needed! See the shiny in action: https://avorion.mutant.enterprises/ Here's the DIY: create a template file called dial.template.playersNow containing this: <!-- start of ./dial.template.playersNow --> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['gauge']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Label', 'Value'], ['', ###PLAYERS###] ]); var options = { height:64 , width:64 , min:0, max: ###MAX###, greenFrom:0, greenTo: ###GRN###, yellowFrom:###GRN###, yellowTo: ###YLW###, redFrom: ###YLW###, redTo: ###MAX###, majorTicks: 2, minorTicks: 1 }; var chart = new google.visualization.Gauge(document.getElementById('chart_div')); chart.draw(data, options); } </script> <div id="chart_div"></div> <!-- end of ./dial.template.playersNow --> create a script called userDial.sh with this (changing values and paths to suit your use case): #!/bin/bash toGRN=9 toYLW=12 playersMAX=16 htmlPath='/var/www/html/FreeRealms' tmpPath='.' playersNOW=$(netstat -aN | grep -i '27000'| grep -i ' ip-'|wc -l) cat ${tmpPath}/dial.template.playersNow | sed -e 's/###PLAYERS###/'${playersNOW}'/g;s/###MAX###/'${playersMAX}'/g;s/###GRN###/'${toGRN}'/g;s/###YLW###/'${toYLW}'/g;' > ${tmpPath}/online.dial.html.tmp cat ${tmpPath}/online.dial.html.tmp > ${htmlPath}/online.dial.html set perms so you can run it: chmod +x ./userDial.sh then run it (twice the first time): ./userDial.sh add to cron at whatever intervals blows your dress up. I'm happy with 1min. enjoy Link to comment Share on other sites More sharing options...
chelatek Posted March 17, 2017 Share Posted March 17, 2017 I came here for EXACTLY this sort of thing, thank you! Link to comment Share on other sites More sharing options...
Mutiegenesis Posted March 17, 2017 Author Share Posted March 17, 2017 I came here for EXACTLY this sort of thing, thank you! The actual command in your playerNow var might be different. It works for my steam-networking=false server, running in AWS. Now if you like that little doodad, check out the in-game chat feed I've got running, my online maps, or my still-a-bit-buggy "Whos Online" thingamabob. Those were/are a bit more complex to implement. Coming soon to the Free Realms will be a "New Ships Register" widgetything which displays the previous (configurable whenever's [hour/day/centon/etc]) ship builds. .MutieG. Link to comment Share on other sites More sharing options...
chelatek Posted March 17, 2017 Share Posted March 17, 2017 I came here for EXACTLY this sort of thing, thank you! The actual command in your playerNow var might be different. It works for my steam-networking=false server, running in AWS. Now if you like that little doodad, check out the in-game chat feed I've got running, my online maps, or my still-a-bit-buggy "Whos Online" thingamabob. Those were/are a bit more complex to implement. Coming soon to the Free Realms will be a "New Ships Register" widgetything which displays the previous (configurable whenever's [hour/day/centon/etc]) ship builds. .MutieG. I checked out your page and I am very jealous, it looks great. This is just a small server for me and some friends but I want to have a page so people can check status and such. By the way there seems to be a typo, the shell script doesn't have the substitution for playersMAX. I added it in and it works great. Thanks again! e: actually never mind, it renders now but the netstat command isn't working, but I'll dive into that. Ubuntu on AWS here so it shouldn't be too hard. Link to comment Share on other sites More sharing options...
Mutiegenesis Posted March 17, 2017 Author Share Posted March 17, 2017 I checked out your page and I am very jealous, it looks great. This is just a small server for me and some friends but I want to have a page so people can check status and such. By the way there seems to be a typo, the shell script doesn't have the substitution for playersMAX. I added it in and it works great. Thanks again! lol, sorry for that. Wanted to get it posted fast cuz I knew someone wanted it. Link to comment Share on other sites More sharing options...
TOP-ic Posted March 17, 2017 Share Posted March 17, 2017 Hi! And could you write a little more detail exactly how to install this widget on your website/forum? Thank you. Sorry for my English. )) Link to comment Share on other sites More sharing options...
Mutiegenesis Posted March 17, 2017 Author Share Posted March 17, 2017 Hi! And could you write a little more detail exactly how to install this widget on your website/forum? Thank you. Sorry for my English. )) The code itself is not meant to be included, only the output from the script. Here's how to use it: 1) gain access to the shell (bash pref'd for me) on your linux host. 2) perform the instructions above, adjusting paths and values to suit your use case. 3) run the script to generate HTML which can be included in a webpage (add to cron if desired). 4) embed the output html fragment in your webpage via an html include, php include, etc) 5) profit? .MutieG. Link to comment Share on other sites More sharing options...
Mutiegenesis Posted March 25, 2017 Author Share Posted March 25, 2017 I've cleaned up my scripts a bit, and added some new stuff Users Online Gauge Who's Playing Now (NEW) In-Game Chat Feed (NEW) See them in action here: https://avorion.mutant.enterprises/ HowTos and examples here: https://www.mutant.enterprises/display/AFR/Website+Scripts Requirements are bash, mysql, cron, tmux, and some general LAMPP knowledge. .MutieG. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now