forked from Jonathan/Peradventure
no longer allows duplicate or empty playernames
This commit is contained in:
parent
523e33363c
commit
514d4ebf40
61
app.lua
61
app.lua
@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
BIN
database.sqlite3
BIN
database.sqlite3
Binary file not shown.
Loading…
Reference in New Issue
Block a user