no longer allows duplicate or empty playernames

This commit is contained in:
Jonathan 2024-03-21 17:12:42 -05:00
parent 523e33363c
commit 514d4ebf40
2 changed files with 53 additions and 8 deletions

61
app.lua
View File

@ -40,14 +40,30 @@ app:get("/game", function(self)
end)
app:post("/character-create", function(self)
self.text = "Created new player"
self.game = games:create({
player_id = self.params.playername
})
self.session.gameref = self.game
return {
self.text, layout = false
}
if self.params.playername == "" then
self.text = "Player name must not be nil. Try again."
return {
self.text, layout = false
}
end
local player_exists = games:find({player_id = self.params.playername})
if player_exists then
self.text = "Player name already exists. Try again."
return {
self.text, layout = false
}
end
if not player_exists then
self.text = "Created new player."
self.game = games:create({
player_id = self.params.playername
})
self.session.gameref = self.game.id
self.link = "<a href='/game'> Play Now</a>"
return {
self.text, self.link, layout = false
}
end
end)
app:match("/map/render", function(self)
@ -84,3 +100,32 @@ return app

Binary file not shown.