aboutsummaryrefslogtreecommitdiff
path: root/src/highscores.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/highscores.js')
-rw-r--r--src/highscores.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/highscores.js b/src/highscores.js
index e735eee..82db612 100644
--- a/src/highscores.js
+++ b/src/highscores.js
@@ -1,10 +1,19 @@
function submitScore(game, score, username){
+ // Prompt for the username
if(username == undefined){
username = prompt("Enter a name to submit score", "");
}
+ // If the user filled out the prompt, post the score
if (!(username == null || username == "")) {
- const request = new Request(`/setScore?game=${game}&username=${username}&score=${score}`);
- fetch(request);
+ // Get a uuid to identify this request by (for idempotency)
+ fetch(new Request(`/uuid`))
+ .then(response => response.text()
+ .then(uuid => {
+ const request = new Request(`/setScore?game=${game}&username=${username}&score=${score}&uuid=${uuid}`);
+ fetch(request);
+ }));
+
}
+ // Return the username for later use by the game
return username
} \ No newline at end of file