From e0e6c30752af4d74ca8eff9058a0edaf788712bd Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 21 Mar 2024 17:48:24 -0500 Subject: [PATCH] Session tokens control player options for create / login --- app.lua | 55 +++++++++++++++++++++++++++++++------------- database.sqlite3 | Bin 28672 -> 40960 bytes lua_scripts/map.lua | 6 ++--- views/game.etlua | 2 +- views/index.etlua | 2 +- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/app.lua b/app.lua index f9dff04..eed884b 100644 --- a/app.lua +++ b/app.lua @@ -1,4 +1,5 @@ local lapis = require("lapis") +local util = require("lapis.util") local app = lapis.Application() local say = require('lua_scripts/main') local mapFunc = require('lua_scripts/map') @@ -15,9 +16,9 @@ app.layout = require "views.layout" app:post("/clickme", function(self) self.text = "Map is already initialized. Beginning game." - self.isPopulated = mapFunc:mapExists(map) + self.isPopulated = mapFunc:mapExists(map, self.session.gameref) if not self.isPopulated then - mapFunc:populate(map) + mapFunc:populate(map, self.session.gameref) self.text = "Populated map." end return { self.text, layout = false } @@ -25,7 +26,7 @@ end) app:get("/", function(self) self.text = say.hello() - self.isPopulated = mapFunc:mapExists(map) + self.isPopulated = mapFunc:mapExists(map, self.session.gameref) return { render = "index", } @@ -33,13 +34,14 @@ end) app:get("/game", function(self) self.text = say.hello() - self.isPopulated = mapFunc:mapExists(map) + self.isPopulated = mapFunc:mapExists(map, self.session.gameref) return { render = "game", } end) app:post("/character-create", function(self) + self.params.playername = util.trim(self.params.playername) if self.params.playername == "" then self.text = "Player name must not be nil. Try again." return { @@ -48,9 +50,12 @@ app:post("/character-create", function(self) end local player_exists = games:find({player_id = self.params.playername}) if player_exists then - self.text = "Player name already exists. Try again." + self.text = "Welcome back, " .. self.params.playername .. "." + local game = games:find({player_id = self.params.playername}) + self.session.gameref = game.id + self.link = " Play Now" return { - self.text, layout = false + self.text, self.link, layout = false } end if not player_exists then @@ -67,18 +72,20 @@ app:post("/character-create", function(self) end) app:match("/map/render", function(self) - self.tiles = {} - for h = 1, 10 do - self.tiles[h] = {} - for i = 1, 10 do - -- The map database has floor_stone and wall_floor instead of simple ASCII characters - -- So we run mapFunc:mapDecrypt to convert it back to the desired characters for visual display - local tile = map:find({ x = h, y = i }) - self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type) + if mapFunc:mapExists(map, self.session.gameref) then + self.tiles = {} + for h = 1, 10 do + self.tiles[h] = {} + for i = 1, 10 do + -- The map database has floor_stone and wall_floor instead of simple ASCII characters + -- So we run mapFunc:mapDecrypt to convert it back to the desired characters for visual display + local tile = map:find({ x = h, y = i }) + self.tiles[h][i] = mapFunc:mapDecrypt(tile.occupied_by_type) + end end + return { render = "map", layout = false } end - return { render = "map", layout = false } -end) + end) return app @@ -112,6 +119,22 @@ return app + + + + + + + + + + + + + + + + diff --git a/database.sqlite3 b/database.sqlite3 index a1896368c241c466ca7e2c444e89b9af0cc5472e..4413c81295e8b29868b103b46ffd97b20a118f64 100644 GIT binary patch literal 40960 zcmeI4e~cZ~b;sYlnR#z!-g`4K@69|@GvnDn+Y}WSr zN4(x$uh(D$0nIq70wq6)6eT2tmZnKa{)m#ap+rgusVX6bf=bemhPF`?sv=rQ6-XO_ zNYwAS@80!2*F+JODkafffmxsLoqOkV?#w&idv?Wj+cqDbo9H?)J$rO~uB)f?mXhO? z)^~N4O3tTBrBZ}{)t8TNJoOj+*U`TJ4c}spckXi*d3mUzo~nZmz~)_x*vAKhi24mku;wl{eFJ~!`5=8 zy?nW|OAs7CHi@I~*zt*DCnl!$O&EW58H*tuDmE;=~Uazrc(@wIggId;GZ(P z7J)aFfRp0+Ac9l#-%an^cVg!7#Qw3pr^Z+=bb+Vr>@5t#@FF_Ymy=)6TNfp-b-wwn zub>@ZGhj1dGhj1dGhj1dGhj1dGhj1dGhj1dGhj3D`;dXKcsFh{$SLx<+b^2|n*o~vn*o~vn*o~vn*o~vn*o~vn*o~vn}I*z4A}GkAMoZ{G@AjN0hRcTl-}*U^8GdU^8GdU^8Gd zU^8GdU^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mU z1aY9C1vq$?iz5XIoIA_Kp@IaC-OR=);HBx)z7V$YR}i6s{K{% z)3u^DS-Y;bwzi}eMXyB9MvvjA{vVD`M0=tuqKl&i;cMYf@H77}haV5`3=f1`!rpLE z=mjqY-w(bK{AuvPU@905)&^ZcrTR16s{OJVuo_uHq@Vv?Ok=D?w##UvGGOrW60Bo$`KprFkp6=qJLpwA=~=1%<9X|$Toa^ScC zjV5^k^JGxaX_5*vWl*Tw^ac(bi->j;OsDR^5vFDnolErQsGpryohI(UA*fChci<3I zr-?go2%^(;mIL>jh3GYL2adkCYBcfYCNxS{CYm#z;y?X@v7;>o1;jSXgbk&&4FXQYB}-dC{QBaGn z6R7p(C{|ECC*B-|AbL);v`HuhtyJU5Z{4-M`7J zx=ng>6ui`JB3`38ikVcyi8n_fP{WD#xYyic)o<$MAK|S+^qat}H%E~Q(QTrz)*QwB zs@KGSRRV(QHSu4TfFOEJbVnw%>Ne@WFac=lHW9SZ9K}qk-Nc)t5YTQC(EQgXAfVaQ z5lm=wo5W+GH%BoZt)|X+zR|4$ouZ11kdq1N%e;J0=F!jR_0*HyN-fEM_rK*vw+^M;-vd#tIbx diff --git a/lua_scripts/map.lua b/lua_scripts/map.lua index 9da9245..43b3fe5 100644 --- a/lua_scripts/map.lua +++ b/lua_scripts/map.lua @@ -52,9 +52,9 @@ local map = { end end end, - mapExists = function(self, map) - local f = map:select("limit 1") - if not f[1] then + mapExists = function(self, map, game) + local f = map:find({game_ref = game}) + if not f then return false else return true diff --git a/views/game.etlua b/views/game.etlua index 6def7a1..d12a8b5 100644 --- a/views/game.etlua +++ b/views/game.etlua @@ -7,7 +7,7 @@ <% end %>

Game

-
+
<% render("views.player_ui") %> diff --git a/views/index.etlua b/views/index.etlua index 59709e6..88adbe8 100644 --- a/views/index.etlua +++ b/views/index.etlua @@ -9,7 +9,7 @@

Log In / Create Game

-

Player will be created if player name does not already exist.

+

Player will be created if player name does not already exist. Names may not contain whitespace.