Pages: [1]

The Story: Restoring the Minecraft Stats Box
Posts: 9 Views: 1247

Wintermoot
  • Regional Stability Squad
  • The Greyscale Magi-Monk
  • I've recently been told that people don't know what goes into some of the stuff I do behind the scenes, so I thought it would be neat to discuss in detail what went into updating the Minecraft stats box, a relatively minor project that still had a good bit of work behind it. If there's interests in posts like these, I might make more in the future. :)

    Restoring the Minecraft Stats Box
    Since moving to our new Minecraft server host, @trader has done the heavy lifting of making the server work and then making it run more efficiently. Thanks to him, I’ve had to do very little to get things going, and I greatly appreciate trader for everything he’s taken on to make the move work, not to mention for providing the hosting to start with!

    One of the issues that required my attention though was updating the website code so that the Minecraft stats box on the forum index page would work with our new host. This box displays the server status and the players that are online, so you don’t actually have to open up Minecraft to see. Our old host had a custom REST API to get this data from, but this wasn’t the case with the new host, so we had to go about finding a new way of getting this data.

    A few weeks back, trader gave me some links to libraries that use Minecraft’s Query protocol, which allows a server to broadcast basic information about the server. When I started working with them yesterday though, I ran into a big problem: these libraries use sockets to communicate with the Minecraft server, and our webhost (and most shared webhosting for that matter) doesn’t allow the full capacity to write to sockets in order to prevent people from running some demanding types of servers. I had hit a virtual wall.

    Finding an Alternative Solution
    My options were to either give up on having server stats on the website or search for a webhost that didn’t have those restrictions. I didn’t like either option, so I went to Google to look for an alternative. Fortunately, I found two websites that do the querying for you and then provide the data in a nice REST API, and I decided to go with the one that allowed the data to be updated the quickest (every five minutes): https://mcapi.us/

    Beyond just being the best technical solution, I found another reason for adopting mcapi. In reading the site, I came across the website of the person who created and runs it: Syfaro, a purple fox who among his other projects has created a tool to upload furry art to multiple furry websites. After reading it, I have a good feeling about him. I’d like to think he’d feel at home in Wintreath, and that makes me more comfortable about using his tool. Maybe someday I’ll contact him in appreciation, or buy him a cup of coffee.

    Coding It All In
    All that was to write the code that pulled the data from mcapi and displayed it on the forum page. The main challenge was making sure our website only pulled from the API at least every five minutes and stored that data on our end to use in the meantime. Technically, I could have pulled the data from the API everytime someone came to the forum and received cached data, but that’s hardly considerate to the mcapi server when it’s going to be the same data for five minutes. Ultimately, this is what happens when someone comes to the page:
    • The script pulls the MC server data that’s stored on our server. This data includes the last time that the data was updated from the API.
    • Using that time, the script checks to see if at least five minutes have passed. If it is not, it returns the stored data to the forum skin, and that’s what you see.
    • If at least five minutes has passed, the script pulls fresh data from the API. In the process, it converts the array of player names we get from the API and converts it into a string complete with formatted commas and stores it as well. This is so that this doesn’t have to be done everytime someone comes to the page, instead it’s already stored and ready to go. This data is stored on our website and is what’s used for the next five minutes until we can get fresh data from the API yet again.
    And that’s how the Minecraft server stats portion of the index page works.

    I also changed it so that the stats are only shown to members that are signed in, in respect of our own server resources. Ever since we got dinged from our webhost for using too many CPU resources during Clickwar, I’ve tried to make sure that our pages run the minimum amount of code needed. The forum front page is the most visited page on the website, and most of the ‘guests’ aren’t even people but bots (usually search bots cataloging the forum). When we already require people to register on the forums to request MC permissions, is it worth the resources to show this to guests? I decided that it wasn’t, so guests will instead see a message asking them to sign in to view the stats.

    Oh Yeah, lol
    Here’s the reason the old code always said the server was online, as @taulover had already guessed. I guess I never got around to figuring out the entire API the old host was using. Thankfully, this one is much easier to use and is much better documented.

    Code: [Select]
    $mcServerStatus = 'Online';

    if($mcServerStatus == 'Online')
        $mcServerStatus = '<span style="color:green;">' . $mcServerStatus . '</span>';
    4 people like this post: taulover, Hydra, trader, Michi


    I went all the way to Cassadega to commune with the dead
    They said "You'd better look alive"
    Wintermoot
    • The Greyscale Magi-Monk
    • Posts: 19,449
    • Karma: 9,677
    • Weather: ❄️
    • Regional Stability Squad
    • Pronouns
      He/Him/His
      Orientation
      Demisexual
      Wintreath Nation
      Logged
    taulover
  • Regional Stability Squad
  • Seeker of Knowledge
  • Very nice!

    I had been using Mojang tech director Dinnerbone's original mcquery CLI tool as a stopgap in the meantime, and had thoughts of wrapping the Python script up into a Flask web server on a Digital Ocean droplet or something.

    Of course there are already APIs hosted online already, haha, I should have thought of that. :D
    Résumé
    Wintreath:
    Citizen: 8 April 2015 - present
    From the Ashes RP Game Master: 29 November 2015 - 24 July 2018
    Skydande Vakt Marshal: 29 November 2015 - 28 February 2017
    Skrifa of the 13th Underhusen: 13 December 2015 - 8 February 2016
    RP Guild Councillor: 9 February 2016 - 6 March 2018
    Ambassador to Lovely: 23 February 2016 - 17 August 2016
    Werewolf VII co-host: 11 May 2016 - 5 June 2016
    Skrifa of the 18th Underhusen: 8 October 2016 - 7 December 2016
    Ambassador to Balder: 1 December 2016 - 1 March 2022
    Skrifa of the 19th Underhusen: 7 December 2016 - 9 February 2017
    Ambassador to the INWU: 11 March 2017 - 1 March 2022
    Ambassador to the Versutian Federation: 18 August 2017 - 22 March 2018
    Thane of Integration: 29 September 2017 - 7 March 2018
    Speaker of the 24th Underhusen: 10 October 2017 - 7 December 2017
    October 2017 Wintreath's Finest: 4 November 2017
    Speaker pro tempore of the 25th Underhusen: 9 December 2017 - 7 February 2018
    Wintreath's Finest of 2017: 6 January 2018
    Werewolf XIV host: 20 January 2018 - 23 February 2018
    February 2018 Wintreath's Finest: 5 March 2018
    Thane of Embassy Dispatches / Foreign Releases and Information / Foreign Dispatches: 7 March 2018 - 15 March 2020
    Speaker of the 28th Underhusen: 10 June 2018 - 7 August 2018
    Second Patriarch of the Noble House of Valeria: 10 October 2018 - present
    Arena Game 6 Host: 28 December 2018 - 9 March 2019
    Librarian of the Underhusen: 29 January 2019 - 12 February 2019
    Speaker of the 32nd Underhusen: 12 February 2019 - 8 April 2019
    March 2019 Wintreath's Finest: 4 April 2019
    Librarian of the Underhusen: 12 April 2019 - 23 October 2020
    Commendation of Wintreath: 24 September 2020
    Peer of the Overhusen: 9 December 2020 - 8 February 2021
    Vice Chancellor of the Landsraad: 26 May 2021 - 15 September 2022
    Arena Game 8 Host: 10 June 2021 - 19 July 2021
    June 2021 Wintreath's Finest: 5 July 2021
    Regional Stability Squad: 28 February 2023 - present
    Minecraft Server Admin: 8 March 2023 - present

    Aura Hyperia/New Hyperion:
    Plebeian: 16 April 2014 - 21 July 2014
    Patrician: 21 July 2014 - present
    Adeptus Mechanicus: 24 October 2014 - 16 November 2014
    Co-founder of New Hyperion: 29 October 2014 - present
    Lord of Propaganda: 16 November 2014 - present
    Mapmaker for Official Region RP: 27 November 2015 - present
    WACom Delegate: 11 November 2017 - present
    Other positions: Hyperian Guardsman, Hyperian Marine (Rank: Scout)
    taulover
    • Seeker of Knowledge
    • Posts: 13,222
    • Karma: 4,253
    • Regional Stability Squad
    • Pronouns
      He/Him/His
      Familial House
      Valeria
      Wintreath Nation
      Logged
    Anthony
  • Former Citizen
  • The Wombateer This City Needs!
  • .-.
    Ok.
    Welcome To Wintreath!
    • The Wombateer This City Needs!
    Anthony
    • Posts: 126
    • Karma: 66
    • Works at Trump's Build-A-Wall Workshop!
    • Former Citizen
    • Pronouns
      He/Him/His
      Wintreath Nation
      Logged
    Wintermoot
  • Regional Stability Squad
  • The Greyscale Magi-Monk
  • Very nice!

    I had been using Mojang tech director Dinnerbone's original mcquery CLI tool as a stopgap in the meantime, and had thoughts of wrapping the Python script up into a Flask web server on a Digital Ocean droplet or something.

    Of course there are already APIs hosted online already, haha, I should have thought of that. :D
    Coming from you, that's high praise indeed. :P

    I'd be curious to know what you mean when you say "Flask web server on a Digital Ocean droplet". It sounds like a thing where you can do things that normal webhosts don't allow, and that'd be good knowledge to have in the future. :)


    I went all the way to Cassadega to commune with the dead
    They said "You'd better look alive"
    Wintermoot
    • The Greyscale Magi-Monk
    • Posts: 19,449
    • Karma: 9,677
    • Weather: ❄️
    • Regional Stability Squad
    • Pronouns
      He/Him/His
      Orientation
      Demisexual
      Wintreath Nation
      Logged
    taulover
  • Regional Stability Squad
  • Seeker of Knowledge
  • Very nice!

    I had been using Mojang tech director Dinnerbone's original mcquery CLI tool as a stopgap in the meantime, and had thoughts of wrapping the Python script up into a Flask web server on a Digital Ocean droplet or something.

    Of course there are already APIs hosted online already, haha, I should have thought of that. :D
    Coming from you, that's high praise indeed. :P

    I'd be curious to know what you mean when you say "Flask web server on a Digital Ocean droplet". It sounds like a thing where you can do things that normal webhosts don't allow, and that'd be good knowledge to have in the future. :)
    Virtual private servers (such as Digital Ocean droplets) basically let you do whatever you want with them. You have root access on a cloud-hosted (virtual) machine (the actual physical machine that it's running on is of course shared). In this day and age they're fairly common.

    In this case Dinnerbone had written up a Python module and command line tool, so I was thinking of wrapping that around existing Python web server frameworks like Flask and making an API endpoint out of that. Of course, that's completely unnecessary when 1. web APIs already exist for this and 2. as it turns out there are already people actively running/providing said APIs online. (It's also maybe overkill to buy and set up VPS hosting to solely use for something like this, probably.)
    1 person likes this post: Wintermoot
    « Last Edit: April 15, 2020, 12:29:07 AM by taulover »
    Résumé
    Wintreath:
    Citizen: 8 April 2015 - present
    From the Ashes RP Game Master: 29 November 2015 - 24 July 2018
    Skydande Vakt Marshal: 29 November 2015 - 28 February 2017
    Skrifa of the 13th Underhusen: 13 December 2015 - 8 February 2016
    RP Guild Councillor: 9 February 2016 - 6 March 2018
    Ambassador to Lovely: 23 February 2016 - 17 August 2016
    Werewolf VII co-host: 11 May 2016 - 5 June 2016
    Skrifa of the 18th Underhusen: 8 October 2016 - 7 December 2016
    Ambassador to Balder: 1 December 2016 - 1 March 2022
    Skrifa of the 19th Underhusen: 7 December 2016 - 9 February 2017
    Ambassador to the INWU: 11 March 2017 - 1 March 2022
    Ambassador to the Versutian Federation: 18 August 2017 - 22 March 2018
    Thane of Integration: 29 September 2017 - 7 March 2018
    Speaker of the 24th Underhusen: 10 October 2017 - 7 December 2017
    October 2017 Wintreath's Finest: 4 November 2017
    Speaker pro tempore of the 25th Underhusen: 9 December 2017 - 7 February 2018
    Wintreath's Finest of 2017: 6 January 2018
    Werewolf XIV host: 20 January 2018 - 23 February 2018
    February 2018 Wintreath's Finest: 5 March 2018
    Thane of Embassy Dispatches / Foreign Releases and Information / Foreign Dispatches: 7 March 2018 - 15 March 2020
    Speaker of the 28th Underhusen: 10 June 2018 - 7 August 2018
    Second Patriarch of the Noble House of Valeria: 10 October 2018 - present
    Arena Game 6 Host: 28 December 2018 - 9 March 2019
    Librarian of the Underhusen: 29 January 2019 - 12 February 2019
    Speaker of the 32nd Underhusen: 12 February 2019 - 8 April 2019
    March 2019 Wintreath's Finest: 4 April 2019
    Librarian of the Underhusen: 12 April 2019 - 23 October 2020
    Commendation of Wintreath: 24 September 2020
    Peer of the Overhusen: 9 December 2020 - 8 February 2021
    Vice Chancellor of the Landsraad: 26 May 2021 - 15 September 2022
    Arena Game 8 Host: 10 June 2021 - 19 July 2021
    June 2021 Wintreath's Finest: 5 July 2021
    Regional Stability Squad: 28 February 2023 - present
    Minecraft Server Admin: 8 March 2023 - present

    Aura Hyperia/New Hyperion:
    Plebeian: 16 April 2014 - 21 July 2014
    Patrician: 21 July 2014 - present
    Adeptus Mechanicus: 24 October 2014 - 16 November 2014
    Co-founder of New Hyperion: 29 October 2014 - present
    Lord of Propaganda: 16 November 2014 - present
    Mapmaker for Official Region RP: 27 November 2015 - present
    WACom Delegate: 11 November 2017 - present
    Other positions: Hyperian Guardsman, Hyperian Marine (Rank: Scout)
    taulover
    • Seeker of Knowledge
    • Posts: 13,222
    • Karma: 4,253
    • Regional Stability Squad
    • Pronouns
      He/Him/His
      Familial House
      Valeria
      Wintreath Nation
      Logged
    Wintermoot
  • Regional Stability Squad
  • The Greyscale Magi-Monk
  • Virtual private servers (such as Digital Ocean droplets) basically let you do whatever you want with them. You have root access on a cloud-hosted (virtual) machine (the actual physical machine that it's running on is of course shared). In this day and age they're fairly common.

    In this case Dinnerbone had written up a Python module and command line tool, so I was thinking of wrapping that around existing Python web server frameworks like Flask and making an API endpoint out of that. Of course, that's completely unnecessary when 1. web APIs already exist for this and 2. as it turns out there are already people actively running/providing said APIs online. (It's also maybe overkill to buy and set up VPS hosting to solely use for something like this, probably.)
    Thanks for elaborating! I've written a note to investigate further in case we run into this issue again...I've ran into this issue before in the past, it seems that scripts that interface with games often use sockets. I'm guessing that with a VPS you have to install Apache and all that on your own? I only have experienced with shared hosting and webhost servers at work.
    1 person likes this post: taulover


    I went all the way to Cassadega to commune with the dead
    They said "You'd better look alive"
    Wintermoot
    • The Greyscale Magi-Monk
    • Posts: 19,449
    • Karma: 9,677
    • Weather: ❄️
    • Regional Stability Squad
    • Pronouns
      He/Him/His
      Orientation
      Demisexual
      Wintreath Nation
      Logged
    taulover
  • Regional Stability Squad
  • Seeker of Knowledge
  • Virtual private servers (such as Digital Ocean droplets) basically let you do whatever you want with them. You have root access on a cloud-hosted (virtual) machine (the actual physical machine that it's running on is of course shared). In this day and age they're fairly common.

    In this case Dinnerbone had written up a Python module and command line tool, so I was thinking of wrapping that around existing Python web server frameworks like Flask and making an API endpoint out of that. Of course, that's completely unnecessary when 1. web APIs already exist for this and 2. as it turns out there are already people actively running/providing said APIs online. (It's also maybe overkill to buy and set up VPS hosting to solely use for something like this, probably.)
    Thanks for elaborating! I've written a note to investigate further in case we run into this issue again...I've ran into this issue before in the past, it seems that scripts that interface with games often use sockets. I'm guessing that with a VPS you have to install Apache and all that on your own? I only have experienced with shared hosting and webhost servers at work.
    Yeah, you'd be setting up everything yourself. I've had to set up an API with Nginx as a reverse proxy, and I would guess that something similar to that would probably work here.

    VPS's can also be a popular option for setting up Minecraft servers btw, I think Chanku mentioned once that the Tekkit server runs on a VPS.
    1 person likes this post: Wintermoot
    Résumé
    Wintreath:
    Citizen: 8 April 2015 - present
    From the Ashes RP Game Master: 29 November 2015 - 24 July 2018
    Skydande Vakt Marshal: 29 November 2015 - 28 February 2017
    Skrifa of the 13th Underhusen: 13 December 2015 - 8 February 2016
    RP Guild Councillor: 9 February 2016 - 6 March 2018
    Ambassador to Lovely: 23 February 2016 - 17 August 2016
    Werewolf VII co-host: 11 May 2016 - 5 June 2016
    Skrifa of the 18th Underhusen: 8 October 2016 - 7 December 2016
    Ambassador to Balder: 1 December 2016 - 1 March 2022
    Skrifa of the 19th Underhusen: 7 December 2016 - 9 February 2017
    Ambassador to the INWU: 11 March 2017 - 1 March 2022
    Ambassador to the Versutian Federation: 18 August 2017 - 22 March 2018
    Thane of Integration: 29 September 2017 - 7 March 2018
    Speaker of the 24th Underhusen: 10 October 2017 - 7 December 2017
    October 2017 Wintreath's Finest: 4 November 2017
    Speaker pro tempore of the 25th Underhusen: 9 December 2017 - 7 February 2018
    Wintreath's Finest of 2017: 6 January 2018
    Werewolf XIV host: 20 January 2018 - 23 February 2018
    February 2018 Wintreath's Finest: 5 March 2018
    Thane of Embassy Dispatches / Foreign Releases and Information / Foreign Dispatches: 7 March 2018 - 15 March 2020
    Speaker of the 28th Underhusen: 10 June 2018 - 7 August 2018
    Second Patriarch of the Noble House of Valeria: 10 October 2018 - present
    Arena Game 6 Host: 28 December 2018 - 9 March 2019
    Librarian of the Underhusen: 29 January 2019 - 12 February 2019
    Speaker of the 32nd Underhusen: 12 February 2019 - 8 April 2019
    March 2019 Wintreath's Finest: 4 April 2019
    Librarian of the Underhusen: 12 April 2019 - 23 October 2020
    Commendation of Wintreath: 24 September 2020
    Peer of the Overhusen: 9 December 2020 - 8 February 2021
    Vice Chancellor of the Landsraad: 26 May 2021 - 15 September 2022
    Arena Game 8 Host: 10 June 2021 - 19 July 2021
    June 2021 Wintreath's Finest: 5 July 2021
    Regional Stability Squad: 28 February 2023 - present
    Minecraft Server Admin: 8 March 2023 - present

    Aura Hyperia/New Hyperion:
    Plebeian: 16 April 2014 - 21 July 2014
    Patrician: 21 July 2014 - present
    Adeptus Mechanicus: 24 October 2014 - 16 November 2014
    Co-founder of New Hyperion: 29 October 2014 - present
    Lord of Propaganda: 16 November 2014 - present
    Mapmaker for Official Region RP: 27 November 2015 - present
    WACom Delegate: 11 November 2017 - present
    Other positions: Hyperian Guardsman, Hyperian Marine (Rank: Scout)
    taulover
    • Seeker of Knowledge
    • Posts: 13,222
    • Karma: 4,253
    • Regional Stability Squad
    • Pronouns
      He/Him/His
      Familial House
      Valeria
      Wintreath Nation
      Logged
    Wintermoot
  • Regional Stability Squad
  • The Greyscale Magi-Monk
  • Yeah, you'd be setting up everything yourself. I've had to set up an API with Nginx as a reverse proxy, and I would guess that something similar to that would probably work here.

    VPS's can also be a popular option for setting up Minecraft servers btw, I think Chanku mentioned once that the Tekkit server runs on a VPS.
    I've set everything up on work servers before, so it's not a problem...it's just that it's more time-consuming and tedious than just registering, paying, and everything's there for you. :P
    1 person likes this post: taulover


    I went all the way to Cassadega to commune with the dead
    They said "You'd better look alive"
    Wintermoot
    • The Greyscale Magi-Monk
    • Posts: 19,449
    • Karma: 9,677
    • Weather: ❄️
    • Regional Stability Squad
    • Pronouns
      He/Him/His
      Orientation
      Demisexual
      Wintreath Nation
      Logged
    taulover
  • Regional Stability Squad
  • Seeker of Knowledge
  • Yeah, you'd be setting up everything yourself. I've had to set up an API with Nginx as a reverse proxy, and I would guess that something similar to that would probably work here.

    VPS's can also be a popular option for setting up Minecraft servers btw, I think Chanku mentioned once that the Tekkit server runs on a VPS.
    I've set everything up on work servers before, so it's not a problem...it's just that it's more time-consuming and tedious than just registering, paying, and everything's there for you. :P
    True, and VPS's can also be more expensive than conventional web hosting at the small scale.
    Résumé
    Wintreath:
    Citizen: 8 April 2015 - present
    From the Ashes RP Game Master: 29 November 2015 - 24 July 2018
    Skydande Vakt Marshal: 29 November 2015 - 28 February 2017
    Skrifa of the 13th Underhusen: 13 December 2015 - 8 February 2016
    RP Guild Councillor: 9 February 2016 - 6 March 2018
    Ambassador to Lovely: 23 February 2016 - 17 August 2016
    Werewolf VII co-host: 11 May 2016 - 5 June 2016
    Skrifa of the 18th Underhusen: 8 October 2016 - 7 December 2016
    Ambassador to Balder: 1 December 2016 - 1 March 2022
    Skrifa of the 19th Underhusen: 7 December 2016 - 9 February 2017
    Ambassador to the INWU: 11 March 2017 - 1 March 2022
    Ambassador to the Versutian Federation: 18 August 2017 - 22 March 2018
    Thane of Integration: 29 September 2017 - 7 March 2018
    Speaker of the 24th Underhusen: 10 October 2017 - 7 December 2017
    October 2017 Wintreath's Finest: 4 November 2017
    Speaker pro tempore of the 25th Underhusen: 9 December 2017 - 7 February 2018
    Wintreath's Finest of 2017: 6 January 2018
    Werewolf XIV host: 20 January 2018 - 23 February 2018
    February 2018 Wintreath's Finest: 5 March 2018
    Thane of Embassy Dispatches / Foreign Releases and Information / Foreign Dispatches: 7 March 2018 - 15 March 2020
    Speaker of the 28th Underhusen: 10 June 2018 - 7 August 2018
    Second Patriarch of the Noble House of Valeria: 10 October 2018 - present
    Arena Game 6 Host: 28 December 2018 - 9 March 2019
    Librarian of the Underhusen: 29 January 2019 - 12 February 2019
    Speaker of the 32nd Underhusen: 12 February 2019 - 8 April 2019
    March 2019 Wintreath's Finest: 4 April 2019
    Librarian of the Underhusen: 12 April 2019 - 23 October 2020
    Commendation of Wintreath: 24 September 2020
    Peer of the Overhusen: 9 December 2020 - 8 February 2021
    Vice Chancellor of the Landsraad: 26 May 2021 - 15 September 2022
    Arena Game 8 Host: 10 June 2021 - 19 July 2021
    June 2021 Wintreath's Finest: 5 July 2021
    Regional Stability Squad: 28 February 2023 - present
    Minecraft Server Admin: 8 March 2023 - present

    Aura Hyperia/New Hyperion:
    Plebeian: 16 April 2014 - 21 July 2014
    Patrician: 21 July 2014 - present
    Adeptus Mechanicus: 24 October 2014 - 16 November 2014
    Co-founder of New Hyperion: 29 October 2014 - present
    Lord of Propaganda: 16 November 2014 - present
    Mapmaker for Official Region RP: 27 November 2015 - present
    WACom Delegate: 11 November 2017 - present
    Other positions: Hyperian Guardsman, Hyperian Marine (Rank: Scout)
    taulover
    • Seeker of Knowledge
    • Posts: 13,222
    • Karma: 4,253
    • Regional Stability Squad
    • Pronouns
      He/Him/His
      Familial House
      Valeria
      Wintreath Nation
      Logged
     
    Pages: [1]