Don't Starve Together

Don't Starve Together

Server Status
 This topic has been pinned, so it's probably important
Jack'lul  [developer] 20 Aug, 2015 @ 11:57am
Usage / Configuration
Configuration
  • API_URL - this is the URL to the API script
  • API_URL_EXTRA - this is the URL to the second API script, empty by default
  • Send_Password - this is optional, if enabled it will send server password with the status data (might be useful if you change password and want it to be accessible on some part of the website), disabled by default, for a reason.

Example modoverrides.lua when using own webserver and my API:
["workshop-503330921"] = { enabled = true, configuration_options = { API_URL = "http://yourserver.com/api.php?secret=your_secret&data=", API_URL_EXTRA = "http://yoursecondserver.com/api.php?secret=your_secret&data=", Send_Password = false, } },
Usage of 'secret' variable is recommended, but...
... if you decide to not use secret variable anyway then the url would look like this:

URL should aways end with the GET variable and '=' at the end.

API
Example API script: http://pastebin.com/exZ7Zu06
It has simple configuration at the top of the file:
$statusfile = "serverstatus.json"; $secret = "your_secret";
Secret must match the value in the API_URL!
Usage of 'secret' variable is optional, but recommended - without it anyone who guesses the URL to the API can send data to it.

If you decide to write your own API script make sure it replies "ok" on success and the result is plaintext.

Showing the Status
I do not provide any script to parse the array.
This is the part where you need some PHP experience.

This example PHP code will load the file and print it's contents as an array:
if(file_exists("serverstatus.json")) { $data = file_get_contents("serverstatus.json"); $data = json_decode($data, true); echo "<pre>".(print_r($data, true))."</pre>"; }
Array is in easy to parse format and mod updates adding more variable shouldn't break your status script.
How the array actually looks like:
Array ( [0] => Array ( [players] => Array ( [0] => Array ( [steamid] => [name] => [Host] [admin] => 1 [userid] => KU_XXXXXXXX [prefab] => [age] => 0 ) ) [statevars] => Array ( [summerlength] => 15 [isdusk] => [isnight] => [moistureceil] => 7514.64355469 [isday] => 1 [timeinphase] => 0.806135336558 [season] => autumn [isfullmoon] => [remainingdaysinseason] => 12 [elapseddaysinseason] => 8 [time] => 0.403067668279 [cycles] => 8 [isspring] => [isautumn] => 1 [issnowing] => [issummer] => [iswinter] => [snowlevel] => 0 [issnowcovered] => [precipitationrate] => 0 [pop] => 0.0479142496411 [springlength] => 20 [iswet] => [winterlength] => 15 [moisture] => 856.246154785 [temperature] => 22.9460207086 [israining] => [phase] => day [autumnlength] => 20 [moonphase] => threequarter [precipitation] => none [wetness] => 0 ) [mods] => Array ( [0] => workshop-503330921 [1] => workshop-378160973 [2] => workshop-362175979 [3] => workshop-458940297 ) [settings] => Array ( [description] => With even more awesome description! [maxplayers] => 8 [session] => 01C00000F96D268F [friends_only] => [servername] => My Awesome Server [clan_id] => [gamemode] => survival [admin_online] => 1 [mods_enabled] => 1 [dedicated] => 1 [passworded] => 1 [password] => bestpassword [pvp] => ) [world] => Array ( [overrides] => Array ( [unprepared] => Array ( [mushroom] => default [carrot] => default [cactus] => default [berrybush] => default ) [misc] => Array ( [autumn] => default [spring] => default [branching] => default [touchstone] => default [winter] => default [world_size] => huge [summer] => default [wildfires] => default [lightning] => default [day] => default [boons] => default [frograin] => default [weather] => default [season_start] => default [loop] => default ) [animals] => Array ( [beefalo] => default [lightninggoat] => default [catcoon] => default [rabbits] => often [hunt] => default [angrybees] => default [birds] => default [perd] => default [moles] => default [tallbirds] => default [alternatehunt] => default [penguins] => default [frogs] => default [beefaloheat] => default [bees] => default [pigs] => often [buzzard] => default [butterfly] => default ) [monsters] => Array ( [krampus] => default [bearger] => default [hounds] => default [walrus] => default [liefs] => default [dragonfly] => default [deerclops] => default [tentacles] => default [goosemoose] => default [chess] => default [spiders] => often [houndmound] => default [merm] => default [lureplants] => default [deciduousmonster] => default ) [resources] => Array ( [meteorspawner] => default [rock_ice] => default [reeds] => default [meteorshowers] => default [flowers] => default [tumbleweed] => default [trees] => default [flint] => default [marshbush] => default [sapling] => default [grass] => default [rock] => default ) ) [preset] => SURVIVAL_TOGETHER ) ) )
I think most of those variables are self-explanatory, the important:
cycles+1 - day (day 1 is cycles=0)
phase - day/dusk/night

Also:
- some variables are empty, this means they are set to 0 / false
- world overrides array will contain entries from server's worldgenoverride.lua (dedicated) or only the changed ones (non-dedicated), posted all options in sample array

BONUS: Server Badge
Example Badge script: http://pastebin.com/eg6MdzTE
Required font: OpenSans-Regular.ttf found here: https://www.google.com/fonts#UsePlace:use/Collection:Open+Sans
Example background image (bg.png): http://i.imgur.com/8678cDk.png
You can use own image, remember it should be 400x100 to work with the example script, transparency is supported!

How the badge will look like: http://i.imgur.com/Y5ljZhN.png
If you're experienced with PHP you can customize the badge.

Last edited by Jack'lul; 4 Dec, 2015 @ 2:23am