Statistics gathering server made for Ludum Dare games
It already happened twice, that one and a half hours before the deadline of the Jam we decided to set up a simple web server in order to send statistics about player decisions. And both times I failed because of stupid reasons.
Next time we are prepared and can reuse this!
Needs Java 11.
java -Dserver.port=5000 -DstatisticsFileFolder=/tmp/ -jar simple-statistics-dump-0.0.1-SNAPSHOT.jar
statisticsFileFolder
should end with a trailing slash! The default is /tmp
.
Server receives entries from clients, stores them all in a big json file and optionally returns a processed version of all entries. This can then be shown to the players.
- Clients submit their statistics to the server
- Server appends those to the
<statisticsFileFolder>/statistics.json
file - Server optionally processes the whole statistics file and computes some result json
- Server responds this result to client
- Client shows info to players
When run, the application exposes two endpoints for sending information to the server.
Namely POST <host>/submit-statistics
with body
{
"ending": "ending1",
"distanceTraveled": 2507,
"endbossDefeated": true
}
and GET <host>/submit-statistics?ending=ending1&distanceTraveled=2507&endbossDefeated=true
.
The POST endpoint should be preferred, but if unforeseen problems with CORS or something arise, then GET might be a useful workaround.
const SERVER_URL = "<HOST>:5000"
export async function sendStatistics(decision) {
const content = {
ending: decision,
distanceTraveled: 2507,
endbossDefeated: true
}
const response = await fetch(`${SERVER_URL}/submit-statistics`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(content)
})
console.log(await response.json());
}